def __init__( self, title, template = None ): Item.__init__( self, Config.getInstance().basepath, title, Config.getInstance().page_ext ) self.datetime = None self.author = None self.categories = [] self.tags = [] self.abstract = "" self.content = "" self.static = False self.template = TemplateManager.getInstance().get( 'post.tpl' if template is None else template )
def create(self): config = Config.getInstance() path = "%s%s%s" % (config.outputpath, os.sep, self.path) if not os.path.exists(path): os.mkdir(path) if config.pager == True and (self.title == "index" or str(self.__class__) in Item.PAGER_ENABLED_CLASSES): pager = Pager("%s.%s" % (self.name, self.extension), "%s-%%d.%s" % (self.name, self.extension)) if hasattr(self, "items"): pager.setPages(self.items) else: pager.setPages(self.objects["pages"]) self.npages = pager.getTotalPages() self.addObject("pager", pager) for filename in pager: filename = os.path.join(path, filename) content = self.render() self.__save_contents(filename, content) else: filename = os.path.join(path, "%s.%s" % (self.name, self.extension)) content = self.render() self.__save_contents(filename, content)
def __build_hierarchy(self): fd = codecs.open( Config.getInstance().hierarchy, "r", "utf-8" ) for line in iter(fd): line = line.strip() if line != '': if ':' in line: ( root, children ) = line.split( ':', 1 ) root = root.strip() children = [ s.strip() for s in children.strip().split(',') ] else: root = line children = [] h_root = None for category in self.hierarchy: h_root = self.__find_in_hyerarchy( root, category ) if h_root != None: break if h_root == None: h_root = self.__find_category(root) if h_root != None: self.hierarchy.append(h_root) for child in children: h_child = self.__find_category(child) if h_root is not None and h_child is not None: h_root.children.append(h_child) fd.close()
def create( self ): Item.create(self) # create only authors not already done if self.author != None and not os.path.exists( os.path.join( Config.getInstance().outputpath, self.author.url ) ): self.author.create() for category in self.categories: # create only categories not already done if not os.path.exists( os.path.join( Config.getInstance().outputpath, category.url ) ): category.create() for tag in self.tags: # create only tags not already done if not os.path.exists( os.path.join( Config.getInstance().outputpath, tag.url ) ): tag.create()
def __init__( self, title ): Item.__init__( self, Config.getInstance().basepath + os.sep + 'categories.txt', title, Config.getInstance().page_ext ) self.title = title self.items = [] self.children = [] self.template = TemplateManager.getInstance().get('category.tpl') self.sorted = False
def __build_hierarchy(self): fd = codecs.open(Config.getInstance().hierarchy, "r", "utf-8") for line in iter(fd): line = line.strip() if line != '': if ':' in line: (root, children) = line.split(':', 1) root = root.strip() children = [s.strip() for s in children.strip().split(',')] else: root = line children = [] h_root = None for category in self.hierarchy: h_root = self.__find_in_hyerarchy(root, category) if h_root != None: break if h_root == None: h_root = self.__find_category(root) if h_root != None: self.hierarchy.append(h_root) for child in children: h_child = self.__find_category(child) if h_root is not None and h_child is not None: h_root.children.append(h_child) fd.close()
def get(self, username): id = username.lower() if not self.authors.has_key(id): self.authors[id] = AuthorParser().parse( os.path.join(Config.getInstance().dbpath, ("%s.txt" % (username)))) return self.authors[id]
def __init__(self, firstpage, format): self.current = 0 self.pagen = 0 self.firstpage = firstpage self.format = format self.pages = [] self.max = 0 self.left = 0 self.total = 0 self.config = Config.getInstance()
def __init__( self, firstpage, format ): self.current = 0 self.pagen = 0 self.firstpage = firstpage self.format = format self.pages = [] self.max = 0 self.left = 0 self.total = 0 self.config = Config.getInstance()
def __init__( self, username ): Item.__init__( self, Config.getInstance().basepath + os.sep + 'members', username, Config.getInstance().page_ext ) self.username = username self.items = [] self.avatar = "" self.email = "" self.website = "" self.abstract = "" self.content = "" self.template = TemplateManager.getInstance().get('author.tpl') self.sorted = False
def __init__(self): config = Config.getInstance() self.lookup = TemplateLookup( directories = [config.tplpath], output_encoding = 'utf-8', input_encoding = 'utf-8', encoding_errors = 'replace', cache_enabled = True, cache_type = 'file', cache_dir = config.tplcache, collection_size = 1024 )
def create(self): Item.create(self) # create only authors not already done if self.author != None and not os.path.exists( os.path.join(Config.getInstance().outputpath, self.author.url)): self.author.create() for category in self.categories: # create only categories not already done if not os.path.exists( os.path.join(Config.getInstance().outputpath, category.url)): category.create() for tag in self.tags: # create only tags not already done if not os.path.exists( os.path.join(Config.getInstance().outputpath, tag.url)): tag.create()
def __init__(self): self.config = Config.getInstance() self.dbdir = os.path.join( self.config.dbpath, 'pages' ) self.files = [] if os.path.exists( self.dbdir ): for folder, subdirs, files in os.walk( self.dbdir ): for fname in files: self.files.append( os.path.realpath( os.path.join( folder, fname ) ) ) self.path = os.path.dirname( os.path.realpath( __file__ ) ) self.pages = [] self.progress = None self.statics = None self.index = None self.e404 = None self.sitemap = None self.feed = None
def __init__( self, title ): Item.__init__( self, Config.getInstance().basepath + os.sep + 'tags', title, Config.getInstance().page_ext ) self.title = title self.items = [] self.template = TemplateManager.getInstance().get('tag.tpl') self.sorted = False
def get( self, username ): id = username.lower() if not self.authors.has_key(id): self.authors[id] = AuthorParser().parse( os.path.join( Config.getInstance().dbpath, ( "%s.txt" % (username) ) ) ) return self.authors[id]
def render( cls, template, **kwargs ): return template.render( config = Config.getInstance(), categories = swg.core.categorymanager.CategoryManager.getInstance().get(), tags = swg.core.tagmanager.TagManager.getInstance().get(), **kwargs )