Mailinglist Archive: zypp-commit (149 mails)

< Previous Next >
[zypp-commit] r5347 - in /trunk/repotools: input/rpmdir.rb input/rpmfile.rb lib/hasher.rb lib/package.rb output/rpmmd.rb
  • From: dmacvicar@xxxxxxxxxxxxxxxx
  • Date: Wed, 11 Apr 2007 23:16:14 -0000
  • Message-id: <20070411231614.4F5402369A@xxxxxxxxxxxxxxxx>
Author: dmacvicar
Date: Thu Apr 12 01:16:13 2007
New Revision: 5347

URL: http://svn.opensuse.org/viewcvs/zypp?rev=5347&view=rev
Log:

- progress in the YUM generator
- progress in the rpm dir input plugin, almost all tags I need

still cant figure how to insert the metadata tag in primary.xml


Added:
    trunk/repotools/lib/hasher.rb
Modified:
    trunk/repotools/input/rpmdir.rb
    trunk/repotools/input/rpmfile.rb
    trunk/repotools/lib/package.rb
    trunk/repotools/output/rpmmd.rb

Modified: trunk/repotools/input/rpmdir.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/repotools/input/rpmdir.rb?rev=5347&r1=5346&r2=5347&view=diff
==============================================================================
--- trunk/repotools/input/rpmdir.rb (original)
+++ trunk/repotools/input/rpmdir.rb Thu Apr 12 01:16:13 2007
@@ -1,3 +1,4 @@
+require 'rubygems'
 require 'rpm'
 require 'input/rpmfile'
 require 'pathname'

Modified: trunk/repotools/input/rpmfile.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/repotools/input/rpmfile.rb?rev=5347&r1=5346&r2=5347&view=diff
==============================================================================
--- trunk/repotools/input/rpmfile.rb (original)
+++ trunk/repotools/input/rpmfile.rb Thu Apr 12 01:16:13 2007
@@ -1,6 +1,8 @@
+require 'rubygems'
 require 'rpm'
 require "lib/arch"
 require "lib/package"
+require "lib/hasher"
 
 #
 # Input plugin for a single rpm file
@@ -59,8 +61,12 @@
 # Package interface from a RPM Package
 #
 class RPMPackageAdapter
-  def initialize( rpm_package )
+
+  attr_accessor :filename
+
+  def initialize( rpm_package, filename )
     @rpm_package = rpm_package
+    @filename = filename
   end
     
   def kind
@@ -79,6 +85,11 @@
     @rpm_package.version.e
   end
   
+  def sha1sum
+    h = Hasher.new("sha1", @filename)
+    h.hashsum
+  end
+
   def pre
     pre?
   end
@@ -86,13 +97,31 @@
   def method_missing( sym, *args)
     case sym.to_s
       when 'group'
-        return self[RPM::TAG_GROUP]
+        return @rpm_package[RPM::TAG_GROUP]
       when 'license'
-        return self[RPM::TAG_LICENSE]
+        return @rpm_package[RPM::TAG_LICENSE]
       when 'description'
-        return self[RPM::TAG_DESCRIPTION]
+        return @rpm_package[RPM::TAG_DESCRIPTION]
       when 'summary'
-        return self[RPM::TAG_SUMMARY]
+        return @rpm_package[RPM::TAG_SUMMARY]
+      when 'url'
+        return @rpm_package[RPM::TAG_URL]
+      when 'buildtime'
+        return @rpm_package[RPM::TAG_BUILDTIME]
+      when 'buildhost'
+        return @rpm_package[RPM::TAG_BUILDHOST]
+      when 'size'
+        return @rpm_package[RPM::TAG_SIZE]
+      when 'archivesize'
+        return @rpm_package[RPM::TAG_ARCHIVESIZE]
+      when 'vendor'
+        return @rpm_package[RPM::TAG_VENDOR]
+      when 'distribution'
+        return @rpm_package[RPM::TAG_DISTRIBUTION]
+      when 'sourcerpm'
+        return @rpm_package[RPM::TAG_SOURCERPM]
+      when 'sigsize'
+        return @rpm_package[RPM::TAG_SIGSIZE]
       when 'provides', 'requires','conflicts', 'obsoletes'
         a = Array.new
         @rpm_package.send(sym).each do | dep |
@@ -106,7 +135,7 @@
         return @rpm_package.send( sym )
       rescue Exception => e
         puts e
-        puts sym
+        puts "Method #{sym} : args : #{args.to_s} : #{RPM::TAG_URL}"
       end
       raise "oops!"
     end
@@ -124,7 +153,8 @@
   
   def start( consumer )
     rpm_package = RPM::Package.new(@filename)
-    consumer.consume( RPMPackageAdapter.new(rpm_package) )
+    adapter = RPMPackageAdapter.new(rpm_package, @filename)
+    consumer.consume(adapter)
   end
     
   def stop

