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

Python unipath.pathof函数代码示例

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

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



在下文中一共展示了pathof函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: parseExceptionsFile

def parseExceptionsFile(filename):
    safename = utf8_str(filename)
    words_list = []
    snippet = min(32, os.path.getsize(pathof(safename)))
    raw = open(pathof(safename), 'rb').read(snippet)
    if raw.startswith(codecs.BOM_UTF8):
        enc = 'utf-8-sig'
    else:
        encodings = ['utf-8', 'utf-16' 'windows-1252', 'windows-1250']
        for e in encodings:
            try:
                fh = file_open(pathof(safename), 'r', encoding=e)
                fh.readlines()
                fh.seek(0)
            except UnicodeDecodeError:
                print('Got unicode error with %s , trying different encoding' % e)
            else:
                break
        enc = e
    try:
        with file_open(pathof(safename), 'r', encoding=enc) as fd:
            words_list = [line.rstrip() for line in fd]
        # words_list = filter(None, words_list)
        words_list = [_f for _f in words_list if _f]
        print('Parsing apostrophe exception file %s' % filename)
    except:
        print('Error parsing apostrophe exception file %s: ignoring' % filename)
        words_list = []
    return words_list
开发者ID:dougmassay,项目名称:punctuationsmarten-sigil-plugin,代码行数:29,代码来源:plugin.py


示例3: epub_zip_up_book_contents

def epub_zip_up_book_contents(ebook_path, epub_filepath):
    outzip = zipfile.ZipFile(pathof(epub_filepath), 'w')
    files = unipath.walk(ebook_path)
    if 'mimetype' in files:
        outzip.write(pathof(os.path.join(ebook_path, 'mimetype')), pathof('mimetype'), zipfile.ZIP_STORED)
    else:
        raise Exception('mimetype file is missing')
    files.remove('mimetype')
    for file in files:
        filepath = os.path.join(ebook_path, file)
        outzip.write(pathof(filepath),pathof(file),zipfile.ZIP_DEFLATED)
    outzip.close()
开发者ID:CedarLogic,项目名称:Sigil,代码行数:12,代码来源:epub_utils.py


示例4: __init__

    def __init__(self, ebook_root, outdir, op, plugin_dir, plugin_name, debug=False):
        self._debug = debug
        self.ebook_root = pathof(ebook_root)
        # plugins and plugin containers can get name and user plugin dir
        self.plugin_dir = pathof(plugin_dir)
        self.plugin_name = plugin_name
        self.outdir = pathof(outdir)
        # dictionaries used to map opf manifest information
        self.id_to_href = {}
        self.id_to_mime = {}
        self.href_to_id = {}
        self.spine_ppd = None
        self.spine = []
        self.guide = []
        self.package_tag = ""
        self.metadataxml = ""
        self.op = op
        if self.op is not None:
            # copy in data from parsing of initial opf
            self.opfname = op.opfname
            self.id_to_href = op.get_manifest_id_to_href_dict().copy()
            self.id_to_mime = op.get_manifest_id_to_mime_dict().copy()
            self.href_to_id = op.get_href_to_manifest_id_dict().copy()
            self.spine_ppd = op.get_spine_ppd()
            self.spine = op.get_spine()
            self.guide = op.get_guide()
            self.package_tag = op.get_package_tag()
            self.metadataxml = op.get_metadataxml()
        self.other = []  # non-manifest file information
        self.id_to_filepath = {}
        self.modified = {}
        self.added = []
        self.deleted = []

        # walk the ebook directory tree building up initial list of
        # all unmanifested (other) files
        for filepath in unipath.walk(ebook_root):
            book_href = filepath.replace(os.sep, "/")
            # OS X file names and paths use NFD form. The EPUB
            # spec requires all text including filenames to be in NFC form.
            book_href = unicodedata.normalize("NFC", book_href)
            # if book_href file in manifest convert to manifest id
            id = None
            if book_href.startswith("OEBPS/"):
                href = book_href[6:]
                id = self.href_to_id.get(href, None)
            if id is None:
                self.other.append(book_href)
                self.id_to_filepath[book_href] = filepath
            else:
                self.id_to_filepath[id] = filepath
开发者ID:apys,项目名称:Sigil,代码行数:51,代码来源:wrapper.py


