Class: Slackware::Package
- Inherits:
-
Object
- Object
- Slackware::Package
- Defined in:
- lib/slackware/package.rb
Direct Known Subclasses
Constant Summary collapse
- RE_FILE_LIST =
/^FILE LIST:/
- RE_COMPRESSED_PACKAGE_SIZE =
/^COMPRESSED PACKAGE SIZE:\s+(.*)$/
- RE_UNCOMPRESSED_PACKAGE_SIZE =
/^UNCOMPRESSED PACKAGE SIZE:\s+(.*)$/
- RE_PACKAGE_LOCATION =
/^PACKAGE LOCATION:\s+(.*)$/
- RE_PACKAGE_DESCRIPTION =
/^PACKAGE DESCRIPTION:\s+(.*)$/
- FMT_UPGRADE_TIME =
"%F %H:%M:%S"
Instance Attribute Summary collapse
-
#arch ⇒ Object
Returns the value of attribute arch.
-
#build ⇒ Object
Returns the value of attribute build.
-
#file ⇒ Object
Returns the value of attribute file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#owned_files ⇒ Object
Returns the value of attribute owned_files.
-
#path ⇒ Object
Returns the value of attribute path.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#tag_sep ⇒ Object
Returns the value of attribute tag_sep.
-
#time ⇒ Object
Returns the value of attribute time.
-
#upgrade_time ⇒ Object
Returns the value of attribute upgrade_time.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
-
.parse(name) ⇒ Object
Package.parse class method.
Instance Method Summary collapse
-
#compressed_size ⇒ Object
Accessor for the COMPRESSED PACKAGE SIZE from the package file.
-
#compressed_size=(size) ⇒ Object
Setter for the COMPRESSED PACKAGE SIZE, in the event you are parsing a repo file.
-
#fullname ⇒ Object
Reassemble the package name as it would be in file form.
-
#get_owned_files ⇒ Object
Accessor for the FILE LIST from the package file unless the :owned_files symbol is populated.
-
#get_path ⇒ Object
Fill in the path information.
-
#get_time ⇒ Object
populates and returns self.time.
-
#initialize(name = nil) ⇒ Package
constructor
A new instance of Package.
- #inspect ⇒ Object
-
#package_description ⇒ Object
Accessor for the PACKAGE DESCRIPTION from the package file.
-
#package_description=(desc) ⇒ Object
Setter for the PACKAGE DESCRIPTION, in the event you are parsing a repo file.
-
#package_location ⇒ Object
Accessor for the PACKAGE LOCATION from the package file.
-
#package_location=(path) ⇒ Object
Setter for the PACKAGE LOCATION, in the event you are parsing a repo file.
-
#parse(name) ⇒ Object
pkg.parse instance method for parsing the package information.
-
#set_owned_files ⇒ Object
Set the file list in the package object in memory.
-
#uncompressed_size ⇒ Object
Accessor for the UNCOMPRESSED PACKAGE SIZE from the package file.
-
#uncompressed_size=(size) ⇒ Object
Setter for the UNCOMPRESSED PACKAGE SIZE, in the event you are parsing a repo file.
Constructor Details
#initialize(name = nil) ⇒ Package
Returns a new instance of Package.
38 39 40 |
# File 'lib/slackware/package.rb', line 38 def initialize(name = nil) self.name = name end |
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def arch @arch end |
#build ⇒ Object
Returns the value of attribute build.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def build @build end |
#file ⇒ Object
Returns the value of attribute file.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def file @file end |
#name ⇒ Object
Returns the value of attribute name.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def name @name end |
#owned_files ⇒ Object
Returns the value of attribute owned_files.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def owned_files @owned_files end |
#path ⇒ Object
Returns the value of attribute path.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def path @path end |
#tag ⇒ Object
Returns the value of attribute tag.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def tag @tag end |
#tag_sep ⇒ Object
Returns the value of attribute tag_sep.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def tag_sep @tag_sep end |
#time ⇒ Object
Returns the value of attribute time.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def time @time end |
#upgrade_time ⇒ Object
Returns the value of attribute upgrade_time.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def upgrade_time @upgrade_time end |
#version ⇒ Object
Returns the value of attribute version.
37 38 39 |
# File 'lib/slackware/package.rb', line 37 def version @version end |
Class Method Details
.parse(name) ⇒ Object
Package.parse class method
71 72 73 74 75 |
# File 'lib/slackware/package.rb', line 71 def self::parse(name) p = self.new() p.parse(name) return p end |
Instance Method Details
#compressed_size ⇒ Object
Accessor for the COMPRESSED PACKAGE SIZE from the package file
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/slackware/package.rb', line 150 def compressed_size if not(@compressed_size.nil?) return @compressed_size end f = File.open(self.path + '/' + self.fullname) while true if (f.readline =~ RE_COMPRESSED_PACKAGE_SIZE) return $1 end end end |
#compressed_size=(size) ⇒ Object
Setter for the COMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
164 165 166 |
# File 'lib/slackware/package.rb', line 164 def compressed_size=(size) @compressed_size = size end |
#fullname ⇒ Object
Reassemble the package name as it would be in file form
78 79 80 81 82 83 84 85 |
# File 'lib/slackware/package.rb', line 78 def fullname if (self.upgrade_time) time = self.upgrade_time.strftime("%F,%H:%M:%S") return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep), "upgraded", time].join("-") else return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep)].join("-") end end |
#get_owned_files ⇒ Object
Accessor for the FILE LIST from the package file unless the :owned_files symbol is populated
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/slackware/package.rb', line 170 def get_owned_files unless self.owned_files.nil? return self.owned_files else files = [] File.open(self.path + '/' + self.fullname) do |f| while true break if f.eof? line = f.readline() begin if line.force_encoding("US-ASCII") =~ RE_FILE_LIST f.seek(2, IO::SEEK_CUR) break end rescue ArgumentError # ArgumentError: invalid byte sequence in US-ASCII # so dumb, i wish i could determine a better solution for this true end end begin files = f.readlines().map {|line| line.rstrip.force_encoding("US-ASCII") } rescue ArgumentError Log.instance.debug("Slackware::Package") { "encoding in : " + self.path + '/' + self.fullname } end end return files end end |
#get_path ⇒ Object
Fill in the path information
227 228 229 230 231 232 |
# File 'lib/slackware/package.rb', line 227 def get_path if (self.path.nil? && File.exist?(Paths::installed_packages() + "/" + self.name)) self.path = Paths::installed_packages() return Paths::installed_packages() end end |
#get_time ⇒ Object
populates and returns self.time
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/slackware/package.rb', line 213 def get_time if (self.time.nil? && self.path) if (File.exist?(self.path + "/" + self.fullname)) self.time = File.mtime(self.path + "/" + self.fullname) end elsif (not(self.path) && (self.time.nil?)) if (File.exist?(Paths::installed_packages() + "/" + self.fullname)) self.time = File.mtime(Paths::installed_packages() + "/" + self.fullname) end end return self.time end |
#inspect ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/slackware/package.rb', line 234 def inspect "#<%s:0x%x name=\"%s\" version=\"%s\" arch=\"%s\" build=%s tag=\"%s\">" % [ self.class.name, self.object_id, self.name, self.version, self.arch, self.build, self.tag ] end |
#package_description ⇒ Object
Accessor for the PACKAGE DESCRIPTION from the package file
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/slackware/package.rb', line 88 def package_description if not(@package_description.nil?) return @package_description end f = File.open(self.path + '/' + self.fullname) while true if (f.readline =~ RE_PACKAGE_DESCRIPTION) desc = f.take_while {|l| not(l =~ RE_FILE_LIST) }.map {|l| l.sub(/^#{self.name}:\s?/, '').chomp } return desc end end end |
#package_description=(desc) ⇒ Object
Setter for the PACKAGE DESCRIPTION, in the event you are parsing a repo file
107 108 109 |
# File 'lib/slackware/package.rb', line 107 def package_description=(desc) @package_description = desc end |
#package_location ⇒ Object
Accessor for the PACKAGE LOCATION from the package file
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/slackware/package.rb', line 112 def package_location if not(@package_location.nil?) return @package_location end f = File.open(self.path + '/' + self.fullname) while true if (f.readline =~ RE_PACKAGE_LOCATION) return $1 end end end |
#package_location=(path) ⇒ Object
Setter for the PACKAGE LOCATION, in the event you are parsing a repo file
126 127 128 |
# File 'lib/slackware/package.rb', line 126 def package_location=(path) @package_location = path end |
#parse(name) ⇒ Object
pkg.parse instance method for parsing the package information
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/slackware/package.rb', line 43 def parse(name) if name.include?("/") self.path = File.dirname(name) name = File.basename(name) end if (name =~ RE_REMOVED_NAMES) name = $1 self.upgrade_time = Time.strptime($2 + ' ' + $3, fmt=FMT_UPGRADE_TIME) end arr = name.split('-') build = arr.pop if (build.include?("_")) self.tag_sep = "_" self.build = build.split(self.tag_sep)[0] self.tag = build.split(self.tag_sep)[1..-1].join(self.tag_sep) elsif (build =~ RE_BUILD_TAG) self.build = $1 self.tag = $2 else self.build = build self.tag = "" end self.arch = arr.pop self.version = arr.pop self.name = arr.join('-') end |
#set_owned_files ⇒ Object
Set the file list in the package object in memory
203 204 205 206 207 208 209 210 |
# File 'lib/slackware/package.rb', line 203 def set_owned_files if self.owned_files.nil? self.owned_files = get_owned_files() return true else return false end end |
#uncompressed_size ⇒ Object
Accessor for the UNCOMPRESSED PACKAGE SIZE from the package file
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/slackware/package.rb', line 131 def uncompressed_size if not(@uncompressed_size.nil?) return @uncompressed_size end f = File.open(self.path + '/' + self.fullname) while true if (f.readline =~ RE_UNCOMPRESSED_PACKAGE_SIZE) return $1 end end end |
#uncompressed_size=(size) ⇒ Object
Setter for the UNCOMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
145 146 147 |
# File 'lib/slackware/package.rb', line 145 def uncompressed_size=(size) @uncompressed_size = size end |