repos
/
darcsweb
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Support repos with semi-strange characters.
Annotate for file /mkconfig.py
2005-07-01 albertogli
1
#!/usr/bin/env python
04:36:53 '
2
'
3
"""
'
4
A darcsweb configuration generator
'
5
----------------------------------
'
6
'
7
This is a small utility that generates configuration files for darcsweb, in
'
8
case you're lazy and/or have many repositories.
'
9
'
10
It receives four parameters: the base URL for your repositories, the base
'
11
description, the encoding and the directory to get the repositories from.
'
12
It replaces the string "NAME" with the name of the directory that holds the
'
13
repository, so you can specify urls and descriptions with the name in them.
'
14
'
15
Then, it generates an appropiate configuration for each repository in the
'
16
directory. It outputs the configuration to stdout, so you can redirect it to
'
17
config.py. For example:
'
18
'
19
$ mkconf.py "http://example.com/darcs/NAME" "Repo for NAME" latin1 \\
'
20
~/devel/repos/ >> config.py
'
21
'
22
Remember that you still need to do the base configuration by hand. You can do
'
23
that by copying the sample included with darcsweb.
'
24
"""
'
25
'
26
'
27
import sys
'
28
import os
2005-07-03 albertogli
29
import string
21:39:57 '
30
import urllib
2005-07-01 albertogli
31
04:36:53 '
32
'
33
def help():
'
34
print "Error: wrong parameter count"
'
35
print __doc__
2005-07-03 albertogli
36
21:39:57 '
37
def filter_class(s):
'
38
"Filter s so the new string can be used as a class name."
'
39
allowed = string.ascii_letters + string.digits + '_'
'
40
l = [c for c in s if c in allowed]
'
41
return string.join(l, "")
'
42
'
43
def filter_url(s):
'
44
"Filter s so the new string can be used in a raw url."
'
45
return urllib.quote_plus(s, ':/')
2005-07-01 albertogli
46
04:36:53 '
47
'
48
# check parameters
'
49
if len(sys.argv) != 5:
'
50
help()
'
51
sys.exit(0)
'
52
'
53
myself, baseurl, basedesc, baseencoding, basepath = sys.argv
'
54
'
55
dirs = os.listdir(basepath)
'
56
for d in dirs:
'
57
path = basepath + '/' + d
'
58
if not os.path.isdir(path + '/_darcs'):
'
59
# not a repo, skip
'
60
continue
'
61
s = \
'
62
"""
2005-07-03 albertogli
63
class %(classname)s:
2005-07-01 albertogli
64
reponame = '%(name)s'
04:36:53 '
65
repodesc = '%(desc)s'
'
66
repodir = '%(dir)s'
'
67
repourl = '%(url)s'
'
68
repoencoding = '%(encoding)s'
'
69
""" % {
2005-07-03 albertogli
70
'classname': filter_class(d),
2005-07-01 albertogli
71
'name': d,
04:36:53 '
72
'desc': basedesc.replace('NAME', d),
'
73
'dir': os.path.abspath(basepath + '/' + d),
2005-07-03 albertogli
74
'url': filter_url(baseurl.replace('NAME', d)),
2005-07-01 albertogli
75
'encoding': baseencoding,
04:36:53 '
76
}
'
77
print s
'
78