comparison silvermirror/hg.py @ 17:f8edfc9c28ba

a really hacky way to disable...for temporary sanity and long term backing down from insanity
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 18 Jun 2013 15:58:35 -0700
parents 5a909090fb24
children 183cee927d8b
comparison
equal deleted inserted replaced
16:76eac0c9953a 17:f8edfc9c28ba
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2
2 """ 3 """
3 stub for the hg backend of silvermirror 4 stub for the hg backend of silvermirror
4 """ 5 """
5 6
6 import lxml.html 7 try:
7 import mercurial 8 import lxml.html
9 import mercurial
10 from mercurial import commands, hg, ui
11 requirements_fulfilled = True
12 except ImportError as e:
13 _import_error = e
14 requirements_fulfilled = False
15
8 import os 16 import os
9 import sys 17 import sys
10 from mercurial import commands, hg, ui
11 from optparse import OptionParser 18 from optparse import OptionParser
12 19
13 def update(host, path): 20 def update(host, path):
14 """ 21 """
15 get changes from host on path 22 get changes from host on path
16 """ 23 """
17 _ui = ui.ui() 24 _ui = ui.ui()
18 url = '%s/%s' % (host, path) 25 url = '%s/%s' % (host, path)
19 try: 26 try:
20 repo = hg.repository(_ui, path) 27 repo = hg.repository(_ui, path)
21 print 'Updating %s:' % path 28 print 'Updating %s:' % path
22 except Exception, e: 29 except Exception, e:
23 repo = hg.repository(_ui, url) 30 repo = hg.repository(_ui, url)
24 print 'Cloning %s:' % path 31 print 'Cloning %s:' % path
33 # """ 40 # """
34 41
35 # ui = ui.ui() 42 # ui = ui.ui()
36 # files = [ os.path.join(path, f) for f in os.listdir(path) ] 43 # files = [ os.path.join(path, f) for f in os.listdir(path) ]
37 # directories = [ f for f in files if os.path.isdir(f) ] 44 # directories = [ f for f in files if os.path.isdir(f) ]
38 45
39 # repos = [] 46 # repos = []
40 # for d in directories: 47 # for d in directories:
41 # try: 48 # try:
42 # repo = hg.repository(ui, d) 49 # repo = hg.repository(ui, d)
43 # repos.append(os.path.basename(d)) 50 # repos.append(os.path.basename(d))
45 # pass 52 # pass
46 # return repos 53 # return repos
47 54
48 def repositories(url): 55 def repositories(url):
49 """ 56 """
50 returns the list of reposotories under a URL of an hg server 57 returns the list of repositories under a URL of an hg server
51 """ 58 """
52 element = lxml.html.parse(url) 59 element = lxml.html.parse(url)
53 tds = element.xpath('//tr[position() > 1]/td[1]') 60 tds = element.xpath('//tr[position() > 1]/td[1]')
54 repos = [ i.text_content() for i in tds ] 61 repos = [ i.text_content() for i in tds ]
55 return repos 62 return repos
61 parser.add_option('-d', '--directory', dest='directory', 68 parser.add_option('-d', '--directory', dest='directory',
62 default=os.path.join(os.environ['HOME'], 'hg')) 69 default=os.path.join(os.environ['HOME'], 'hg'))
63 parser.add_option('--list', dest='list', 70 parser.add_option('--list', dest='list',
64 action='store_true', default=False) 71 action='store_true', default=False)
65 options, args = parser.parse_args(args) 72 options, args = parser.parse_args(args)
73 if not requirements_fulfilled:
74 # Hack; this should all be better o_O
75 parser.error("Must have mercurial and lxml packages to use, sorry")
66 if not options.host: 76 if not options.host:
67 parser.print_usage() 77 parser.print_usage()
68 parser.exit() 78 parser.exit()
69 79
70 # kill trailing slash 80 # kill trailing slash
80 os.mkdir(options.directory) 90 os.mkdir(options.directory)
81 91
82 os.chdir(options.directory) 92 os.chdir(options.directory)
83 for repo in repos: 93 for repo in repos:
84 update(options.host, repo) 94 update(options.host, repo)
85
86 95
87 if __name__ == '__main__': 96 if __name__ == '__main__':
88 main() 97 main()