Mercurial > hg > silvermirror
annotate silvermirror/hg.py @ 27:a648f57b1921
STUB: silvermirror/hg.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 31 Jan 2014 19:26:34 -0800 |
parents | 16a12d660609 |
children | 03911cb46f53 |
rev | line source |
---|---|
1
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
2 |
1
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 stub for the hg backend of silvermirror |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 |
27 | 7 import os |
8 import sys | |
9 import argparse | |
10 | |
11 _import_error = None | |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
12 try: |
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
13 import lxml.html |
27 | 14 except ImportError as _import_error: |
15 pass | |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
16 |
1
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 def update(host, path): |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 get changes from host on path |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 """ |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
22 _ui = ui.ui() |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
23 url = '%s/%s' % (host, path) |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
24 try: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
25 repo = hg.repository(_ui, path) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
26 print 'Updating %s:' % path |
8
0da780dd81d0
use bare exception for some reason i can no longer remember
k0s <k0scist@gmail.com>
parents:
6
diff
changeset
|
27 except Exception, e: |
27 | 28 import pdb;pdb.set_trace() |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
29 repo = hg.repository(_ui, url) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
30 print 'Cloning %s:' % path |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
31 commands.clone(_ui, repo, pull=False, uncompressed=False, rev=None, noupdate=False) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
32 return |
2
0d9094bb98b0
adding function to return all hg repos on a path
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
33 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
34 commands.pull(_ui, repo, url, rev=None, force=False, update=True) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
35 |
24 | 36 # TODO: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
37 # def repositories(path): |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
38 # """ |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
39 # return all hg repositories in a path |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
40 # """ |
2
0d9094bb98b0
adding function to return all hg repos on a path
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
41 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
42 # ui = ui.ui() |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
43 # files = [ os.path.join(path, f) for f in os.listdir(path) ] |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
44 # directories = [ f for f in files if os.path.isdir(f) ] |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
45 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
46 # repos = [] |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
47 # for d in directories: |
26 | 48 # try: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
49 # repo = hg.repository(ui, d) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
50 # repos.append(os.path.basename(d)) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
51 # except mercurial.repo.RepoError: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
52 # pass |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
53 # return repos |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
54 |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
55 def repositories(url): |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
56 """ |
17
f8edfc9c28ba
a really hacky way to disable...for temporary sanity and long term backing down from insanity
Jeff Hammel <jhammel@mozilla.com>
parents:
9
diff
changeset
|
57 returns the list of repositories under a URL of an hg server |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
58 """ |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
59 element = lxml.html.parse(url) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
60 tds = element.xpath('//tr[position() > 1]/td[1]') |
24 | 61 repos = [i.text_content() for i in tds] |
2
0d9094bb98b0
adding function to return all hg repos on a path
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
62 return repos |
3 | 63 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
64 |
3 | 65 def main(args=sys.argv[1:]): |
27 | 66 """CLI""" |
67 | |
68 # parse command line | |
69 parser = argparse.ArgumentParser(description=__doc__) | |
70 parser.add_argument('host', dest='host', | |
71 help="URL of mercurial repository index page") | |
72 parser.add_argument('-d', '--directory', dest='directory', | |
25 | 73 default=os.path.join(os.environ['HOME'], 'hg'), |
27 | 74 help="base directory to clone/update to [DEFAULT: %default]") |
75 parser.add_argument('--list', dest='list', | |
76 action='store_true', default=False, | |
77 help="list repositories and exit") | |
78 options = parser.parse_args(args) | |
79 if _import_error is not None: | |
80 # XXX better error handling | |
81 parser.error("Must have hglib and lxml package to use, sorry: {}".format(_import_error)) | |
3 | 82 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
83 # kill trailing slash |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
84 options.host = options.host.rstrip('/') |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
85 |
27 | 86 # get repositories |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
87 repos = repositories(options.host) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
88 if options.list: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
89 for repo in repos: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
90 print repo |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
91 sys.exit(0) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
92 |
27 | 93 # clone/update repos to directory |
9
5a909090fb24
make the destination directory for mirroring if it doesnt exist
k0s <k0scist@gmail.com>
parents:
8
diff
changeset
|
94 if not os.path.exists(options.directory): |
5a909090fb24
make the destination directory for mirroring if it doesnt exist
k0s <k0scist@gmail.com>
parents:
8
diff
changeset
|
95 os.mkdir(options.directory) |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
96 for repo in repos: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
97 update(options.host, repo) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
98 |
3 | 99 if __name__ == '__main__': |
100 main() |