生成项目文件
        :return:
        :rtype:
13045
def gen_opf(self, book_idx):
        
        if self._chapterization:
            title = '{title}-{book_idx}'.format(title=self._title, book_idx=book_idx)
            book = 'book-{book_idx}'.format(book_idx=book_idx)
            toc = 'toc-{book_idx}'.format(book_idx=book_idx)
        else:
            title = '{title}'.format(title=self._title)
            book = 'book'
            toc = 'toc'

        opf_file = """<?xml version="1.0" encoding="utf-8"?>
<package unique-identifier="uid" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:asd="http://www.idpf.org/asdfaf">
    <metadata>
        <dc-metadata  xmlns:dc="http://purl.org/metadata/dublin_core" xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
            <dc:Title>{title}</dc:Title>
            <dc:Language>zh-cn</dc:Language>
            <dc:Creator>{author}</dc:Creator>
            <dc:Copyrights>{author}</dc:Copyrights>
            <dc:Publisher>Alexander.Li</dc:Publisher>
            <x-metadata>
                <EmbeddedCover>{cover}</EmbeddedCover>
            </x-metadata>
        </dc-metadata>
    </metadata>
    <manifest>
        <item id="toc" properties="nav" href="{book}.html" media-type="application/xhtml+xml"/>
        <item id="content" media-type="application/xhtml+xml" href="{book}.html"></item>
        <item id="cover-image" media-type="image/png" href="{cover}"/>
        <item id="ncx" media-type="application/x-dtbncx+xml" href="{toc}.ncx"/>
    </manifest>
    <spine toc="ncx">
        <itemref idref="cover-image"/>
        <itemref idref="toc"/>
        <itemref idref="content"/>
    </spine>
    <guide>
        <reference type="toc" title="{title_name}" href="{book}.html#toc"/>
        <reference type="content" title="Book" href="{book}.html"/>
    </guide>
</package>
        """.format(
            title_name='目录',
            author=self._author,
            title=title,
            cover=self._cover_img,
            book=book,
            toc=toc
        )
        return opf_file
510527
def files(self, paths, access=None, extensions=None,
              minsize=None, recursion=False):
        
        self.__init__()
        self.access = access
        self.filetype = 'file'
        self.extensions = extensions
        self.minsize = minsize
        self.paths = paths
        self.recursion = recursion

        return _sorter(self._generator_file())
1136534
def create(self):
        
        lib.gp_camera_folder_make_dir(
            self._cam._cam, self.parent.path.encode(), self.name.encode(),
            self._cam._ctx)
1219657
def gen_static(self, output_folder):
        
        files = []
        for l in self.file_listers:
            files += l()
        for f in files:
            _logger.info("generating %s" % f)
            content = self.get(f)
            loc = os.path.join(output_folder, f)
            d = os.path.dirname(loc)
            if not os.path.exists(d):
                os.makedirs(d)
            with open(loc, "wb") as file_:
                file_.write(content)
718392
def generate_temporary_file(folder='/tmp', prefix='helpme', ext='json'):
    '''

    '''        
    tmp = next(tempfile._get_candidate_names())
    return '%s/%s.%s.%s' %(folder, prefix, tmp, ext)
536155
def create_output_directory(cls, outdir):
        """"""
        cls.PATH = outdir
        try:
            os.mkdir(outdir)
        except FileExistsError:
            pass
77378
def create(self):
        
        if os.path.isfile(self.path):
            if not os.path.exists(self.path):
                with open(self.path, 'w') as fileobj:
                    fileobj.write('')
        else:
            os.makedirs(self.path)
