Mercurial > hg > silvermirror
annotate silvermirror/hg.py @ 28:03911cb46f53
STUB: setup.py silvermirror/hg.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 31 Jan 2014 19:34:46 -0800 |
parents | a648f57b1921 |
children | 882b26fbfcd3 |
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 |
28
03911cb46f53
STUB: setup.py silvermirror/hg.py
Jeff Hammel <k0scist@gmail.com>
parents:
27
diff
changeset
|
7 import hglib # http://mercurial.selenic.com/wiki/PythonHglib |
27 | 8 import os |
9 import sys | |
10 import argparse | |
11 | |
12 _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
|
13 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
|
14 import lxml.html |
27 | 15 except ImportError as _import_error: |
16 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
|
17 |
1
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 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
|
20 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 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
|
22 """ |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
23 _ui = ui.ui() |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
24 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
|
25 try: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
26 repo = hg.repository(_ui, path) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
27 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
|
28 except Exception, e: |
27 | 29 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
|
30 repo = hg.repository(_ui, url) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
31 print 'Cloning %s:' % path |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
32 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
|
33 return |
2
0d9094bb98b0
adding function to return all hg repos on a path
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
34 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
35 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
|
36 |
24 | 37 # TODO: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
38 # def repositories(path): |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
39 # """ |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
40 # 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
|
41 # """ |
2
0d9094bb98b0
adding function to return all hg repos on a path
k0s <k0scist@gmail.com>
parents:
1
diff
changeset
|
42 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
43 # ui = ui.ui() |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
44 # 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
|
45 # 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
|
46 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
47 # repos = [] |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
48 # for d in directories: |
26 | 49 # try: |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
50 # repo = hg.repository(ui, d) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
51 # 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
|
52 # except mercurial.repo.RepoError: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
53 # pass |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
54 # return repos |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
55 |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
56 def repositories(url): |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
57 """ |
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
|
58 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
|
59 """ |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
60 element = lxml.html.parse(url) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
61 tds = element.xpath('//tr[position() > 1]/td[1]') |
24 | 62 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
|
63 return repos |
3 | 64 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
65 |
3 | 66 def main(args=sys.argv[1:]): |
27 | 67 """CLI""" |
68 | |
69 # parse command line | |
70 parser = argparse.ArgumentParser(description=__doc__) | |
71 parser.add_argument('host', dest='host', | |
72 help="URL of mercurial repository index page") | |
73 parser.add_argument('-d', '--directory', dest='directory', | |
25 | 74 default=os.path.join(os.environ['HOME'], 'hg'), |
27 | 75 help="base directory to clone/update to [DEFAULT: %default]") |
76 parser.add_argument('--list', dest='list', | |
77 action='store_true', default=False, | |
78 help="list repositories and exit") | |
79 options = parser.parse_args(args) | |
80 if _import_error is not None: | |
81 # XXX better error handling | |
82 parser.error("Must have hglib and lxml package to use, sorry: {}".format(_import_error)) | |
3 | 83 |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
84 # kill trailing slash |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
85 options.host = options.host.rstrip('/') |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
86 |
27 | 87 # get repositories |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
88 repos = repositories(options.host) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
89 if options.list: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
90 for repo in repos: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
91 print repo |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
92 sys.exit(0) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
93 |
27 | 94 # 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
|
95 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
|
96 os.mkdir(options.directory) |
6
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
97 for repo in repos: |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
98 update(options.host, repo) |
c999b2f16159
adding functionality to update/clone a bunch of hg repos
k0s <k0scist@gmail.com>
parents:
5
diff
changeset
|
99 |
3 | 100 if __name__ == '__main__': |
101 main() |