def format(self): '''Formats the self.wikitext and returns the content as HTML source (unicode). ''' # Format the content. content = format_text(self.wikitext, self.pagename) # Process links to subpages in this category. subpages = [] for fname, prag in all_pragmas.items(): if self.pagename in prag.multiple('#category'): subpages.append(wikiutil.inputFile2pageName(fname)) if subpages: lines = [ '', '<a name="#category-subpages"></a>', '<h1>%s</h1>' % (config.text.subpages % dict(value=self.pagename)), '<div id="category-subpages">', '<table>', '<tr>', '<td>', '<ul>' ] subpages.sort(lambda a, b: -(a.lower() < b.lower())) num_of_columns = 3 m = len(subpages) p = m / num_of_columns if m % num_of_columns: p += 1 for i in xrange(m): if i > 0 and i % p == 0: lines.extend(['</ul>', '</td>', '<td>', '<ul>']) lines.append( '<li><a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(subpages[i]), subpages[i])) lines.extend(['</ul>', '</td>', '</tr>', '</table>', '</div>']) content += '\n'.join(lines) # Process categories this page belongs to. categories = self.pragmas.multiple('#category') if categories: categories.sort(lambda a, b: -(a.lower() < b.lower())) for category in categories: fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) assert os.path.exists(fname), '%s does not exist' % fname links = [ '<a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(name), name) for name in categories ] if len(links) > 1: format = config.text.categories else: format = config.text.category lines = ['', '<p class="categories-links">'] lines.append(format % dict(value=' | '.join(links))) lines.append('</p>') content += '\n'.join(lines) return content
def format(self): '''Formats the self.wikitext and returns the content as HTML source (unicode). ''' # Format the content. content = format_text(self.wikitext, self.pagename) # Process links to subpages in this category. subpages = [] for fname, prag in all_pragmas.items(): if self.pagename in prag.multiple('#category'): subpages.append(wikiutil.inputFile2pageName(fname)) if subpages: lines = ['', '<a name="#category-subpages"></a>', '<h1>%s</h1>' % (config.text.subpages % dict(value=self.pagename)), '<div id="category-subpages">', '<table>', '<tr>', '<td>', '<ul>'] subpages.sort(lambda a, b: -(a.lower() < b.lower())) num_of_columns = 3 m = len(subpages) p = m / num_of_columns if m % num_of_columns: p += 1 for i in xrange(m): if i > 0 and i % p == 0: lines.extend(['</ul>', '</td>', '<td>', '<ul>']) lines.append('<li><a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(subpages[i]), subpages[i])) lines.extend(['</ul>', '</td>', '</tr>', '</table>', '</div>']) content += '\n'.join(lines) # Process categories this page belongs to. categories = self.pragmas.multiple('#category') if categories: categories.sort(lambda a, b: -(a.lower() < b.lower())) for category in categories: fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) assert os.path.exists(fname), '%s does not exist' % fname links = ['<a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(name), name) for name in categories] if len(links) > 1: format = config.text.categories else: format = config.text.category lines = ['', '<p class="categories-links">'] lines.append(format % dict(value=' | '.join(links))) lines.append('</p>') content += '\n'.join(lines) return content
def process(wikipages): donepages = [] # Load all pragmas. global all_pragmas # used by Content objects too all_pragmas = Pragmas(force_update=wikipages) # Check for deleted pages. for filename, pragmas in all_pragmas.previous_items(): if not os.path.exists(filename): # Process categories so the page is removed from them. for category in pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) if fname not in wikipages: wikipages.append(fname) all_pragmas.remove(filename) # Process the pages. while wikipages: filename = wikipages[0] del wikipages[0] assert os.path.exists(filename), '%s does not exist' % filename pagename = wikiutil.inputFile2pageName(filename) pragmas = all_pragmas[filename] prev_pragmas = all_pragmas.previous(filename) # Prepare the namespace for the generator script. globs = dict(pagename=pagename, summary=pragmas.single('#summary', ''), genconfig=config.generator) print filename # Process categories this page was added to. for category in pragmas.multiple('#category'): if category not in prev_pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) if fname not in donepages and fname not in wikipages: wikipages.append(fname) # Process categories this page was removed from. for category in prev_pragmas.multiple('#category'): if category not in pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) if os.path.exists(fname): wikiutil.assertFileNameCase(fname) if fname not in donepages and fname not in wikipages and \ os.path.exists(fname): wikipages.append(fname) # Load included pages. for inc in pragmas.multiple('#include'): args = inc.split() assert len( args) == 3 and args[1] == 'as', '#include pragma syntax error' globs[args[2]] = Content(args[0]) # Create a HTML using the generator script. globs.update( dict(content=Content(pagename), modify_time=time.strftime( config.general.timeformat, time.gmtime(os.path.getmtime(filename))), generate_time=time.strftime(config.general.timeformat, time.gmtime()), out=codecs.open(wikiutil.pageName2outputFile(pagename), 'wt', encoding=config.charset))) try: for args in pragmas.multiple('#execute'): exec args in globs execfile(config.general.generator, globs) except: globs['out'].close() os.remove(wikiutil.pageName2outputFile(pagename)) raise globs['out'].close() if filename not in donepages: donepages.append(filename) # Add pages including the current page to processing. for filename, pragmas in all_pragmas.items(): try: inc = pragmas.single('#include').split(None, 1)[0] except ValueError: continue if inc != pagename: continue if filename not in donepages and filename not in wikipages: assert os.path.exists(filename), '%s does not exist' % filename wikipages.append(filename)
def process(wikipages): donepages = [] # Load all pragmas. global all_pragmas # used by Content objects too all_pragmas = Pragmas(force_update=wikipages) # Check for deleted pages. for filename, pragmas in all_pragmas.previous_items(): if not os.path.exists(filename): # Process categories so the page is removed from them. for category in pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) if fname not in wikipages: wikipages.append(fname) all_pragmas.remove(filename) # Process the pages. while wikipages: filename = wikipages[0] del wikipages[0] assert os.path.exists(filename), '%s does not exist' % filename pagename = wikiutil.inputFile2pageName(filename) pragmas = all_pragmas[filename] prev_pragmas = all_pragmas.previous(filename) # Prepare the namespace for the generator script. globs = dict(pagename=pagename, summary=pragmas.single('#summary', ''), genconfig=config.generator) print filename # Process categories this page was added to. for category in pragmas.multiple('#category'): if category not in prev_pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) if fname not in donepages and fname not in wikipages: wikipages.append(fname) # Process categories this page was removed from. for category in prev_pragmas.multiple('#category'): if category not in pragmas.multiple('#category'): fname = wikiutil.pageName2inputFile(category) if os.path.exists(fname): wikiutil.assertFileNameCase(fname) if fname not in donepages and fname not in wikipages and \ os.path.exists(fname): wikipages.append(fname) # Load included pages. for inc in pragmas.multiple('#include'): args = inc.split() assert len(args) == 3 and args[1] == 'as', '#include pragma syntax error' globs[args[2]] = Content(args[0]) # Create a HTML using the generator script. globs.update(dict(content=Content(pagename), modify_time=time.strftime(config.general.timeformat, time.gmtime(os.path.getmtime(filename))), generate_time=time.strftime(config.general.timeformat, time.gmtime()), out=codecs.open(wikiutil.pageName2outputFile(pagename), 'wt', encoding=config.charset))) try: for args in pragmas.multiple('#execute'): exec args in globs execfile(config.general.generator, globs) except: globs['out'].close() os.remove(wikiutil.pageName2outputFile(pagename)) raise globs['out'].close() if filename not in donepages: donepages.append(filename) # Add pages including the current page to processing. for filename, pragmas in all_pragmas.items(): try: inc = pragmas.single('#include').split(None, 1)[0] except ValueError: continue if inc != pagename: continue if filename not in donepages and filename not in wikipages: assert os.path.exists(filename), '%s does not exist' % filename wikipages.append(filename)