1048123
def _to_tarfile(self, file_generator):
        
        if file_generator.to_path_compression == "tar":
            tar_mode = "w"
        elif file_generator.to_path_compression == "tar.gz":
            tar_mode = "w:gz"
        elif file_generator.to_path_compression == 'tar.bz2':
            tar_mode = "w:bz2"
        else:
            tar_mode = "w"

        with tarfile.open(file_generator.to_path, mode=tar_mode) as outfile:
            for f in file_generator:
                outpath = self._output_path(f.source, file_generator.to_format, archive=True)
                info = tarfile.TarInfo(outpath)
                data = f.writestr(file_generator.to_format).encode()
                info.size = len(data)
                outfile.addfile(tarinfo=info, fileobj=io.BytesIO(data))
1165447
def method_file_cd(f):
    
    @wraps(f)
    def wrapper(self, *args, **kwargs):
        with preserve_current_directory():
            self.GetDirectory().cd()
            return f(self, *args, **kwargs)
    return wrapper
713878
def get_base_dir():
    
    return os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
846178
def to_file_path(self, path_prefix):
        
        with self._path_prefix_to_files(path_prefix, 'w') as (array_file, vocab_file):
            self.to_files(array_file, vocab_file)
289965
def dir():
        
        dir = [
            'access', 'chdir', 'chmod', 'chown', 'close', 'fstat', 'fsync',
            'getcwd', 'lchmod', 'link', 'listdir', 'lstat', 'makedirs',
            'mkdir', 'mknod', 'open', 'read', 'readlink', 'remove',
            'removedirs', 'rename', 'rmdir', 'stat', 'symlink', 'umask',
            'unlink', 'utime', 'walk', 'write'
        ]
        if IS_PY2:
            dir += ['getcwdu']
        else:
            dir += ['getcwdb', 'replace']
            if sys.platform.startswith('linux'):
                dir += [
                    'fdatasync', 'getxattr', 'listxattr',
                    'removexattr', 'setxattr'
                ]
        if use_scandir:
            dir += ['scandir']
        return dir
593652
def create_archive_dir(self):
        
        archive_dir = os.path.join(self.tmp_dir, self.archive_name)
        os.makedirs(archive_dir, 0o700)
        return archive_dir
1349867
def convert(self):
        
        if not os.path.exists(os.path.dirname(self.file_generator.to_path)):
            dirname = os.path.dirname(self.file_generator.to_path)
            if dirname:
                os.makedirs(dirname)

        if os.path.isdir(self.file_generator.from_path):
            self._many_to_many()
        elif os.path.isfile(self.file_generator.from_path) or fileio.GenericFilePath.is_url(self.file_generator.from_path):
            if self.file_generator.from_path_compression in ("zip", "tar", "tar.gz", "tar.bz2"):
                self._many_to_many()
            elif self.file_generator.from_path_compression in ("gz", "bz2"):
                self._one_to_one()
            elif not self.file_generator.from_path_compression:
                self._one_to_one()
        elif self.file_generator.from_path.isdigit():
            self._one_to_one()
        else:
            raise TypeError('Unknown input file format: "{}"'.format(self.file_generator.from_path))
461125
def makedir(self):
        
        try:
            os.makedirs(self.model_dir)
        except OSError as exception:
            if exception.errno != errno.EEXIST:
                raise
789650
def create_file(self, filename, indented_data=None):
        
        filedir, filename = os.path.split(filename)
        if filedir:
            self.create_directory(filedir)
        path = os.path.join(self.path, filedir, filename)
        data = indented_data
        if isinstance(data, bytes) and not isinstance(data, str):
            # This is binary data rather than text.
            mode = 'wb'
        else:
            mode = 'w'
            if data:
                data = textwrap.dedent(data)
        with open(path, mode) as fi:
            if data:
                fi.write(data)
        return path
63428
def generate_and_cache(path=user_path):
    '''
    
    '''
    data = tools.generate()
    if not path:
        return data
    try:
        directory = os.path.dirname(path)
        if not os.path.exists(directory):
            os.makedirs(directory)
        with open(path, 'wb') as f:
            pickle.dump((data_version, module_version, data), f)
    except (PermissionError, ValueError) as e:
        warnings.warn('Unable to write cache file "%s": %s' % (path, e))
    return data