Example #1
0
    def get_wiki_content(self, pagename):
        location = os.path.join(WIKI_DATA, pagename)
        data = self.parser.parse_wiki_text(NewtonUtils.get_file_contents(location), pagename)
#        print data[0]
        content = "%s%s%s" % (NewtonWikiText.WIKI_PAGE_HEADER, data[0], NewtonWikiText.WIKI_PAGE_FOOTER)
        content = content.replace("@PAGENAME@", pagename)
        content = content.replace("@MODDATE@", data[1])
        content = content.replace("@PIXMAPS_DIR@", PIXMAPS_DIR)
        content = content.replace("@STYLESHEET@", os.path.join(WIKI_STYLES, self.config.get_string(KEY_STYLESHEET, "Blue") + ".css"))
        return (location, content)
Example #2
0
    def __init__(self, config):
        self.config = config
        if not NewtonUtils.check_path_exists(WIKI_DIR):
            NewtonUtils.make_path(WIKI_DIR)
        if not NewtonUtils.check_path_exists(WIKI_DATA):
            NewtonUtils.make_path(WIKI_DATA)
        if not NewtonUtils.check_path_exists(WIKI_MEDIA):
            NewtonUtils.make_path(WIKI_MEDIA)
        if not NewtonUtils.check_path_exists(WIKI_STYLES):
            NewtonUtils.make_path(WIKI_STYLES)
        if not NewtonUtils.check_path_exists(WIKI_HOME):
            NewtonUtils.write_wiki_file(os.path.join(WIKI_DATA, 'NewtonHome'), 
                    NewtonWikiText.NEWTON_HOME_TEXT)
        # we have to overwrite the default styles and NewtonSyntax to allow extra features
        NewtonUtils.write_wiki_file(os.path.join(WIKI_STYLES, 'Human.css'), 
                NewtonUtils.get_file_contents(os.path.join(DATA_DIR, 'Human.css')).replace("@PIXMAPS_DIR@", PIXMAPS_DIR))
        NewtonUtils.write_wiki_file(os.path.join(WIKI_STYLES, 'Blue.css'), 
                NewtonUtils.get_file_contents(os.path.join(DATA_DIR, 'Blue.css')).replace("@PIXMAPS_DIR@", PIXMAPS_DIR))
        NewtonUtils.write_wiki_file(os.path.join(WIKI_DATA, 'NewtonSyntax'), 
                NewtonWikiText.NEWTON_SYNTAX_TEXT)

        self.parser = TextParser(config)

        self.history = History()
Example #3
0
 def get_search_results(self, pattern):
     results = []
     for root, dirs, files in os.walk(WIKI_DATA):
         for file in files:
             path = os.path.join(root, file)
             contents = NewtonUtils.get_file_contents(path)
             if pattern.lower() in contents.lower():
                 page = path.replace(WIKI_DATA, '').replace('/', '::')
                 results.append(page)
     if len(results):
         result_html = '<p><ol>\n'
         for result in results:
             result_html += '<div class="level2"><li class="level2"><span class="li"><a href="%s" class="wikilink1">%s</a></span></li></div>' % ("data/" + result, result)
         result_html += '</ol></p>'
     else:
         result_html = "<p>No results found.</p>"
     content = "%s%s%s" % (NewtonWikiText.WIKI_PAGE_HEADER, result_html, NewtonWikiText.WIKI_PAGE_FOOTER)
     content = content.replace("@PAGENAME@", 'Search Results: %s' % pattern)
     content = content.replace("@MODDATE@", 'N/A')
     content = content.replace("@PIXMAPS_DIR@", PIXMAPS_DIR)
     content = content.replace("@STYLESHEET@", os.path.join(WIKI_STYLES, self.config.get_string(KEY_STYLESHEET, 'Blue') + ".css"))
     return content
Example #4
0
 def get_raw_wiki_text(self, pagename):
     location = os.path.join(WIKI_DATA, pagename)
     raw_text = NewtonUtils.get_file_contents(location)
     return raw_text