Exemplo n.º 1
0
def static(path, input):
    '''Compile and collect static files'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    if exists(path):
        print('"{0}" directory already exists and will be erased'.format(path))
        if input and not prompt_bool('Are you sure'):
            exit(-1)

    cmdenv = CommandLineEnvironment(assets, log)
    # cmdenv.clean()
    cmdenv.build(production=True)

    print('Deleting static directory {0}'.format(path))
    shutil.rmtree(path)

    print('Copying assets into "{0}"'.format(path))
    shutil.copytree(assets.directory, path)

    for prefix, source in manager.app.config['STATIC_DIRS']:
        print('Copying %s to %s', source, prefix)
        destination_path = join(path, prefix)
        if not exists(destination_path):
            makedirs(destination_path)
        for filename in iglob(join(source, '*')):
            print(filename)
            if isdir(filename):
                continue
            shutil.copy(filename, destination_path)
        # shutil.copy(static_dir, path)

    print('Done')
Exemplo n.º 2
0
    def build(self):
        logger = getLogger('webassets')
        logger.addHandler(StreamHandler())
        logger.setLevel(DEBUG)

        cli_environment = CommandLineEnvironment(self.env, logger)
        cli_environment.invoke("build", args={})
Exemplo n.º 3
0
def js():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.WARNING)

    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 4
0
def main():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    call(["coffee", "-c", "src/tambur.coffee"])
    call(["coffee", "-c", "src/tambur_publisher.coffee"])

    env = Environment('.', '/static')
    jsonjs = Bundle(
            'deps/json2.js', filters='yui_js', output='out/json2.min.js')
    sockjs = Bundle(
            'deps/web_socket.js', filters='yui_js', output='out/web_socket.min.js')
    tamburjs = Bundle(
            'deps/swfobject.js',
            'src/tambur.js', output='out/tambur.js')
    tamburminjs = Bundle(
            'deps/swfobject.js',
            'src/tambur.js', filters='yui_js', output='out/tambur.min.js')
    publishjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', output='out/tambur_pub.js')
    publishminjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', filters='yui_js', output='out/tambur_pub.min.js')
    env.register('tambur.js', tamburjs)
    env.register('tambur.min.js', tamburminjs)
    env.register('tambur_pub.js', publishjs)
    env.register('tambur_pub.min.js', publishminjs)
    env.register('json2.js', jsonjs)
    env.register('web_socket.js', sockjs)
    cmdenv = CommandLineEnvironment(env, log)
    cmdenv.build()
Exemplo n.º 5
0
def _init_webassets(debug=False):
    assets_env = Environment(directory=SITE_ASSET_DIR,
                             url=SITE_ASSET_URL_PREFIX,
                             cache=WEBASSETS_CACHE_DIR,
                             load_path=[SITE_ASSET_SRC_DIR])
    assets_env.debug = debug

    js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js')
    css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css')

    assets_env.register('app_js', js)
    assets_env.register('app_css', css)

    cmd = CommandLineEnvironment(assets_env, log)

    p = Process(target=lambda: cmd.watch())

    def signal_handler(sig, frame):
        try:
            p.terminate()
        except Exception:
            pass
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler)
    p.start()

    return assets_env
Exemplo n.º 6
0
def build_assets():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 7
0
    def run(self):
        from webassets import Bundle
        from webassets import Environment
        from webassets.script import CommandLineEnvironment

        css = Bundle('curious/src/css/app.css',
                     output='curious/dist/curious.css')
        js = Bundle('curious/src/js/*.js', output='curious/dist/curious.js')
        jsm = Bundle('curious/src/js/*.js',
                     filters='jsmin',
                     output='curious/dist/curious.min.js')
        jst = Bundle('curious/src/html/*.html',
                     filters='jst',
                     output='curious/dist/curious_jst.js')

        assets_env = Environment('./curious/static')
        assets_env.cache = self.cache_dir
        assets_env.register('css', css)
        assets_env.register('js', js)
        assets_env.register('jsmin', jsm)
        assets_env.register('jst', jst)

        log = logging.getLogger('webassets')
        log.addHandler(logging.StreamHandler())
        log.setLevel(logging.DEBUG)

        cmdenv = CommandLineEnvironment(assets_env, log)
        cmdenv.build()
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
 def _build_webassets(self):
     # Set up a logger
     log = logging.getLogger('webassets')
     log.addHandler(logging.StreamHandler())
     log.setLevel(logging.DEBUG)
     cmdenv = CommandLineEnvironment(self.webassets_env, log)
     cmdenv.build()
Exemplo n.º 10
0
 def _build_webassets(self):
     # Set up a logger
     log = logging.getLogger('webassets')
     log.addHandler(logging.StreamHandler())
     log.setLevel(logging.DEBUG)
     cmdenv = CommandLineEnvironment(self.webassets_env, log)
     cmdenv.build()
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
def main():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    call(["coffee", "-c", "src/tambur.coffee"])
    call(["coffee", "-c", "src/tambur_publisher.coffee"])

    env = Environment('.', '/static')
    tamburjs = Bundle(
            'deps/sockjs-0.3.js',
            'src/tambur.js', output='out/tambur.js')
    tamburminjs = Bundle(
            'deps/sockjs-0.3.js',
            'src/tambur.js', filters='yui_js', output='out/tambur.min.js')
    publishjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', output='out/tambur_pub.js')
    publishminjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', filters='yui_js', output='out/tambur_pub.min.js')
    env.register('tambur.js', tamburjs)
    env.register('tambur.min.js', tamburminjs)
    env.register('tambur_pub.js', publishjs)
    env.register('tambur_pub.min.js', publishminjs)
    cmdenv = CommandLineEnvironment(env, log)
    cmdenv.build()
Exemplo n.º 13
0
Arquivo: cli.py Projeto: mardix/Mocha
def build_assets(app):
    from webassets.script import CommandLineEnvironment
    assets_env = app.jinja_env.assets_environment
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)
    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 14
0
 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)
Exemplo n.º 15
0
    def run(self):
        assets_env = get_webassets_env({
            'debug': False,
            'static_files_dir': STATIC,
        })

        cmdenv = CommandLineEnvironment(assets_env, log)
        cmdenv.build()

        self.copy_assets()
def clear_css_cache():
    import logging
    from webassets.script import CommandLineEnvironment

    # Setup a logger
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.clean()
Exemplo n.º 17
0
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', {})
Exemplo n.º 18
0
def build_assets(mod):
    from webassets.script import CommandLineEnvironment

    module = import_module(mod, True)
    assets_env = module.app.jinja_env.assets_environment

    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 19
0
def gen_static():
    # Setup a logger
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)
    assets_env = Environment()
    assets_env.directory = "static/"
    assets_env.debug = True
    assets_env.register(bundles)
    cmdenv = CommandLineEnvironment(assets_env, log)
    # This would also work
    cmdenv.build()
Exemplo n.º 20
0
def _buildassets(app):

    from webassets.script import CommandLineEnvironment

    module = get_app_serve_module(app)
    assets_env = module.app.jinja_env.assets_environment

    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 21
0
def scss_compile(static_path):
    webassets = Environment()
    webassets.directory = static_path
    webassets.url = static_path
    webassets.register('css_all', css_all)
    #webassets.manifest = 'cache' if not app.debug else False
    webassets.manifest = False
    webassets.cache = False
    webassets.debug = False
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)
    cmdenv = CommandLineEnvironment(webassets, log)
    # This would also work
    cmdenv.build()
Exemplo n.º 22
0
    def test_watch_config_file(self):
        """The watch command has an eye on the config file. This is an
        extension to the base watch command."""
        try:
            import yaml
        except ImportError:
            raise SkipTest()

        self.cmd_env = CommandLineEnvironment(self.env, logging)
        self.cmd_env.commands['watch'] = \
            GenericArgparseImplementation.WatchCommand(
                self.cmd_env, argparse.Namespace(config=self.path('config.yml')))

        self.create_files({'in': 'foo'})
        template = """
directory: .
bundles:
  foo:
    contents:
        - in
    output: %s
"""
        self.create_files({'config.yml': template % 'outA'})

        with self:
            time.sleep(0.1)
            # Change the config file; this change is detected; we update
            # the timestamp explicitly or we might not have enough precision
            self.create_files({'config.yml': template % 'outB'})
            self.setmtime('config.yml', mod=100)
            time.sleep(0.2)

        # The second output file has been built
        assert self.get('outB') == 'foo'
Exemplo n.º 23
0
 def _webassets_cmd(cmd):
     """Helper to run a webassets command."""
     from webassets.script import CommandLineEnvironment
     logger = logging.getLogger('webassets')
     logger.addHandler(logging.StreamHandler())
     logger.setLevel(logging.DEBUG)
     cmdenv = CommandLineEnvironment(
         current_app.jinja_env.assets_environment, logger)
     getattr(cmdenv, cmd)()
Exemplo n.º 24
0
def static(path, input):
    '''Compile and collect static files'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.build()

    if exists(path):
        print('"{0}" directory already exists and will be erased'.format(path))
        if input and not prompt_bool('Are you sure'):
            exit(-1)
        shutil.rmtree(path)

    print('Copying assets into "{0}"'.format(path))
    shutil.copytree(assets.directory, path)

    print('Done')
