python类resource_string()的实例源码

easy_install.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _load_template(dev_path):
        """
        There are a couple of template scripts in the package. This
        function loads one of them and prepares it for use.
        """
        # See https://github.com/pypa/setuptools/issues/134 for info
        # on script file naming and downstream issues with SVR4
        name = 'script.tmpl'
        if dev_path:
            name = name.replace('.tmpl', ' (dev).tmpl')

        raw_bytes = resource_string('setuptools', name)
        return raw_bytes.decode('utf-8')
easy_install.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def install_site_py(self):
        """Make sure there's a site.py in the target dir, if needed"""

        if self.sitepy_installed:
            return  # already did it, or don't need to

        sitepy = os.path.join(self.install_dir, "site.py")
        source = resource_string("setuptools", "site-patch.py")
        source = source.decode('utf-8')
        current = ""

        if os.path.exists(sitepy):
            log.debug("Checking existing site.py in %s", self.install_dir)
            with io.open(sitepy) as strm:
                current = strm.read()

            if not current.startswith('def __boot():'):
                raise DistutilsError(
                    "%s is not a setuptools-generated site.py; please"
                    " remove it." % sitepy
                )

        if current != source:
            log.info("Creating %s", sitepy)
            if not self.dry_run:
                ensure_directory(sitepy)
                with io.open(sitepy, 'w', encoding='utf-8') as strm:
                    strm.write(source)
            self.byte_compile([sitepy])

        self.sitepy_installed = True
easy_install.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _load_template(dev_path):
        """
        There are a couple of template scripts in the package. This
        function loads one of them and prepares it for use.
        """
        # See https://github.com/pypa/setuptools/issues/134 for info
        # on script file naming and downstream issues with SVR4
        name = 'script.tmpl'
        if dev_path:
            name = name.replace('.tmpl', ' (dev).tmpl')

        raw_bytes = resource_string('setuptools', name)
        return raw_bytes.decode('utf-8')
easy_install.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def install_site_py(self):
        """Make sure there's a site.py in the target dir, if needed"""

        if self.sitepy_installed:
            return  # already did it, or don't need to

        sitepy = os.path.join(self.install_dir, "site.py")
        source = resource_string("setuptools", "site-patch.py")
        source = source.decode('utf-8')
        current = ""

        if os.path.exists(sitepy):
            log.debug("Checking existing site.py in %s", self.install_dir)
            with io.open(sitepy) as strm:
                current = strm.read()

            if not current.startswith('def __boot():'):
                raise DistutilsError(
                    "%s is not a setuptools-generated site.py; please"
                    " remove it." % sitepy
                )

        if current != source:
            log.info("Creating %s", sitepy)
            if not self.dry_run:
                ensure_directory(sitepy)
                with io.open(sitepy, 'w', encoding='utf-8') as strm:
                    strm.write(source)
            self.byte_compile([sitepy])

        self.sitepy_installed = True
easy_install.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_win_launcher(type):
    """
    Load the Windows launcher (executable) suitable for launching a script.

    `type` should be either 'cli' or 'gui'

    Returns the executable as a byte string.
    """
    launcher_fn = '%s.exe' % type
    if is_64bit():
        launcher_fn = launcher_fn.replace(".", "-64.")
    else:
        launcher_fn = launcher_fn.replace(".", "-32.")
    return resource_string('setuptools', launcher_fn)
easy_install.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def load_launcher_manifest(name):
    manifest = pkg_resources.resource_string(__name__, 'launcher manifest.xml')
    if six.PY2:
        return manifest % vars()
    else:
        return manifest.decode('utf-8') % vars()
eggs.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, engine):
        if resource_string is None:
            raise RuntimeError("Setuptools must be installed to use the egg loader")
        super(Loader, self).__init__(engine)
eggs.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def get_contents(self, origin):
        try:
            source = resource_string(origin.app_name, origin.pkg_name)
        except:
            raise TemplateDoesNotExist(origin)

        if six.PY2:
            source = source.decode(self.engine.file_charset)

        return source
easy_install.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _load_template(dev_path):
        """
        There are a couple of template scripts in the package. This
        function loads one of them and prepares it for use.
        """
        # See https://github.com/pypa/setuptools/issues/134 for info
        # on script file naming and downstream issues with SVR4
        name = 'script.tmpl'
        if dev_path:
            name = name.replace('.tmpl', ' (dev).tmpl')

        raw_bytes = resource_string('setuptools', name)
        return raw_bytes.decode('utf-8')
