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


Python unipath.exists函数代码示例

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


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

示例1: copy_book_contents_to

 def copy_book_contents_to(self, destdir):
     destdir = unicode_str(destdir)
     if destdir is None or not unipath.isdir(destdir):
         raise WrapperException('destination directory does not exist')
     for id in self.id_to_filepath:
         rpath = self.id_to_filepath[id]
         in_manifest = id in self.id_to_mime
         data = self.readfile(id)
         filepath = os.path.join(destdir,rpath)
         base = os.path.dirname(filepath)
         if not unipath.exists(base):
             os.makedirs(base)
         if isinstance(data,text_type):
             data = utf8_str(data)
         with open(pathof(filepath),'wb') as fp:
             fp.write(data)
     for id in self.book_href_to_filepath:
         rpath = self.book_href_to_filepath[id]
         data = self.readotherfile(id)
         filepath = os.path.join(destdir,rpath)
         base = os.path.dirname(filepath)
         if not unipath.exists(base):
             os.makedirs(base)
         if isinstance(data,text_type):
             data = utf8_str(data)
         with open(pathof(filepath),'wb') as fp:
             fp.write(data)
开发者ID:Sigil-Ebook,项目名称:Sigil,代码行数:27,代码来源:wrapper.py

示例2: 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

示例3: readotherfile

 def readotherfile(self, book_href):
     id = unicode_str(book_href)
     if id in self.id_to_href:
         raise WrapperException('Incorrect interface routine - use readfile')
     # handle special case of trying to read the opf
     if id is not None and id == "OEBPS/content.opf":
         return self.build_opf()
     filepath = self.id_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException('book href does not exist')
     basedir = self.ebook_root
     if id in self.added or id in self.modified:
         basedir = self.outdir
     filepath = os.path.join(basedir, filepath)
     if not unipath.exists(filepath):
         raise WrapperException('File Does Not Exist')
     basename = os.path.basename(filepath)
     ext = os.path.splitext(basename)[1]
     ext = ext.lower()
     mime = ext_mime_map.get(ext,'')
     data = b''
     with open(filepath,'rb') as fp:
         data = fp.read()
     if mime.endswith('+xml'):
         data = unicode_str(data)
     return data
开发者ID:JksnFst,项目名称:Sigil,代码行数:26,代码来源:wrapper.py

示例4: 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

示例5: write_opf

 def write_opf(self):
     if self.op is not None:
         filepath = pathof(os.path.join(self.outdir, 'OEBPS', self.opfname))
         base = os.path.dirname(filepath)
         if not unipath.exists(base):
             os.makedirs(base)
         with open(filepath,'wb') as fp:
             data = utf8_str(self.build_opf())
             fp.write(data)
开发者ID:JksnFst,项目名称:Sigil,代码行数:9,代码来源:wrapper.py

示例6: writefile

 def writefile(self, id, data):
     id = unicode_str(id)
     filepath = self.id_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException('Id does not exist in manifest')
     mime = self.id_to_mime.get(id,'')
     filepath = os.path.join(self.outdir, filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(pathof(base))
     if mime.endswith('+xml') or isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath,'wb') as fp:
         fp.write(data)
     self.modified[id] = 'file'
开发者ID:pwr,项目名称:Sigil,代码行数:15,代码来源:wrapper.py

示例7: writeotherfile

 def writeotherfile(self, book_href, data):
     id = unicode_str(book_href)
     filepath = self.id_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException('book href does not exist')
     if id in PROTECTED_FILES:
         raise WrapperException('Attempt to modify protected file')
     filepath = os.path.join(self.outdir, filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(base)
     if isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath,'wb') as fp:
         fp.write(data)
     self.modified[id] = 'file'
开发者ID:pwr,项目名称:Sigil,代码行数:16,代码来源:wrapper.py

示例8: 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

示例9: writeotherfile

 def writeotherfile(self, book_href, data):
     id = unicode_str(book_href)
     if id in self.id_to_href:
         raise WrapperException("Incorrect interface routine - use writefile")
     filepath = self.id_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException("book href does not exist")
     if id in PROTECTED_FILES:
         raise WrapperException("Attempt to modify protected file")
     filepath = os.path.join(self.outdir, filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(base)
     if isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath, "wb") as fp:
         fp.write(data)
     self.modified[id] = "file"
开发者ID:apys,项目名称:Sigil,代码行数:18,代码来源:wrapper.py

示例10: readfile

 def readfile(self, id):
     id = unicode_str(id)
     filepath = self.id_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException('Id does not exist in manifest')
     # already added or modified it will be in outdir
     basedir = self.ebook_root
     if id in self.added or id in self.modified:
         basedir = self.outdir
     filepath = os.path.join(basedir, filepath)
     if not unipath.exists(filepath):
         raise WrapperException('File Does Not Exist')
     data = ''
     with open(filepath,'rb') as fp:
         data = fp.read()
     mime = self.id_to_mime.get(id,'')
     if mime.endswith('+xml'):
         data = unicode_str(data)
     return data
开发者ID:pwr,项目名称:Sigil,代码行数:19,代码来源:wrapper.py

