当前位置: 首页>>代码示例>>Python>>正文


Python FilePath.preauthChild方法代码示例

本文整理汇总了Python中twisted.python.filepath.FilePath.preauthChild方法的典型用法代码示例。如果您正苦于以下问题:Python FilePath.preauthChild方法的具体用法?Python FilePath.preauthChild怎么用?Python FilePath.preauthChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.filepath.FilePath的用法示例。


在下文中一共展示了FilePath.preauthChild方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import preauthChild [as 别名]
def main(argv):
    # input
    posts = FilePath(argv[1])

    # output
    blog = FilePath(argv[2])

    # Since Sphinx gets confused by image paths with "special" characters in
    # them, generate new names for all the image paths and a mapping from the
    # old names to the new names.
    images = FilePath(argv[3])

    imagepaths = []
    for post in images.children():
        if post.isdir():
            imagepaths.append(post)
            safe = post.sibling(fixpath(post.basename()))
            if post != safe and not safe.isdir():
                post.moveTo(safe)
                safe.linkTo(post)

    entries = []
    for post in posts.children():
        data = post.getContent().decode("utf-8")
        ignored, header, body = data.split(b"---", 2)
        meta = dict((text.strip() for text in line.split(":", 1)) for line in header.splitlines() if line.strip())
        date = datetime.strptime(meta["date"], "%Y/%m/%d %H:%M:%S")

        parent = blog.preauthChild(
            ("%d/%02d/%02d" % (date.year, date.month, date.day)).encode("utf-8"))
        title = fixpath(meta["title"].strip().lower().encode("utf-8")).decode("utf-8")
        entry = parent.child((title + ".rst").encode("utf-8"))

        header = HEADER_TEMPLATE % dict(
            author=meta["author"].strip(), categories="none",
            tags=meta["categories"].strip(), title=meta["title"].strip(),
            underbar="=" * len(meta["title"].strip()))

        for path in imagepaths:
            body = body.replace(
                u"/" + path.basename().decode("utf-8") + u"/",
                u"/" + fixpath(path.basename()).decode("utf-8") + u"/")

        if not parent.isdir():
            parent.makedirs()

        entry.setContent((header + html2rst(body)).encode("utf-8"))

        entries.append(entry)

    entries.sort()
    entries.reverse()

    sitemap = SITEMAP % dict(
        entries="".join([
                "\n   " + "/".join(entry.segmentsFrom(blog))
                for entry in entries]))
    blog.child(b"master.rst").setContent(sitemap.encode("utf-8"))

    FilePath(b"conf.py").copyTo(blog.child(b"conf.py"))
开发者ID:exarkun,项目名称:blogofile2tinkerer,代码行数:62,代码来源:blogofile2tinkerer.py

示例2: createSkeleton

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import preauthChild [as 别名]
def createSkeleton(siteDir):
    fromDir = FilePath(warp.__file__).sibling("priv").child("skeleton")

    for entryName in (l.strip() for l in fromDir.child("MANIFEST").open()):
        entry = fromDir.preauthChild(entryName)

        destination = siteDir.preauthChild(entryName)

        if destination.exists():
            continue

        print "  Copying %s" % entryName

        if not destination.parent().exists():
            os.makedirs(destination.parent().path)

        entry.copyTo(destination)

    print "Done! Run with 'twistd -n warp'"
开发者ID:rjweir,项目名称:warp,代码行数:21,代码来源:skeleton.py

示例3: do_peekfs

# 需要导入模块: from twisted.python.filepath import FilePath [as 别名]
# 或者: from twisted.python.filepath.FilePath import preauthChild [as 别名]
def do_peekfs(cmd,path,*args):
    global dsklst

    # wstring simply writes a string to new file
    def _wstring(fp):
        def _wrap(path,string):
            # Right teh filez LOL -KTHXBYE, LOLCATZ
            tehfile=path.open('w')
            tehfile.write(string)
            tehfile.close()
        return lambda *args: _wrap(fp,*args)

    def _wget(fp):
        def _wrap(path,url):
            req=urllib2.urlopen(url).read()
            tehfile=path.open('wb')
            tehfile.write(req)
            tehfile.close()
        return lambda *args: _wrap(fp,*args)

    # wstring writes a string to file
    def _astring(fp):
        def _wrap(path,string):
            tehfile=path.open('a')
            # Pydocs say both that this should be a no-op
            # BUT also say that some systems will not seek on their own?
            # we're just being careful here...
            tehfile.seek(0,os.SEEK_END)
            tehfile.write(string)
            tehfile.close()
        return lambda *args: _wrap(fp,*args)

    # Templating engine
    def _template(fp):
        def _wrap(path,**template):
            scratchfile=path.dirname()+"."+path.basename()+".tmp"
            fh=path.open('r')

            sfp=FilePath(scratchfile)
            sfh=sfp.open('w')
            seeklast=0
            for buffer in fh.readlines():
                for line in buffer:
                    sfh.write(line.format(**template))
            sfh.flush()
            sfh.close()
            fh.close()

            sfp.moveTo(path.realpath())
        return lambda *args: _wrap(fp,*args)

    def _sed(fp):
        return lambda rxp: do_sed(rxp,fp)

    def _urlextract(fp):
        return lambda url: do_urlextract(fp,url)

    def _extract(fp):
        return lambda *args: do_extract(fp,*args)

    def _moveTo(fp):
        return lambda path: fp.moveTo(FilePath(path))

    def _copyTo(fp):
        return lambda path: fp.copyTo(FilePath(path))

    def _ls(fp):
        def _wrap(fp,glob="*"):
            map (lambda f: f.basename(), fp.globChildren(glob))
        return lambda *args: _wrap(fp,*args)

    def _b64get(fp):
        return lambda: base64.b64encode(fp.getContent())

    def _b64put(fp):
        def _wrap(path,content):
            if path.exists and not is_regularf(path):
                return False
            return path.setContent(base64.b64decode(content))
        return lambda *args: _wrap(fp,*args)

    mntpnt=dsklst['/'].real_mountpoint()

    # Make sure the user mounts us, don't auto-mount
    if not os.path.ismount(mntpnt):
        return False

    os.chdir(mntpnt)
    os.chroot(mntpnt)

    pp=FilePath('/')
    # We're safe /w preauthChild since we're chroot'ed
    fp=pp.preauthChild(path)

    """
    Mapping the t.p.f.FilePath methods
    which we will allow, to human-names
    we can accessed via cmd arg
    """
    return {
#.........这里部分代码省略.........
开发者ID:ewindisch,项目名称:nodestored,代码行数:103,代码来源:nodestored.py


注:本文中的twisted.python.filepath.FilePath.preauthChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。