def test_post_processing(self): """ post_processing behaves correctly. Files that are alterable should always be post-processed; files that aren't should be skipped. collectstatic has already been called once in setUp() for this testcase, therefore we check by verifying behavior on a second run. """ collectstatic_args = { 'interactive': False, 'verbosity': 0, 'link': False, 'clear': False, 'dry_run': False, 'post_process': True, 'use_default_ignore_patterns': True, 'ignore_patterns': ['*.ignoreme'], } collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**collectstatic_args) stats = collectstatic_cmd.collect() self.assertIn(os.path.join('cached', 'css', 'window.css'), stats['post_processed']) self.assertIn(os.path.join('cached', 'css', 'img', 'window.png'), stats['unmodified']) self.assertIn(os.path.join('test', 'nonascii.css'), stats['post_processed']) self.assertPostCondition()
def test_post_processing(self): """Test that post_processing behaves correctly. Files that are alterable should always be post-processed; files that aren't should be skipped. collectstatic has already been called once in setUp() for this testcase, therefore we check by verifying behavior on a second run. """ collectstatic_args = { 'interactive': False, 'verbosity': '0', 'link': False, 'clear': False, 'dry_run': False, 'post_process': True, 'use_default_ignore_patterns': True, 'ignore_patterns': ['*.ignoreme'], } collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**collectstatic_args) stats = collectstatic_cmd.collect() self.assertIn(os.path.join('cached', 'css', 'window.css'), stats['post_processed']) self.assertIn(os.path.join('cached', 'css', 'img', 'window.png'), stats['unmodified']) self.assertIn(os.path.join('test', 'nonascii.css'), stats['post_processed'])
def test_post_processing(self): """ Test that post_processing behaves correctly. Files that are alterable should always be post-processed; files that aren't should be skipped. collectstatic has already been called once in setUp() for this testcase, therefore we check by verifying behavior on a second run. """ collectstatic_args = { "interactive": False, "verbosity": 0, "link": False, "clear": False, "dry_run": False, "post_process": True, "use_default_ignore_patterns": True, "ignore_patterns": ["*.ignoreme"], } collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**collectstatic_args) stats = collectstatic_cmd.collect() self.assertIn(os.path.join("cached", "css", "window.css"), stats["post_processed"]) self.assertIn(os.path.join("cached", "css", "img", "window.png"), stats["unmodified"]) self.assertIn(os.path.join("test", "nonascii.css"), stats["post_processed"])
def test_post_processing(self): """ post_processing behaves correctly. Files that are alterable should always be post-processed; files that aren't should be skipped. collectstatic has already been called once in setUp() for this testcase, therefore we check by verifying behavior on a second run. """ collectstatic_args = { "interactive": False, "verbosity": 0, "link": False, "clear": False, "dry_run": False, "post_process": True, "use_default_ignore_patterns": True, "ignore_patterns": ["*.ignoreme"], } collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**collectstatic_args) stats = collectstatic_cmd.collect() self.assertIn(os.path.join("cached", "css", "window.css"), stats["post_processed"]) self.assertIn(os.path.join("cached", "css", "img", "window.png"), stats["unmodified"]) self.assertIn(os.path.join("test", "nonascii.css"), stats["post_processed"]) # No file should be yielded twice. self.assertCountEqual(stats["post_processed"], set(stats["post_processed"])) self.assertPostCondition()
def handle(self, **options): self.set_options(**options) force = options.get('force', False) # base page_themes = 0 tpl_dirs = merge(DIRS, app_template_dirs) templatedirs = [d for d in tpl_dirs if os.path.isdir(d)] for templatedir in templatedirs: for dirpath, subdirs, filenames in os.walk(templatedir): if 'base/page' in dirpath: for f in filenames: # ignore private and hidden members if not f.startswith("_") and not f.startswith("."): page_template = get_or_create_template( f, force=force, prefix="base/page") if not page_template: self.stdout.write("Missing template %s" % f) continue # create themes with bases try: page_theme = PageTheme.objects.get( name=f.split(".")[0]) except PageTheme.DoesNotExist: page_theme = PageTheme() page_theme.label = '{} layout'.format( f.split(".")[0].title()) page_theme.name = f.split(".")[0] page_theme.template = page_template page_theme.save() page_themes += 1 if page_themes > 0: self.stdout.write( 'Successfully created {} page themes'.format(page_themes)) cmd = CollectStatic() cmd.stdout = self.stdout collect_static = cmd.handle( **{ 'interactive': False, 'link': False, 'clear': False, 'dry_run': False, 'ignore_patterns': [], 'use_default_ignore_patterns': True, 'post_process': True, 'verbosity': 0 }) collected = self.collect() self.stdout.write("Page themes synced {}".format( self.page_themes_updated)) self.stdout.write("Page Skins synced {}".format(self.skins_updated))
def handle(self, **options): self.set_options(**options) force = options.get('force', False) # base page_themes = 0 tpl_dirs = merge(DIRS, app_template_dirs) templatedirs = [d for d in tpl_dirs if os.path.isdir(d)] for templatedir in templatedirs: for dirpath, subdirs, filenames in os.walk(templatedir): if 'base/page' in dirpath: for f in filenames: # ignore private and hidden members if not f.startswith("_") and not f.startswith("."): page_template = get_or_create_template( f, force=force, prefix="base/page") if not page_template: self.stdout.write("Missing template %s" % f) continue # create themes with bases try: page_theme = PageTheme.objects.get( name=f.split(".")[0]) except PageTheme.DoesNotExist: page_theme = PageTheme() page_theme.label = '{} layout'.format( f.split(".")[0].title()) page_theme.name = f.split(".")[0] page_theme.template = page_template page_theme.save() page_themes += 1 if page_themes > 0: self.stdout.write( 'Successfully created {} page themes'.format(page_themes)) cmd = CollectStatic() cmd.stdout = self.stdout collect_static = cmd.handle( **{'interactive': False, 'link': False, 'clear': False, 'dry_run': False, 'ignore_patterns': [], 'use_default_ignore_patterns': True, 'post_process': True, 'verbosity': 0}) collected = self.collect() self.stdout.write( "Page themes synced {}".format(self.page_themes_updated)) self.stdout.write("Page Skins synced {}".format(self.skins_updated))
def delete_file(self, path, prefixed_path, source_storage): if self.comparison_method == 'modified_time': return CollectStatic.delete_file(self, path, prefixed_path, source_storage) elif self.storage.exists(prefixed_path): should_delete = self.compare(path, prefixed_path, source_storage) if should_delete: if self.dry_run: self.log(u"Pretending to delete '%s'" % path) else: self.log(u"Deleting '%s'" % path) self.storage.delete(prefixed_path) else: self.log(u"Skipping '%s' (not modified)" % path) return False return True
def auto_collectstatic(): c = Command() options = { "verbosity": 1, "settings": None, "pythonpath": None, "traceback": False, "no_color": False, "interactive": False, "post_process": True, "ignore_patterns": [], "dry_run": False, "clear": False, "link": False, "use_default_ignore_patterns": True, } c.interactive = options["interactive"] c.verbosity = options["verbosity"] c.symlink = options["link"] c.clear = options["clear"] c.dry_run = options["dry_run"] ignore_patterns = options["ignore_patterns"] if options["use_default_ignore_patterns"]: ignore_patterns += apps.get_app_config("staticfiles").ignore_patterns c.ignore_patterns = list(set(ignore_patterns)) c.post_process = options["post_process"] c.collect()
def collect(self): collectstatic_cmd = CollectstaticCommand() collectstatic_cmd.set_options(**COLLECTSTATIC_ARGS) return collectstatic_cmd.collect()