示例11: addfile

 def addfile(self, uniqueid, basename, data, mime=None, properties=None, fallback=None, overlay=None):
     uniqueid = unicode_str(uniqueid)
     basename = unicode_str(basename)
     mime = unicode_str(mime)
     if mime is None:
         ext = os.path.splitext(basename)[1]
         ext = ext.lower()
         mime = ext_mime_map.get(ext, None)
     if mime is None:
         raise WrapperException("Mime Type Missing")
     if mime.startswith("audio"):
         base = 'Audio'
     elif mime.startswith("video"):
         base = "Video"
     else:
         base = mime_base_map.get(mime,'Misc')
     href = base + "/" + basename
     if uniqueid in self.id_to_href:
         raise WrapperException('Manifest Id is not unique')
     if href in self.href_to_id:
         raise WrapperException('Basename is not unique')
     # now actually write out the new file
     filepath = href.replace("/",os.sep)
     filepath = os.path.join('OEBPS', filepath)
     self.id_to_filepath[uniqueid] = filepath
     filepath = os.path.join(self.outdir,filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(base)
     if mime.endswith('+xml') or isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath,'wb') as fp:
         fp.write(data)
     self.id_to_href[uniqueid] = href
     self.id_to_mime[uniqueid] = mime
     self.id_to_props[uniqueid] = properties
     self.id_to_fall[uniqueid] = fallback
     self.id_to_over[uniqueid] = overlay
     self.href_to_id[href] = uniqueid
     self.added.append(uniqueid)
     self.modified['OEBPS/content.opf'] = 'file'
     return uniqueid
开发者ID:JksnFst,项目名称:Sigil,代码行数:42,代码来源:wrapper.py

示例12: writeotherfile

 def writeotherfile(self, book_href, data):
     id = unicode_str(book_href)
     id = unquoteurl(id)
     if id is None:
         raise WrapperException('None is not a valid book href')
     if id not in self.other and id in self.id_to_href:
         raise WrapperException('Incorrect interface routine - use writefile')
     filepath = self.book_href_to_filepath.get(id, None)
     if filepath is None:
         raise WrapperException('Book href does not exist')
     if id in PROTECTED_FILES:
         raise WrapperException('Attempt to modify protected file')
     filepath = os.path.join(self.outdir, filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(base)
     if isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath,'wb') as fp:
         fp.write(data)
     self.modified[id] = 'file'
开发者ID:Sigil-Ebook,项目名称:Sigil,代码行数:21,代码来源:wrapper.py

示例13: addfile

 def addfile(self, uniqueid, basename, data, mime=None):
     uniqueid = unicode_str(uniqueid)
     basename = unicode_str(basename)
     mime = unicode_str(mime)
     if mime is None:
         ext = os.path.splitext(basename)[1]
         ext = ext.lower()
         mime = ext_mime_map.get(ext, None)
     if mime is None:
         raise WrapperException("Mime Type Missing")
     if mime.startswith("audio"):
         base = "Audio"
     elif mime.startswith("video"):
         base = "Video"
     else:
         base = mime_base_map.get(mime, "Misc")
     href = base + "/" + basename
     if uniqueid in self.id_to_href:
         raise WrapperException("Manifest Id is not unique")
     if href in self.href_to_id:
         raise WrapperException("Basename is not unique")
     # now actually write out the new file
     filepath = href.replace("/", os.sep)
     filepath = os.path.join("OEBPS", filepath)
     self.id_to_filepath[uniqueid] = filepath
     filepath = os.path.join(self.outdir, filepath)
     base = os.path.dirname(filepath)
     if not unipath.exists(base):
         os.makedirs(base)
     if mime.endswith("+xml") or isinstance(data, text_type):
         data = utf8_str(data)
     with open(filepath, "wb") as fp:
         fp.write(data)
     self.id_to_href[uniqueid] = href
     self.id_to_mime[uniqueid] = mime
     self.href_to_id[href] = uniqueid
     self.added.append(uniqueid)
     self.modified["OEBPS/content.opf"] = "file"
     return uniqueid
开发者ID:apys,项目名称:Sigil,代码行数:39,代码来源:wrapper.py

示例14: cmdDo

    def cmdDo(self):
        global CRITERIA

        if self.dashBox.current() == 0:
            dash_settings = ''
        elif self.dashBox.current() == 1:
            dash_settings = 'd'
        elif self.dashBox.current() == 2:
            dash_settings = 'i'
        else:
            dash_settings = 'D'

        if self.use_file.get():
            self.cust_file_path.config(state="normal")
            if len(self.cust_file_path.get()):
                apos_exception_file = self.cust_file_path.get()
                if not unipath.exists(utf8_str(apos_exception_file)):
                    print ('Apostrophe exception file %s does not exist!' % apos_exception_file)
                    apos_exception_file = None
            else:
                apos_exception_file = None
            self.cust_file_path.config(state="readonly")
        else:
            apos_exception_file = None
        CRITERIA['apos_exception_file'] = apos_exception_file

        smarty_attr = self.edu_quotes.get() + dash_settings + self.edu_ellipses.get()
        if smarty_attr == '':
            smarty_attr = '0'
        CRITERIA['smarty_attr'] = smarty_attr

        CRITERIA['use_unicode'] = self.unicodevar.get()

        indices = self.filelist.curselection()
        CRITERIA['files'] = [self.filelist.get(index) for index in indices]

        self.quitApp()
开发者ID:dougmassay,项目名称:punctuationsmarten-sigil-plugin,代码行数:37,代码来源:plugin.py

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