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


Python Index.read方法代码示例

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


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

示例1: update_repo

# 需要导入模块: from pisi.index import Index [as 别名]
# 或者: from pisi.index.Index import read [as 别名]
def update_repo(repo):

    ctx.ui.info('* Updating repository: %s' % repo)
    index = Index()
    index.read(ctx.repodb.get_repo(repo).indexuri.get_uri(), repo)
    index.update_db(repo)
    ctx.ui.info('* Package database updated.')
开发者ID:Tayyib,项目名称:uludag,代码行数:9,代码来源:api.py

示例2: __init__

# 需要导入模块: from pisi.index import Index [as 别名]
# 或者: from pisi.index.Index import read [as 别名]
class PisiCrawler:
    """ Lists and downloads pisi packages in a given repository """

    def __init__(self):
        """Constructor"""

    # -------------------------------------------------------------------
    def readRepo(self, repo_url, dest_dir="./"):
        """Reads repo and fetches index files"""
        ### Imports ###
        from pisi.index import Index
        from os import mkdir

        ### Check if address got a trailing slash ###
        if repo_url.split("/")[-1]:  # If not, add a trailing slash.
            self.repo_url = repo_url + "/"
        else:  #  Else, use it.
            self.repo_url = repo_url

        ### Check dest_dir ###
        if dest_dir.split("/")[-1]:
            dest_dir = dest_dir + "/"

        self.dest_dir = dest_dir + self.repo_url.split("/")[-2]
        self.index_url = self.repo_url + "pisi-index.xml.bz2"

        ### Create Pisi-Index instance ###
        self.pi = Index()
        try:
            self.pi.read_uri(self.index_url, self.dest_dir)
        except:
            pass
        self.pi.read((self.dest_dir + "/pisi-index.xml"))

    # -------------------------------------------------------------------
    def listPackages(self, fullURI=True):
        """Lists packages for given repo address.
        
        listPackages(fullURI=True)
            
        Set fullURI to False to get just package names.
        """
        ### Iterate over packages ###
        i = 1
        for p in self.pi.packages:
            if fullURI:
                print i, "--", self.repo_url + p.packageURI
            else:
                print i, "--", p.packageURI
            i += 1

    # -------------------------------------------------------------------
    def getPackageList(self):
        """Returns a list of package uri's"""
        liste = []
        for p in self.pi.packages:
            p_uri = self.repo_url + p.packageURI
            liste.append(p_uri)
        return liste

    # ----------------------------------------------------------------------
    def fetchPackages(self, destination=None):
        """Downloads packages to destination directory """
        from urlgrabber.grabber import URLGrabber
        from urlgrabber.progress import TextMeter
        from os import path, chdir

        if destination:
            chdir(destination)
        else:
            chdir(self.dest_dir)

        ### URLGrabber objects ###
        t = TextMeter()
        g = URLGrabber(progress_obj=t)

        ### Start Iteration over list of packages' URIs ###
        for uri in self.getPackageList():
            pisifile = uri.split("/")[-1]
            if path.exists(pisifile):
                print pisifile, "--- No Update! Skipping..."
                continue
            try:
                g.urlgrab(uri)
            except:
                print "Error while downloading file %s" % pisifile
                break
        print "Finished."

    # ----------------------------------------------------------------------
    def generatePackageContents(to="cpickle"):
        """Generates lspisi outputs of pisi packages.
        Filetypes; cpickle, pickle, text"""
        pass
开发者ID:havan,项目名称:porsuk,代码行数:96,代码来源:pisi_crawler.py


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