def action(rebuild=False, watch=False, check=False, clean=False, quiet=('q', False), verbose=('v', False)): if len(filter(bool, [rebuild, watch, clean, check])) != 1: print "Error: exactly one of --rebuild, --watch, --check or --clean must be given" return 1 if rebuild: command = 'rebuild' elif watch: command = 'watch' elif clean: command = 'clean' elif check: command = 'check' log.setLevel(logging.DEBUG if verbose else ( logging.WARNING if quiet else logging.INFO)) cmdenv = CommandLineEnvironment(environment, log) if loaders: log.info('Finding bundles...') for loader in loaders: environment.add( *[b for b in loader.load_bundles() if not b.is_container]) cmdenv.invoke(command)
def build(self): logger = getLogger('webassets') logger.addHandler(StreamHandler()) logger.setLevel(DEBUG) cli_environment = CommandLineEnvironment(self.env, logger) cli_environment.invoke("build", args={})
def handle(self, *args, **options): valid_commands = CommandLineEnvironment.Commands if len(args) > 1: raise CommandError('Invalid number of subcommands passed: %s' % ", ".join(args)) elif len(args) == 0: raise CommandError('You need to specify a subcommand: %s' % ', '.join(valid_commands)) # Create log log = logging.getLogger('django-assets') log.setLevel({0: logging.WARNING, 1: logging.INFO, 2: logging.DEBUG}[int(options.get('verbosity', 1))]) log.addHandler(logging.StreamHandler()) # If the user requested it, search for bundles defined in templates if options.get('parse_templates'): log.info('Searching templates...') # Note that we exclude container bundles. By their very nature, # they are guaranteed to have been created by solely referencing # other bundles which are already registered. get_env().add(*[b for b in self.load_from_templates() if not b.is_container]) if len(get_env()) == 0: raise CommandError('No asset bundles were found. ' 'If you are defining assets directly within your ' 'templates, you want to use the --parse-templates ' 'option.') # Execute the requested subcommand cmd = CommandLineEnvironment(get_env(), log) try: cmd.invoke(args[0]) except AssetCommandError, e: raise CommandError(e)
def handle(self, app, **kwargs): assets = Environment(app) assets.url = app.static_url_path# = os.path.join(_appdir, 'static') assets.register('all_css', app.bundles['all_css_min']) assets.register('all_js', app.bundles['all_js_min']) log = logging.getLogger('webassets') log.addHandler(logging.StreamHandler()) log.setLevel(logging.DEBUG) cmdenv = CommandLineEnvironment(assets, log) cmdenv.invoke('build', kwargs)
def rebuild_assets(config): config = config.copy() config['assets.debug'] = True assets = make_assets(config) assets_dir = assets.env.directory # Remove existing assets for name, bundle in assets.env._named_bundles.items(): path = os.path.join(assets_dir, bundle.output) % {'version': '*'} for p in glob.iglob(path): os.unlink(p) cmdenv = CommandLineEnvironment(assets.env, logging.getLogger('assets')) cmdenv.invoke('build', {})
def action(rebuild=False, watch=False, clean=False, quiet=('q', False), verbose=('v', False)): if len(filter(bool, [rebuild, watch, clean])) != 1: print "Error: exactly one of --rebuild, --watch or --clean must be given" return 1 if rebuild: command = 'rebuild' elif watch: command = 'watch' elif clean: command = 'clean' log.setLevel(logging.DEBUG if verbose else (logging.WARNING if quiet else logging.INFO)) cmdenv = CommandLineEnvironment(environment, log) if loaders: log.info('Finding bundles...') for loader in loaders: environment.add(*[b for b in loader.load_bundles() if not b.is_container]) cmdenv.invoke(command)
log.setLevel(logging.__dict__[args.loglevel]) loader = PythonLoader('webassets_config') assets_env = loader.load_environment() assets_env.debug = args.debug cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build() if args.debug: print("The following files are produced by assets pipeline:") print(assets_env['js'].urls()) print(assets_env['css'].urls()) if args.command != 'build': cmdenv.invoke(args.command, {}) if args.reference: index = open(args.reference_tmpl, 'r') index_contents = index.read() index.close() js_prepped = [ '<link rel="stylesheet" href="%s" type="text/css" />' % url for url in assets_env['css'].urls() ] css_prepped = [ '<script src="%s" type="text/javascript"></script>' % url for url in assets_env['js'].urls() ] index_contents = index_contents\
log.setLevel(logging.__dict__[args.loglevel]) loader = PythonLoader('webassets_config') assets_env = loader.load_environment() assets_env.debug = args.debug cmdenv = CommandLineEnvironment(assets_env, log) cmdenv.build() if args.debug: print("The following files are produced by assets pipeline:") print(assets_env['js'].urls()) print(assets_env['css'].urls()) if args.command != 'build': cmdenv.invoke(args.command, {}) if args.reference: index = open(args.reference_tmpl, 'r') index_contents = index.read() index.close() js_prepped = ['<link rel="stylesheet" href="%s" type="text/css" />' % url for url in assets_env['css'].urls()] css_prepped = ['<script src="%s" type="text/javascript"></script>' % url for url in assets_env['js'].urls()] index_contents = index_contents\ .replace('<!--JS_ASSETS-->', "\n".join(css_prepped))\ .replace('<!--CSS_ASSETS-->', "\n".join(js_prepped)) patched = open(args.reference_output ,'w+') patched.write(index_contents) patched.close()