forked from mozilla/mozmill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
carton-mozmill.py
executable file
·86 lines (67 loc) · 2.31 KB
/
carton-mozmill.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
"""
create a mozmill carton
"""
import optparse
import os
import shutil
import sys
import tempfile
try:
from subprocess import check_call as call
except ImportError:
from subprocess import call
### stuff that should be in the stdlib
def which(fileName, path=os.environ['PATH']):
"""python equivalent of which; should really be in the stdlib"""
dirs = path.split(os.pathsep)
for dir in dirs:
if os.path.isfile(os.path.join(dir, fileName)):
return os.path.join(dir, fileName)
def require(url):
"""
import a module from the web
url should be like scheme://host.name/path/to/module.py
"""
import imp
import urllib2
contents = urllib2.urlopen(url).read()
filename = url.rsplit('/', 1)[-1]
modulename = filename.rsplit('.', 1)[-1]
fd, filename = tempfile.mkstemp(suffix='.py', prefix=modulename)
os.write(fd, contents)
os.close(fd)
module = imp.load_source(modulename, filename)
os.remove(filename)
return module
### requirements
carton = require('http://k0s.org/mozilla/hg/carton/raw-file/tip/carton.py')
git = which('git')
MOZBASE = 'git://github.com/mozilla/mozbase.git'
MOZMILL = 'git://github.com/mozilla/mozmill.git'
def main(args=sys.argv[1:]):
assert git, 'git executable not found!'
# parse command line options
parser = optparse.OptionParser()
parser.add_option('--name', dest='name', default='mozmill-env',
help='name of the environment')
options, args = parser.parse_args(args)
# checkout mozbase
tempdir = tempfile.mkdtemp()
mozbasedir = os.path.join(tempdir, 'mozbase')
call([git, 'clone', MOZBASE, mozbasedir])
# checkout mozmill
mozmilldir = os.path.join(tempdir, 'mozmill')
call([git, 'clone', MOZMILL, mozmilldir])
# make a carton
carton.main([options.name, mozmilldir, mozbasedir,
'--python-script', 'src/mozbase/setup_development.py',
'--python-script', 'src/mozmill/setup_development.py',
])
# remove vestiges
shutil.rmtree(tempdir)
if __name__ == '__main__':
main()