From a786d30f5a6d8c145f0aae8e62b3ad2ffb8851cc Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Sat, 1 Sep 2007 18:20:16 -0700 Subject: Refactor gitosis-gitweb to move temp file handling out of main. --- gitosis/gitweb.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'gitosis/gitweb.py') diff --git a/gitosis/gitweb.py b/gitosis/gitweb.py index aff0b90..69f6c7d 100644 --- a/gitosis/gitweb.py +++ b/gitosis/gitweb.py @@ -37,7 +37,7 @@ def _escape_filename(s): s = s.replace('"', '\\"') return s -def generate(config, fp): +def generate_fp(config, fp): """ Generate a config file and projects list for ``gitweb``. @@ -94,6 +94,26 @@ def generate(config, fp): line = ' '.join([urllib.quote_plus(s) for s in response]) print >>fp, line +def generate(config, path): + """ + Generate a config file and projects list for ``gitweb``. + + :param config: configuration to read projects from + :type config: RawConfigParser + + :param path: path to write projects list to + :type path: str + """ + tmp = '%s.%d.tmp' % (path, os.getpid()) + + f = file(tmp, 'w') + try: + generate_fp(config=config, fp=f) + finally: + f.close() + + os.rename(tmp, path) + def _getParser(): import optparse parser = optparse.OptionParser( @@ -120,12 +140,4 @@ def main(): cfg = RawConfigParser() cfg.read(options.config) - tmp = '%s.%d.tmp' % (path, os.getpid()) - - f = file(tmp, 'w') - try: - generate(config=cfg, fp=f) - finally: - f.close() - - os.rename(tmp, path) + generate(config=cfg, path=path) -- cgit v1.2.3