def test(argv=None, completer=None, run_all=False): op = OptionParser(usage="Usage: amp test [options]", add_help_option=False) op.add_option('-a', '--all', dest='all', action='store_true', help="run the comprehensive test suite") op.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help="enable verbose mode") testers = ['python', 'go', 'js'] if completer: return op, ListCompleter(testers) options, args = parse_options(op, argv, completer) if not args: args = testers args = set(args) if options.all: run_all = True if 'python' in args: py_tests(PYTHON_TEST_MODULES, verbose=options.verbose) if 'go' in args: go_tests() if 'js' in args: js_tests(verbose=options.verbose)
def hub(argv=None, completer=None): op = OptionParser( usage="Usage: amp hub [register|update] [options]", add_help_option=False ) options, args = parse_options(op, argv, completer, True)
def deploy(argv=None, completer=None): op = OptionParser( usage="Usage: amp deploy <instance-name> [options]", add_help_option=False ) op.add_option('--test', dest='test', action='store_true', default=False, help="run tests before completing the switch") options, args = parse_options(op, argv, completer, True)
def build(argv=None, completer=None): op = OptionParser(usage="Usage: amp build [options]", add_help_option=False) op.add_option('--role', dest='role', default='default', help="specify a non-default role to build") options, args = parse_options(op, argv, completer) load_role(options.role) install_packages()
def build(argv=None, completer=None): op = OptionParser(usage="Usage: amp build [options]", add_help_option=False) op.add_option('--role', dest='role', default='default', help="specify a non-default role to build") options, args = parse_options(op, argv, completer) load_role(options.role) install_packages() _, retcode = run_command( [sys.executable, join(AMPIFY_ROOT, 'environ', 'assetgen')], retcode=True, redirect_stdout=False, redirect_stderr=False ) if retcode: sys.exit(retcode)
def check(argv=None, completer=None): op = OptionParser(usage="Usage: amp check", add_help_option=False) options, args = parse_options(op, argv, completer) log("Checking the current revision id for your code.", PROGRESS) revision_id = do( 'git', 'show', '--pretty=oneline', '--summary', redirect_stdout=True ).split()[0] log("Checking the latest commits on GitHub.", PROGRESS) commit_info = urlopen( 'http://github.com/api/v2/json/commits/list/tav/ampify/master' ).read() latest_revision_id = decode_json(commit_info)['commits'][0]['id'] if revision_id != latest_revision_id: exit("A new version is available. Please run `git pull`.") log("Your checkout is up-to-date.", SUCCESS)
def run(argv=None, completer=None): op = OptionParser( usage="Usage: amp run <instance-name> [options] [stop|quit|restart]", add_help_option=False ) op.add_option('-d', '--debug', dest='debug', action='store_true', help="enable debug mode") op.add_option("--file", dest="filename", help="input file to read data from") if completer: return op, DirCompleter(AMPIFY_ROOT_PARENT) options, args = parse_options(op, argv, completer, True) if options.debug: settings.debug = True instance_name, instance_root = normalise_instance_name(args[0])
def init(argv=None, completer=None): op = OptionParser( usage="Usage: amp init <instance-name> [options]", add_help_option=False ) op.add_option('--clobber', dest='clobber', action='store_true', help="clobber any existing files/directories if they exist") op.add_option('--from', dest='git_repo', default='', help="initialise by cloning the given git repository") options, args = parse_options(op, argv, completer) git_repo = options.git_repo if git_repo: if args: instance_name = args[0] else: instance_name = git_repo.split('/')[-1].rsplit('.', 1)[0] if not instance_name: exit(ERRMSG_GIT_NAME_DETECTION) else: if args: instance_name = args[0] else: op.print_help() sys.exit(1) instance_name, instance_root = normalise_instance_name(instance_name) clobber = options.clobber if exists(instance_root): if not clobber: exit( "ERROR: A directory already exists at %s\n " "Use the --clobber parameter to overwrite the directory" % instance_root ) chdir(instance_root) diff = do('git', 'diff', '--cached', '--name-only', redirect_stdout=1) if diff.strip(): error( "ERROR: You have a dirty working tree at %s\n " "Please either commit your changes or move your files.\n" % instance_root ) error(" These are the problematic files:") for filename in diff.strip().splitlines(): log(" %s" % filename, ERROR) print first_run = 0 else: create = query("Create a instance at %s" % instance_root).lower() if not create.startswith('y'): sys.exit(2) makedirs(instance_root) print print("Created %s" % instance_root) print chdir(instance_root) do('git', 'init') print readme = open('README.md', 'wb') readme.close() do('git', 'add', 'README.md') do('git', 'commit', '-m', "Initialised the instance [amp].") first_run = 1 diff = do('git', 'diff', '--cached', '--name-only', redirect_stdout=1) if diff.strip(): do('git', 'commit', '-m', "Updated instance [amp].") print(DEBUG)