コード例 #1
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
def getArticleFilesWithoutExt(d):
    """
    @param d::str = a full path to a directory
    @return::[str] where each string is an article in the directory without
        the ".md" extension
    """
    fns, _ = butil.getFilesDirs(d)
    arts = sorted(
        [fn[:-3] for fn in fns if fn[-3:] == ".md" and not fn[:1] == "~"])
    return arts
コード例 #2
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
コード例 #3
0
ファイル: wiki.py プロジェクト: cabalamat/catwiki
def getDirPan(siteName, pathName):
    """ return the pathname for a directory
    @param siteName::str = the site name
    @param pathName::str = the pathname within the site
    @return::str = the full pathname to the directory (which may or may
        not exist). If the site doesn't exist, returns "".
    """
    if not siteName: return ""
    for stub in config.SITE_STUBS:
        _, dirs = butil.getFilesDirs(stub)
        if siteName in dirs:
            return butil.join(stub, siteName, pathName)
    #//for
    return ""
コード例 #4
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
def getDirPan(siteName, pathName):
    """ return the pathname for a directory
    @param siteName::str = the site name
    @param pathName::str = the pathname within the site
    @return::str = the full pathname to the directory (which may or may
        not exist). If the site doesn't exist, returns "".
    """
    if not siteName: return ""
    for stub in config.SITE_STUBS:
        _, dirs = butil.getFilesDirs(stub)
        if siteName in dirs:
            return butil.join(stub, siteName, pathName)
    #//for
    return ""
コード例 #5
0
ファイル: sites.py プロジェクト: cabalamat/catwiki
def siteListH():
    """ return HTML containing a list of sites 
    @return::str
    """
    h = "<p>\n"
    for stub in config.SITE_STUBS:
        _, dirs = butil.getFilesDirs(stub)
        for siteName in dirs:
            h += (("<span class='loc-sitename'><a href='/{siteName}/info'><i class='fa fa-bank'></i> {siteName}</a></span> -- under <code>{stub}</code><br>\n")
                .format(siteName=siteName,
                        stub=stub))     
        #//for siteName
    #//for stub   
    h += "</p>\n"
    return h        
コード例 #6
0
ファイル: sites.py プロジェクト: neuroradiology/catwiki
def siteListH():
    """ return HTML containing a list of sites 
    @return::str
    """
    h = "<p>\n"
    for stub in config.SITE_STUBS:
        _, dirs = butil.getFilesDirs(stub)
        for siteName in dirs:
            h += (("<span class='loc-sitename'><a href='/{siteName}/info'>"
                   "<i class='fa fa-bank'></i> {siteName}</a></span> -- "
                   "under <code>{stub}</code><br>\n").format(siteName=siteName,
                                                             stub=stub))
        #//for siteName
    #//for stub
    h += "</p>\n"
    return h
コード例 #7
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
def getArticlePan(siteName, pathName):
    """ return the pathname for an article
    @param siteName::str = the site name
    @param pathName::str = the pathname within the site
    @return::str = the full pathname to the article (which may or may
        not exist). If the site doesn't exist, returns "".
    """
    #prvars("siteName pathName")
    if not siteName: return ""
    for stub in config.SITE_STUBS:
        _, dirs = butil.getFilesDirs(stub)
        if siteName in dirs:
            return getArticlePan2(stub, siteName, pathName)
            #return butil.join(stub, siteName, pathName + ".md")
    #//for
    return ""
