aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <dakkar@thenautilus.net>2009-01-17 18:27:24 +0100
committerRobin H. Johnson <robbat2@gentoo.org>2009-01-17 13:18:27 -0800
commit6aedc4b406bbe17bba4819a0b7ebf097f814af35 (patch)
treeb7a13726d20c230b21e3537a1e3f69e96997be59
parentHandle git-1.6 which installs example hooks with .sample as a suffix so they ... (diff)
downloadgitosis-gentoo-6aedc4b406bbe17bba4819a0b7ebf097f814af35.tar.gz
gitosis-gentoo-6aedc4b406bbe17bba4819a0b7ebf097f814af35.tar.bz2
gitosis-gentoo-6aedc4b406bbe17bba4819a0b7ebf097f814af35.zip
Patch adding cgit support to gitosis-gentoo
Me and lu_zero have been working on this patch a bit more, now it also supports grouping the repositories in the cgit repo list, see http://www.thenautilus.net/cgit/ for an example.
-rw-r--r--gitosis/cgit.py113
-rw-r--r--gitosis/run_hook.py5
2 files changed, 118 insertions, 0 deletions
diff --git a/gitosis/cgit.py b/gitosis/cgit.py
new file mode 100644
index 0000000..8d12d02
--- /dev/null
+++ b/gitosis/cgit.py
@@ -0,0 +1,113 @@
+"""
+Generate ``cgit`` project list based on ``gitosis.conf``.
+
+To plug this into ``cgit``, put in your global config file the
+following line::
+
+ include=/path/to/your/repos.list
+"""
+
+import os, urllib, logging
+
+from ConfigParser import NoSectionError, NoOptionError
+
+from gitosis import util
+from gitosis.configutil import getboolean_default, get_default
+
+field_map={'description':'repo.desc',
+ 'owner':'repo.owner',
+ 'readme':'repo.readme',
+ }
+
+def generate_project_list_fp(config, fp):
+ """
+ Generate projects list for ``cgit``.
+
+ :param config: configuration to read projects from
+ :type config: RawConfigParser
+
+ :param fp: writable for ``repos.list``
+ :type fp: (file-like, anything with ``.write(data)``)
+ """
+ log = logging.getLogger('gitosis.cgit.generate_projects_list')
+
+ repositories = util.getRepositoryDir(config)
+
+ global_enable = getboolean_default(config, 'gitosis', 'cgit', False)
+ grouped_sections={}
+
+ for section in config.sections():
+ sectiontitle = section.split(None, 1)
+ if not sectiontitle or sectiontitle[0] != 'repo':
+ continue
+
+ enable = getboolean_default(config, section, 'cgit', global_enable)
+
+ if not enable:
+ continue
+ groupname = get_default(config, section, 'cgit_group', "")
+ grouped_sections.setdefault(groupname,[]).append(section)
+
+ for groupname, group in grouped_sections.iteritems():
+ if groupname:
+ print >> fp, 'repo.group=%s'%(groupname)
+
+ for section in group:
+ sectiontitle = section.split(None, 1)
+
+ name = sectiontitle[1]
+
+ fullpath = _repository_path(log, repositories, name, name)
+
+ print >> fp, 'repo.url=%s'%(name)
+
+ if fullpath is None:
+ continue
+
+ print >> fp, 'repo.path=%s'%(fullpath)
+
+ for field_pair in field_map.iteritems():
+ try:
+ field_value = config.get(section, field_pair[0])
+ except (NoSectionError, NoOptionError):
+ continue
+ else:
+ print >> fp, '%s=%s'%(field_pair[1],field_value)
+
+def _repository_path(log, repositories, name, default_value):
+ """
+ Check if the repository exists by the common name, or with a .git suffix,
+ and return the full pathname.
+ """
+ fullpath=os.path.join(repositories, name)
+ if not os.path.exists(fullpath):
+ namedotgit = '%s.git' % name
+ fullpath=os.path.join(repositories, namedotgit)
+ if os.path.exists(fullpath):
+ return fullpath
+ else:
+ log.warning(
+ 'Cannot find %(name)r in %(repositories)r'
+ % dict(name=name, repositories=repositories))
+ return None
+ return fullpath
+
+def generate_project_list(config, path):
+ """
+ Generate 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())
+
+ fp = file(tmp, 'w')
+ try:
+ generate_project_list_fp(config=config, fp=fp)
+ finally:
+ fp.close()
+
+ os.rename(tmp, path)
diff --git a/gitosis/run_hook.py b/gitosis/run_hook.py
index ef12310..99d8b70 100644
--- a/gitosis/run_hook.py
+++ b/gitosis/run_hook.py
@@ -9,6 +9,7 @@ import sys
from gitosis import repository
from gitosis import ssh
from gitosis import gitweb
+from gitosis import cgit
from gitosis import gitdaemon
from gitosis import app
from gitosis import util
@@ -29,6 +30,10 @@ def build_reposistory_data(config):
config=config,
path=os.path.join(generated, 'projects.list'),
)
+ cgit.generate_project_list(
+ config=config,
+ path=os.path.join(generated, 'repos.list'),
+ )
gitdaemon.set_export_ok(
config=config,
)