def start(): """ Start processing from the command line Loads the path to the config (from the argument variables) and runs the minification process run with squeezeit [relative path to bundle config file] """ #Confirm the command line arguments exist if len(squeezeit.sys.argv) <= 1: squeezeit.logging.critical("Pass the location of the bundle file. See readme") squeezeit.sys.exit(1) bundleconfig = squeezeit.sys.argv[1] #Start the processing (Yes that's about it for this file) squeezeit.compress(bundleconfig)
def init_squeezeit(config, dep_pathes): """ By using *squeezeit* library - minimize, pack and combine js/css files to bundles. Next check their names and prepare it to later include in jinja templates. Prepare static view *static* that will serve files from squeezeit output directory. """ s = config.registry.settings prefered_version = s.get('projectksi.web_deps.squeezeit.prefered_version', 'gz') config_path = s.get('projectksi.web_deps.squeezeit.config', '../config.yaml') #Start the processing squeezeit.compress(config_path) #os.remove(tmp_config_path) publish_path = dep_pathes['output'] try: include_css = config.registry.include_css except AttributeError: include_css = [] try: include_js = config.registry.include_js except AttributeError: include_js = [] yaml_files = [f for f in os.listdir(publish_path) if f.endswith('.yaml')] for f in yaml_files: stream = open('/'.join([publish_path, f]), 'r') data = yaml.load(stream) stream.close() if 'css' in data['ksipack']: include_css.append(data['ksipack']['css']['output'][prefered_version]) if 'javascript' in data['ksipack']: include_js.append(data['ksipack']['javascript']['output'][prefered_version]) rel_publish_dir = relpath(publish_path, './projectksi') config.registry.include_css = ['/'.join([rel_publish_dir, f]) for f in include_css] config.registry.include_js = ['/'.join([rel_publish_dir, f]) for f in include_js] config.add_static_view('static', rel_publish_dir, cache_max_age=3600)