fix last part of rpm providing and add example that demonstrate such functionality
authorJosef Reidinger <jreidinger@suse.cz>
Wed, 15 Feb 2012 12:41:23 +0000 (13:41 +0100)
committerJosef Reidinger <jreidinger@suse.cz>
Wed, 15 Feb 2012 12:41:23 +0000 (13:41 +0100)
examples/ruby/download_rpms.rb [new file with mode: 0644]
swig/PackageProvider.i

diff --git a/examples/ruby/download_rpms.rb b/examples/ruby/download_rpms.rb
new file mode 100644 (file)
index 0000000..b676de4
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+
+require 'tmpdir'
+require 'zypp'
+include Zypp
+
+def initialize_repo dir
+  rm_opts = RepoManagerOptions.new Pathname.new(dir)
+  repo_manager = RepoManager.new rm_opts
+  #ignore certificate issues
+  KeyRing.setDefaultAccept( KeyRing::ACCEPT_UNKNOWNKEY |
+        KeyRing::ACCEPT_VERIFICATION_FAILED | KeyRing::ACCEPT_UNSIGNED_FILE |
+        KeyRing::TRUST_KEY_TEMPORARILY )
+  repo_info = RepoInfo.new
+  url = Zypp::Url.new "http://download.opensuse.org/distribution/openSUSE-stable/repo/oss"
+  repo_info.setBaseUrl(url)
+  repo_info.setKeepPackages(true)
+  repo_alias = "repo"
+  repo_info.setAlias repo_alias
+  repo_manager.addRepository repo_info
+  repo_manager.refreshMetadata repo_info
+  repo_manager.buildCache repo_info
+  repo_manager.loadFromCache repo_info
+  return repo_manager
+end
+
+Dir.mktmpdir do |dir|
+  #do not lock global zypp
+  ENV["ZYPP_LOCKFILE_ROOT"] = dir
+  zypp = ZYppFactory.instance.getZYpp
+  zypp.initializeTarget Pathname.new dir
+  puts "initialize repository. It can take serious amount of time"
+  repo_manager = initialize_repo dir
+  rma = RepoMediaAccess.new
+  zypp.pool.each_by_name("libzypp") do |pi|
+    r = pi.resolvable
+    puts "downloading rpm for #{r.name}-#{r.edition}"
+    path = PackageProvider.provide(rma,asKindPackage(pi))
+    FileUtils.cp path.to_s,dir
+  end
+  puts "downloaded files:"
+  puts `ls -l #{dir}/*.rpm`
+end
index ac1c657..a6fc356 100644 (file)
@@ -1,10 +1,26 @@
+%inline
+{
+  namespace zypp 
+  {
+    class WrappedManagedFile 
+    {
+    public:
+      WrappedManagedFile(ManagedFile managed_file){ mf = managed_file; }
+      const std::string & asString(){ mf->asString();}
+    private:
+      ManagedFile mf;
+    };
+  }
+}
 %include "zypp/repo/PackageProvider.h"
 %extend zypp::repo::PackageProvider {
-  static zypp::ManagedFile provide( zypp::repo::RepoMediaAccess & rm, const zypp::Package_constPtr pkg )
+  static zypp::WrappedManagedFile* provide( zypp::repo::RepoMediaAccess & rm, const zypp::Package_constPtr pkg )
   {
     zypp::Package::constPtr pkg_type(pkg);
     zypp::repo::DeltaCandidates dc;
     zypp::repo::PackageProvider pp(rm,pkg_type,dc);
-    return pp.providePackage();
+    zypp::ManagedFile mf = pp.providePackage();
+    zypp::WrappedManagedFile* res = new zypp::WrappedManagedFile(mf);
+    return res;
   }
 }