def get_repo_doc(self, repo_name): if not self.has_repo(repo_name): raise RepoError(_("Repository %s does not exist.") % repo) repo = self.get_repo(repo_name) index_path = repo.indexuri.get_uri() #FIXME Local index files should also be cached. if File.is_compressed(index_path) or repo.indexuri.is_remote_file(): index = os.path.basename(index_path) index_path = pisi.util.join_path(ctx.config.index_dir(), repo_name, index) if File.is_compressed(index_path): index_path = os.path.splitext(index_path)[0] if not os.path.exists(index_path): ctx.ui.warning(_("%s repository needs to be updated") % repo_name) return piksemel.newDocument("PISI") try: return piksemel.parse(index_path) except Exception, e: raise RepoError(_("Error parsing repository index information. Index file does not exist or is malformed."))
def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None): uri = File.make_uri(uri) localpath = File.download(uri, tmpDir,sha1sum=sha1sum,compress=compress,sign=sign) try: self.doc = iks.parse(localpath) return self.doc except Exception, e: raise Error(_("File '%s' has invalid XML") % (localpath) )
def readxml(self, uri, tmpDir='/tmp', sha1sum=False, compress=None, sign=None): uri = File.make_uri(uri) localpath = File.download(uri, tmpDir,sha1sum=sha1sum,compress=compress,sign=sign) try: self.doc = NoExtDtdReader.parseUri(Ft.Lib.Uri.OsPathToUri(localpath)) return self.doc.documentElement except Ft.FtException, e: raise Error(_("File '%s' has invalid XML: %s") % (localpath, str(e)) )
def readxml(self, uri, tmpDir = '/tmp'): uri = File.make_uri(uri) localpath = File.download(uri, tmpDir) try: self.doc = ParsePath(localpath) return self.doc.documentElement except Ft.FtException, e: raise Error(_("File '%s' has invalid XML: %s") % (localpath, str(e)) )
def readxml(self, uri, tmpDir="/tmp"): uri = File.make_uri(uri) localpath = File.download(uri, tmpDir) try: self.doc = NoExtDtdReader.parseUri(Ft.Lib.Uri.OsPathToUri(localpath)) return self.doc.documentElement except Ft.FtException, e: raise Error(_("File '%s' has invalid XML: %s") % (localpath, str(e)))
def readxml(self, uri, tmpDir="/tmp"): uri = File.make_uri(uri) localpath = File.download(uri, tmpDir) try: self.doc = mdom.parse(localpath) except ExpatError, inst: raise Error(_("File '%s' has invalid XML: %s\n") % (fileName, str(inst)))
def readxml(self, uri, tmpDir="/tmp", sha1sum=False, compress=None, sign=None, copylocal=False): uri = File.make_uri(uri) # try: localpath = File.download(uri, tmpDir, sha1sum=sha1sum, compress=compress, sign=sign, copylocal=copylocal) # except IOError, e: # raise Error(_("Cannot read URI %s: %s") % (uri, unicode(e)) ) try: self.doc = iks.parse(localpath) return self.doc except Exception, e: raise Error(_("File '%s' has invalid XML") % (localpath))
def testMakeUri(self): spec = SpecFile("repos/pardus-2007/system/base/curl/pspec.xml") url = uri.URI(spec.source.archive[0].uri) self.assert_(File.make_uri(url))
def testChooseMethod(self): compress = File('repos/contrib-2007/pisi-index.xml', File.read) self.assert_(File.choose_method('pisi.conf', compress))
def testFileNo(self): f = File('repos/pardus-2007/system/base/curl/pspec.xml', File.read) assert not 3 == f.fileno()
def testDecompress(self): localfile = open('repos/pardus-2007/system/base/curl/pspec.xml', File.read) compress = open('repos/contrib-2007/pisi-index.xml', File.read) self.assertTrue(File.decompress(localfile, compress))
def writexml(self, uri, tmpDir = '/tmp', sha1sum=False, compress=None, sign=None): f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign) PrettyPrint(self.rootNode(), stream = f) f.close()
def check_signature(self, filename, repo): tmpdir = os.path.join(ctx.config.index_dir(), repo) File.check_signature(filename, tmpdir)
def testLocalFile(self): f = File("tests/popt/pspec.xml", File.read) x = f.readlines() self.assert_(len(x)>0)
def testRemoteRead(self): f = File('http://www.gnu.org/licenses/gpl2.txt', File.read) r = f.readlines() assert (len(r) > 0)
def testRemoteRead(self): f = File("https://github.com/examachine/pisi/wiki", File.read) x = f.readlines() self.assert_(len(x)>0)
def testIsatty(self): f = File('repos/pardus-2007/system/base/curl/pspec.xml', File.read) assert not f.isatty()
def testRemoteRead(self): f = File( 'http://www.pardus.org.tr/urunler/pardus-2009.2-Geronticus_eremita-surum-notlari-tr.html', File.read) r = f.readlines() assert (len(r) > 0)
def testLocalFile(self): f = File('repos/pardus-2007/system/base/curl/pspec.xml', File.read) r = f.readlines() assert (len(r) > 0)
def testDecompress(self): localfile = File('repos/pardus-2007/system/base/curl/pspec.xml', File.read) compress = File('repos/contrib-2007/pisi-index.xml', File.read) self.assert_(File.decompress(localfile,compress))
def download(self, uri, transferdir): # fix auth info and download uri = File.make_uri(uri) if self.authinfo: uri.set_auth_info(self.authinfo) File.download(uri, transferdir)
def writexml(self, uri, tmpDir="/tmp", sha1sum=False, compress=None, sign=None): f = File(uri, File.write, sha1sum=sha1sum, compress=compress, sign=sign) f.write(self.doc.toPrettyString()) f.close()
def testMakeUri(self): self.spec = SpecFile() self.url = uri.URI(self.spec.source.archive.uri) f = File('repos/pardus-2007/system/base/curl/pspec.xml', File.read) self.assert_(f.make_uri('uri'))
def testChooseMethod(self): compress = File('repos/contrib-2007/eopkg-index.xml', File.read) self.assert_(File.choose_method('pisi.conf', compress))
def main(): global options # Parse options parser = OptionParser(usage="%prog [options]", version="%prog 1.0") parser.add_option("-N", "--no-color", action="store_false", dest="color", default=True, help=_("don't use colors")) parser.add_option("-p", "--packages", action="store_true", dest="packages", default=False, help=_("show package names")) parser.add_option("-l", "--long", action="store_true", dest="long", default=False, help=_("show details of advisories")) parser.add_option("-a", "--all", action="store_false", dest="affected", default=True, help=_("show all advisories")) parser.add_option("-F", "--no-fetch", action="store_false", dest="fetch", default=True, help=_("don't download PLSA index")) (options, args) = parser.parse_args() # Get locale lang = os.environ["LC_ALL"].split("_")[0] # Show package details in --long if options.long: options.packages = True # Create work directory if not os.access("/tmp/plsa", os.F_OK): os.mkdir("/tmp/plsa") # Init PISI API pisi.api.init(database=True, comar=False, write=False) # Get installed packages installed_packages = {} for package in ctx.installdb.list_installed(): # Release comparison seems enough installed_packages[package] = int(ctx.installdb.get_version(package)[1]) # List of orphaned packages orphaned = [] # Get list of reporsitories plsas = {} for repo in ctx.repodb.list(): uri = ctx.repodb.get_repo(repo).indexuri.get_uri() plsafile = "%s/plsa-index.xml.bz2" % uri[0:uri.rfind("/")] tmpfile = "/tmp/plsa/%s.xml" % repo if options.fetch: print _("Downloading PLSA database of %s") % repo try: fetch_url(plsafile, "/tmp/plsa", progress=ctx.ui.Progress) except FetchError, e: print _("Unable to download %s: %s") % (plsafile, e) continue print _("Checking file integrity of %s") % repo try: fetch_url("%s.sha1sum" % plsafile, "/tmp/plsa") except FetchError, e: print _("Unable to download checksum of %s") % repo continue orig_sha1sum = file("%s.sha1sum" % plsafile).readlines()[0].split()[0] if sha1_file(plsafile) != orig_sha1sum: print _("File integrity of %s compromised.") % plsafile continue print _("Unpacking PLSA database of %s") % repo try: File.decompress("/tmp/plsa/plsa-index.xml.bz2", File.bz2) except: print _("Unable to decompress %s") % plsafile continue os.rename("/tmp/plsa/plsa-index.xml", tmpfile) os.unlink("/tmp/plsa/plsa-index.xml.bz2") plsas[repo] = tmpfile
def testRemoteRead(self): f = File("http://uludag.org.tr/haberler/rootfs0.2.html", File.read) x = f.readlines() self.assert_(len(x)>0)
def testRemoteRead(self): f = File('http://uludag.org.tr/bulten/index.html', File.read) r = f.readlines() assert (len(r) > 0)
def download(self, uri, transferdir): # fix auth info and download uri = File.make_uri(uri) File.download(uri, transferdir)
def testRemoteRead(self): f = File('http://www.pardus.org.tr/urunler/pardus-2009.2-Geronticus_eremita-surum-notlari-tr.html', File.read) r = f.readlines() assert (len(r) > 0)
def testChooseMethod(self): compress = open('repos/contrib-2007/pisi-index.xml', File.read) self.assertTrue(File.choose_method('pisi.conf', compress))