diff options
author | Tommi Virtanen <tv@eagain.net> | 2007-09-01 18:20:16 -0700 |
---|---|---|
committer | Tommi Virtanen <tv@eagain.net> | 2007-09-01 18:28:06 -0700 |
commit | a786d30f5a6d8c145f0aae8e62b3ad2ffb8851cc (patch) | |
tree | da536238f290e1db4e9029e6bc793301402c2c75 /gitosis/gitweb.py | |
parent | Add utilities for fast-import, exporting repository. (diff) | |
download | gitosis-dakkar-a786d30f5a6d8c145f0aae8e62b3ad2ffb8851cc.tar.gz gitosis-dakkar-a786d30f5a6d8c145f0aae8e62b3ad2ffb8851cc.tar.bz2 gitosis-dakkar-a786d30f5a6d8c145f0aae8e62b3ad2ffb8851cc.zip |
Refactor gitosis-gitweb to move temp file handling out of main.
Diffstat (limited to 'gitosis/gitweb.py')
-rw-r--r-- | gitosis/gitweb.py | 32 |
1 files changed, 22 insertions, 10 deletions
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) |