2012-04-18 03:21:41 +04:00
|
|
|
# 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/.
|
|
|
|
|
2012-04-18 03:39:13 +04:00
|
|
|
import ConfigParser
|
2012-04-13 03:50:29 +04:00
|
|
|
import inspect
|
|
|
|
import platform
|
2012-04-18 03:39:13 +04:00
|
|
|
import StringIO
|
2012-04-03 03:52:35 +04:00
|
|
|
import sys
|
2012-04-13 03:50:29 +04:00
|
|
|
import traceback
|
2012-04-03 03:52:35 +04:00
|
|
|
|
2012-04-17 23:00:27 +04:00
|
|
|
# General information common to all stoneridge programs
|
2012-04-17 23:25:30 +04:00
|
|
|
os_name = None
|
|
|
|
os_version = None
|
2012-04-17 23:00:27 +04:00
|
|
|
download_platform = None
|
|
|
|
download_suffix = None
|
2012-04-17 21:27:18 +04:00
|
|
|
|
2012-04-17 23:00:27 +04:00
|
|
|
# Paths that multiple programs need to know about
|
|
|
|
installroot = None
|
|
|
|
workdir = None
|
2012-04-18 03:21:41 +04:00
|
|
|
downloaddir = None
|
2012-04-17 23:00:27 +04:00
|
|
|
bindir = None
|
|
|
|
testroot = None
|
|
|
|
outdir = None
|
2012-04-18 03:21:41 +04:00
|
|
|
archivedir = None
|
|
|
|
logdir = None
|
2012-04-13 03:50:29 +04:00
|
|
|
|
|
|
|
def main(_main):
|
|
|
|
"""Mark a function as the main function to run when run as a script.
|
|
|
|
If that function throws an exception, we'll print the traceback to
|
|
|
|
stderr and exit.
|
|
|
|
"""
|
|
|
|
parent = inspect.stack()[1][0]
|
|
|
|
name = parent.f_locals.get('__name__', None)
|
|
|
|
if name == '__main__':
|
2012-04-18 03:39:13 +04:00
|
|
|
rval = 0
|
2012-04-13 03:50:29 +04:00
|
|
|
try:
|
2012-04-18 03:39:13 +04:00
|
|
|
rval = _main()
|
|
|
|
if rval is None:
|
|
|
|
rval = 0
|
2012-04-13 03:50:29 +04:00
|
|
|
except Exception, e:
|
|
|
|
traceback.print_tb(sys.exc_info()[2], None, sys.stderr)
|
|
|
|
sys.exit(1)
|
2012-04-18 03:39:13 +04:00
|
|
|
sys.exit(rval)
|
2012-04-13 03:50:29 +04:00
|
|
|
return _main
|
2012-04-17 23:00:27 +04:00
|
|
|
|
2012-04-18 03:21:41 +04:00
|
|
|
def update(conffile):
|
|
|
|
"""Update the stone ridge installation from the latest source
|
|
|
|
"""
|
2012-04-18 03:39:13 +04:00
|
|
|
cp = ConfigParser.SafeConfigParser()
|
|
|
|
cp.load([conffile])
|
|
|
|
|
|
|
|
try:
|
|
|
|
scheme = cp.get('update', 'scheme')
|
|
|
|
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e:
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
url = cp.get('update', 'url')
|
|
|
|
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError), e:
|
|
|
|
url = None
|
|
|
|
|
|
|
|
if scheme == 'hg':
|
|
|
|
args = ['hg', 'pull', '-u']
|
|
|
|
elif scheme == 'git':
|
|
|
|
args = ['git', 'pull']
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
if url:
|
|
|
|
args.append(url)
|
|
|
|
|
|
|
|
outbuf = StringIO.StringIO()
|
|
|
|
if subprocess.call(args, stdout=outbuf, stderr=subprocess.STDOUT):
|
|
|
|
sys.stderr.write('Error updating Stone Ridge\n')
|
|
|
|
sys.stderr.write(outbuf.getvalue())
|
|
|
|
outbuf.close()
|
2012-04-18 03:21:41 +04:00
|
|
|
|
2012-04-20 21:50:18 +04:00
|
|
|
def _determine_os_name(self):
|
|
|
|
"""Determine the os from platform.system
|
|
|
|
"""
|
|
|
|
global os_name
|
|
|
|
os_name = platform.system().lower()
|
|
|
|
if os_name == 'darwin':
|
|
|
|
os_name = 'mac'
|
|
|
|
|
|
|
|
def _determine_os_version():
|
|
|
|
"""Determine the os version
|
|
|
|
"""
|
|
|
|
global os_version
|
|
|
|
if os_name == 'linux':
|
|
|
|
os_version = ' '.join(platform.linux_distribution[0:2])
|
|
|
|
elif os_name == 'mac':
|
|
|
|
os_version = platform.mac_ver[0]
|
|
|
|
elif system == 'windows':
|
|
|
|
os_version = platform.win32_ver()[1]
|
|
|
|
else:
|
|
|
|
os_version = 'Unknown'
|
|
|
|
|
|
|
|
def _determine_download_platform():
|
|
|
|
"""Determine which platform to download files for
|
|
|
|
"""
|
|
|
|
global download_platform
|
|
|
|
if os_name == 'linux':
|
|
|
|
if platform.machine() == 'x86_64':
|
|
|
|
download_platform = 'linux64'
|
|
|
|
else:
|
|
|
|
download_platform = 'linux32
|
|
|
|
elif os_name == 'windows':
|
|
|
|
if platform.machine() == 'x86_64':
|
|
|
|
download_platform = 'win64'
|
|
|
|
else:
|
|
|
|
download_platform = 'win32'
|
|
|
|
else:
|
|
|
|
download_platform = os_name
|
|
|
|
|
|
|
|
def _determine_download_suffix():
|
|
|
|
"""Determine the suffix of the firefox archive to download
|
|
|
|
"""
|
|
|
|
global download_suffix
|
|
|
|
if os_name == 'linux':
|
|
|
|
download_suffix = 'tar.bz2'
|
|
|
|
elif os_name == 'mac':
|
|
|
|
download_suffix = 'dmg'
|
|
|
|
else:
|
|
|
|
download_suffix = 'zip'
|
|
|
|
|
|
|
|
def _determine_bindir():
|
|
|
|
"""Determine the location of the firefox binary based on platform
|
|
|
|
"""
|
|
|
|
global bindir
|
|
|
|
if os_name == 'mac':
|
|
|
|
bindir = os.path.join(workdir, 'FirefoxNightly.app', 'Contents',
|
|
|
|
'MacOS')
|
|
|
|
else:
|
|
|
|
bindir = os.path.join(workdir, 'firefox')
|
|
|
|
|
|
|
|
def setup_dirnames(srroot, srwork):
|
|
|
|
"""Determine the directory names and platform information to be used
|
|
|
|
by this run of stone ridge
|
|
|
|
"""
|
|
|
|
global installroot
|
|
|
|
global workdir
|
|
|
|
global downloaddir
|
|
|
|
global testroot
|
|
|
|
global outdir
|
|
|
|
global archivedir
|
|
|
|
global logdir
|
|
|
|
|
|
|
|
installroot = os.path.abspath(srroot)
|
|
|
|
workdir = os.path.abspath(srwork)
|
|
|
|
downloaddir = os.path.join(workdir, 'dl')
|
|
|
|
testroot = os.path.join(installroot, 'tests')
|
|
|
|
outdir = os.path.join(workdir, 'out')
|
|
|
|
archivedir = os.path.join(installroot, 'archives')
|
|
|
|
logdir = os.path.join(installroot, 'logs')
|
|
|
|
|
|
|
|
_determine_os_name()
|
|
|
|
_determine_os_version()
|
|
|
|
_determine_download_platform()
|
|
|
|
_determine_download_suffix()
|
|
|
|
_determine_bindir()
|
|
|
|
|
2012-04-17 23:00:27 +04:00
|
|
|
class ArgumentParser(argparse.ArgumentParser):
|
2012-04-20 21:50:18 +04:00
|
|
|
"""An argument parser for stone ridge programs that handles the arguments
|
|
|
|
required by all of them
|
|
|
|
"""
|
2012-04-17 23:00:27 +04:00
|
|
|
def __init__(self, **kwargs):
|
2012-04-18 03:21:41 +04:00
|
|
|
argparse.ArgumentParser.__init__(self, **kwargs)
|
2012-04-17 23:00:27 +04:00
|
|
|
|
|
|
|
self.add_argument('--root', dest='_sr_root_', required=True,
|
|
|
|
help='Root of Stone Ridge installation')
|
|
|
|
self.add_argument('--workdir', dest='_sr_work_', required=True,
|
|
|
|
help='Directory to do all the work in')
|
|
|
|
|
2012-04-18 03:21:41 +04:00
|
|
|
def parse_args(self, **kwargss):
|
|
|
|
args = argparse.ArgumentParser.parse_args(self, **kwargs)
|
2012-04-17 23:00:27 +04:00
|
|
|
|
2012-04-20 21:50:18 +04:00
|
|
|
setup_dirnames(args['_sr_root_'], args['_sr_work_'])
|
2012-04-17 23:00:27 +04:00
|
|
|
|
|
|
|
return args
|