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