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


Python Profile.load方法代码示例

本文整理汇总了Python中profile.Profile.load方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.load方法的具体用法?Python Profile.load怎么用?Python Profile.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在profile.Profile的用法示例。


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

示例1: Installer

# 需要导入模块: from profile import Profile [as 别名]
# 或者: from profile.Profile import load [as 别名]
class Installer(object):

    def __init__(self, package_dir):
        self._get_url = {
            'toolchain-icestorm': self.get_latest_icestorm,
            'tool-scons': self.get_latest_scons
        }
        self._package_dir = package_dir
        self._profile = Profile()
        self._profile.load()

    def install(self, tool):
        if tool in self._get_url:
            print('Install ' + tool)
            if not isdir(self._package_dir):
                makedirs(self._package_dir)
            assert isdir(self._package_dir)
            url = self._get_url[tool]()
            try:
                dlpath = None
                dlpath = self.download(tool, url, self._package_dir)
                if dlpath:
                    if isdir(join(self._package_dir, tool)):
                        shutil.rmtree(join(self._package_dir, tool))
                    assert isfile(dlpath)
                    self.unpack(dlpath, self._package_dir)
            finally:
                if dlpath:
                    remove(dlpath)
                    filename = splitext(splitext(basename(dlpath))[0])[0]
                    if tool == 'tool-scons':
                        rename(join(self._package_dir, filename),
                               join(self._package_dir, tool))
                    self._profile.packages[tool] = basename(dlpath)
                    self._profile.save()

    def uninstall(self, tool):
        if tool in self._get_url:
            if isdir(join(self._package_dir, tool)):
                print('Uninstall package {0}'.format(tool))
                shutil.rmtree(join(self._package_dir, tool))
            else:
                print('Package {0} is not installed'.format(tool))
            self._profile.remove(tool)
            self._profile.save()

    def get_latest_icestorm(self):
        releases_url = 'https://api.github.com/repos/bqlabs/toolchain-icestorm/releases/latest'
        response = urllib2.urlopen(releases_url)
        packages = json.loads(response.read())
        return packages['assets'][0]['browser_download_url']

    def get_latest_scons(self):
        return 'http://sourceforge.net/projects/scons/files/scons/2.4.1/scons-2.4.1.tar.gz'

    def download(self, tool, url, dest_dir, sha1=None):
        fd = FileDownloader(url, dest_dir)
        if self._profile.check_version(tool, basename(fd.get_filepath())):
            print('Download ' + basename(fd.get_filepath()))
            fd.start()
            fd.verify(sha1)
            return fd.get_filepath()
        else:
            print('Package {0} is already the newest version'.format(tool))
            return None

    def unpack(self, pkgpath, dest_dir):
        fu = FileUnpacker(pkgpath, dest_dir)
        return fu.start()
开发者ID:Peque,项目名称:apio,代码行数:71,代码来源:install.py

示例2: print

# 需要导入模块: from profile import Profile [as 别名]
# 或者: from profile.Profile import load [as 别名]
                "content": jsonstr
            }
        }
    }
    req = requests.post(config.get("github", "endpoint"),
                        data=json.dumps(gist),
                        auth=(config.get("github", "user"), config.get("github", "token")))
    if req.status_code == 201:
        print("Writing to GitHub: " + req.json()["html_url"])

if __name__ == "__main__":
    if len(sys.argv) not in [3, 4]:
        print_help()
        sys.exit(0)
    p_new = Profile()
    p_new.load(open(sys.argv[2]))
    p_base = Profile()
    p_base.about = p_new.about
    p_base.stats["suburi"] = {}
    if len(sys.argv) == 4:
        p_base.load(open(sys.argv[3]))
    section = p_base.stats["suburi"]
    for k, v in p_new.stats["suburi"].iteritems():
        if k in section:
            section[k]["urir_sum"] += v["urir"]
            section[k]["sources"] += 1
        else:
            section[k] = {"urir_sum": v["urir"], "sources": 1}
    jsonstr = p_base.to_json()
    write_json(jsonstr, filepath=sys.argv[1])
#    print(jsonstr)
开发者ID:oduwsdl,项目名称:archive_profiler,代码行数:33,代码来源:profile_merger.py


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