Class: Akabei::Package

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

Defined Under Namespace

Classes: NotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Package

Returns a new instance of Package.



22
23
24
# File 'lib/akabei/package.rb', line 22

def initialize(path)
  @path = Pathname.new(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/akabei/package.rb', line 20

def path
  @path
end

Instance Method Details

#baseObject



99
100
101
# File 'lib/akabei/package.rb', line 99

def base
  pkginfo.pkgbase
end

#compute_checksum(algo) ⇒ Object



55
56
57
# File 'lib/akabei/package.rb', line 55

def compute_checksum(algo)
  Digest(algo).file(@path).hexdigest
end

#csizeObject



39
40
41
# File 'lib/akabei/package.rb', line 39

def csize
  @path.size
end

#descObject



107
108
109
# File 'lib/akabei/package.rb', line 107

def desc
  pkginfo.pkgdesc
end

#extract_pkginfoObject

Raises:



30
31
32
33
34
35
36
37
# File 'lib/akabei/package.rb', line 30

def extract_pkginfo
  ArchiveUtils.each_entry(@path.to_s) do |entry, archive|
    if entry.pathname == '.PKGINFO'
      return PackageInfo.parse(archive.read_data)
    end
  end
  raise NotFound.new(@path, '.PKGINFO')
end

#filenameObject



91
92
93
# File 'lib/akabei/package.rb', line 91

def filename
  @path.basename.to_s
end

#filesObject



118
119
120
121
122
123
124
125
126
# File 'lib/akabei/package.rb', line 118

def files
  xs = []
  ArchiveUtils.each_entry(@path) do |entry|
    unless entry.pathname.start_with?('.')
      xs << entry.pathname
    end
  end
  xs.sort
end

#isizeObject



43
44
45
# File 'lib/akabei/package.rb', line 43

def isize
  pkginfo.size
end

#md5sumObject



47
48
49
# File 'lib/akabei/package.rb', line 47

def md5sum
  @md5sum ||= compute_checksum('MD5')
end

#nameObject



95
96
97
# File 'lib/akabei/package.rb', line 95

def name
  pkginfo.pkgname
end

#pgpsigObject



111
112
113
114
115
116
# File 'lib/akabei/package.rb', line 111

def pgpsig
  sig_file = @path.parent.join("#{filename}.sig")
  if sig_file.readable?
    Base64.strict_encode64(sig_file.binread)
  end
end

#pkginfoObject



26
27
28
# File 'lib/akabei/package.rb', line 26

def pkginfo
  @pkginfo ||= extract_pkginfo
end

#sha256sumObject



51
52
53
# File 'lib/akabei/package.rb', line 51

def sha256sum
  @sha256sum ||= compute_checksum('SHA256')
end

#to_entryObject



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/akabei/package.rb', line 128

def to_entry
  entry = PackageEntry.new
  %w[
    filename
    name
    base
    version
    desc
    groups
    csize
    isize

    md5sum
    sha256sum

    pgpsig

    url
    license
    builddate
    packager
    replaces

    provides
    optdepends
    makedepends
    checkdepends

    files
  ].each do |attr|
    val = send(attr)
    if val.is_a?(Array)
      val.each do |v|
        entry.add(attr, v)
      end
    else
      entry.add(attr, val)
    end
  end
  entry
end

#versionObject



103
104
105
# File 'lib/akabei/package.rb', line 103

def version
  pkginfo.pkgver
end