本文整理汇总了Python中hydeengine.file_system.File类的典型用法代码示例。如果您正苦于以下问题:Python File类的具体用法?Python File怎么用?Python File使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了File类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_variables_are_added
def test_variables_are_added(self):
vars = {}
vars["title"] = "Test Title"
vars["created"] = datetime.now()
vars["updated"] = datetime.now() + timedelta(hours=1)
content = "{%hyde\n"
for key, value in vars.iteritems():
content += " %s: %s\n" % (key, value)
content += "%}"
out = File(self.site.content_folder.child("test_yaml.html"))
self.site.monitor(self.queue)
t = Thread(target=self.yaml_checker,
kwargs={"path":out.path, "vars":vars})
t.start()
out.write(content)
t.join()
assert self.exception_queue.empty()
# Ensure default values are added for all pages
#
temp = File(self.site.content_folder.child("test.html"))
temp.write('text')
page = Page(temp, self.site.content_node)
assert not page.title
assert page.created == datetime.strptime("2000-01-01", "%Y-%m-%d")
assert page.updated == page.created
temp.delete()
out.delete()
示例2: doget
def doget(self, site):
path = self.get_argument("path", None)
if not path:
return
f = File(self.siteinfo.folder.child(path))
if not f.exists:
return
self.write(f.read_all())
示例3: dopost
def dopost(self, site):
path = self.get_argument("path", None)
if not path: return
content = self.get_argument("content", None)
f = File(self.siteinfo.folder.child(path))
f.write(content)
repo = self.settings['sites'][site]['repo']
dvcs = DVCS.load_dvcs(self.siteinfo.folder.path, repo)
dvcs.save_draft()
示例4: test_process_page_rendering
def test_process_page_rendering(self):
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("test_src.html"))
self.site.refresh()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_valid_html})
t.start()
source.copy_to(self.site.content_folder.child("test.html"))
t.join()
assert self.exception_queue.empty()
示例5: test_delete
def test_delete(self):
f = File(self.site.content_folder.child("test.ddd"))
f.write("test")
self.site.refresh()
self.clean_queue()
self.site.monitor(self.queue)
t = Thread(target=self.change_checker,
kwargs={"change":"Deleted", "path":f.path})
t.start()
f.delete()
t.join()
assert self.exception_queue.empty()
示例6: test_add
def test_add(self, direct=False):
self.site.monitor(self.queue)
path = self.site.layout_folder.child("test.ggg")
t = Thread(target=self.change_checker,
kwargs={"change":"Added", "path":path})
t.start()
f = File(path)
f.write("test")
t.join()
if not direct:
f.delete()
assert self.exception_queue.empty()
示例7: test_dates_are_converted_to_datetime
def test_dates_are_converted_to_datetime(self):
vars = {}
vars["created"] = datetime.now().date()
vars["updated"] = (datetime.now() + timedelta(hours=1)).date()
content = "{%hyde\n"
for key, value in vars.iteritems():
content += " %s: %s\n" % (key, value)
content += "%}"
out = File(self.site.content_folder.child("test_yaml.html"))
out.write(content)
page = Page(out, self.site.content_node)
assert not page.title
assert page.created == datetime.combine(vars["created"], time())
assert page.updated == datetime.combine(vars["updated"], time())
out.delete()
示例8: test_delete_dir
def test_delete_dir(self):
d = self.site.content_folder.child_folder("test_test")
f = File(d.child("test.nnn"))
d.make()
f.write("test")
self.site.refresh()
self.clean_queue()
self.site.monitor(self.queue)
t = Thread(target=self.node_remove_checker,
kwargs={"change":"NodeRemoved", "path":d.path})
t.start()
d.delete()
t.join()
d.delete()
assert self.exception_queue.empty()
示例9: test_textile
def test_textile(self):
try:
import textile
except ImportError:
textile = False
print "Textile not found, skipping unit tests"
if textile:
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("src_test_textile.html"))
self.site.refresh()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_valid_textile})
t.start()
source.copy_to(self.site.content_folder.child("test.html"))
t.join()
assert self.exception_queue.empty()
示例10: test_process_css_with_templates
def test_process_css_with_templates(self):
original_MP = settings.MEDIA_PROCESSORS
original_site = settings.SITE_ROOT
settings.MEDIA_PROCESSORS = {"*":{".css":
('hydeengine.media_processors.TemplateProcessor',)}}
settings.SITE_ROOT = "www.hyde-test.bogus/"
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("test_src.css"))
self.site.refresh()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_valid_css})
t.start()
source.copy_to(self.site.media_folder.child("test.css"))
t.join()
settings.MEDIA_PROCESSORS = original_MP
settings.SITE_ROOT = original_site
assert self.exception_queue.empty()
示例11: test_underscored_pages_are_not_rendered
def test_underscored_pages_are_not_rendered(self):
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("test_src.html"))
target = File(self.site.content_folder.child("_test.html"))
self.site.refresh()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_layout_not_rendered})
t.start()
source.copy_to(target)
t.join()
target.delete()
assert self.exception_queue.empty()
示例12: test_restructuredtext
def test_restructuredtext(self):
try:
import docutils
except ImportError:
docutils = False
print "Docutils not found, skipping unit tests"
if docutils:
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("src_test_restructuredtext.html"))
self.site.refresh()
assert self.queue.empty()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_valid_restructuredtext})
t.start()
target = File(self.site.content_folder.child("test.html"))
source.copy_to(target)
t.join()
target.delete()
assert self.exception_queue.empty()
示例13: test_markdown
def test_markdown(self):
try:
import markdown
except ImportError:
markdown = False
print "Markdown not found, skipping unit tests"
if markdown:
self.generator = Generator(TEST_SITE.path)
self.generator.build_siteinfo()
source = File(TEST_ROOT.child("src_test_markdown.html"))
self.site.refresh()
assert self.queue.empty()
self.site.monitor(self.queue)
t = Thread(target=self.checker,
kwargs={"asserter":self.assert_valid_markdown})
t.start()
target = File(self.site.content_folder.child("test_md.html"))
source.copy_to(target)
t.join()
target.delete()
assert self.exception_queue.empty()
示例14: test_filters
def test_filters(self):
site = SiteInfo(settings, TEST_SITE.path)
for name in [".banjo", ".hidden", "junk.abc~"]:
f = File(site.content_folder.child(name))
self.files.append(f)
f.write("junk")
git = site.content_folder.child_folder(".git")
git_child = git.child_folder("child")
git_child_pack = File(git_child.child("pack"))
git.make()
git_child.make()
git_index = File(git.child("index"))
git_index.write("junk")
git_child_pack.write("junk")
original_exclude = settings.FILTER['exclude']
original_include = settings.FILTER['include']
settings.FILTER = {}
site = SiteInfo(settings, TEST_SITE.path)
site.refresh()
for f in self.files:
assert site.find_resource(f)
assert site.find_node(git)
assert site.find_resource(git_index)
assert site.find_node(git_child)
assert site.find_resource(git_child_pack)
settings.FILTER = {
'include': (),
'exclude': (".*","*~")
}
site = SiteInfo(settings, TEST_SITE.path)
site.refresh()
for f in self.files:
assert not site.find_resource(f)
assert not site.find_node(git)
assert not site.find_resource(git_index)
assert not site.find_node(git_child)
assert not site.find_resource(git_child_pack)
settings.FILTER = {
'include': (".banjo",),
'exclude': (".*","*~")
}
site = SiteInfo(settings, TEST_SITE.path)
site.refresh()
for f in self.files:
if f.name == ".banjo":
assert site.find_resource(f)
else:
assert not site.find_resource(f)
assert not site.find_node(git)
assert not site.find_resource(git_index)
settings.FILTER['exclude'] = original_exclude
settings.FILTER['include'] = original_include
self.files.append(git)