# HG changeset patch # User Jeff Hammel # Date 1354319466 28800 # Node ID df6a8049e9a427a62170d95806d66d3ce5ba63fd initial port from http://k0s.org/mozilla/try.py diff -r 000000000000 -r df6a8049e9a4 README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Fri Nov 30 15:51:06 2012 -0800 @@ -0,0 +1,11 @@ +mozillatry +=========== + +push patches to mozilla try server + +---- + +Jeff Hammel + +http://k0s.org/mozilla + diff -r 000000000000 -r df6a8049e9a4 mozillatry.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mozillatry.py Fri Nov 30 15:51:06 2012 -0800 @@ -0,0 +1,129 @@ +#!/usr/bin/env python + +""" +push patches to try +""" + +import optparse +import os +import sys + +from subprocess import check_call as call + +def config(filename): + """read .mozutils.ini config file""" + # XXX stub; this should really use + # e.g. http://k0s.org/mozilla/hg/configuration/ + from ConfigParser import ConfigParser + parser = ConfigParser() + parser.read(filename) + return os.path.expanduser(parser.get('hg', 'mozilla-central')) + +def reset(directory): + """reset an hg directory to a good state""" + assert os.path.exists(directory) and os.path.isdir(directory) + hg_dir = os.path.join(directory, '.hg') + assert os.path.exists(hg_dir) and os.path.isdir(hg_dir) + call(['hg', 'revert', '--no-backup', '--all'], cwd=directory) + call(['hg', 'qpop', '--all'], cwd=directory) + try: + shutil.rmtree(os.path.join(hg_dir, 'patches')) # remove patches + except: + pass + +def update(directory): + """update a mozilla-central checkout""" + assert os.path.exists(directory) and os.path.isdir(directory) + reset(directory) + call(['hg', 'pull'], cwd=directory) + call(['hg', 'update'], cwd=directory) + call(['hg', 'qinit'], cwd=directory) + +def push_to_try(patches, repo, commit, _try='ssh://hg.mozilla.org/try/'): + """push a series of patches to try repository""" + + # ensure the repo is in a good state + update(repo) + + try: + # apply patches + for patch in patches: + call(['hg', 'qimport', patch], cwd=repo) + call(['hg', 'qpush', '--all'], cwd=repo) + call(['hg', 'qseries', '-v'], cwd=repo) + + # push to try + call(['hg', 'qref', '--message', commit], cwd=repo) + call(['hg', 'push', '-f', _try], cwd=repo) + finally: + reset(repo) + +def try_syntax(opt=True, debug=True, unittests=('all'), talos=('all'), bug=None): + """ + return try syntax; see also: + - https://github.com/pbiggar/trychooser + - http://trychooser.pub.build.mozilla.org/ + """ + + assert opt or debug + message = ['try:'] + message += ['-b', '%s%s' % (('d' if debug else ''), ('o' if opt else ''))] + message += ['-u', (','.join(unittests) if unittests else 'none')] + message += ['-t', (','.join(talos) if talos else 'none')] + if bug: + message += ['--post-to-bugzilla', str(bug)] + return ' '.join(message) + +def main(args=sys.argv[1:]): + + # parse command line arguments + usage = '%prog [options] patch <...>' + class PlainDescriptionFormatter(optparse.IndentedHelpFormatter): + """description formatter""" + def format_description(self, description): + description = description.strip() + if description: + return description + '\n' + else: + return '' + parser = optparse.OptionParser(usage=usage, description=__doc__, formatter=PlainDescriptionFormatter()) + parser.add_option('--no-opt', dest='opt', + action='store_false', default=True, + help='no opt builds') + parser.add_option('--no-debug', dest='debug', + action='store_false', default=True, + help='no debug builds') + parser.add_option('-u', dest='unittests', action='append', + help='unittests') + parser.add_option('-t', dest='talos', action='append', + help='talos tests') + parser.add_option('--bug', dest='bug', type='int', + help='post to bugzilla bug #') + parser.add_option('-c', '--config', dest='config', + default=os.path.join(os.environ['HOME'], '.mozutils.ini'), + help='location of config file') + options, args = parser.parse_args(args) + if not args: + parser.print_help() + parser.exit() + if (not options.opt) and (not options.debug): + parser.error("Must enable opt or debug builds") + + # get mozilla-central repository directory + config_file = options.__dict__.pop('config') + if not os.path.exists(config_file): + parser.error("You need a config file at ~/.mozutils.ini") + try_directory = config(config_file) # XXX temporary hack + if not os.path.exists(try_directory): + parser.error("mozilla-central try directory does not exist: %s" % try_directory) + + # build try syntax + commit = try_syntax(**options.__dict__) + print commit + + # push to try + push_to_try(patches=args, repo=try_directory, commit=commit) + +if __name__ == '__main__': + main() + diff -r 000000000000 -r df6a8049e9a4 setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Fri Nov 30 15:51:06 2012 -0800 @@ -0,0 +1,35 @@ +import os +from setuptools import setup + +try: + here = os.path.dirname(os.path.abspath(__file__)) + description = file(os.path.join(here, 'README.txt')).read() +except IOError: + description = None + +version = '0.0' + +deps = [] + +setup(name='mozillatry', + version=version, + description="push patches to mozilla try server", + long_description=description, + classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers + keywords='mozilla', + author='Jeff Hammel', + author_email='jhammel@mozilla.com', + url='http://k0s.org/mozilla', + license='', + py_modules=['mozillatry'], + packages=[], + include_package_data=True, + zip_safe=False, + install_requires=deps, + entry_points=""" + # -*- Entry points: -*- + [console_scripts] + mozillatry = mozillatry:main + """, + ) +