Exemplo n.º 25
0
def static(path, input):
    '''Compile and collect static files'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.build()

    if exists(path):
        print('"{0}" directory already exists and will be erased'.format(path))
        if input and not prompt_bool('Are you sure'):
            exit(-1)
        shutil.rmtree(path)

    print('Copying assets into "{0}"'.format(path))
    shutil.copytree(assets.directory, path)

    print('Done')
Exemplo n.º 26
0
def static(path, no_input):
    '''Compile and collect static files into path'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.build()

    if exists(path):
        warning('{0} directory already exists and will be {1}', white(path), white('erased'))
        if not no_input and not click.confirm('Are you sure'):
            exit_with_error()
        shutil.rmtree(path)

    echo('Copying assets into {0}', white(path))
    shutil.copytree(assets.directory, path)

    success('Done')
Exemplo n.º 27
0
def init_app(app):
    """
    Initilize assets.
    :param app:
    """
    if app.debug:
        webassets = Environment(app)
        webassets.url = app.static_url_path
        webassets.register('css_all', css_all)
        webassets.manifest = False
        webassets.cache = False
        webassets.debug = False
        webassets.cache = not app.debug
        webassets.debug = app.debug
        log = logging.getLogger('webassets')
        log.addHandler(logging.StreamHandler())
        log.setLevel(logging.DEBUG)
        cmdenv = CommandLineEnvironment(webassets, log)
        cmdenv.build()
