From: Michael Schroeder Date: Tue, 30 Oct 2012 10:27:34 +0000 (+0100) Subject: beautify examples a bit X-Git-Tag: BASE-SuSE-Code-12_3-Branch~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48eaa7cda8a370df58e4bc9969e3b272b234b16b;p=thirdparty%2Flibsolv.git beautify examples a bit --- diff --git a/examples/p5solv b/examples/p5solv index 9333b446..a5193a53 100755 --- a/examples/p5solv +++ b/examples/p5solv @@ -41,7 +41,7 @@ sub calc_cookie_ext { my $chksum = solv::Chksum->new($solv::REPOKEY_TYPE_SHA256); $chksum->add("1.1"); $chksum->add($cookie); - $chksum->add_fstat(fileno($f)) if $f; + $chksum->add_fstat(fileno($f)); my $extcookie = $chksum->raw(); substr($extcookie, 0, 1) = chr(1) if ord(substr($extcookie, 0, 1)) == 0; return $extcookie; @@ -191,6 +191,11 @@ sub writecachedrepo { rename($tmpname, $self->cachepath($ext)); } +sub packagespath { + my ($self) = @_; + return ''; +} + package Repo::rpmmd; our @ISA = ('Repo::generic'); @@ -448,6 +453,11 @@ sub load_if_changed { return undef; } +sub packagespath { + my ($self) = @_; + return ($self->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') . '/'; +} + package Repo::unknown; our @ISA = ('Repo::generic'); @@ -714,9 +724,7 @@ if ($cmd eq 'install' || $cmd eq 'erase' || $cmd eq 'up' || $cmd eq 'dup' || $cm my $repo = $p->{'repo'}->{'appdata'}; my ($location, $medianr) = $p->lookup_location(); next unless $location; - if ($repo->{'type'} eq 'susetags') { - $location = ($repo->{'handle'}->lookup_str($solv::SOLVID_META, $solv::SUSETAGS_DATADIR) || 'suse') ."/$location"; - } + $location = $repo->packagespath() . $location; my $chksum = $p->lookup_checksum($solv::SOLVABLE_CHECKSUM); my $f = $repo->download($location, 0, $chksum); die("\n$repo->{'alias'}: $location not found in repository\n") unless $f; diff --git a/examples/pysolv b/examples/pysolv index 479aba2e..b6e7710a 100755 --- a/examples/pysolv +++ b/examples/pysolv @@ -45,30 +45,6 @@ from optparse import OptionParser #import gc #gc.set_debug(gc.DEBUG_LEAK) -def calc_cookie_file(filename): - chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) - chksum.add("1.1") - chksum.add_stat(filename) - return chksum.raw() - -def calc_cookie_fp(fp): - chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) - chksum.add("1.1"); - chksum.add_fp(fp) - return chksum.raw() - -def calc_cookie_ext(f, cookie): - chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) - chksum.add("1.1"); - chksum.add(cookie) - if f: - chksum.add_fstat(f.fileno()) - extcookie = chksum.raw() - # compatibility to c code - if ord(extcookie[0]) == 0: - extcookie[0] = chr(1) - return extcookie - class repo_generic(dict): def __init__(self, name, type, attribs = {}): for k in attribs: @@ -76,6 +52,29 @@ class repo_generic(dict): self.name = name self.type = type + def calc_cookie_file(self, filename): + chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) + chksum.add("1.1") + chksum.add_stat(filename) + return chksum.raw() + + def calc_cookie_fp(self, fp): + chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) + chksum.add("1.1"); + chksum.add_fp(fp) + return chksum.raw() + + def calc_cookie_ext(self, f, cookie): + chksum = solv.Chksum(solv.REPOKEY_TYPE_SHA256) + chksum.add("1.1"); + chksum.add(cookie) + chksum.add_fstat(f.fileno()) + extcookie = chksum.raw() + # compatibility to c code + if ord(extcookie[0]) == 0: + extcookie[0] = chr(1) + return extcookie + def cachepath(self, ext = None): path = re.sub(r'^\.', '_', self.name) if ext: @@ -253,7 +252,7 @@ class repo_generic(dict): self.handle.write_first_repodata(f) if self.type != 'system' and not ext: if 'extcookie' not in self: - self['extcookie'] = calc_cookie_ext(f, self['cookie']) + self['extcookie'] = self.calc_cookie_ext(f, self['cookie']) f.write(self['extcookie']) if not ext: f.write(self['cookie']) @@ -299,6 +298,9 @@ class repo_generic(dict): repodata.internalize() self.writecachedrepo(None, repodata) + def packagespath(self): + return '' + class repo_repomd(repo_generic): def load_if_changed(self): print "rpmmd repo '%s':" % self.name, @@ -309,7 +311,7 @@ class repo_repomd(repo_generic): self.handle.free(True) del self.handle return False - self['cookie'] = calc_cookie_fp(f) + self['cookie'] = self.calc_cookie_fp(f) if self.usecachedrepo(None, True): print "cached" solv.xfclose(f) @@ -415,7 +417,7 @@ class repo_susetags(repo_generic): self.handle.free(True) del self.handle return False - self['cookie'] = calc_cookie_fp(f) + self['cookie'] = self.calc_cookie_fp(f) if self.usecachedrepo(None, True): print "cached" solv.xfclose(f) @@ -531,6 +533,12 @@ class repo_susetags(repo_generic): self.writecachedrepo(ext, repodata) return True + def packagespath(self): + datadir = repo.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DATADIR) + if not datadir: + datadir = 'suse' + return datadir + '/' + class repo_unknown(repo_generic): def load(self, pool): print "unsupported repo '%s': skipped" % self.name @@ -542,7 +550,7 @@ class repo_system(repo_generic): self.handle.appdata = self pool.installed = self.handle print "rpm database:", - self['cookie'] = calc_cookie_file("/var/lib/rpm/Packages") + self['cookie'] = self.calc_cookie_file("/var/lib/rpm/Packages") if self.usecachedrepo(None): print "cached" return True @@ -888,12 +896,8 @@ if cmd == 'install' or cmd == 'erase' or cmd == 'up' or cmd == 'dup' or cmd == ' sys.stdout.flush() continue - if repo.type == 'susetags': - datadir = repo.handle.lookup_str(solv.SOLVID_META, solv.SUSETAGS_DATADIR) - if not datadir: - datadir = 'suse' - location = datadir + '/' + location chksum = p.lookup_checksum(solv.SOLVABLE_CHECKSUM) + location = repo.packagespath() + location f = repo.download(location, False, chksum) if not f: sys.exit("\n%s: %s not found in repository" % (repo.name, location)) diff --git a/examples/rbsolv b/examples/rbsolv index 250f1347..1d7369d7 100755 --- a/examples/rbsolv +++ b/examples/rbsolv @@ -43,7 +43,7 @@ class Repo_generic chksum = Solv::Chksum.new(Solv::REPOKEY_TYPE_SHA256) chksum.add("1.1") chksum.add(cookie) - chksum.add_fstat(f.fileno) if f + chksum.add_fstat(f.fileno) extcookie = chksum.raw() extcookie[0] = 1 if extcookie[0] == 0 return extcookie @@ -115,12 +115,6 @@ class Repo_generic end end - def download_location(location, chksum) - f = download(location, false, chksum) - abort("\n#{@name}: #{location} not found in repository\n") unless f - return f - end - def usecachedrepo(ext, mark = false) cookie = ext ? @extcookie : @cookie begin @@ -213,6 +207,10 @@ class Repo_generic repodata.internalize() writecachedrepo(nil, repodata) end + + def packagespath() + return '' + end end class Repo_rpmmd < Repo_generic @@ -458,12 +456,11 @@ class Repo_susetags < Repo_generic return true end - def download_location(location, chksum) + def packagespath() datadir = @handle.lookup_str(Solv::SOLVID_META, Solv::SUSETAGS_DATADIR) datadir = "suse" unless datadir - super("#{datadir}/#{location}", chksum) + return datadir + '/' end - end class Repo_unknown < Repo_generic @@ -728,8 +725,10 @@ if cmd == 'install' || cmd == 'erase' || cmd == 'up' || cmd == 'dup' || cmd == ' repo = p.repo.appdata location, medianr = p.lookup_location() next unless location + location = repo.packagespath + location chksum = p.lookup_checksum(Solv::SOLVABLE_CHECKSUM) - f = repo.download_location(location, chksum) + f = repo.download(location, false, chksum) + abort("\n#{@name}: #{location} not found in repository\n") unless f newpkgsfp[p.id] = f print "." STDOUT.flush()