Object
connect to PackageKit and create Transaction proxy
return Array of <transaction proxy>,<packagekit interface>,<transaction
Reference: www.packagekit.org/gtk-doc/index.html
# File lib/packagekit.rb, line 118 def self.connect system_bus = DBus::SystemBus.instance # RORSCAN_ITL # connect to PackageKit service via SystemBus pk_service = system_bus.service("org.freedesktop.PackageKit") # RORSCAN_ITL # Create PackageKit proxy object packagekit_proxy = pk_service.object("/org/freedesktop/PackageKit") # learn about object self.no_gc do packagekit_proxy.introspect end # use the (generic) 'PackageKit' interface packagekit_iface = packagekit_proxy["org.freedesktop.PackageKit"] # get transaction id via this interface tid = packagekit_iface.GetTid # retrieve transaction (proxy) object transaction_proxy = pk_service.object(tid[0]) self.no_gc do transaction_proxy.introspect end # use the 'Transaction' interface transaction_iface = transaction_proxy["org.freedesktop.PackageKit.Transaction"] transaction_proxy.default_iface = "org.freedesktop.PackageKit.Transaction" [transaction_iface, packagekit_iface] rescue DBus::Error => dbus_error Rails.logger.warn "Caught DBus error: #{dbus_error.inspect}" raise self.improve_error dbus_error end
returns the modification time of the resolvable which you can use for cache policy purposes
# File lib/packagekit.rb, line 170 def self.mtime # we look for the most recent (max) modification time # of either the package database or libzypp cache files [ "/var/lib/rpm/Packages", "/var/cache/zypp/solv", * Dir["/var/cache/zypp/solv/*/solv"] ].delete_if{ |f| !File.exist?(f) }.map{ |f| File.stat(f).mtime }.max end
temporarily disable Garbage Collector, debugging revealed that crash (bugzilla.novell.com/show_bug.cgi?id=779511) was caused by allocating memory during GC phase this workaround avoids the problem
# File lib/packagekit.rb, line 157 def self.no_gc begin disabled = GC.disable yield ensure GC.enable if disabled GC.start end end
Execute PackageKit transaction method
method: method to execute args: arguments to method signal: signal to intercept (usually "Package") (optional) bg_stat: BackgroundStatus object for reporting progress (optional) block: block to run on signal (optional)
# File lib/packagekit.rb, line 186 def self.transact(method, args, signal = nil, bg_stat = nil, &block) begin error = '' result = nil transaction_iface, packagekit_iface = self.connect proxy = transaction_iface.object # set the custom signal handler if set proxy.on_signal(signal.to_s, &block) if !signal.blank? && block_given? proxy.on_signal("Error") { dbusloop.quit } if bg_stat proxy.on_signal("StatusChanged") do |s| Rails.logger.debug "PackageKit progress: StatusChanged: #{s}" bg_stat.status = s end proxy.on_signal("ProgressChanged") do |p1, p2, p3, p4| Rails.logger.debug "PackageKit progress: ProgressChanged: #{p1}%" # 101% means no progress/subprogress available bg_stat.progress = p1 < 101 ? p1 : -1 bg_stat.subprogress = p2 < 101 ? p2 : -1 end end dbusloop = self.dbusloop proxy, error dbusloop << proxy.bus # Do the call only when all signal handlers are in place, # otherwise Finished can arrive early and dbusloop will never # quit, bnc#561578 # call it after creating the DBus loop (bnc#579001) result = transaction_iface.send(method.to_sym, *args) # run the main loop, process the incoming signals dbusloop.run # bnc#617350, remove signals self.dbusloop_unregister proxy if bg_stat proxy.on_signal("ProgressChanged") proxy.on_signal("StatusChanged") end proxy.on_signal(signal.to_s) if !signal.blank? && block_given? proxy.on_signal("Error") raise PackageKitError.new(error) unless error.blank? rescue DBus::Error => dbus_error raise self.improve_error dbus_error rescue Exception => e raise e end result end
Generated with the Darkfish Rdoc Generator 2.