Set description from config file for gitweb use.

This commit is contained in:
Tommi Virtanen 2007-11-17 17:40:34 +02:00
parent d85d60f73c
commit 4e76065fb7
5 changed files with 156 additions and 7 deletions

View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -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'),

View file

@ -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')