示例5: quitApp

    def quitApp(self):
        global prefs
        if self.edu_quotes.get() == 'q':
            self.gui_prefs['educateQuotes'] = 1
        else:
            self.gui_prefs['educateQuotes'] = 0
        self.gui_prefs['dashes'] = self.dashBox.current()
        if self.edu_ellipses.get() == 'e':
            self.gui_prefs['educateEllipses'] = 1
        else:
            self.gui_prefs['educateEllipses'] = 0
        self.gui_prefs['useFile'] = self.use_file.get()
        if len(self.cust_file_path.get()):
            self.gui_prefs['useFilePath'] = pathof(self.cust_file_path.get())
        else:
            self.gui_prefs['useFilePath'] = ''
        self.gui_prefs['useUnicodeChars'] = self.unicodevar.get()
        self.misc_prefs['windowGeometry'] = self.parent.geometry()

        # copy preferences settings groups pack to global dict
        prefs['gui_selections'] = self.gui_prefs
        prefs['miscellaneous_settings'] = self.misc_prefs
        prefs['update_settings'] = self.update_prefs

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


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


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


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


示例9: unzip_epub_to_dir

def unzip_epub_to_dir(path_to_epub, destdir):
    f = open(pathof(path_to_epub), 'rb')
    sz = ZipFile(f)
    for name in sz.namelist():
        data = sz.read(name)
        name = name.replace("/", os.sep)
        filepath = os.path.join(destdir,name)
        basedir = os.path.dirname(filepath)
        if not os.path.isdir(basedir):
            os.makedirs(basedir)
        with open(filepath,'wb') as fp:
            fp.write(data)
    f.close()
开发者ID:CedarLogic,项目名称:Sigil,代码行数:13,代码来源:epub_utils.py


示例10: fileChooser

 def fileChooser(self):
     file_opt = {}
     file_opt['parent'] = None
     file_opt['title']= 'Select exception file'
     file_opt['defaultextension'] = '.txt'
     file_opt['initialdir'] = unicode_str(self.misc_prefs['lastDir'], 'utf-8')
     file_opt['multiple'] = False
     file_opt['filetypes'] = [('Text Files', '.txt'), ('All files', '.*')]
     inpath = tkinter_filedialog.askopenfilename(**file_opt)
     if len(inpath):
         self.cust_file_path.config(state="normal")
         self.cust_file_path.delete(0, tkinter_constants.END)
         self.cust_file_path.insert(0, os.path.normpath(inpath))
         self.misc_prefs['lastDir'] = pathof(os.path.dirname(inpath))
         self.cust_file_path.config(state="readonly")
开发者ID:dougmassay,项目名称:punctuationsmarten-sigil-plugin,代码行数:15,代码来源:plugin.py


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


示例12: __init__

 def __init__(self, opf_path, debug = False):
     self._debug = debug
     opf_path = pathof(opf_path)
     self.opfname = os.path.basename(opf_path)
     self.opf = None
     with open(opf_path,'rb') as fp:
         self.opf = fp.read().decode('utf-8')
     self.opos = 0
     self.package = None
     self.metadata_attr = None
     self.metadata = []
     self.cover_id = None
     self.manifest_id_to_href = {}
     self.manifest_id_to_mime = {}
     self.href_to_manifest_id = {}
     self.manifest_id_to_properties = {}
     self.spine = []
     self.spine_ppd = None
     self.guide = []
     self.bindings = []
     self._parseData()
开发者ID:ochaslot,项目名称:Sigil-update,代码行数:21,代码来源:opf_parser.py


示例13: __init__

 def __init__(self, opf_path, debug = False):
     self._debug = debug
     opf_path = pathof(opf_path)
     self.opfname = os.path.basename(opf_path)
     self.opf = None
     with open(opf_path,'rb') as fp:
         self.opf = fp.read().decode('utf-8')
     self.opos = 0
     self.package_tag = [None, None]
     # self.package_version = None
     self.metadata_tag = [None, None]
     self.metadata = []
     self.cover_id = None
     self.manifest_id_to_href = {}
     self.manifest_id_to_mime = {}
     self.href_to_manifest_id ={}
     self.spine_ppd = None
     # self.spine_pageattributes = {}
     # self.spine_idrefs = {}
     self.spine = []
     self.guide = []
     self._parseData()
开发者ID:dardrian,项目名称:Sigil,代码行数:22,代码来源:opf_parser.py