Exemplo n.º 28
0
def static(path, no_input):
    '''Compile and collect static files into path'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.build()

    if exists(path):
        warning('{0} directory already exists and will be {1}', white(path), white('erased'))
        if not no_input and not click.confirm('Are you sure'):
            exit_with_error()
        shutil.rmtree(path)

    echo('Copying assets into {0}', white(path))
    shutil.copytree(assets.directory, path)

    success('Done')
Exemplo n.º 29
0
def build(silent=False):
    """ Build the static Files"""
    env = current_app.jinja_env.assets_environment

    cmd = CommandLineEnvironment(env, log)

    directory = env.get_directory()

    mybuild = BuildCommand(cmd)
    mybuild(directory=directory)
Exemplo n.º 30
0
def bundle(**kwargs):
    """
    Webassets bundle management.

    usage: blueberrypy bundle [options]

    Before you can use this command to bundle up your Web assets, you should
    have created either a project skeleton using the 'create' command or
    provided a configuration directory using the global option -c --config_dir.

    options:
      -h, --help                                show this help message and exit
      -C ENV_VAR_NAME, --env-var ENV_VAR_NAME   add the given config from
                                                environment variable name
                                                [default: BLUEBERRYPY_CONFIG]
      -b, --build                               build the asset bundles
      -w, --watch                               automatically rebuild the
                                                asset bundles upon changes in
                                                the static directory
      -c, --clean                               delete the generated asset bundles

    """

    config = BlueberryPyConfiguration(config_dir=kwargs.get('config_dir'),
                                      env_var_name=kwargs.get('env_var'))

    assets_env = config.webassets_env
    if not assets_env:
        raise BlueberryPyNotConfiguredError("Webassets configuration not found.")

    from webassets.script import CommandLineEnvironment
    assets_cli = CommandLineEnvironment(assets_env, logger)

    if kwargs.get("build"):
        try:
            assets_cli.build()
        except AttributeError:
            assets_cli.rebuild()
    elif kwargs.get("watch"):
        assets_cli.watch()
    elif kwargs.get("clean"):
        assets_cli.clean()
Exemplo n.º 31
0
 def test_watch_with_fixed_env_and_no_config(self):
     """[Regression[ The custom 'watch' command does not break if the
     CLI is initialized via fixed environment, instead of reading one from
     a configuration file.
     """
     self.cmd_env = CommandLineEnvironment(self.env, logging)
     self.cmd_env.commands['watch'] = \
         GenericArgparseImplementation.WatchCommand(
             self.cmd_env, argparse.Namespace())
     with self:
         time.sleep(0.1)
Exemplo n.º 32
0
class TestCLI(object):
    def setup(self):
        self.assets_env = Environment("", "")
        self.cmd_env = CommandLineEnvironment(self.assets_env, logging)

    def test_rebuild_container_bundles(self):
        """Test the rebuild command can deal with container bundles.
        """
        a = MockBundle(output="a")
        b1 = MockBundle(output="b1")
        b2 = MockBundle(output="b2")
        b = MockBundle(b1, b2)
        self.assets_env.add(a, b)

        self.cmd_env.rebuild()

        assert a.build_called
        assert not b.build_called
        assert b1.build_called
        assert b2.build_called
Exemplo n.º 33
0
class TestCLI(object):
    def setup(self):
        self.assets_env = Environment('', '')
        self.cmd_env = CommandLineEnvironment(self.assets_env, logging)

    def test_rebuild_container_bundles(self):
        """Test the rebuild command can deal with container bundles.
        """
        a = MockBundle(output='a')
        b1 = MockBundle(output='b1')
        b2 = MockBundle(output='b2')
        b = MockBundle(b1, b2)
        self.assets_env.add(a, b)

        self.cmd_env.rebuild()

        assert a.build_called
        assert not b.build_called
        assert b1.build_called
        assert b2.build_called
Exemplo n.º 34
0
def build():
    '''Compile static files'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    # Override some local config
    current_app.config['DEBUG'] = False
    current_app.config['ASSETS_DEBUG'] = False
    current_app.config['REQUIREJS_RUN_IN_DEBUG'] = True

    cmdenv = CommandLineEnvironment(assets, log)
    cmdenv.build(production=True)

    print('Performing require.js optimization')
    buildfile = join(assets.directory, 'js', 'app.build.js')
    # bust = 'pragmas.bust={0}'.format(time.time())
    params = ['r.js', '-o', buildfile]
    subprocess.call(params)

    print('Done')
