def test_can_remove_file(): f = FS(__file__).parent c = f.child_folder('__test__') c.make() assert c.exists txt = "abc" abc = File(c.child('abc.txt')) abc.write(txt) assert abc.exists abc.delete() assert not abc.exists abc.delete() assert True # No Exception c.delete()
def _create_tag_archive(self, config): """ Generates archives for each tag based on the given configuration. """ if not 'template' in config: raise self.template.exception_class( "No Template specified in tagger configuration.") content = self.site.content.source_folder source = Folder(config.get('source', '')) target = content.child_folder(config.get('target', 'tags')) if not target.exists: target.make() # Write meta data for the configuration meta = config.get('meta', {}) meta_text = u'' if meta: import yaml meta_text = yaml.dump(meta, default_flow_style=False) extension = config.get('extension', 'html') template = config['template'] archive_text = u""" --- extends: false %(meta)s --- {%% set tag = site.tagger.tags['%(tag)s'] %%} {%% set source = site.content.node_from_relative_path('%(node)s') %%} {%% set walker = source['walk_resources_tagged_with_%(tag_nospace)s'] %%} {%% extends "%(template)s" %%} """ for tagname, tag in self.site.tagger.tags.to_dict().iteritems(): tag_data = { "tag": tagname, "tag_nospace": tagname.replace(' ','_'), "node": source.name, "template": template, "meta": meta_text } text = archive_text % tag_data archive_file = File(target.child("%s.%s" % (tagname, extension))) archive_file.delete() archive_file.write(text.strip()) self.site.content.add_resource(archive_file)
def _create_tag_archive(self, config): """ Generates archives for each tag based on the given configuration. """ if not 'template' in config: raise self.template.exception_class( "No Template specified in tagger configuration.") content = self.site.content.source_folder source = Folder(config.get('source', '')) target = content.child_folder(config.get('target', 'tags')) if not target.exists: target.make() # Write meta data for the configuration meta = config.get('meta', {}) meta_text = u'' if meta: import yaml meta_text = yaml.dump(meta, default_flow_style=False) extension = config.get('extension', 'html') template = config['template'] archive_text = u""" --- extends: false %(meta)s --- {%% set tag = site.tagger.tags['%(tag)s'] %%} {%% set source = site.content.node_from_relative_path('%(node)s') %%} {%% set walker = source['walk_resources_tagged_with_%(tag)s'] %%} {%% extends "%(template)s" %%} """ for tagname, tag in self.site.tagger.tags.to_dict().iteritems(): tag_data = { "tag": tagname, "node": source.name, "template": template, "meta": meta_text } text = archive_text % tag_data archive_file = File(target.child("%s.%s" % (tagname, extension))) archive_file.delete() archive_file.write(text.strip()) self.site.content.add_resource(archive_file)
def _create_group_archive(self, config,groupname): """ Generates archives for each tag based on the given configuration. """ if not 'template' in config: raise self.template.exception_class( "No Template specified in grouper configuration.") content = self.site.content.source_folder source = Folder(config.get('source', '')) target = content.child_folder(config.get('target', 'groups')) if not target.exists: target.make() # Write meta data for the configuration meta = config.get('meta', {}) meta_text = u'' if meta: import yaml meta_text = yaml.dump(meta, default_flow_style=False) extension = config.get('extension', 'html') template = config['template'] archive_text = u""" --- extends: false %(meta)s --- {%% set tag = site.groups_index['%(group)s'] %%} {%% set source = site.content.node_from_relative_path('%(node)s') %%} {%% set walker = source.walk_resources_grouped_by_%(group)s %%} {%% extends "%(template)s" %%} """ group_data = { "group": groupname, "node": source.name, "template": template, "meta": meta_text } text = archive_text % group_data archive_file = File(target.child("%s.%s" % (groupname, extension))) archive_file.delete() archive_file.write(text.strip()) self.site.content.add_resource(archive_file)