示例14: __init__

    def __init__(self, ebook_root, outdir, op, plugin_dir, plugin_name, debug = False):
        self._debug = debug
        self.ebook_root = pathof(ebook_root)
        # plugins and plugin containers can get name and user plugin dir
        self.plugin_dir = pathof(plugin_dir)
        self.plugin_name = plugin_name
        self.outdir = pathof(outdir)

        # initialize the sigil cofiguration info passed in outdir with sigil.cfg
        self.appdir = None
        self.usrsupdir = None
        self.selected = []
        cfg = ''
        with open(os.path.join(self.outdir, 'sigil.cfg'), 'rb') as f:
            cfg = f.read().decode('utf-8')
        cfg = cfg.replace("\r", "")
        cfg_lst = cfg.split("\n")
        if len(cfg_lst) >= 2:
            self.appdir = cfg_lst.pop(0)
            self.usrsupdir = cfg_lst.pop(0)
            self.selected = cfg_lst
        os.environ['SigilGumboLibPath'] = self.get_gumbo_path()

        # dictionaries used to map opf manifest information
        self.id_to_href = {}
        self.id_to_mime = {}
        self.href_to_id = {}
        self.id_to_props = {}
        self.id_to_fall = {}
        self.id_to_over = {}
        self.spine_ppd = None
        self.spine = []
        self.guide = []
        self.package_tag = None
        self.epub_version = None
        # self.metadata_attr = None
        # self.metadata = []
        self.metadataxml = ''
        self.op = op
        if self.op is not None:
            # copy in data from parsing of initial opf
            self.opfname = op.opfname
            self.id_to_href = op.get_manifest_id_to_href_dict().copy()
            self.id_to_mime = op.get_manifest_id_to_mime_dict().copy()
            self.href_to_id = op.get_href_to_manifest_id_dict().copy()
            self.id_to_props = op.get_manifest_id_to_properties_dict().copy()
            self.id_to_fall = op.get_manifest_id_to_fallback_dict().copy()
            self.id_to_over = op.get_manifest_id_to_overlay_dict().copy()
            self.spine_ppd = op.get_spine_ppd()
            self.spine = op.get_spine()
            self.guide = op.get_guide()
            self.package_tag = op.get_package_tag()
            self.epub_version = op.get_epub_version()
            # self.metadata = op.get_metadata()
            # self.metadata_attr = op.get_metadata_attr()
            self.metadataxml = op.get_metadataxml()
        self.other = []  # non-manifest file information
        self.id_to_filepath = {}
        self.modified = {}
        self.added = []
        self.deleted = []

        # walk the ebook directory tree building up initial list of
        # all unmanifested (other) files
        for filepath in unipath.walk(ebook_root):
            book_href = filepath.replace(os.sep, "/")
            # OS X file names and paths use NFD form. The EPUB
            # spec requires all text including filenames to be in NFC form.
            book_href = unicodedata.normalize('NFC', book_href)
            # if book_href file in manifest convert to manifest id
            id = None
            if book_href.startswith('OEBPS/'):
                href = book_href[6:]
                id = self.href_to_id.get(href,None)
            if id is None:
                self.other.append(book_href)
                self.id_to_filepath[book_href] = filepath
            else:
                self.id_to_filepath[id] = filepath
开发者ID:JksnFst,项目名称:Sigil,代码行数:79,代码来源:wrapper.py


示例15: run

def run(bk):
    global prefs
    prefs = bk.getPrefs()

    # set default preference values
    if 'use_file_path' not in prefs:
        prefs['use_file_path'] = expanduser('~')
    if 'check_for_updates' not in prefs:
        prefs['check_for_updates'] = True
    if 'last_time_checked' not in prefs:
        prefs['last_time_checked'] = str(datetime.now() - timedelta(hours=delta+1))
    if 'last_online_version' not in prefs:
        prefs['last_online_version'] = '0.1.0'

    if prefs['check_for_updates']:
        chk = UpdateChecker(prefs['last_time_checked'], prefs['last_online_version'], bk._w)
        update_available, online_version, time = chk.update_info()
        # update preferences with latest date/time/version
        prefs['last_time_checked'] = time
        if online_version is not None:
            prefs['last_online_version'] = online_version
        if update_available:
            title = 'Plugin Update Available'
            msg = 'Version {} of the {} plugin is now available.'.format(online_version, bk._w.plugin_name)
            show_msgbox(title, msg, 'info')

    if 'META-INF/{}'.format(XMLFILE) in bk._w.other:
        title = 'File Already Present!'
        msg = 'The {} file is already present. Please delete it before trying to add another'.format(XMLFILE)
        show_msgbox(title, msg, 'error')
        return 0

    if _DEBUG_:
        print('Python sys.path: {}\n'.format(sys.path))

    inpath = fileChooser()
    if inpath == '' or not os.path.exists(inpath):
        print('iBooks XML file selection canceled!')
        bk.savePrefs(prefs)
        return 0

    if _DEBUG_:
        print('Path to XML file: {}\n'.format(inpath))

    # Save last directory accessed to JSON prefs
    prefs['use_file_path'] = pathof(os.path.dirname(inpath))

    # Save prefs to json
    bk.savePrefs(prefs)

    try:
        with file_open(inpath,'rb')as fp:
            data = fp.read()
    except:
        title = 'Unexpected error!'
        msg = 'Error reading the {} file. Perhaps it is corrupt or missing?'.format(XMLFILE)
        show_msgbox(title, msg, 'error')
        return -1

    if _DEBUG_:
        print('Internal epub href: META-INF/{}\n'.format(XMLFILE))

    bk.addotherfile('META-INF/{}'.format(XMLFILE), data)

    return 0