コード例 #8
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 
コード例 #9
0
ファイル: wiki.py プロジェクト: cabalamat/catwiki
def getIndex(siteName, pathName):
    """ get an index of a directory.
    @param siteName::str
    @param pathName::str
    @return::(str,str) =title,html
    """
    def isArticle(fn):
        """ is a filename an article? """
        return (fn[-3:]==".md" and not fn[:1]=="~")


    if pathName[-1:] == "/":
        uPath = pathName[:-1]
    else:
        uPath = pathName
    dirPan = getDirPan(siteName, uPath)
    #prvars()
    if not os.path.isdir(dirPan):
        h = "<p>Directory {} does not exist.</p>\n".format(pathName)
        return h

    fns, dirs = butil.getFilesDirs(dirPan)
    dirs = [d for d in dirs if d[:1] != "."]
    arts = sorted([fn[:-3]
                  for fn in fns
                  if isArticle(fn)])
    nonArticles = sorted([fn
                  for fn in fns
                  if not isArticle(fn)])
    dirs = sorted(dirs)
    h = ("<h1><i class='fa fa-list'></i> Index of articles in "
         " /{}</h1>\n").format(pathName)
    items = []
    nonArticleItems = []
    if arts:
        for fn in arts:
            text = getTitle(butil.join(dirPan, fn+".md"))
            if text==fn: 
                text = ""
            else:
                text = " - " + text
                
            if fn=="home": 
                item = form("<a href='{fn}'>"
                    "<span class='home-icon'><i class='fa fa-home'></i></span>"
                    " {fn}</a>{text}",
                    fn = fn,
                    text = text)
            else:    
                item = form("<a href='{fn}'>"
                    "<i class='fa fa-file-text-o'></i> {fn}</a>{text}",
                    fn = fn,
                    text = text)
                
            items.append(item)
        #//for
        h += bsColumns(items, 3)
    if nonArticles:
        for fn in nonArticles:
            nonArticleItems.append(form("<a href='{fn}'>"
                "<i class='fa fa-file-o'></i> "
                "{fn}</a>",
                fn = fn))
        #//for
        h += "<h3>Other files</h3>\n" + bsColumns(nonArticleItems, 3)
    if dirs:
        dirItems = []
        for d in dirs:
            dirItems.append(("<a href='{d}/'><i class='fa fa-folder'></i> "
                  "{text}</a>").format(
                d = d,
                text = d,
            ))
        #//for
        h += "<h3>Folders</h3>\n" + bsColumns(dirItems, 3)

    title = "Index of {}".format(pathName)
    return title, h
コード例 #10
0
ファイル: wiki.py プロジェクト: neuroradiology/catwiki
def getIndex(siteName, pathName):
    """ get an index of a directory.
    @param siteName::str
    @param pathName::str
    @return::(str,str) =title,html
    """
    def isArticle(fn):
        """ is a filename an article? """
        return (fn[-3:] == ".md" and not fn[:1] == "~")

    if pathName[-1:] == "/":
        uPath = pathName[:-1]
    else:
        uPath = pathName
    dirPan = getDirPan(siteName, uPath)
    #prvars()
    if not os.path.isdir(dirPan):
        h = "<p>Directory {} does not exist.</p>\n".format(pathName)
        return h

    fns, dirs = butil.getFilesDirs(dirPan)
    dirs = [d for d in dirs if d[:1] != "."]
    arts = sorted([fn[:-3] for fn in fns if isArticle(fn)])
    nonArticles = sorted([fn for fn in fns if not isArticle(fn)])
    dirs = sorted(dirs)
    h = ("<h1><i class='fa fa-list'></i> Index of articles in "
         " /{}</h1>\n").format(pathName)
    items = []
    nonArticleItems = []
    if arts:
        for fn in arts:
            text = getTitle(butil.join(dirPan, fn + ".md"))
            if text == fn:
                text = ""
            else:
                text = " - " + text

            if fn == "home":
                item = form(
                    "<a href='{fn}'>"
                    "<span class='home-icon'><i class='fa fa-home'></i></span>"
                    " {fn}</a>{text}",
                    fn=fn,
                    text=text)
            else:
                item = form(
                    "<a href='{fn}'>"
                    "<i class='fa fa-file-text-o'></i> {fn}</a>{text}",
                    fn=fn,
                    text=text)

            items.append(item)
        #//for
        h += bsColumns(items, 3)
    if nonArticles:
        for fn in nonArticles:
            hf = form(
                "<a href='{fn}'>"
                "<i class='fa fa-file-o'></i> "
                "{fn}</a>",
                fn=fn)
            if hasImageExtension(fn):
                hf += form(
                    "<br>\n<a href='{fn}'>"
                    "<img class='index_image' src='{fn}'>"
                    "</a>",
                    fn=fn)
            nonArticleItems.append(hf)
        #//for
        h += "<h3>Other files</h3>\n" + bsColumns(nonArticleItems, 3)
    if dirs:
        dirItems = []
        for d in dirs:
            dirItems.append(("<a href='{d}/'><i class='fa fa-folder'></i> "
                             "{text}</a>").format(
                                 d=d,
                                 text=d,
                             ))
        #//for
        h += "<h3>Folders</h3>\n" + bsColumns(dirItems, 3)

    title = "Index of {}".format(pathName)
    return title, h