Exemplo n.º 35
0
def build():
    '''Compile static files'''
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    # Override some local config
    current_app.config['DEBUG'] = False
    current_app.config['ASSETS_DEBUG'] = False
    current_app.config['REQUIREJS_RUN_IN_DEBUG'] = True

    cmdenv = CommandLineEnvironment(theme.assets, log)
    cmdenv.build(production=True)

    print('Performing require.js optimization')
    buildfile = join(theme.assets.directory, 'js', 'app.build.js')
    # bust = 'pragmas.bust={0}'.format(time.time())
    params = ['r.js', '-o', buildfile]
    subprocess.call(params)

    print('Done')
Exemplo n.º 36
0
def main():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    env = Environment('.', '/static')
    jsonjs = Bundle(
            'deps/json2.js', filters='yui_js', output='out/json2.min.js')
    sockjs = Bundle(
            'deps/web_socket.js', filters='yui_js', output='out/web_socket.min.js')
    tamburjs = Bundle(
            'deps/swfobject.js',
            'src/tambur_comet_fallback.js',
            'src/tambur_connection.js',
            'src/tambur_logger.js',
            'src/tambur_utils.js',
            'src/tambur_stream.js', output='out/tambur.js')
    tamburminjs = Bundle(
            'deps/swfobject.js',
            'src/tambur_comet_fallback.js',
            'src/tambur_connection.js',
            'src/tambur_logger.js',
            'src/tambur_utils.js',
            'src/tambur_stream.js', filters='yui_js', output='out/tambur.min.js')
    publishjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', output='out/tambur_pub.js')
    publishminjs = Bundle(
            'deps/sha1.js',
            'deps/oauth.js',
            'src/tambur_publisher.js', filters='yui_js', output='out/tambur_pub.min.js')
    env.register('tambur.js', tamburjs)
    env.register('tambur.min.js', tamburminjs)
    env.register('tambur_pub.js', publishjs)
    env.register('tambur_pub.min.js', publishminjs)
    env.register('json2.js', jsonjs)
    env.register('web_socket.js', sockjs)
    cmdenv = CommandLineEnvironment(env, log)
    cmdenv.build()