开发者ID:dougmassay,项目名称:addibooksxml-sigil-plugin,代码行数:65,代码来源:plugin.py


示例16: run

def run(bk):
    global prefs
    prefs = bk.getPrefs()

    # set default preference values
    if 'use_file_path' not in prefs:
        prefs['use_file_path'] = expanduser('~')
    if 'azw3_epub_version' not in prefs:
        prefs['azw3_epub_version'] = "2"  # A, F, 2 or 3
    if 'use_hd_images' not in prefs:
        prefs['use_hd_images'] = True
    if 'use_src_from_dual_mobi' not in prefs:
        prefs['use_src_from_dual_mobi'] = True
    if 'asin_for_kindlegen_plugin' not in prefs:
        prefs['asin_for_kindlegen_plugin'] = False
    if 'preserve_kindleunpack_meta' not in prefs:
        prefs['preserve_kindleunpack_meta'] = False

    if 'last_time_checked' not in prefs:
        prefs['last_time_checked'] = str(datetime.now() - timedelta(hours=7))
    if 'last_online_version' not in prefs:
        prefs['last_online_version'] = '0.1.0'

    chk = UpdateChecker(prefs['last_time_checked'], prefs['last_online_version'], bk._w)
    update_available, online_version, time = chk.update_info()
    # update preferences with latest date/time/version
    prefs['last_time_checked'] = time
    if online_version is not None:
        prefs['last_online_version'] = online_version
    if update_available:
        title = 'Plugin Update Available'
        msg = 'Version {} of the {} plugin is now available.'.format(online_version, bk._w.plugin_name)
        update_msgbox(title, msg)

    if _DEBUG_:
        print('Python sys.path', sys.path)
        print('Default AZW3 epub version:', prefs['azw3_epub_version'])

    inpath = fileChooser()
    if inpath == '' or not os.path.exists(inpath):
        print('No input file selected!')
        bk.savePrefs(prefs)
        return 0

    print ('Path to Kindlebook {0}'.format(inpath))
    from mobi_stuff import mobiProcessor, topaz
    if topaz(inpath):
        print('Kindlebook is in Topaz format: can\'t open!')
        bk.savePrefs(prefs)
        return -1

    mobionly = False
    mp = mobiProcessor(inpath, prefs['azw3_epub_version'],  prefs['use_hd_images'])
    # Save last directory accessed to JSON prefs
    prefs['use_file_path'] = pathof(os.path.dirname(inpath))
    if mp.isEncrypted:
        print('Kindlebook is encrypted: can\'t open!')
        bk.savePrefs(prefs)
        return -1
    if mp.isPrintReplica:
        print('Kindlebook is a Print Replica: can\'t open!')
        bk.savePrefs(prefs)
        return -1
    if not mp.isComboFile and not mp.isKF8:
        mobionly = True

    with make_temp_directory() as temp_dir:
        TWEAK = True
        asin = None
        if not mobionly:
            epub, opf, src = mp.unpackEPUB(temp_dir)
            if src is not None and isEPUB(src) and prefs['use_src_from_dual_mobi']:
                print ('Using included kindlegen sources.')
                epub = src
            else:
                # If user requested no tweaks through preferences, use standard epub from KindleUnpack
                if not prefs['asin_for_kindlegen_plugin'] and not prefs['preserve_kindleunpack_meta']:
                    TWEAK = False
                elif prefs['asin_for_kindlegen_plugin']:
                    if opf is not None:
                        # Get asin from metadata and put it in a dc:meta that the Kindlegen plugin can use.
                        asin = get_asin(opf)
                        if asin is not None:
                            asin = unicode_str(asin)
                    else:
                        TWEAK = False
                if TWEAK:
                    # Modify the opf with the requested tweaks and build a new epub
                    if tweak_opf(opf, asin, preserve_comments=prefs['preserve_kindleunpack_meta']):
                        os.remove(epub)
                        with temp_epub_handle(delete=False) as new_epub:
                            epub_zip_up_book_contents(os.path.join(temp_dir,'mobi8'), new_epub)
                        epub = new_epub
        else:
            from quickepub import QuickEpub
            mobidir, mobi_html, mobi_opf, mobiBaseName = mp.unpackMOBI(temp_dir)
            if not prefs['asin_for_kindlegen_plugin'] and not prefs['preserve_kindleunpack_meta']:
                TWEAK = False
            elif prefs['asin_for_kindlegen_plugin']:
                if mobi_opf is not None:
#.........这里部分代码省略.........
开发者ID:dougmassay,项目名称:kindleimport-sigil-plugin,代码行数:101,代码来源:plugin.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python unipath.FSPath类代码示例发布时间:2022-05-27
下一篇:
Python unipath.isfile函数代码示例发布时间: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