diff options
author | Tommi Virtanen <tv@eagain.net> | 2007-11-17 17:40:34 +0200 |
---|---|---|
committer | Tommi Virtanen <tv@eagain.net> | 2007-11-17 17:40:34 +0200 |
commit | 4e76065fb7752385a9a1212ff15d776498d5bedd (patch) | |
tree | 01d0dab9cd5d6c34de1971522830bfae20de1b17 | |
parent | Make repository.export work even with relative git_dir. (diff) | |
download | gitosis-gentoo-4e76065fb7752385a9a1212ff15d776498d5bedd.tar.gz gitosis-gentoo-4e76065fb7752385a9a1212ff15d776498d5bedd.tar.bz2 gitosis-gentoo-4e76065fb7752385a9a1212ff15d776498d5bedd.zip |
Set description from config file for gitweb use.
-rw-r--r-- | TODO.rst | 3 | ||||
-rw-r--r-- | example.conf | 4 | ||||
-rw-r--r-- | gitosis/gitweb.py | 52 | ||||
-rw-r--r-- | gitosis/run_hook.py | 3 | ||||
-rw-r--r-- | gitosis/test/test_gitweb.py | 101 |
5 files changed, 156 insertions, 7 deletions
@@ -30,9 +30,6 @@ - test with ssh:// -- write description to a file, make REPO.git/description symlink to it - if it doesn't exist (thus not overwriting local changes) - - gitweb knows about cloneurl, handle like description - gitweb knows about README.html, figure out how to generate from e.g. diff --git a/example.conf b/example.conf index 411a647..09ee5f4 100644 --- a/example.conf +++ b/example.conf @@ -34,8 +34,8 @@ map readonly visiblename2 = actualname2 gitweb = yes ## Oneline description of the project, mostly for gitweb. -## NOT YET IMPLEMENTED. -# description = blah blah +description = blah blah + ## Owner of this repository. Used in gitweb list of projects. owner = John Doe diff --git a/gitosis/gitweb.py b/gitosis/gitweb.py index fad4e84..b4b538b 100644 --- a/gitosis/gitweb.py +++ b/gitosis/gitweb.py @@ -47,7 +47,7 @@ def generate_project_list_fp(config, fp): :param fp: writable for ``projects.list`` :type fp: (file-like, anything with ``.write(data)``) """ - log = logging.getLogger('gitosis.gitweb') + log = logging.getLogger('gitosis.gitweb.generate_projects_list') repositories = util.getRepositoryDir(config) @@ -113,3 +113,53 @@ def generate_project_list(config, path): f.close() os.rename(tmp, path) + + +def set_descriptions(config): + """ + Set descriptions for gitweb use. + """ + log = logging.getLogger('gitosis.gitweb.set_descriptions') + + repositories = util.getRepositoryDir(config) + + for section in config.sections(): + l = section.split(None, 1) + type_ = l.pop(0) + if type_ != 'repo': + continue + if not l: + continue + + try: + description = config.get(section, 'description') + except (NoSectionError, NoOptionError): + continue + + if not description: + continue + + name, = l + + if not os.path.exists(os.path.join(repositories, name)): + namedotgit = '%s.git' % name + if os.path.exists(os.path.join(repositories, namedotgit)): + name = namedotgit + else: + log.warning( + 'Cannot find %(name)r in %(repositories)r' + % dict(name=name, repositories=repositories)) + continue + + path = os.path.join( + repositories, + name, + 'description', + ) + tmp = '%s.%d.tmp' % (path, os.getpid()) + f = file(tmp, 'w') + try: + print >>f, description + finally: + f.close() + os.rename(tmp, path) diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py index a5ed9d0..a7943fc 100644 --- a/gitosis/run_hook.py +++ b/gitosis/run_hook.py @@ -28,6 +28,9 @@ def post_update(cfg, git_dir): os.path.join(export, 'gitosis.conf'), os.path.join(export, '..', 'gitosis.conf'), ) + gitweb.set_descriptions( + config=cfg, + ) gitweb.generate_project_list( config=cfg, path=os.path.join(git_dir, 'projects.list'), diff --git a/gitosis/test/test_gitweb.py b/gitosis/test/test_gitweb.py index cf37a44..635e555 100644 --- a/gitosis/test/test_gitweb.py +++ b/gitosis/test/test_gitweb.py @@ -5,7 +5,7 @@ from ConfigParser import RawConfigParser from cStringIO import StringIO from gitosis import gitweb -from gitosis.test.util import mkdir, maketemp, readFile +from gitosis.test.util import mkdir, maketemp, readFile, writeFile def test_projectsList_empty(): cfg = RawConfigParser() @@ -123,3 +123,102 @@ def test_projectsList_path(): eq(got, '''\ foo.git ''') + +def test_description_none(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + mkdir(path) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'description', 'foodesc') + gitweb.set_descriptions( + config=cfg, + ) + got = readFile(os.path.join(path, 'description')) + eq(got, 'foodesc\n') + +def test_description_repo_missing(): + # configured but not created yet; before first push + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'description', 'foodesc') + gitweb.set_descriptions( + config=cfg, + ) + assert not os.path.exists(os.path.join(tmp, 'foo')) + assert not os.path.exists(os.path.join(tmp, 'foo.git')) + +def test_description_repo_missing_parent(): + # configured but not created yet; before first push + tmp = maketemp() + path = os.path.join(tmp, 'foo/bar.git') + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'description', 'foodesc') + gitweb.set_descriptions( + config=cfg, + ) + assert not os.path.exists(os.path.join(tmp, 'foo')) + +def test_description_default(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + mkdir(path) + writeFile( + os.path.join(path, 'description'), + 'Unnamed repository; edit this file to name it for gitweb.\n', + ) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'description', 'foodesc') + gitweb.set_descriptions( + config=cfg, + ) + got = readFile(os.path.join(path, 'description')) + eq(got, 'foodesc\n') + +def test_description_not_set(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + mkdir(path) + writeFile( + os.path.join(path, 'description'), + 'i was here first\n', + ) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + gitweb.set_descriptions( + config=cfg, + ) + got = readFile(os.path.join(path, 'description')) + eq(got, 'i was here first\n') + +def test_description_again(): + tmp = maketemp() + path = os.path.join(tmp, 'foo.git') + mkdir(path) + cfg = RawConfigParser() + cfg.add_section('gitosis') + cfg.set('gitosis', 'repositories', tmp) + cfg.add_section('repo foo') + cfg.set('repo foo', 'description', 'foodesc') + gitweb.set_descriptions( + config=cfg, + ) + gitweb.set_descriptions( + config=cfg, + ) + got = readFile(os.path.join(path, 'description')) + eq(got, 'foodesc\n') |