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): 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): 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)