• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python unipath.isfile函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中unipath.isfile函数的典型用法代码示例。如果您正苦于以下问题:Python isfile函数的具体用法?Python isfile怎么用?Python isfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: deleteotherfile

 def deleteotherfile(self, book_href):
     id = unicode_str(book_href)
     if id in self.id_to_href:
         raise WrapperException('Incorrect interface routine - use deletefile')
     filepath = self.id_to_filepath.get(id, None)
     if id is None:
         raise WrapperException('book href does not exist')
     if id in PROTECTED_FILES:
         raise WrapperException('attempt to delete protected file')
     add_to_deleted = True
     # if file was added or modified delete file from outdir
     if id in self.added or id in self.modified:
         filepath = os.path.join(self.outdir,filepath)
         if unipath.exists(filepath) and unipath.isfile(filepath):
             os.remove(filepath)
         if id in self.added:
             self.added.remove(id)
             add_to_deleted = False
         if id in self.other:
             self.other.remove(id)
         if id in self.modified:
             del self.modified[id]
     if add_to_deleted:
         self.deleted.append(('other', id, book_href))
     del self.id_to_filepath[id]
开发者ID:JksnFst,项目名称:Sigil,代码行数:25,代码来源:wrapper.py


示例2: deletefile

 def deletefile(self, id):
     id = unicode_str(id)
     filepath = self.id_to_filepath.get(id, None)
     if id is None:
         raise WrapperException('id does not exist in manifest')
     add_to_deleted = True
     # if file was added or modified, delete file from outdir
     if id in self.added or id in self.modified:
         filepath = os.path.join(self.outdir,filepath)
         if unipath.exists(filepath) and unipath.isfile(filepath):
             os.remove(pathof(filepath))
         if id in self.added:
             self.added.remove(id)
             add_to_deleted = False
         if id in self.modified:
             del self.modified[id]
     # remove from manifest
     href = self.id_to_href[id]
     del self.id_to_href[id]
     del self.id_to_mime[id]
     del self.href_to_id[href]
     # remove from spine
     new_spine = []
     was_modified = False
     for sid, linear in self.spine:
         if sid != id:
             new_spine.append((sid, linear))
         else:
             was_modified = True
     if was_modified:
         setspine(new_spine)
     if add_to_deleted:
         self.deleted.append(id)
         self.modified['OEBPS/content.opf'] = 'file'
     del self.id_to_filepath[id]
开发者ID:pwr,项目名称:Sigil,代码行数:35,代码来源:wrapper.py


示例3: addotherfile

 def addotherfile(self, book_href, data) :
     id = unicode_str(book_href)
     if id in self.other:
         raise WrapperException('book href must be unquie')
     desired_path = id.replace("/",os.sep)
     filepath = os.path.join(self.outdir,desired_path)
     if unipath.isfile(filepath):
         raise WrapperException('desired path already exists')
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(pathof(base))
     if isinstance(data, text_type):
         data = utf8_str(data)
     with open(pathof(filepath),'wb')as fp:
         fp.write(data)
     self.other.append(id)
     self.added.append(id)
     self.id_to_filepath[id] = desired_path
开发者ID:JksnFst,项目名称:Sigil,代码行数:18,代码来源:wrapper.py


示例4: main

def main(argv=unicode_argv()):

    if len(argv) != 5:
        failed(None, msg="Launcher: improper number of arguments passed to launcher.py")
        return -1

    ebook_root = argv[1]
    outdir = argv[2]
    script_type = argv[3]
    target_file = argv[4]
    script_home = os.path.dirname(target_file)
    script_module = os.path.splitext(os.path.basename(target_file))[0]

    # do basic sanity checking anyway
    if script_type not in SUPPORTED_SCRIPT_TYPES:
        failed(None, msg="Launcher: script type %s is not supported" % script_type)
        return -1

    ok = unipath.exists(ebook_root) and unipath.isdir(ebook_root)
    ok = ok and unipath.exists(outdir) and unipath.isdir(outdir)
    ok = ok and unipath.exists(script_home) and unipath.isdir(script_home)
    ok = ok and unipath.exists(target_file) and unipath.isfile(target_file)
    if not ok:
        failed(None, msg="Launcher: missing or incorrect paths passed in")
        return -1

    # update sys with path to target module home directory
    if script_home not in sys.path:
        sys.path.append(script_home)

    # load and parse opf if present
    op = None
    opf_path = os.path.join(ebook_root, "OEBPS", "content.opf")
    if unipath.exists(opf_path) and unipath.isfile(opf_path):
        op = Opf_Parser(opf_path)

    # create a wrapper for record keeping and safety
    rk = Wrapper(ebook_root, outdir, op)

    # get the correct container
    if script_type == "edit":
        bc = BookContainer(rk)
    elif script_type == "input":
        bc = InputContainer(rk)
    else:
        bc = OutputContainer(rk)

    # start the target script
    ps = ProcessScript(script_type, script_module, bc)
    ps.launch()

    # get standard error and standard out from the target script
    successmsg = ""
    for data in ps.stdouttext:
        successmsg += unicode_str(data)
    successmsg = escapeit(successmsg)
    errorlog = ""
    for data in ps.stderrtext:
        errorlog += unicode_str(data)
    errorlog = escapeit(errorlog)

    # get the target's script wrapper xml
    resultxml = "".join(ps.wrapout)
    resultxml += "<msg>\n"
    if ps.exitcode == 0:
        resultxml += successmsg
        if _DEBUG:
            resultxml += errorlog
    else:
        if _DEBUG:
            resultxml += successmsg
        resultxml += errorlog
    resultxml += "</msg>\n</wrapper>\n"

    # write it to stdout and exit
    if PY3:
        sys.stdout.buffer.write(utf8_str(resultxml))
    else:
        sys.stdout.write(utf8_str(resultxml))
    return 0
开发者ID:pwr,项目名称:Sigil,代码行数:80,代码来源:launcher.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python unipath.pathof函数代码示例发布时间:2022-05-27
下一篇:
Python unipath.exists函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap