本文整理汇总了Python中post.Post.normalize方法的典型用法代码示例。如果您正苦于以下问题:Python Post.normalize方法的具体用法?Python Post.normalize怎么用?Python Post.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类post.Post
的用法示例。
在下文中一共展示了Post.normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_drafts
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import normalize [as 别名]
def process_drafts(self):
"""
Traverse drafts dir looking for posts to publish
"""
tools.mkdirp(self.s.DRAFTS_PUBLISH_NOW_DIR)
for f in os.listdir(self.s.DRAFTS_DIR):
if f.endswith(self.s.MD_EXT):
# skip files scheduled for publishing
if os.path.exists(os.path.join(self.s.DRAFTS_PUBLISH_NOW_DIR, f)): continue
# Create post instance from file
logging.info("Creating post instance from file %s." % f)
try:
post = Post(os.path.join(self.s.DRAFTS_DIR, f), self.s)
except PostIsDraftException:
continue
if post.status and (post.status.upper() == self.s.POST_STATUS_PUBLISH.upper()):
post.normalize()
self.prepare_post(post)
template = self.j2.get_template(self.s.PERMALINK_TEMPLATE)
html = template.render(
blog_title=self.s.BLOG_TITLE,
blog_url=self.s.BLOG_URL,
blog_description=self.s.BLOG_DESCRIPTION,
post=post,
prev_page_url=None,
next_page_url=None,
)
fname = "%s%s" % (os.path.splitext(os.path.split(f)[1])[0], self.s.HTML_EXT)
self.write_html(self.s.DRAFTS_PREVIEW_DIR, fname, html)
logging.info("Wrote preview post to %s" % fname)
示例2: process_publish_now
# 需要导入模块: from post import Post [as 别名]
# 或者: from post.Post import normalize [as 别名]
def process_publish_now(self, publish_future=False):
"""
Scans PUBLISH_NOW_DIR for post with 'publish' status.
Args:
publish_future:
if False, won't publish posts with date later than today.
if True, will publish everything in directory.
"""
for f in os.listdir(self.s.DRAFTS_PUBLISH_NOW_DIR):
if f.endswith(self.s.MD_EXT):
source_file = os.path.join(self.s.DRAFTS_PUBLISH_NOW_DIR, f)
post = Post(source_file, self.s)
if not publish_future:
# skip future posts
if self.is_in_future(post):
continue
post.set_status(published=True)
post.normalize()
# Check layout: post or page?
if post.layout.lower()==self.s.POST_TYPE_PAGE.lower():
dest_fname = "%s%s" % (post.slug, self.s.MD_EXT)
dest_dir = self.s.PAGES_DIR
tools.mkdirp(dest_dir)
try:
shutil.copy(source_file, os.path.join(dest_dir, dest_fname))
os.remove(source_file)
self.remove_post_review(post)
except IOError as e:
logging.error('Could not move file %s to %s. Error: %s.' % (source_file,
os.path.join(dest_dir, dest_fname), e))
else:
sequence = self.get_next_sequence(post.date.year, post.date.month, post.date.day)
# output filename has form YYYYMMDD-p##-slug.md
if sequence > self.s.MAX_POSTS_PER_DAY:
raise Exception("Max posts per day is 99. Got %d posts for %04d-%02d-%02d." %
sequence, post.date.year, post.date.month, post.date.day
)
dest_fname = "%04d%02d%02d-p%02d-%s%s" % (post.date.year,
post.date.month, post.date.day,
sequence,
post.slug, self.s.MD_EXT)
# copy post to posts dir YYYY/MM
dest_dir = os.path.join(self.s.POSTS_DIR, "%04d" % post.date.year, "%02d" % post.date.month)
tools.mkdirp(dest_dir)
try:
shutil.copy(source_file, os.path.join(dest_dir, dest_fname))
os.remove(source_file)
except IOError as e:
logging.error('Could not move file %s to %s. Error: %s.' % (source_file,
os.path.join(dest_dir, dest_fname), e))