2 Generate ``gitweb`` project list based on ``gitosis.conf``.
4 To plug this into ``gitweb``, you have two choices.
6 - The global way, edit ``/etc/gitweb.conf`` to say::
8 $projects_list = "/path/to/your/projects.list";
10 Note that there can be only one such use of gitweb.
12 - The local way, create a new config file::
14 do "/etc/gitweb.conf" if -e "/etc/gitweb.conf";
15 $projects_list = "/path/to/your/projects.list";
16 # see ``repositories`` in the ``gitosis`` section
17 # of ``~/.gitosis.conf``; usually ``~/repositories``
18 # but you need to expand the tilde here
19 $projectroot = "/path/to/your/repositories";
21 Then in your web server, set environment variable ``GITWEB_CONFIG``
22 to point to this file.
24 This way allows you have multiple separate uses of ``gitweb``, and
25 isolates the changes a bit more nicely. Recommended.
28 import os
, urllib
, logging
30 from ConfigParser
import NoSectionError
, NoOptionError
32 from gitosis
import util
34 def _escape_filename(s
):
35 s
= s
.replace('\\', '\\\\')
36 s
= s
.replace('$', '\\$')
37 s
= s
.replace('"', '\\"')
40 def generate_project_list_fp(config
, fp
):
42 Generate projects list for ``gitweb``.
44 :param config: configuration to read projects from
45 :type config: RawConfigParser
47 :param fp: writable for ``projects.list``
48 :type fp: (file-like, anything with ``.write(data)``)
50 log
= logging
.getLogger('gitosis.gitweb.generate_projects_list')
52 repositories
= util
.getRepositoryDir(config
)
55 global_enable
= config
.getboolean('gitosis', 'gitweb')
56 except (NoSectionError
, NoOptionError
):
59 for section
in config
.sections():
60 l
= section
.split(None, 1)
68 enable
= config
.getboolean(section
, 'gitweb')
69 except (NoSectionError
, NoOptionError
):
70 enable
= global_enable
77 if not os
.path
.exists(os
.path
.join(repositories
, name
)):
78 namedotgit
= '%s.git' % name
79 if os
.path
.exists(os
.path
.join(repositories
, namedotgit
)):
83 'Cannot find %(name)r in %(repositories)r'
84 % dict(name
=name
, repositories
=repositories
))
88 owner
= config
.get(section
, 'owner')
89 except (NoSectionError
, NoOptionError
):
93 username
= config
.get('user %s' % owner
, 'name')
94 except (NoSectionError
, NoOptionError
):
97 response
.append(username
)
98 response
.append(owner
)
100 line
= ' '.join([urllib
.quote_plus(s
) for s
in response
])
103 def generate_project_list(config
, path
):
105 Generate projects list for ``gitweb``.
107 :param config: configuration to read projects from
108 :type config: RawConfigParser
110 :param path: path to write projects list to
113 tmp
= '%s.%d.tmp' % (path
, os
.getpid())
117 generate_project_list_fp(config
=config
, fp
=f
)
124 def set_descriptions(config
):
126 Set descriptions for gitweb use.
128 log
= logging
.getLogger('gitosis.gitweb.set_descriptions')
130 repositories
= util
.getRepositoryDir(config
)
132 for section
in config
.sections():
133 l
= section
.split(None, 1)
141 description
= config
.get(section
, 'description')
142 except (NoSectionError
, NoOptionError
):
150 if not os
.path
.exists(os
.path
.join(repositories
, name
)):
151 namedotgit
= '%s.git' % name
152 if os
.path
.exists(os
.path
.join(repositories
, namedotgit
)):
156 'Cannot find %(name)r in %(repositories)r'
157 % dict(name
=name
, repositories
=repositories
))
165 tmp
= '%s.%d.tmp' % (path
, os
.getpid())
168 print >>f
, description