Class: RepoMate::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/repomate/package.rb

Overview

Class for reading debian packages

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fullname, suitename, component) ⇒ Package

Init



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/repomate/package.rb', line 17

def initialize(fullname, suitename, component)
  @fullname   = fullname
  @suitename  = suitename
  @component  = component
  @basename   = File.basename(fullname)
  @mtime      = File.mtime(fullname)
  @pkgdbfile  = File.join(Cfg.rootdir, "packages.db")
  @pkgdb      = Database.new(@pkgdbfile)

  check_package
  create_table

  @controlfile  = read_controlfile
  @name         = @controlfile['Package']
  @version      = @controlfile['Version']
  @architecture = @controlfile['Architecture']
  @newbasename  = "#{@name}-#{@version}_#{@architecture}.deb"
end

Instance Attribute Details

#architectureObject (readonly)

Returns the value of attribute architecture.



14
15
16
# File 'lib/repomate/package.rb', line 14

def architecture
  @architecture
end

#basenameObject (readonly)

Returns the value of attribute basename.



14
15
16
# File 'lib/repomate/package.rb', line 14

def basename
  @basename
end

#componentObject (readonly)

Returns the value of attribute component.



14
15
16
# File 'lib/repomate/package.rb', line 14

def component
  @component
end

#controlfileObject (readonly)

Returns the value of attribute controlfile.



14
15
16
# File 'lib/repomate/package.rb', line 14

def controlfile
  @controlfile
end

#fullnameObject (readonly)

Returns the value of attribute fullname.



14
15
16
# File 'lib/repomate/package.rb', line 14

def fullname
  @fullname
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/repomate/package.rb', line 14

def name
  @name
end

#newbasenameObject (readonly)

Returns the value of attribute newbasename.



14
15
16
# File 'lib/repomate/package.rb', line 14

def newbasename
  @newbasename
end

#suitenameObject (readonly)

Returns the value of attribute suitename.



14
15
16
# File 'lib/repomate/package.rb', line 14

def suitename
  @suitename
end

#versionObject (readonly)

Returns the value of attribute version.



14
15
16
# File 'lib/repomate/package.rb', line 14

def version
  @version
end

Instance Method Details

#create_checksumsObject

Creates the checksums for a package



61
62
63
64
65
66
67
# File 'lib/repomate/package.rb', line 61

def create_checksums
  # puts "Ins: #{@basename}"
  md5      = Digest::MD5.file(@fullname).to_s
  sha1     = Digest::SHA1.file(@fullname).to_s
  sha256   = Digest::SHA2.new(256).file(@fullname).to_s
  @pkgdb.query("insert into checksums values ( datetime('now'), '#{@basename}', '#{@suitename}', '#{@mtime.iso8601}', '#{md5}', '#{sha1}', '#{sha256}' )")
end

#create_tableObject

Create the package table



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/repomate/package.rb', line 37

def create_table
  sql = "create table if not exists checksums (
          date varchar(25),
          basename varchar(70),
          suitename varchar(20),
          mtime varchar(25),
          md5 varchar(32),
          sha1 varchar(40),
          sha256 varchar(64)
  )"
  @pkgdb.query(sql)
end

#delete_checksumsObject

Gets checksums for the given package



70
71
72
73
# File 'lib/repomate/package.rb', line 70

def delete_checksums
  # puts "Del: #{@basename}"
  @pkgdb.query("delete from checksums where basename = '#{@basename}'")
end

#load_checksumsObject

Gets checksums for the given package



51
52
53
54
55
56
57
58
# File 'lib/repomate/package.rb', line 51

def load_checksums
  result = []

  @pkgdb.query("select md5, sha1, sha256 from checksums where basename = '#{@basename}' and mtime = '#{@mtime.iso8601}' and suitename = '#{@suitename}'").each do |row|
    result = row
  end
  result
end