Exemplo n.º 37
0
def _init_webassets(debug=False, generate=False):
    assets_env = Environment(directory=SITE_ASSET_DIR,
                             url=SITE_ASSET_URL_PREFIX,
                             cache=WEBASSETS_CACHE_DIR,
                             load_path=[SITE_ASSET_SRC_DIR])
    assets_env.debug = debug

    js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js')
    css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css')

    assets_env.register('app_js', js)
    assets_env.register('app_css', css)

    cmd = CommandLineEnvironment(assets_env, log)

    if generate:
        cmd.build()
        return assets_env

    Process(target=lambda: cmd.watch()).start()

    return assets_env
Exemplo n.º 38
0
    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)
Exemplo n.º 39
0
def _init_webassets(debug=False, generate=False):
    assets_env = Environment(directory=SITE_ASSET_DIR,
                             url=SITE_ASSET_URL_PREFIX,
                             cache=WEBASSETS_CACHE_DIR,
                             load_path=[SITE_ASSET_SRC_DIR])
    assets_env.debug = debug

    js = Bundle('js/*.js', filters='uglifyjs', output='js/app.js')
    css = Bundle('sass/*.scss', filters='scss,cssmin', output='css/app.css')

    assets_env.register('app_js', js)
    assets_env.register('app_css', css)

    cmd = CommandLineEnvironment(assets_env, log)

    if generate:
        cmd.build()
        return assets_env

    Process(target=lambda: cmd.watch()).start()

    return assets_env
Exemplo n.º 40
0
  def run(self):
    from webassets import Bundle
    from webassets import Environment
    from webassets.script import CommandLineEnvironment

    css = Bundle('curious/src/css/app.css', output='curious/dist/curious.css')
    js = Bundle('curious/src/js/*.js', output='curious/dist/curious.js')
    jsmin = Bundle('curious/src/js/*.js', filters='jsmin', output='curious/dist/curious.min.js')
    jst = Bundle('curious/src/html/*.html', filters='jst', output='curious/dist/curious_jst.js')

    assets_env = Environment('./curious/static')
    assets_env.cache = self.cache_dir
    assets_env.register('css', css)
    assets_env.register('js', js)
    assets_env.register('jsmin', jsmin)
    assets_env.register('jst', jst)

    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)

    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.build()
Exemplo n.º 41
0
def bundle(**kwargs):
    """
    Webassets bundle management.

    usage: blueberrypy bundle [options]

    Before you can use this command to bundle up your Web assets, you should
    have created either a project skeleton using the 'create' command or
    provided a configuration directory using the global option -c --config_dir.

    options:
      -h, --help   show this help message and exit
      -b, --build  build the asset bundles
      -w, --watch  automatically rebuild the asset bundles upon changes in the
                   static directory
      -c, --clean  delete the generated asset bundles

    """

    config = BlueberryPyConfiguration(config_dir=kwargs.get("config_dir"))

    assets_env = config.webassets_env
    if not assets_env:
        raise BlueberryPyNotConfiguredError("Webassets configuration not found.")

    from webassets.script import CommandLineEnvironment
    assets_cli = CommandLineEnvironment(assets_env, logger)

    if kwargs.get("build"):
        try:
            assets_cli.build()
        except AttributeError:
            assets_cli.rebuild()
    elif kwargs.get("watch"):
        assets_cli.watch()
    elif kwargs.get("clean"):
        assets_cli.clean()
Exemplo n.º 42
0
def build(debug=True, cache=True):
    env = _setup_env(debug, cache)
    log = _load_logger()
    cmdenv = CommandLineEnvironment(env, log)

    cmdenv.rebuild()
Exemplo n.º 43
0
def assets_():
    CommandLineEnvironment(assets, getLogger('flask')).build()
