Exemple #1
0
def sources_filename_from_ppa_entry(entry):
    """
    takes a PPA SourceEntry and returns a filename suitable for sources.list.d
    """
    import apt_pkg
    name = "%s.list" % apt_pkg.URItoFileName(entry.uri)
    return name
Exemple #2
0
def get_release_filename_for_pkg(cache, pkgname, label, release):
    " get the release file that provides this pkg "
    if not cache.has_key(pkgname):
        return None
    pkg = cache[pkgname]
    ver = None
    # look for the version that comes from the repos with
    # the given label and origin
    for aver in pkg._pkg.VersionList:
        if aver == None or aver.FileList == None:
            continue
        for verFile, index in aver.FileList:
            #print verFile
            if (verFile.Origin == label and verFile.Label == label
                    and verFile.Archive == release):
                ver = aver
    if not ver:
        return None
    indexfile = cache._list.FindIndex(ver.FileList[0][0])
    for metaindex in cache._list.List:
        for m in metaindex.IndexFiles:
            if (indexfile and indexfile.Describe == m.Describe
                    and indexfile.IsTrusted):
                dir = apt_pkg.Config.FindDir("Dir::State::lists")
                name = apt_pkg.URItoFileName(
                    metaindex.URI) + "dists_%s_Release" % metaindex.Dist
                return dir + name
    return None
Exemple #3
0
 def _copyRelease(self, signatures, targetdir=None):
     " copy the release file "
     if not targetdir:
         targetdir = apt_pkg.Config.find_dir("Dir::State::lists")
     diskname = self._readDiskName()
     for sig in signatures:
         releasef = os.path.splitext(sig)[0]
         # copy both Release and Release.gpg
         for f in (sig, releasef):
             fname = apt_pkg.URItoFileName("cdrom:[%s]/%s" %
                                           (diskname, f[f.find("dists"):]))
             shutil.copy(f, os.path.join(targetdir, fname))
     return True
Exemple #4
0
 def _copyTranslations(self, translations, targetdir=None):
     if not targetdir:
         targetdir = apt_pkg.Config.find_dir("Dir::State::lists")
     diskname = self._readDiskName()
     for f in translations:
         fname = apt_pkg.URItoFileName("cdrom:[%s]/%s" %
                                       (diskname, f[f.find("dists"):]))
         outf = os.path.join(targetdir, os.path.splitext(fname)[0])
         if f.endswith(".gz"):
             g = gzip.open(f)
             out = open(outf, "w")
             # uncompress in 64k chunks
             while True:
                 s = g.read(64000)
                 out.write(s)
                 if s == "":
                     break
         else:
             shutil.copy(f, outf)
     return True
Exemple #5
0
    def load(self):
        """
        Regenerates the fake configuration and load the packages server.
        """
        if not self.loaded:
            log.msg("Loading Packages database for "+self.status_dir,'apt_pkg')
            
            shutil.rmtree(self.status_dir+'/apt/lists/')
            os.makedirs(self.status_dir+'/apt/lists/partial')
            sources = open(self.status_dir+'/'+'apt/etc/sources.list', 'w')
            for file in self.packages.keys():
                # we should probably clear old entries from self.packages and
                # take into account the recorded mtime as optimization
                fake_uri='http://apt-proxy:'+file
                source_line='deb '+dirname(fake_uri)+'/ /'
                listpath=(self.status_dir+'/apt/lists/'
                          +apt_pkg.URItoFileName(fake_uri))
                sources.write(source_line+'\n')

                try:
                    #we should empty the directory instead
                    os.unlink(listpath)
                except:
                    pass
                os.symlink('../../../../../'+file, listpath)
            sources.close()
            for key, value in self.local_config.items():
                apt_pkg.Config[key] = value
            apt_pkg.InitSystem()

            if log.isEnabled('apt'):
                self.cache = apt_pkg.GetCache()
            else:
                # apt_pkg prints progress messages to stdout, disable
                self.__save_stdout()
                self.cache = apt_pkg.GetCache()
                self.__restore_stdout()

            self.records = apt_pkg.GetPkgRecords(self.cache)
            self.loaded = 1