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 opt_new(self): ''' New article from command line. This will help the user create a particular file. ''' obj = super().opt_new() print('Article was successfully created!') if ltools.ask_sure(prompt='Do you want to edit it right now?'): self.opt_edit_content(obj.id) return obj
def opt_delete(self, id): '''Deletes an existing category.''' categories, to_delete = {id: self[id]}, [id] categories_copy = self._objects.copy() while to_delete: to_delete = [] for cat_id, cat in categories_copy.items(): if cat.parent in categories: categories[cat.id] = cat to_delete.append(cat.id) for cat_id in to_delete: del categories_copy[cat_id] print('All categories to be deleted:') for cat in categories.values(): print('{level} - {name}'.format( name=cat.name, level=' ' * (cat.level() - categories[id].level()))) if ltools.ask_sure(): for cat in categories.values(): cat.deleted = True self.cm.save() print('Categories successfully deleted!')
def opt_delete(self, id): '''Deletes an existing category.''' categories, to_delete = {id: self[id]}, [id] categories_copy = self._objects.copy() while to_delete: to_delete = [] for cat_id, cat in categories_copy.items(): if cat.parent in categories: categories[cat.id] = cat to_delete.append(cat.id) for cat_id in to_delete: del categories_copy[cat_id] print('All categories to be deleted:') for cat in categories.values(): print('{level} - {name}'.format( name=cat.name, level=(' ' * (cat.level() - categories[id].level())) )) if ltools.ask_sure(): for cat in categories.values(): cat.deleted = True self.cm.save() print('Categories successfully deleted!')