Exemplo n.º 44
0
                   'js/app.js',
                   filters='uglifyjs',
                   output='js/electris-footer.min.js')

css = Bundle('bootstrap/css/bootstrap.min.css',
             'bootstrap/css/bootstrap-responsive.min.css',
             'css/template.css',
             'css/app.css',
             'css/sponsorship.css',
             filters='yui_css',
             output='css/electris.min.css')

static.register('js_header', header_js)
static.register('js_footer', footer_js)
static.register('css', css)

header_js.urls()
footer_js.urls()
css.urls()

import logging
from webassets.script import CommandLineEnvironment

# Setup a logger
log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

cmdenv = CommandLineEnvironment(static, log)
cmdenv.watch()
Exemplo n.º 45
0
 def setup(self):
     self.assets_env = Environment('', '')
     self.cmd_env = CommandLineEnvironment(self.assets_env, logging)
Exemplo n.º 46
0
def build_assets():
    from webassets.script import CommandLineEnvironment
    CommandLineEnvironment(env, assets_logger).build()
Exemplo n.º 47
0
def compile():
    """Compile assets."""

    log = logging.getLogger(__name__)
    cmd = CommandLineEnvironment(get_env(), log)
    cmd.build()
Exemplo n.º 48
0
def watch(debug=False, cache=False):
    env = _setup_env(debug, cache)
    log = _load_logger()
    cmdenv = CommandLineEnvironment(env, log)

    cmdenv.watch()
Exemplo n.º 49
0
def build_assets():
    CommandLineEnvironment(assets_env, logger).build()
Exemplo n.º 50
0
import logging
from os import makedirs, path

from webassets.script import CommandLineEnvironment
from cunhajacaiu import assets
from cunhajacaiu.settings import STATIC_PATH

for dir in ('css', 'js'):
    makedirs(path.join(path.abspath(STATIC_PATH), dir), exist_ok=True)

log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

cli = CommandLineEnvironment(assets, log)
cli.build()
Exemplo n.º 51
0
    filters='uglifyjs',
    output='js/electris-footer.min.js')

css = Bundle(
    'bootstrap/css/bootstrap.min.css',
    'bootstrap/css/bootstrap-responsive.min.css',
    'css/template.css',
    'css/app.css',
    'css/sponsorship.css',
    filters='yui_css',
    output='css/electris.min.css')

static.register('js_header', header_js)
static.register('js_footer', footer_js)
static.register('css', css)

header_js.urls()
footer_js.urls()
css.urls()

import logging
from webassets.script import CommandLineEnvironment

# Setup a logger
log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

cmdenv = CommandLineEnvironment(static, log)
cmdenv.watch()
Exemplo n.º 52
0
def watch_assets():
    log = logging.getLogger('webassets')
    log.addHandler(logging.StreamHandler())
    log.setLevel(logging.DEBUG)
    cmdenv = CommandLineEnvironment(assets_env, log)
    cmdenv.watch()
Exemplo n.º 53
0
import logging

from webassets import Environment
from webassets import Bundle
from webassets.script import CommandLineEnvironment

# Bundle and minify the javascript
# Since Flask isn't serving the JS this needs to be done here
# before the static files are pulled down on nginx
# Kind of not the way I was hoping to handle this

log = logging.getLogger('webassets')
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)

env = Environment('mojibake/static', '/static')
js = Bundle('js/jquery.min.js',
            'js/jquery-ui.custom.js',
            'js/skel.min.js',
            'js/skel-panels.min.js',
            'js/init.js',
            'js/mojibake.js',
            filters='jsmin',
            output='js/packed.js')
env.register('js_all', js)

# From the docs
# https://webassets.readthedocs.org/en/latest/script.html
cmdenv = CommandLineEnvironment(env, log)
cmdenv.build()
Exemplo n.º 54
0
def compile():
    """Compile assets."""

    log = logging.getLogger(__name__)
    cmd = CommandLineEnvironment(get_env(), log)
    cmd.build()
Exemplo n.º 55
0
 def setup(self):
     super(TestCLI, self).setup()
     self.assets_env = self.env
     self.cmd_env = CommandLineEnvironment(self.assets_env, logging)
Exemplo n.º 56
0
def compile():
    assets_cle = CommandLineEnvironment(current_app.assets, current_app.logger)
    assets_cle.build()