Added: trunk/repotools/lib/hasher.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/repotools/lib/hasher.rb?rev=5347&view=auto
==============================================================================
--- trunk/repotools/lib/hasher.rb (added)
+++ trunk/repotools/lib/hasher.rb Thu Apr 12 01:16:13 2007
@@ -0,0 +1,45 @@
+#
+# A Simple Hash Code Calculator
+# Returns SHA1 and MD5 hash for any given file
+# Author: Alessio Saltarin
+#
+
+require 'digest/md5'
+require 'digest/sha1'
+
+$BUFLEN = 1024
+
+class Hasher
+  # Constructor
+  # method = "SHA1" or "MD5"
+  # filepath = Full filepath
+  def initialize(method, filepath)
+    if (method.upcase == "-SHA1")
+      @hashfunc = Digest::SHA1.new
+      @hashname = "SHA1"
+    else
+      @hashfunc = Digest::MD5.new
+      @hashname = "MD5"
+    end
+    @fullfilename = filepath
+  end
+
+  def hashname
+    @hashname
+  end
+
+  # Compute hash code
+  def hashsum
+    open(@fullfilename, "r") do |io|
+      puts "Reading "+@fullfilename
+      counter = 0
+      while (!io.eof)
+        readBuf = io.readpartial($BUFLEN)
+        putc '.' if ((counter+=1) % 3 == 0)
+        @hashfunc.update(readBuf)
+      end
+    end
+    return @hashfunc.hexdigest
+  end
+end
+

Modified: trunk/repotools/lib/package.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/repotools/lib/package.rb?rev=5347&r1=5346&r2=5347&view=diff
==============================================================================
--- trunk/repotools/lib/package.rb (original)
+++ trunk/repotools/lib/package.rb Thu Apr 12 01:16:13 2007
@@ -12,6 +12,8 @@
   attr_accessor :authors
   attr_accessor :shared
 
+  #attr_accessor :url
+
   alias package_group group
 
   def initialize( name, epoch = nil, version = nil, release = nil, architecture = nil )

Modified: trunk/repotools/output/rpmmd.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/repotools/output/rpmmd.rb?rev=5347&r1=5346&r2=5347&view=diff
==============================================================================
--- trunk/repotools/output/rpmmd.rb (original)
+++ trunk/repotools/output/rpmmd.rb Thu Apr 12 01:16:13 2007
@@ -37,6 +37,10 @@
     
     # primary builder
     @primary_builder = Builder::XmlMarkup.new(:target => $stdout, :indent => 2)
+    x = Builder::XmlMarkup.new(:target => $stdout, :indent => 2)
+    x.instruct! :xml, :version=>"1.0", :encoding => "UTF-8"
+    x.metadata :xmlns=>"http://linux.duke.edu/metadata/common", ;'xmlns:rpm'.to_sym=>"http://linux.duke.edu/metadata/rpm", ;'xmlns:suse'.to_sym=>"http://novell.com/package/metadata/suse/common";
+    
   end
 
 =begin
@@ -51,21 +55,22 @@
       x.name p.name
       x.arch p.arch
       x.version :epoch=> p.epoch, :ver=>p.version, :rel=>p.release
-      x.checksum "blah", :type => "sha"
-      #x.summary p.summary
-      #x.description p.description
-      #x.packager p.packager
-      x.url "http://www.google.com";
+      x.checksum p.sha1sum, :type => "sha"
+      x.summary p.summary
+      x.description p.description
+      x.packager p.packager
+      x.url p.url
       x.time :file=>"1170984108", :build=>"1170983970"
-      x.size :package=>"131630", :installed=>"132421", :archive=>"133956"
-      x.location :href=>"location"
+      x.size :package=> File.size(p.filename), :installed=>p.size, :archive=>p.archivesize
+      x.location :href=>p.filename
       x.format {
-        x.rpm :license, "GNU General Public License (GPL)"
-        x.rpm :vendor, "SUSE LINUX Products GmbH, Nuernberg, Germany"
-        x.rpm :group, "System/Base"
-        x.rpm :buildhost, "gray.suse.de"
-        x.rpm :sourcerpm
-#x.rpm :header-range, :start=>"360", :end=>"4955"
+        x.rpm :license, p.license
+        x.rpm :vendor, p.vendor
+        x.rpm :group, p.group
+        x.rpm :buildhost, p.host
+        x.rpm :sourcerpm, p.sourcerpm
+        # FIXME this range is wrong
+        x.rpm 'header-range'.to_sym, :start=>"#{96 + p.sigsize}", :end=>"4955"
         [ :requires, :provides, :conflicts ].each do | dept |
           x.rpm(dept) {
             p.send( dept ).each do | cap |

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages