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))