def main(argv=None): argv = argv or sys.argv[1:] op = OptionParser(usage=( "Usage: assetgen [<path/to/assetgen.yaml> ...] [options]\n\n" "Note:\n" " If you don't specify assetgen.yaml file paths, then `git\n" " ls-files *assetgen.yaml` will be used to detect all config\n" " files in the current repository. So you need to be inside\n" " a git repository's working tree." )) op.add_option( '-v', '--version', action='store_true', help="show program's version number and exit" ) op.add_option( '--clean', action='store_true', help="remove all generated files" ) op.add_option( '--debug', action='store_true', help="set debug mode" ) op.add_option( '--extension', action='append', dest='path', help="specify a python extension file (may be repeated)" ) op.add_option( '--force', action='store_true', help="force rebuild of all files" ) op.add_option( '--profile', dest='name', default='default', help="specify a profile to use" ) op.add_option( '--watch', action='store_true', help="keep running assetgen on a loop" ) autocomplete(op) options, files = op.parse_args(argv) if options.version: print 'assetgen 0.1' sys.exit() if options.debug: global DEBUG DEBUG = True clean = options.clean extensions = options.path force = options.force profile = options.name watch = options.watch if extensions: scope = globals() for ext in extensions: execfile(ext, scope, {}) if files: for file in files: if not isfile(file): exit("Could not find %s" % file) if not files: if not is_git(): op.print_help() sys.exit() root = SCMConfig().root files = run_command( ['git', 'ls-files', '*assetgen.yaml'], cwd=root ).strip().splitlines() if not files: op.print_help() sys.exit() files = [join(root, file) for file in files] files = [realpath(file) for file in files] if watch: mtime_cache = {} for file in files: mtime_cache[file] = stat(file)[ST_MTIME] generators = [AssetGenRunner(file, profile, force) for file in files] if clean: for assetgen in generators: assetgen.clean() sys.exit() if watch: while 1: try: for assetgen in generators: assetgen.run() for idx, file in enumerate(files): mtime = stat(file)[ST_MTIME] if mtime > mtime_cache[file]: mtime_cache[file] = mtime generators[idx] = AssetGenRunner(file, profile, force) sleep(1) except AppExit: sleep(3) except KeyboardInterrupt: break else: try: for assetgen in generators: assetgen.run() except AppExit: sys.exit(1)
def main(argv=None): """Handle the bolt command line call.""" if argv is None: argv = sys.argv[1:] op = OptionParser( usage="bolt <command-1> <command-2> ... [options]", ) op.add_option( '-v', '--version', action='store_true', default=False, help="show program's version number and exit" ) op.add_option( '-f', dest='file', default="Boltfile", help="set the name or path of the bolt file [Boltfile]" ) op.add_option( '-d', dest='defaults_file', default=_rc_path(), help="set the path of the defaults file [~/.bolt.yaml]" ) op.add_option( '-i', dest='identity', action='append', default=None, help="path to SSH private key file(s) -- may be repeated" ) op.add_option( '--hide', metavar='LEVELS', help="comma-separated list of output levels to hide" ) op.add_option( '--show', metavar='LEVELS', help="comma-separated list of output levels to show" ) op.add_option( '--disable', metavar='HOOKS', help="comma-separated list of hooks to disable" ) op.add_option( '--enable', metavar='HOOKS', help="comma-separated list of hooks to enable" ) op.add_option( '--list', action='store_true', default=False, help="show the list of available tasks and exit" ) op.add_option( '--no-pty', action='store_true', default=False, help="do not use pseudo-terminal in run/sudo" ) options, args = op.parse_args(argv) setup_defaults(options.defaults_file) # Load the Boltfile. runner = init_task_runner(options.file, getcwd()) # Autocompletion support. autocomplete_items = runner.tasks.keys() if 'autocomplete' in env: autocomplete_items += env.autocomplete autocomplete(op, ListCompleter(autocomplete_items)) if options.version: print("bolt %s" % __version__) sys.exit() if options.no_pty: env.always_use_pty = False if options.identity: env.key_filename = options.identity split_string = lambda s: filter(None, map(str.strip, s.split(','))) # Handle output levels. if options.show: for level in split_string(options.show): output[level] = True if options.hide: for level in split_string(options.hide): output[level] = False if output.debug: print("Using Boltfile: %s" % runner.path) # Handle hooks related options. if options.disable: for hook in split_string(options.disable): DISABLED_HOOKS.append(hook) if options.enable: for hook in split_string(options.enable): ENABLED_HOOKS.append(hook) if options.list: print('\n'.join(sorted(runner.tasks))) sys.exit() tasks = [] idx = 0 # Parse command line arguments. for task in args: # Initialise variables. _args = [] _kwargs = {} _ctx = None # Handle +env flags. if task.startswith('+'): if ':' in task: name, value = task[1:].split(':', 1) env[name] = value else: env[task[1:]] = True continue # Handle @context specifiers. if task.startswith('@'): if not idx: continue ctx = (task[1:],) existing = tasks[idx-1][3] if existing: new = list(existing) new.extend(ctx) ctx = tuple(new) tasks[idx-1][3] = ctx continue # Handle tasks with parameters. if ':' in task: task, argstr = task.split(':', 1) for pair in _escape_split(',', argstr): k, _, v = pair.partition('=') if _: _kwargs[k] = v else: _args.append(k) idx += 1 task_name = task.replace('_', '-') if task_name not in runner.tasks: abort("Task not found:\n\n%s" % indent(task)) tasks.append([task_name, _args, _kwargs, _ctx]) if not tasks: runner.display_listing() sys.exit() runner.run(tasks)
def main(argv=None): argv = argv or sys.argv[1:] op = OptionParser(usage=( "Usage: assetgen [<path/to/assetgen.yaml> ...] [options]\n\n" "Note:\n" " If you don't specify assetgen.yaml file paths, then `git\n" " ls-files *assetgen.yaml` will be used to detect all config\n" " files in the current repository. So you need to be inside\n" " a git repository's working tree.\n\n" " And if you specify a URL as a `source`, then it will be\n" " downloaded to ~/.assetgen -- you can override this by\n" " setting the env variable $ASSETGEN_DOWNLOADS_DIRECTORY")) op.add_option('-v', '--version', action='store_true', help="show program's version number and exit") op.add_option('--clean', action='store_true', help="remove all generated files") op.add_option('--debug', action='store_true', help="set debug mode") op.add_option('--extension', action='append', dest='path', help="specify a python extension file (may be repeated)") op.add_option('--force', action='store_true', help="force rebuild of all files") op.add_option('--nuke', action='store_true', help="remove all generated and downloaded files") op.add_option('--profile', dest='name', default='default', help="specify a profile to use") op.add_option('--watch', action='store_true', help="keep running assetgen on a loop") autocomplete(op) options, files = op.parse_args(argv) if options.version: print 'assetgen 0.2.2' sys.exit() if options.debug: global DEBUG DEBUG = True clean = options.clean extensions = options.path force = options.force nuke = options.nuke profile = options.name watch = options.watch if extensions: scope = globals() for ext in extensions: execfile(ext, scope, {}) if files: for file in files: if not isfile(file): exit("Could not find %s" % file) if not files: if not is_git(): op.print_help() sys.exit() root = SCMConfig().root files = run_command(['git', 'ls-files', '*assetgen.yaml'], cwd=root).strip().splitlines() if not files: op.print_help() sys.exit() files = [join(root, file) for file in files] files = [realpath(file) for file in files] if watch: mtime_cache = {} for file in files: mtime_cache[file] = stat(file)[ST_MTIME] generators = [AssetGenRunner(file, profile, force) for file in files] if nuke: if isdir(DOWNLOADS_PATH): print "=> Removing:", DOWNLOADS_PATH rmtree(DOWNLOADS_PATH) clean = 1 if clean: for assetgen in generators: assetgen.clean() sys.exit() if watch: while 1: try: for assetgen in generators: assetgen.run() for idx, file in enumerate(files): mtime = stat(file)[ST_MTIME] if mtime > mtime_cache[file]: mtime_cache[file] = mtime generators[idx] = AssetGenRunner(file, profile, force) sleep(1) except AppExit: sleep(3) except KeyboardInterrupt: break else: try: for assetgen in generators: assetgen.run() except AppExit: sys.exit(1)
def main(argv=None): argv = argv or sys.argv[1:] op = OptionParser(usage=( "Usage: assetgen [<path/to/assetgen.yaml> ...] [options]\n\n" "Note:\n" " If you don't specify assetgen.yaml file paths, then `git\n" " ls-files *assetgen.yaml` will be used to detect all config\n" " files in the current repository. So you need to be inside\n" " a git repository's working tree.\n\n" " And if you specify a URL as a `source`, then it will be\n" " downloaded to ~/.assetgen -- you can override this by\n" " setting the env variable $ASSETGEN_DOWNLOADS" )) op.add_option( '-v', '--version', action='store_true', help="show program's version number and exit" ) op.add_option( '--clean', action='store_true', help="remove all generated files" ) op.add_option( '--debug', action='store_true', help="set debug mode" ) op.add_option( '--extension', action='append', dest='path', help="specify a python extension file (may be repeated)" ) op.add_option( '--force', action='store_true', help="force rebuild of all files" ) op.add_option( '--nuke', action='store_true', help="remove all generated and downloaded files" ) op.add_option( '--profile', dest='name', default='default', help="specify a profile to use" ) op.add_option( '--watch', action='store_true', help="keep running assetgen on a loop" ) autocomplete(op) options, files = op.parse_args(argv) if options.version: print 'assetgen %s' % __release__ sys.exit() if options.debug: global DEBUG DEBUG = True clean = options.clean extensions = options.path force = options.force nuke = options.nuke profile = options.name watch = options.watch if extensions: scope = globals() for ext in extensions: execfile(ext, scope, {}) if files: for file in files: if not isfile(file): exit("Could not find %s" % file) if not files: if not is_git(): op.print_help() sys.exit() root = SCMConfig().root files = run_command( ['git', 'ls-files', '*assetgen.yaml'], cwd=root ).strip().splitlines() if not files: op.print_help() sys.exit() files = [join(root, file) for file in files] files = [realpath(file) for file in files] if watch: change_checker = FileChangeDetector() for file in files: change_checker.mark_clean(file) generators = [AssetGenRunner(file, profile, force, nuke) for file in files] if nuke: if isdir(DOWNLOADS_PATH): log.info("Removing: %s" % DOWNLOADS_PATH) rmtree(DOWNLOADS_PATH) clean = 1 if clean: for assetgen in generators: assetgen.clean() sys.exit() if watch: while 1: try: for assetgen in generators: assetgen.run() for idx, file in enumerate(files): if change_checker.is_changed(file): generators[idx] = AssetGenRunner(file, profile, force) change_checker.mark_clean(file) sleep(1) except AppExit: sleep(3) except KeyboardInterrupt: break else: try: for assetgen in generators: assetgen.run() except AppExit: sys.exit(1)
def main(argv=None, show_help=False): argv = argv or sys.argv[1:] # Set the script name to ``redpill`` so that OptionParser error messages # don't display a potentially confusing ``redpill.py`` to end users. sys.argv[0] = 'redpill' major_listing = '\n'.join( " %-10s %s" % (cmd, MAJOR_COMMANDS[cmd].__doc__) for cmd in sorted(MAJOR_COMMANDS) ) mini_listing = '\n'.join( " %-10s %s" % (cmd, MINI_COMMANDS[cmd].__doc__) for cmd in sorted(MINI_COMMANDS) ) usage = ("""%s\nUsage: redpill <command> [options] \nCommands: \n%s\n\n%s \nSee `redpill help <command>` for more info on a specific command.""" % (__doc__, major_listing, mini_listing)) autocomplete( OptionParser(add_help_option=False), ListCompleter(AUTOCOMPLETE_COMMANDS.keys()), subcommands=AUTOCOMPLETE_COMMANDS ) if not argv: show_help = True else: command = argv[0] argv = argv[1:] if command in ['help', '-h', '--help']: if argv: command = argv[0] argv = ['--help'] if command in MINI_COMMANDS: help = MINI_COMMANDS[command].__doc__ print "Usage: redpill %s\n\n %s\n" % (command, help) sys.exit() else: show_help = True elif command in ['-v', '--version']: version() sys.exit() elif command in MINI_COMMANDS: MINI_COMMANDS[command]() sys.exit() if show_help: print usage sys.exit() if command in MAJOR_COMMANDS: return MAJOR_COMMANDS[command](argv) # We support git-command like behaviour. That is, if there's an external # binary named ``redpill-foo`` available on the ``$PATH``, then running ``redpill # foo`` will automatically delegate to it. try: output, retcode = run_command( ['redpill-%s' % command] + argv, retcode=True, redirect_stdout=False, redirect_stderr=False ) except CommandNotFound: exit("ERROR: Unknown command %r" % command) if retcode: sys.exit(retcode)