1 #!/usr/bin/python |
|
2 import sys |
|
3 |
|
4 from subprocess import call as sbp_call, Popen, PIPE |
|
5 from urllib import urlopen |
|
6 import os |
|
7 from os import path as osp, pardir, chdir |
|
8 |
|
9 |
|
10 def find_mercurial(): |
|
11 print "trying to find mercurial from the command line ..." |
|
12 print '-' * 20 |
|
13 tryhg = sbp_call(['hg', '--version']) |
|
14 if tryhg: |
|
15 print 'mercurial seems to be unavailable, please install it' |
|
16 raise |
|
17 print '-' * 20 |
|
18 def hg_call(args): |
|
19 return sbp_call(['hg'] + args) |
|
20 |
|
21 return hg_call |
|
22 |
|
23 |
|
24 BASE_URL = 'http://www.logilab.org/hg/' |
|
25 |
|
26 to_clone = ['fyzz', 'yams', 'rql', |
|
27 'logilab/common', 'logilab/constraint', 'logilab/database', |
|
28 'logilab/devtools', 'logilab/mtconverter', |
|
29 'cubes/blog', 'cubes/calendar', 'cubes/card', 'cubes/comment', |
|
30 'cubes/datafeed', 'cubes/email', 'cubes/file', 'cubes/folder', |
|
31 'cubes/forgotpwd', 'cubes/keyword', 'cubes/link', 'cubes/localperms', |
|
32 'cubes/mailinglist', 'cubes/nosylist', 'cubes/person', |
|
33 'cubes/preview', 'cubes/registration', 'cubes/rememberme', |
|
34 'cubes/tag', 'cubes/vcsfile', 'cubes/zone'] |
|
35 |
|
36 # a couple of functions to be used to explore available |
|
37 # repositories and cubes |
|
38 def list_repos(repos_root): |
|
39 assert repos_root.startswith('http://') |
|
40 hgwebdir_repos = (repo.strip() |
|
41 for repo in urlopen(repos_root + '?style=raw').readlines() |
|
42 if repo.strip()) |
|
43 prefix = osp.commonprefix(hgwebdir_repos) |
|
44 return (repo[len(prefix):].strip('/') |
|
45 for repo in hgwebdir_repos) |
|
46 |
|
47 def list_all_cubes(base_url=BASE_URL): |
|
48 all_repos = list_repos(base_url) |
|
49 #search for cubes |
|
50 for repo in all_repos: |
|
51 if repo.startswith('cubes'): |
|
52 to_clone.append(repo) |
|
53 |
|
54 def get_latest_debian_tag(path): |
|
55 proc = Popen(['hg', '-R', path, 'tags'], stdout=PIPE) |
|
56 out, _err = proc.communicate() |
|
57 for line in out.splitlines(): |
|
58 if 'debian-version' in line: |
|
59 return line.split()[0] |
|
60 |
|
61 def main(): |
|
62 if len(sys.argv) == 1: |
|
63 base_url = BASE_URL |
|
64 elif len(sys.argv) == 2: |
|
65 base_url = sys.argv[1] |
|
66 else: |
|
67 sys.stderr.write('usage %s [base_url]\n' % sys.argv[0]) |
|
68 sys.exit(1) |
|
69 hg_call = find_mercurial() |
|
70 print len(to_clone), 'repositories will be cloned' |
|
71 base_dir = osp.normpath(osp.join(osp.dirname(__file__), pardir, pardir)) |
|
72 chdir(base_dir) |
|
73 not_updated = [] |
|
74 for repo in to_clone: |
|
75 url = base_url + repo |
|
76 if '/' not in repo: |
|
77 target_path = repo |
|
78 else: |
|
79 assert repo.count('/') == 1, repo |
|
80 directory, repo = repo.split('/') |
|
81 if not osp.isdir(directory): |
|
82 os.mkdir(directory) |
|
83 open(osp.join(directory, '__init__.py'), 'w').close() |
|
84 target_path = osp.join(directory, repo) |
|
85 if osp.exists(target_path): |
|
86 print target_path, 'seems already cloned. Skipping it.' |
|
87 else: |
|
88 hg_call(['clone', '-U', url, target_path]) |
|
89 tag = get_latest_debian_tag(target_path) |
|
90 if tag: |
|
91 print 'updating to', tag |
|
92 hg_call(['update', '-R', target_path, tag]) |
|
93 else: |
|
94 not_updated.append(target_path) |
|
95 print """ |
|
96 CubicWeb dependencies and standard set of cubes have been fetched and |
|
97 update to the latest stable version. |
|
98 |
|
99 You should ensure your PYTHONPATH contains `%(basedir)s`. |
|
100 You might want to read the environment configuration section of the documentation |
|
101 at http://docs.cubicweb.org/admin/setup.html#environment-configuration |
|
102 |
|
103 You can find more cubes at http://www.cubicweb.org. |
|
104 Clone them from `%(baseurl)scubes/` into the `%(basedir)s%(sep)scubes%(sep)s` directory. |
|
105 |
|
106 To get started you may read http://docs.cubicweb.org/tutorials/base/index.html. |
|
107 """ % {'basedir': os.getcwd(), 'baseurl': base_url, 'sep': os.sep} |
|
108 if not_updated: |
|
109 sys.stderr.write('WARNING: The following repositories were not updated (no debian tag found):\n') |
|
110 for path in not_updated: |
|
111 sys.stderr.write('\t-%s\n' % path) |
|
112 |
|
113 if __name__ == '__main__': |
|
114 main() |
|
115 |
|
116 |
|
117 |
|