Esempio n. 1
0
    def __call__(self, filename):
        #>>>>> find file
        pan = None # marker for file not found
        for d in self.dirs:
            pan = butil.join(d, filename)
            if butil.fileExists(pan): break
            pan = None
        #//for
        if pan==None:
            msg = "File %s not found in any of %r" % (filename, self.dirs)
            raise IOError(msg)

        #>>>>> read file
        fh = open(pan, 'r')
        s = fh.read()
        fh.close()

        #>>>>> need to convert to unicode?
        toUnicode = False
        for ch in s:
            if ord(ch)>127:
                #prvars("s ch")
                toUnicode = True
                break
        #//for
        #prvars("toUnicode")
        if not toUnicode: return s

        return unicode(s, "utf_8")
Esempio n. 2
0
def getArticleSource(siteName, pathName):
    articlePan = getArticlePan(siteName, pathName)
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        return src
    else:
        return ""
Esempio n. 3
0
def getArticleSource(siteName, pathName):
    articlePan = getArticlePan(siteName, pathName)
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        return src
    else:
        return ""
Esempio n. 4
0
def articleExists(d, an):
    """
    @param d::str = a full path to a directory
    @param an::str = a filename within that directory, but without the 
        ".md" extension 
    @return::bool = whether the article (an) exists    
    """
    pan = butil.join(d, an + ".md")
    return butil.fileExists(pan)
Esempio n. 5
0
def siteInfo(siteName):
    """ Display information about a site.
    """
    import wiki
    tem = jinjaEnv.get_template("generic_10_2.html")

    dirPan = wiki.getDirPan(siteName, "")
    realPan = os.path.realpath(dirPan)
    realPanInfo = ""
    if realPan != dirPan:
        realPanInfo = form(
            "<p>Canonical path is <code>{realPan}"
            "</code> .</p>\n",
            realPan=realPan)
    #prvars("dirPan realPan realPanInfo")
    fns, dirs = butil.getFilesDirs(dirPan)
    if butil.fileExists(butil.join(dirPan, "home.md")):
        homePageInfo = form(
            "View <a href='/{siteName}/w/home'>"
            "<i class='fa fa-home'></i> home page</a>.",
            siteName=siteName)
    else:
        homePageInfo = form("""There is no home page.
             <a href='/{siteName}/wikiedit/home'>
                <i class='fa fa-plus'></i>
                Create one</a>.""",
                            siteName=siteName)

    contents = """\
<h1>Information about site <i class='fa fa-bank'></i> {siteName}</h1>

<p><b>{siteName}</b> is stored in directory <code>{siteRoot}</code> .</p>
{realPanInfo}

<p>There are {numPages} pages in the root folder, and {numSubDirs} sub-folders.
<a href='/{siteName}/w/'><i class='fa fa-folder'></i>
View root folder</a>.
</p>

<p>{homePageInfo}</p>
""".format(
        siteName=siteName,
        siteRoot=dirPan,
        realPanInfo=realPanInfo,
        numPages=len(fns),
        numSubDirs=len(dirs),
        homePageInfo=homePageInfo,
    )
    h = tem.render(
        siteName=siteName,
        title="Information about " + siteName,
        nav2=wiki.locationSitePath(siteName, ""),
        wikiText=contents,
    )
    return h
Esempio n. 6
0
def getArticleBody(siteName, pathName):
    """ given an article name, return the body of the article.
    @return ::(str,str) =title,html
    """
    articlePan = getArticlePan(siteName, pathName)
    #prvars()
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        src = convertQuickLinks(src)
        contents = md(src)
        return pathName, contents
    else:
        h = form("<p>({pathName} does not exist; "
            "<a href='/{siteName}/wikiedit/{pathName}'>create it</a>)</p>\n",
            siteName = htmlEscape(siteName),
            pathName = htmlEscape(pathName))
        return (pathName, h)
Esempio n. 7
0
def siteInfo(siteName):
    """ Display information about a site.
    """
    import wiki
    tem = jinjaEnv.get_template("generic_10_2.html")
    
    dirPan = wiki.getDirPan(siteName, "")
    fns, dirs = butil.getFilesDirs(dirPan)
    if butil.fileExists(butil.join(dirPan, "home.md")):
         homePageInfo = form("View <a href='/{siteName}/w/home'>"
             "<i class='fa fa-home'></i> home page</a>.",
             siteName = siteName)           
    else:                                
         homePageInfo = form("""There is no home page.
             <a href='/{siteName}/wikiedit/home'>
                <i class='fa fa-plus'></i>
                Create one</a>.""",
             siteName = siteName)  
         
    contents = """\
<h1>Information about site <i class='fa fa-bank'></i> {siteName}</h1>

<p><b>{siteName}</b> is stored in directory <code>{siteRoot}</code> .</p>

<p>There are {numPages} pages in the root folder, and {numSubDirs} sub-folders.
<a href='/{siteName}/w/'><i class='fa fa-folder'></i>
View root folder</a>.
</p>

<p>{homePageInfo}</p>
""".format(
        siteName = siteName,
        siteRoot = dirPan,
        numPages = len(fns),
        numSubDirs = len(dirs),
        homePageInfo = homePageInfo,
    )
    h = tem.render(
    
        siteName = siteName,
        title = "Information about " + siteName,
        nav2 = wiki.locationSitePath(siteName, ""),
        wikiText = contents,
    )
    return h 
Esempio n. 8
0
def getArticleBody(siteName, pathName):
    """ given an article name, return the body of the article.
    @return ::(str,str) =title,html
    """
    articlePan = getArticlePan(siteName, pathName)
    #prvars()
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        src = convertQuickLinks(src)
        contents = md(src)
        return pathName, contents
    else:
        h = form(
            "<p>({pathName} does not exist; "
            "<a href='/{siteName}/wikiedit/{pathName}'>create it</a>)</p>\n",
            siteName=htmlEscape(siteName),
            pathName=htmlEscape(pathName))
        return (pathName, h)