コード例 #1
0
ファイル: butno.py プロジェクト: cabalamat/butno
    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")
コード例 #2
0
ファイル: wiki.py プロジェクト: cabalamat/catwiki
def getArticleSource(siteName, pathName):
    articlePan = getArticlePan(siteName, pathName)
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        return src
    else:
        return ""
コード例 #3
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
def getArticleSource(siteName, pathName):
    articlePan = getArticlePan(siteName, pathName)
    if butil.fileExists(articlePan):
        src = butil.readFileUtf8(articlePan)
        return src
    else:
        return ""
コード例 #4
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
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)
コード例 #5
0
ファイル: sites.py プロジェクト: neuroradiology/catwiki
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
コード例 #6
0
ファイル: wiki.py プロジェクト: cabalamat/catwiki
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)
コード例 #7
0
ファイル: sites.py プロジェクト: cabalamat/catwiki
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 
コード例 #8
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
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)