X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Frbsolv;h=be633f3caf42ef14468b157bf7e1874bf27d0ba4;hb=9d82811ac90c5db61fca60e3e7c95ba58bc66393;hp=e011010536ac9759033386f84c097e872bdf1e9a;hpb=0424ef2001157e0bf0385da84828a6075c8d291c;p=platform%2Fupstream%2Flibsolv.git diff --git a/examples/rbsolv b/examples/rbsolv index e011010..be633f3 100755 --- a/examples/rbsolv +++ b/examples/rbsolv @@ -44,9 +44,7 @@ class Repo_generic chksum.add("1.1") chksum.add(cookie) chksum.add_fstat(f.fileno) - extcookie = chksum.raw() - extcookie[0] = 1 if extcookie[0] == 0 - return extcookie + return chksum.raw() end def cachepath(ext = nil) @@ -68,6 +66,7 @@ class Repo_generic end end @cookie = nil + @extcookie = nil if !dorefresh && usecachedrepo(nil) puts "repo: '#{@name}' cached" return true @@ -152,17 +151,17 @@ class Repo_generic return true end - def writecachedrepo(ext, info = nil) + def writecachedrepo(ext, repodata = nil) return if @incomplete begin Dir::mkdir("/var/cache/solv", 0755) unless FileTest.directory?("/var/cache/solv") f = Tempfile.new('.newsolv-', '/var/cache/solv') f.chmod(0444) sf = Solv::xfopen_fd('', f.fileno) - if !info + if !repodata @handle.write(sf) elsif ext - info.write(sf) + repodata.write(sf) else @handle.write_first_repodata(sf) end @@ -179,12 +178,12 @@ class Repo_generic if sf if !ext @handle.empty() - abort("internal error, cannot reload solv file") unless @handle.add_solv(sf, Solv::Repo::SOLV_ADD_NO_STUBS) + abort("internal error, cannot reload solv file") unless @handle.add_solv(sf, repodata ? 0 : Solv::Repo::SOLV_ADD_NO_STUBS) else - info.extend_to_repo() + repodata.extend_to_repo() flags = Solv::Repo::REPO_EXTEND_SOLVABLES flags |= Solv::Repo::REPO_LOCALPOOL if ext != 'DL' - info.add_solv(sf, flags) + repodata.add_solv(sf, flags) end sf.close end @@ -214,12 +213,39 @@ class Repo_generic def packagespath() return '' end + + @@langtags = { + Solv::SOLVABLE_SUMMARY => Solv::REPOKEY_TYPE_STR, + Solv::SOLVABLE_DESCRIPTION => Solv::REPOKEY_TYPE_STR, + Solv::SOLVABLE_EULA => Solv::REPOKEY_TYPE_STR, + Solv::SOLVABLE_MESSAGEINS => Solv::REPOKEY_TYPE_STR, + Solv::SOLVABLE_MESSAGEDEL => Solv::REPOKEY_TYPE_STR, + Solv::SOLVABLE_CATEGORY => Solv::REPOKEY_TYPE_ID, + } + + def add_ext_keys(ext, repodata, h) + if ext == 'DL' + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOSITORY_DELTAINFO) + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_FLEXARRAY) + elsif ext == 'DU' + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::SOLVABLE_DISKUSAGE) + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_DIRNUMNUMARRAY) + elsif ext == 'FL' + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::SOLVABLE_FILELIST) + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_DIRSTRARRAY) + else + @@langtags.sort.each do |langid, langtype| + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, @handle.pool.id2langid(langid, ext, true)) + repodata.add_idarray(h, Solv::REPOSITORY_KEYS, langtype) + end + end + end end class Repo_rpmmd < Repo_generic def find(what) - di = @handle.Dataiterator(Solv::SOLVID_META, Solv::REPOSITORY_REPOMD_TYPE, what, Solv::Dataiterator::SEARCH_STRING) + di = @handle.Dataiterator_meta(Solv::REPOSITORY_REPOMD_TYPE, what, Solv::Dataiterator::SEARCH_STRING) di.prepend_keyname(Solv::REPOSITORY_REPOMD) for d in di dp = d.parentpos() @@ -285,13 +311,7 @@ class Repo_rpmmd < Repo_generic repodata.set_poolstr(h, Solv::REPOSITORY_REPOMD_TYPE, what) repodata.set_str(h, Solv::REPOSITORY_REPOMD_LOCATION, filename) repodata.set_checksum(h, Solv::REPOSITORY_REPOMD_CHECKSUM, filechksum) - if ext == 'DL' - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOSITORY_DELTAINFO) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_FLEXARRAY) - elsif ext == 'FL' - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::SOLVABLE_FILELIST) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_DIRSTRARRAY) - end + add_ext_keys(ext, repodata, h) repodata.add_flexarray(Solv::SOLVID_META, Solv::REPOSITORY_EXTERNAL, h) end @@ -337,7 +357,7 @@ end class Repo_susetags < Repo_generic def find(what) - di = @handle.Dataiterator(Solv::SOLVID_META, Solv::SUSETAGS_FILE_NAME, what, Solv::Dataiterator::SEARCH_STRING) + di = @handle.Dataiterator_meta(Solv::SUSETAGS_FILE_NAME, what, Solv::Dataiterator::SEARCH_STRING) di.prepend_keyname(Solv::SUSETAGS_FILE) for d in di dp = d.parentpos() @@ -394,41 +414,18 @@ class Repo_susetags < Repo_generic return true end - @@langtags = { - Solv::SOLVABLE_SUMMARY => Solv::REPOKEY_TYPE_STR, - Solv::SOLVABLE_DESCRIPTION => Solv::REPOKEY_TYPE_STR, - Solv::SOLVABLE_EULA => Solv::REPOKEY_TYPE_STR, - Solv::SOLVABLE_MESSAGEINS => Solv::REPOKEY_TYPE_STR, - Solv::SOLVABLE_MESSAGEDEL => Solv::REPOKEY_TYPE_STR, - Solv::SOLVABLE_CATEGORY => Solv::REPOKEY_TYPE_ID, - } - def add_ext(repodata, what, ext) (filename, filechksum) = find(what) h = repodata.new_handle() repodata.set_str(h, Solv::SUSETAGS_FILE_NAME, filename) repodata.set_checksum(h, Solv::SUSETAGS_FILE_CHECKSUM, filechksum) - if ext == 'DL' - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOSITORY_DELTAINFO) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_FLEXARRAY) - elsif ext == 'DU' - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::SOLVABLE_DISKUSAGE) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_DIRNUMNUMARRAY) - elsif ext == 'FL' - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::SOLVABLE_FILELIST) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, Solv::REPOKEY_TYPE_DIRSTRARRAY) - else - @@langtags.sort.each do |langid, langtype| - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, @handle.pool.id2langid(langid, ext, true)) - repodata.add_idarray(h, Solv::REPOSITORY_KEYS, langtype) - end - end + add_ext_keys(ext, repodata, h) repodata.add_flexarray(Solv::SOLVID_META, Solv::REPOSITORY_EXTERNAL, h) end def add_exts repodata = @handle.add_repodata(0) - di = @handle.Dataiterator(Solv::SOLVID_META, Solv::SUSETAGS_FILE_NAME, nil, 0) + di = @handle.Dataiterator_meta(Solv::SUSETAGS_FILE_NAME, nil, 0) di.prepend_keyname(Solv::SUSETAGS_FILE) for d in di filename = d.str @@ -494,7 +491,7 @@ class Repo_system < Repo_generic end f = Solv::xfopen(cachepath()) @handle.add_rpmdb_reffp(f, Solv::Repo::REPO_REUSE_REPODATA) - f.close + f.close if f writecachedrepo(nil) return true end @@ -503,7 +500,7 @@ end args = ARGV cmd = args.shift -cmdabbrev = { 'li' => 'list', 'in' => 'install', 'rm' => 'erase', +cmdabbrev = { 'ls' => 'list', 'in' => 'install', 'rm' => 'erase', 've' => 'verify', 'se' => 'search' } cmd = cmdabbrev[cmd] if cmdabbrev.has_key?(cmd) @@ -527,7 +524,7 @@ end for reposdir in reposdirs do next unless FileTest.directory?(reposdir) for reponame in Dir["#{reposdir}/*.repo"].sort do - cfg = IniFile.new(reponame) + cfg = IniFile.load(reponame) cfg.each_section do |ali| repoattr = { 'alias' => ali, 'enabled' => 0, 'priority' => 99, 'autorefresh' => 1, 'type' => 'rpm-md', 'metadata_expire' => 900} repoattr.update(cfg[ali]) @@ -560,7 +557,7 @@ end if cmd == 'search' pool.createwhatprovides() sel = pool.Selection - for di in pool.Dataiterator(0, Solv::SOLVABLE_NAME, args[0], Solv::Dataiterator::SEARCH_SUBSTRING | Solv::Dataiterator::SEARCH_NOCASE) + for di in pool.Dataiterator(Solv::SOLVABLE_NAME, args[0], Solv::Dataiterator::SEARCH_SUBSTRING | Solv::Dataiterator::SEARCH_NOCASE) sel.add_raw(Solv::Job::SOLVER_SOLVABLE, di.solvid) end for s in sel.solvables @@ -641,7 +638,7 @@ while true break if problems.empty? for problem in problems puts "Problem #{problem.id}/#{problems.count}:" - puts problem.findproblemrule.info.problemstr + puts problem solutions = problem.solutions for solution in solutions puts " Solution #{solution.id}:" @@ -695,9 +692,9 @@ for cl in trans.classify(Solv::Transaction::SOLVER_TRANSACTION_SHOW_OBSOLETES | elsif cl.type == Solv::Transaction::SOLVER_TRANSACTION_UPGRADED puts "#{cl.count} upgraded packages:" elsif cl.type == Solv::Transaction::SOLVER_TRANSACTION_VENDORCHANGE - puts "#{cl.count} vendor changes from '#{cl.fromdep}' to '#{cl.todep}':" + puts "#{cl.count} vendor changes from '#{cl.fromstr}' to '#{cl.tostr}':" elsif cl.type == Solv::Transaction::SOLVER_TRANSACTION_ARCHCHANGE - puts "#{cl.count} arch changes from '#{cl.fromdep}' to '#{cl.todep}':" + puts "#{cl.count} arch changes from '#{cl.fromstr}' to '#{cl.tostr}':" else next end @@ -712,7 +709,7 @@ for cl in trans.classify(Solv::Transaction::SOLVER_TRANSACTION_SHOW_OBSOLETES | end puts "install size change: #{trans.calc_installsizechange()} K\n\n" -while true: +while true print("OK to continue (y/n)? ") STDOUT.flush yn = STDIN.gets.strip @@ -720,14 +717,14 @@ while true: abort if yn == 'n' || yn == 'q' end -newpkgs = trans.newpackages() +newpkgs = trans.newsolvables() newpkgsfp = {} if !newpkgs.empty? downloadsize = 0 for p in newpkgs downloadsize += p.lookup_num(Solv::SOLVABLE_DOWNLOADSIZE) end - puts "Downloading #{newpkgs.length} packages, #{downloadsize} K" + puts "Downloading #{newpkgs.length} packages, #{downloadsize / 1024} K" for p in newpkgs repo = p.repo.appdata location, medianr = p.lookup_location() @@ -745,7 +742,7 @@ end puts "Committing transaction:" puts -trans.order(0) +trans.order() for p in trans.steps steptype = trans.steptype(p, Solv::Transaction::SOLVER_TRANSACTION_RPM_ONLY) if steptype == Solv::Transaction::SOLVER_TRANSACTION_ERASE @@ -758,6 +755,7 @@ for p in trans.steps f = newpkgsfp.delete(p.id) next unless f mode = steptype == Solv::Transaction::SOLVER_TRANSACTION_INSTALL ? '-U' : '-i' + f.cloexec(0) system('rpm', mode, '--force', '--nodeps', '--nodigest', '--nosignature', "/dev/fd/#{f.fileno().to_s}") || abort("rpm failed: #{$? >> 8}") f.close end