easy_install.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def install_site_py(self):
        """Make sure there's a site.py in the target dir, if needed"""

        if self.sitepy_installed:
            return  # already did it, or don't need to

        sitepy = os.path.join(self.install_dir, "site.py")
        source = resource_string("setuptools", "site-patch.py")
        source = source.decode('utf-8')
        current = ""

        if os.path.exists(sitepy):
            log.debug("Checking existing site.py in %s", self.install_dir)
            with io.open(sitepy) as strm:
                current = strm.read()

            if not current.startswith('def __boot():'):
                raise DistutilsError(
                    "%s is not a setuptools-generated site.py; please"
                    " remove it." % sitepy
                )

        if current != source:
            log.info("Creating %s", sitepy)
            if not self.dry_run:
                ensure_directory(sitepy)
                with io.open(sitepy, 'w', encoding='utf-8') as strm:
                    strm.write(source)
            self.byte_compile([sitepy])

        self.sitepy_installed = True
easy_install.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def load_launcher_manifest(name):
    manifest = pkg_resources.resource_string(__name__, 'launcher manifest.xml')
    if six.PY2:
        return manifest % vars()
    else:
        return manifest.decode('utf-8') % vars()
_vulkan.py 文件源码 项目:pyVulkan 作者: bglgwyng 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _cdef(header):
        ffi.cdef(_pkg_resources.resource_string(__name__, header))
_vulkan.py 文件源码 项目:pyVulkan 作者: bglgwyng 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _cdef(header):
        ffi.cdef(_pkg_resources.resource_string(__name__, header).decode())
vulkan.template.py 文件源码 项目:pyVulkan 作者: bglgwyng 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _cdef(header):
        ffi.cdef(_pkg_resources.resource_string(__name__, header))
vulkan.template.py 文件源码 项目:pyVulkan 作者: bglgwyng 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def _cdef(header):
        ffi.cdef(_pkg_resources.resource_string(__name__, header).decode())
postcards.py 文件源码 项目:postcards 作者: abertschi 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def do_command_generate(self, args):
        target_location = str(os.path.join(os.getcwd(), 'config.json'))

        if os.path.isfile(target_location):
            self.logger.error('config file already exist in current directory.')
            exit(1)

        content = pkg_resources.resource_string(__name__, 'template_config.json').decode('utf-8')
        file = open(target_location, 'w')
        file.write(content)
        file.close()

        self.logger.info('empty config file generated at {}'.format(target_location))
commandscollector.py 文件源码 项目:puppeter 作者: coi-gov-pl 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __resource_string(self, path):
        # noinspection PyTypeChecker
        return self.__load_resource(pkg_resources.resource_string, self.__configurer, path) \
            .decode("utf-8")
commandscollector.py 文件源码 项目:puppeter 作者: coi-gov-pl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __get_linesof_script(self, script):
        format = script['format']  # type: ScriptFormat
        shellscript = script['script']  # type: str
        if format is ScriptFormat.PUPPET:
            tpl = self.__load_resource(pkg_resources.resource_string, self, 'puppet-apply.sh') \
                .decode("utf-8")
            f = NamedTemporaryFile(delete=False)
            tmpfilename = f.name
            f.close()
            os.unlink(f.name)
            tpl = AtTemplate(tpl)
            shellscript = tpl.substitute(dict(tmpfilename=tmpfilename, pp=shellscript))

        return shellscript.split("\n")
core.py 文件源码 项目:bossimage 作者: cloudboss 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def user_data(config):
    if type(config['user_data']) == dict:
        with open(config['user_data']['file']) as f:
            return f.read()

    if not config['user_data'] and config['connection'] == 'winrm':
        ud = pr.resource_string('bossimage', 'win-userdata.txt')
    else:
        ud = config['user_data']
    return ud
data.py 文件源码 项目:pogoiv 作者: tmwilder 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def get_csv(file_name):
    contents = resource_string('pogoiv', 'data/%s' % file_name)

    if sys.version_info >= (3, 0):
        f = StringIO(contents.decode('utf-8'))
    else:
        f = BytesIO(contents)

    return csv.reader(f, delimiter='\t')


问题


面经


文章

微信
公众号

扫码关注公众号