def parse_new_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] if post_content: post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) dir_name = os.path.join(settings.PUBLISH_DIR, post_tmp.url.strip("/\\")) file_path = os.path.join(dir_name, 'index.html') if os.path.exists(file_path): os.remove(file_path) else: logger.warning("Field to remove file: '{0}".format(post_tmp.title)) post_tmp = Post(filename=filename) file_content = open(os.path.join(filename),'r')\ .read().decode('utf8') if not post_tmp.check_illegal(file_content, filename=filename): # If the post_content is not illegal, pass it. logger.warning("This post doesn't have a correct format: '{0}".format(filename)) continue else: post_tmp.parse() self.posts.append(post_tmp) self.new_posts.append(post_tmp) post_dict = post_tmp.__dict__.copy() post_dict['pub_time'] = time.mktime( post_dict['pub_time'].timetuple()) post_dict.pop('config', None) last_mod_time = os.path.getmtime( os.path.join(filename)) post_dict_in_db = { 'last_mod_time': last_mod_time, 'content': post_dict} self.database.set_item('posts', filename, post_dict_in_db)
def parse_removed_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) self.database.remove_item('posts', filename) self.removed_posts.append(post_tmp) dname = os.path.join(settings.PUBLISH_DIR, post_tmp.url.strip("/\\")) filepath = os.path.join(dname, 'index.html') try: os.remove(filepath) except Exception, e: logger.warning("Field to remove file: '{0}".format(post_tmp.title))
def parse_removed_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) self.database.remove_item('posts', filename) self.removed_posts.append(post_tmp) dname = os.path.join(settings.PUBLISH_DIR, post_tmp.url.strip("/\\")) filepath = os.path.join(dname, 'index.html') try: os.remove(filepath) except Exception, e: logger.warning("Field to remove file: '{0}".format( post_tmp.title))
def parse_old_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) self.posts.append(post_tmp) post_dict = post_tmp.__dict__.copy() post_dict['pub_time'] = time.mktime( post_dict['pub_time'].timetuple()) post_dict.pop('config', None) last_mod_time = os.path.getmtime( os.path.join(filename)) post_dict_in_db = { 'last_mod_time': last_mod_time, 'content': post_dict} self.database.set_item('posts', filename, post_dict_in_db)
def parse_old_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) self.posts.append(post_tmp) post_dict = post_tmp.__dict__.copy() post_dict['pub_time'] = time.mktime( post_dict['pub_time'].timetuple()) post_dict.pop('config', None) last_mod_time = os.path.getmtime(os.path.join(filename)) post_dict_in_db = { 'last_mod_time': last_mod_time, 'content': post_dict } self.database.set_item('posts', filename, post_dict_in_db)
def parse_new_posts(self, filename_list): for filename in filename_list: post_content = self.database.get_item('posts', filename)['content'] if post_content: post_tmp = Post(filename=filename) post_tmp.parse_from_db(post_content) dir_name = os.path.join(settings.PUBLISH_DIR, post_tmp.url.strip("/\\")) file_path = os.path.join(dir_name, 'index.html') if os.path.exists(file_path): os.remove(file_path) else: logger.warning("Field to remove file: '{0}".format( post_tmp.title)) post_tmp = Post(filename=filename) file_content = open(os.path.join(filename),'r')\ .read().decode('utf8') if not post_tmp.check_illegal(file_content, filename=filename): # If the post_content is not illegal, pass it. logger.warning( "This post doesn't have a correct format: '{0}".format( filename)) continue else: post_tmp.parse() self.posts.append(post_tmp) self.new_posts.append(post_tmp) post_dict = post_tmp.__dict__.copy() post_dict['pub_time'] = time.mktime( post_dict['pub_time'].timetuple()) post_dict.pop('config', None) last_mod_time = os.path.getmtime(os.path.join(filename)) post_dict_in_db = { 'last_mod_time': last_mod_time, 'content': post_dict } self.database.set_item('posts', filename, post_dict_in_db)