def sub(root): res = [] for root, filename in ltools.filter_files(fltr, root, *(subdirs[1:])): res.append(ltools.join('/', *(subdirs + (filename,)))) ltools.copy(ltools.join(root, filename), ltools.join(out_root, filename)) return res
def sub(root): res = [] for root, filename in ltools.filter_files(fltr, root, *(subdirs[1:])): res.append(ltools.join('/', *(subdirs + (filename, )))) ltools.copy(ltools.join(root, filename), ltools.join(out_root, filename)) return res
def load(self, modules, args): self.build_dir = tempfile.mkdtemp(prefix='lpbm_') if args.output is not None: self.output_dir = ltools.abspath(args.output) else: self.output_dir = ltools.join(args.exec_path, 'result') if not os.path.exists(self.output_dir): msg = 'I didn\'t find directory/symbolic link named `{path}`' msg += ' where to put the blog.' sys.exit(msg.format(path=self.output_dir)) if not args.noconfirm: msg = 'Are you sure you want to generate your blog in `{path}`?\n' msg += 'This action will remove all its contents!' if not ltools.ask_sure(prompt=msg.format(path=self.output_dir)): sys.exit('Nothing was done.') theme = self.modules['config']['theme.name'] or 'default' if args.theme is not None: theme = args.theme self.root = ltools.join(ltools.ROOT, 'themes', theme) if not os.path.exists(self.root): sys.exit('I don\'t know this theme. ({})'.format(theme)) # Menu header. menu_header = None menu_path = lpbm.tools.join(args.exec_path, 'menu.markdown') if os.path.exists(menu_path): with codecs.open(menu_path, 'r', 'utf-8') as f: menu_header = markdown.markdown(f.read()) # Jinja2 Environment Globals global _ENV _ENV = jinja2.Environment(loader=jinja2.FileSystemLoader( ltools.join(self.root, 'templates'))) _ENV.filters.update({ 'authors_list': do_authors_list, 'markdown': do_markdown, 'slugify': do_slugify, 'sorted': do_sorted, }) categories_menu = self.modules['categories'].recursive_view() cats_visible = self._get_categories() def _categories_menu(c): return dict([(i, (cat, _categories_menu(children))) for i, (cat, children) in c.items() if cat.id in cats_visible]) categories_menu = _categories_menu(categories_menu) _ENV.globals.update({ 'authors_mod': self.modules['authors'], 'categories_menu': categories_menu, 'config_mod': self.modules['config'], 'menu_header': menu_header, })
def load(self, modules, args): self.build_dir = tempfile.mkdtemp(prefix='lpbm_') if args.output is not None: self.output_dir = ltools.abspath(args.output) else: self.output_dir = ltools.join(args.exec_path, 'result') if not os.path.exists(self.output_dir): msg = 'I didn\'t find directory/symbolic link named `{path}`' msg += ' where to put the blog.' sys.exit(msg.format(path=self.output_dir)) if not args.noconfirm: msg = 'Are you sure you want to generate your blog in `{path}`?\n' msg += 'This action will remove all its contents!' if not ltools.ask_sure(prompt=msg.format(path=self.output_dir)): sys.exit('Nothing was done.') theme = self.modules['config']['theme.name'] or 'default' if args.theme is not None: theme = args.theme self.root = ltools.join(ltools.ROOT, 'themes', theme) if not os.path.exists(self.root): sys.exit('I don\'t know this theme. ({})'.format(theme)) # Menu header. menu_header = None menu_path = lpbm.tools.join(args.exec_path, 'menu.markdown') if os.path.exists(menu_path): with codecs.open(menu_path, 'r', 'utf-8') as f: menu_header = markdown.markdown(f.read()) # Jinja2 Environment Globals global _ENV _ENV = jinja2.Environment(loader=jinja2.FileSystemLoader( ltools.join(self.root, 'templates') )) _ENV.filters.update({ 'authors_list': do_authors_list, 'markdown': do_markdown, 'slugify': do_slugify, 'sorted': do_sorted, }) categories_menu = self.modules['categories'].recursive_view() cats_visible = self._get_categories() def _categories_menu(c): return dict([(i, (cat, _categories_menu(children))) for i, (cat, children) in c.items() if cat.id in cats_visible]) categories_menu = _categories_menu(categories_menu) _ENV.globals.update({ 'authors_mod': self.modules['authors'], 'categories_menu': categories_menu, 'config_mod': self.modules['config'], 'menu_header': menu_header, })
def load(self, modules, args): filename = ltools.join(args.exec_path, 'authors.cfg') self.cm = cm_module.ConfigModel(filename) # Now loads all authors. for section in self.cm.config.sections(): self.register_object(Author, section)
def render_rss(self): def rss_item(article): def rss_aut(author_id): try: author = self.modules['authors'][author_id] return '{email} ({full_name})'.format( email = author.email, full_name = author.full_name(), ) except lpbm.exceptions.ModelDoesNotExistError: return '[deleted]' authors = ltools.join_names([rss_aut(a) for a in article.authors]) return PyRSS2Gen.RSSItem( title = article.title, link = '{base_url}articles/{html_filename}'.format( base_url = self.modules['config']['general.url'], html_filename = article.html_filename(), ), author = authors, guid = str(article.id), description = do_markdown(article.content, code=False), pubDate = article.date, ) print('Generating RSS file.') articles = self._get_articles(self.modules['config']['rss.nb_articles'] or 10) rss = PyRSS2Gen.RSS2( title = self.modules['config']['general.title'], link = self.modules['config']['general.url'], description = self.modules['config']['general.subtitle'], lastBuildDate = datetime.datetime.now(), items = [rss_item(a) for a in articles], ) rss_path = ltools.join(self.build_dir, 'rssfeed.xml') with codecs.open(rss_path, 'w', 'utf-8') as f: rss.write_xml(f, encoding='utf-8')
def load(self, modules, args): filename = ltools.join(args.exec_path, 'categories.cfg') self.cm = cm_module.ConfigModel(filename) # Now we load all the categories. for section in self.cm.config.sections(): self.register_object(Category, section)
def load(self, modules, args): filename = ltools.join(args.exec_path, 'categories.cfg') self.cm = cm_module.ConfigModel(filename) # Now we load all the categories. for section in self.cm.config.sections(): obj = self.register_object(Category, section)
def _copy_static_dir(self, statics, fltr, *subdirs): out_root = self._build_path(*subdirs) def sub(root): res = [] for root, filename in ltools.filter_files(fltr, root, *(subdirs[1:])): res.append(ltools.join('/', *(subdirs + (filename,)))) ltools.copy(ltools.join(root, filename), ltools.join(out_root, filename)) return res sub(self.root) statics.extend(sub(ltools.join(self.args.exec_path, 'medias')))
def _copy_static_dir(self, statics, fltr, *subdirs): out_root = self._build_path(*subdirs) def sub(root): res = [] for root, filename in ltools.filter_files(fltr, root, *(subdirs[1:])): res.append(ltools.join('/', *(subdirs + (filename, )))) ltools.copy(ltools.join(root, filename), ltools.join(out_root, filename)) return res sub(self.root) statics.extend(sub(ltools.join(self.args.exec_path, 'medias')))
def process(self, modules, args): if args.list: # We must show all available options. self.list_options() elif args.check: # Check if the file is of the good format. self.check_options() elif args.set: # We must set the variable. self.set_var(args.set) elif args.unset: # We want to unset some variable. self.unset_var(args.unset) else: self.parser.print_help() try: with open(ltools.join(args.exec_path, 'lpbm.cfg'), 'w') as f: self.config.write(f) except IOError: pass
def load(self, modules, args): config_path = ltools.join(args.exec_path, 'lpbm.cfg') if not os.path.exists(config_path): sys.exit('This execution path ({}) doesn\'t look like an LPBM' ' blog.'.format(args.exec_path)) self.config = configparser.ConfigParser() self.config.read(config_path) # Getting logging related configurations logging_conf = dict() for section in self.config.sections(): if not section.startswith('logging'): continue logging_conf[section] = dict() for option in self.config[section]: logging_conf[section][option] = self.config[section][option] if args.debug: logging_conf.update({'logging-std': {'level': 'DEBUG'}}) lpbm.logging.configure(logging_conf)
def render_rss(self): def rss_item(article): def rss_aut(author_id): try: author = self.modules['authors'][author_id] return '{email} ({full_name})'.format( email=author.email, full_name=author.full_name(), ) except lpbm.exceptions.ModelDoesNotExistError: return '[deleted]' authors = ltools.join_names([rss_aut(a) for a in article.authors]) return PyRSS2Gen.RSSItem( title=article.title, link='{base_url}articles/{html_filename}'.format( base_url=self.modules['config']['general.url'], html_filename=article.html_filename(), ), author=authors, guid=str(article.id), description=do_markdown(article.content, code=False), pubDate=article.date, ) print('Generating RSS file.') articles = self._get_articles(self.modules['config']['rss.nb_articles'] or 10) rss = PyRSS2Gen.RSS2( title=self.modules['config']['general.title'], link=self.modules['config']['general.url'], description=self.modules['config']['general.subtitle'], lastBuildDate=datetime.datetime.now(), items=[rss_item(a) for a in articles], ) rss_path = ltools.join(self.build_dir, 'rssfeed.xml') with codecs.open(rss_path, 'w', 'utf-8') as f: rss.write_xml(f, encoding='utf-8')
def load(self, modules, args): f = lambda a: a.endswith('.markdown') for root, filename in ltools.filter_files(f, self.args.exec_path, 'articles'): self.register_object(Article, ltools.join(root, filename))
def _build_path(self, *args): lpbm.tools.mkdir_p(ltools.join(self.build_dir, *(args[:-1]))) return ltools.join(self.build_dir, *args)