slack-utils 0.6.2 → 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,3 +15,4 @@ printf("%d should be removed\n", (pkgs & c[:removed].map {|p| p.name }).count)
15
15
  #p pkgs & c[:removed].map {|p| p.name }
16
16
  ca = c[:added].map {|p| p.name }
17
17
  printf("%d should be added\n", (ca.count - (pkgs & ca).count))
18
+ # vim : set sw=2 sts=2 et :
@@ -1,4 +1,6 @@
1
- # Copyright 2010,2011 Vincent Batts, Vienna, VA
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2010,2011,2012 Vincent Batts, Vienna, VA
2
4
  # All rights reserved.
3
5
  #
4
6
  # Redistribution and use of this source, with or without modification, is
@@ -21,79 +23,84 @@
21
23
  require 'optparse'
22
24
 
23
25
  module Slackware
24
- class Args
25
- def self.parse(args,flags = nil, banner = nil)
26
- flags = [] unless flags.is_a?(Array)
27
- options = {}
28
-
29
- opts = OptionParser.new do |opts|
30
- if banner
31
- opts.banner = banner
32
- end
33
- if flags.include?(:color)
34
- opts.on("-c", "--color", "Colorize output") do |o|
35
- options[:color] = o
36
- end
37
- end
38
- if flags.include?(:epoch)
39
- opts.on("-e", "--epoch", "Print the time stamp in seconds since 1970-01-01 00:00:00 UTC ") do |o|
40
- options[:epoch] = o
41
- end
42
- end
43
- if flags.include?(:pkg_name)
44
- opts.on("-p", "--pkg [NAME]", "Package PKGNAME (loose match)") do |o|
45
- options[:pkg] = o
46
- end
47
- end
48
- if flags.include?(:pkg_version)
49
- opts.on("-V", "--Version [VERSION]", "Package VERSION (loose match)") do |o|
50
- options[:version] = o
51
- end
52
- end
53
- if flags.include?(:pkg_arch)
54
- opts.on("-a", "--arch [ARCH]", "Package ARCH (exact match)") do |o|
55
- options[:arch] = o
56
- end
57
- end
58
- if flags.include?(:pkg_build)
59
- opts.on("-b", "--build [BUILD]", "Package BUILD (exact match)") do |o|
60
- options[:build] = o
61
- end
62
- end
63
- if flags.include?(:pkg_tag)
64
- opts.on("-t", "--tag [TAG]", "Package TAG (loose match)") do |o|
65
- options[:tag] = o
66
- end
67
- end
68
- if flags.include?(:case_insensitive)
69
- opts.on("-i", "When searching, do a case insensitive match") do |o|
70
- options[:case_insensitive] = o
71
- end
72
- end
73
- if flags.include?(:force_all)
74
- opts.on("-f", "--force", "force me to show all files") do |o|
75
- options[:force] = o
76
- end
77
- end
78
-
79
- opts.on("-v", "--version", "Display version of this software") do |o|
80
- printf("slack-utils version: %s, Slackware version: %s\n",
81
- Slackware::UTILS_VERSION,
82
- Slackware::System.version
83
- )
84
- exit(0)
85
- end
86
- end
87
-
88
- begin
26
+ # Args is the unified arguement parser for the slack-utils utilities.
27
+ class Args
28
+ def self.parse(args,flags = nil, banner = nil)
29
+ flags = [] unless flags.is_a?(Array)
30
+ options = {}
89
31
 
90
- opts.parse!
91
- return options
32
+ opts = OptionParser.new do |opts|
33
+ if banner
34
+ opts.banner = banner
35
+ end
36
+ if flags.include?(:color)
37
+ opts.on("-c", "--color", "Colorize output") do |o|
38
+ options[:color] = o
39
+ end
40
+ end
41
+ if flags.include?(:epoch)
42
+ opts.on("-e", "--epoch", "Print the time stamp in seconds since 1970-01-01 00:00:00 UTC ") do |o|
43
+ options[:epoch] = o
44
+ end
45
+ end
46
+ if flags.include?(:pkg_name)
47
+ opts.on("-p", "--pkg [NAME]", "Package PKGNAME (loose match)") do |o|
48
+ options[:pkg] = o
49
+ end
50
+ end
51
+ if flags.include?(:pkg_version)
52
+ opts.on("-V", "--Version [VERSION]", "Package VERSION (loose match)") do |o|
53
+ options[:version] = o
54
+ end
55
+ end
56
+ if flags.include?(:pkg_arch)
57
+ opts.on("-a", "--arch [ARCH]", "Package ARCH (exact match)") do |o|
58
+ options[:arch] = o
59
+ end
60
+ end
61
+ if flags.include?(:pkg_build)
62
+ opts.on("-b", "--build [BUILD]", "Package BUILD (exact match)") do |o|
63
+ options[:build] = o
64
+ end
65
+ end
66
+ if flags.include?(:pkg_tag)
67
+ opts.on("-t", "--tag [TAG]", "Package TAG (loose match)") do |o|
68
+ options[:tag] = o
69
+ end
70
+ end
71
+ if flags.include?(:case_insensitive)
72
+ opts.on("-i", "When searching, do a case insensitive match") do |o|
73
+ options[:case_insensitive] = o
74
+ end
75
+ end
76
+ if flags.include?(:force_all)
77
+ opts.on("-f", "--force", "force me to show all files") do |o|
78
+ options[:force] = o
79
+ end
80
+ end
81
+ if flags.include?(:debug)
82
+ opts.on("-D", "--debug", "show debugging output") do |o|
83
+ options[:debug] = o
84
+ end
85
+ end
92
86
 
93
- rescue OptionParser::InvalidOption => ex
94
- $stderr.write("ERROR: #{e.message}, see --help\n")
95
- exit(1)
96
- end
97
- end
87
+ opts.on("-v", "--version", "Display version of this software") do |o|
88
+ printf("slack-utils version: %s, Slackware version: %s\n",
89
+ Slackware::UTILS_VERSION,
90
+ Slackware::System.version
91
+ )
92
+ exit(0)
98
93
  end
94
+ end
95
+
96
+ begin
97
+ opts.parse!
98
+ return options
99
+ rescue OptionParser::InvalidOption => ex
100
+ $stderr.write("ERROR: #{e.message}, see --help\n")
101
+ exit(1)
102
+ end
103
+ end
104
+ end
99
105
  end
106
+ # vim : set sw=2 sts=2 et :
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  # Copyright 2010,2011 Vincent Batts, Vienna, VA
2
4
  # All rights reserved.
3
5
  #
@@ -139,3 +141,4 @@ end
139
141
 
140
142
 
141
143
 
144
+ # vim : set sw=2 sts=2 et :
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  # Copyright 2010,2011 Vincent Batts, Vienna, VA
2
4
  # All rights reserved.
3
5
  #
@@ -41,16 +43,16 @@ module Slackware
41
43
 
42
44
  # The regular entry, accounting for usb-and-pxe-installers directory,
43
45
  # and notes after the action
44
- re_package_entry0 = Regexp.new(/^(([\w+-]+).*\/.*):\s+(\w+).*\.?$/)
46
+ re_package_entry0 = /^(([\w+-]+).*\/.*):\s+(\w+).*\.?$/
45
47
  # Some didn't have an action after the name
46
- re_package_entry1 = Regexp.new(/^(([\w+-]+).*\/.*):/)
48
+ re_package_entry1 = /^(([\w+-]+).*\/.*):/
47
49
  # and some didn't have the ':' or an action
48
- re_package_entry2 = Regexp.new(/^(([\w+-]+).*\/.*\.t[gbx]z)/)
50
+ re_package_entry2 = /^(([\w+-]+).*\/.*\.t[gbx]z)/
49
51
  # combine them
50
52
  RE_PACKAGE_ENTRY = Regexp.union(re_package_entry0, re_package_entry1, re_package_entry2)
51
53
 
52
54
  # (* Security fix *)
53
- RE_SECURITY_FIX = Regexp.new(/\(\*\s+security\s+fix\s+\*\)/i)
55
+ RE_SECURITY_FIX = /\(\*\s+security\s+fix\s+\*\)/i
54
56
 
55
57
  # for hacks sake, make these usbable elsewhere
56
58
  def self::re_date ; RE_DATE ; end
@@ -150,21 +152,21 @@ module Slackware
150
152
  end
151
153
 
152
154
  def parse(opts = {:file => nil, :data => nil})
153
- if not(opts[:file].nil?)
154
- @updates = parse_this_file(opts[:file]).updates
155
+ if not(opts[:file].nil?)
156
+ @updates = parse_this_file(opts[:file]).updates
155
157
  elsif not(@file.nil?)
156
- @updates = parse_this_file(@file).updates
157
- end
158
- return self
158
+ @updates = parse_this_file(@file).updates
159
+ end
160
+ return self
159
161
  end
160
162
 
161
163
  # Class method
162
164
  def self::parse(file)
163
- return parse_this_file(file)
165
+ return parse_this_file(file)
164
166
  end
165
167
 
166
168
  def self::open(file)
167
- return parse_this_file(file)
169
+ return parse_this_file(file)
168
170
  end
169
171
 
170
172
  def inspect
@@ -180,7 +182,7 @@ module Slackware
180
182
  # * take packge notes until
181
183
  # * next package or entry separator
182
184
  # * separator creates next change entry
183
- def parse_this_file(file)
185
+ def self::parse_this_file(file)
184
186
  f_handle = ""
185
187
  if file.is_a?(File)
186
188
  f_handle = file
@@ -270,3 +272,4 @@ module Slackware
270
272
 
271
273
  end
272
274
  end
275
+ # vim : set sw=2 sts=2 et :
@@ -0,0 +1,53 @@
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2012 Vincent Batts, Vienna, VA
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use of this source, with or without modification, is
7
+ # permitted provided that the following conditions are met:
8
+ #
9
+ # 1. Redistributions of this source must retain the above copyright
10
+ # notice, this list of conditions and the following disclaimer.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
13
+ # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14
+ # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
15
+ # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
18
+ # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
19
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
20
+ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
+
23
+ require 'logger'
24
+ require 'singleton'
25
+
26
+ module Slackware
27
+
28
+ # Log is a subclass of Logger, but is implemented as a singleton,
29
+ # so it can be used across library in a somewhat unified manner.
30
+ # Example:
31
+ # require 'slackware/log'
32
+ #
33
+ # slog = Slackware::Log.instance
34
+ # slog.info("LOG ALL THE THINGS!")
35
+ # slog.debug('my_app') { ex.backtrace }
36
+ #
37
+ class Log < Logger
38
+ include Singleton
39
+
40
+ # Since Singleton does a lazy loader, this will not get initialized
41
+ # until it is first used. So it'll be nil, or you can set $logdev early on.
42
+ # It defaults to WARN level and STDERR
43
+ def initialize(*args)
44
+ if $logdev
45
+ super($logdev, args)
46
+ else
47
+ super(STDERR, args)
48
+ end
49
+ end
50
+ end # class Log
51
+ end # module Slackware
52
+
53
+ # vim : set sw=2 sts=2 et :
@@ -1,4 +1,6 @@
1
- # Copyright 2010,2011 Vincent Batts, Vienna, VA
1
+ # encoding: UTF-8
2
+
3
+ # Copyright 2010,2011,2012 Vincent Batts, Vienna, VA
2
4
  # All rights reserved.
3
5
  #
4
6
  # Redistribution and use of this source, with or without modification, is
@@ -19,211 +21,238 @@
19
21
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20
22
 
21
23
  require 'time'
24
+ require 'slackware/log'
25
+ require 'slackware/paths'
22
26
 
23
27
  module Slackware
24
- class Package
25
- attr_accessor :time, :path, :file, :name, :version, :arch, :build, :tag, :tag_sep, :upgrade_time, :owned_files
26
- def initialize(name = nil)
27
- self.name = name
28
- end
29
-
30
- # pkg.parse instance method for parsing the package information
31
- def parse(name)
32
- if name.include?("/")
33
- self.path = File.dirname(name)
34
- name = File.basename(name)
35
- end
36
- if (name =~ RE_REMOVED_NAMES)
37
- name = $1
38
- self.upgrade_time = Time.strptime($2 + ' ' + $3, fmt='%F %H:%M:%S')
39
- end
40
- arr = name.split('-')
41
- build = arr.pop
42
- if (build.include?("_"))
43
- self.tag_sep = "_"
44
- self.build = build.split(self.tag_sep)[0]
45
- self.tag = build.split(self.tag_sep)[1..-1].join(self.tag_sep)
46
- elsif (build =~ RE_BUILD_TAG)
47
- self.build = $1
48
- self.tag = $2
49
- else
50
- self.build = build
51
- self.tag = ""
52
- end
53
- self.arch = arr.pop
54
- self.version = arr.pop
55
- self.name = arr.join('-')
56
- end
57
-
58
- # Package.parse class method
59
- def self::parse(name)
60
- p = self.new()
61
- p.parse(name)
62
- return p
63
- end
64
-
65
- # Reassemble the package name as it would be in file form
66
- def fullname
67
- if (self.upgrade_time)
68
- time = self.upgrade_time.strftime("%F,%H:%M:%S")
69
- return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep), "upgraded", time].join("-")
70
- else
71
- return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep)].join("-")
72
- end
73
- end
74
-
75
- # Accessor for the PACKAGE DESCRIPTION from the package file
76
- def package_description
77
- if not(@package_description.nil?)
78
- return @package_description
79
- end
80
-
81
- f = File.open(self.path + '/' + self.fullname)
82
- while true
83
- if (f.readline =~ /^PACKAGE DESCRIPTION:\s+(.*)$/)
84
- desc = f.take_while {|l|
85
- not(l =~ /FILE LIST:/)
28
+ class Package
29
+ RE_FILE_LIST = /^FILE LIST:/
30
+ RE_COMPRESSED_PACKAGE_SIZE = /^COMPRESSED PACKAGE SIZE:\s+(.*)$/
31
+ RE_UNCOMPRESSED_PACKAGE_SIZE = /^UNCOMPRESSED PACKAGE SIZE:\s+(.*)$/
32
+ RE_PACKAGE_LOCATION = /^PACKAGE LOCATION:\s+(.*)$/
33
+ RE_PACKAGE_DESCRIPTION = /^PACKAGE DESCRIPTION:\s+(.*)$/
34
+
35
+ FMT_UPGRADE_TIME = "%F %H:%M:%S"
36
+
37
+ attr_accessor :time, :path, :file, :name, :version, :arch, :build, :tag, :tag_sep, :upgrade_time, :owned_files
38
+ def initialize(name = nil)
39
+ self.name = name
40
+ end
41
+
42
+ # pkg.parse instance method for parsing the package information
43
+ def parse(name)
44
+ if name.include?("/")
45
+ self.path = File.dirname(name)
46
+ name = File.basename(name)
47
+ end
48
+ if (name =~ RE_REMOVED_NAMES)
49
+ name = $1
50
+ self.upgrade_time = Time.strptime($2 + ' ' + $3, fmt=FMT_UPGRADE_TIME)
51
+ end
52
+ arr = name.split('-')
53
+ build = arr.pop
54
+ if (build.include?("_"))
55
+ self.tag_sep = "_"
56
+ self.build = build.split(self.tag_sep)[0]
57
+ self.tag = build.split(self.tag_sep)[1..-1].join(self.tag_sep)
58
+ elsif (build =~ RE_BUILD_TAG)
59
+ self.build = $1
60
+ self.tag = $2
61
+ else
62
+ self.build = build
63
+ self.tag = ""
64
+ end
65
+ self.arch = arr.pop
66
+ self.version = arr.pop
67
+ self.name = arr.join('-')
68
+ end
69
+
70
+ # Package.parse class method
71
+ def self::parse(name)
72
+ p = self.new()
73
+ p.parse(name)
74
+ return p
75
+ end
76
+
77
+ # Reassemble the package name as it would be in file form
78
+ def fullname
79
+ if (self.upgrade_time)
80
+ time = self.upgrade_time.strftime("%F,%H:%M:%S")
81
+ return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep), "upgraded", time].join("-")
82
+ else
83
+ return [self.name, self.version, self.arch, [self.build, self.tag].join(self.tag_sep)].join("-")
84
+ end
85
+ end
86
+
87
+ # Accessor for the PACKAGE DESCRIPTION from the package file
88
+ def package_description
89
+ if not(@package_description.nil?)
90
+ return @package_description
91
+ end
92
+
93
+ f = File.open(self.path + '/' + self.fullname)
94
+ while true
95
+ if (f.readline =~ RE_PACKAGE_DESCRIPTION)
96
+ desc = f.take_while {|l|
97
+ not(l =~ RE_FILE_LIST)
86
98
  }.map {|l|
87
99
  l.sub(/^#{self.name}:\s?/, '').chomp
88
100
  }
89
- return desc
90
- end
91
- end
92
- end
93
-
94
- # Setter for the PACKAGE DESCRIPTION, in the event you are parsing a repo file
95
- def package_description=(desc)
96
- @package_description = desc
97
- end
98
-
99
- # Accessor for the PACKAGE LOCATION from the package file
100
- def package_location
101
- if not(@package_location.nil?)
102
- return @package_location
103
- end
104
-
105
- f = File.open(self.path + '/' + self.fullname)
106
- while true
107
- if (f.readline =~ /^PACKAGE LOCATION:\s+(.*)$/)
108
- return $1
109
- end
110
- end
111
- end
112
-
113
- # Setter for the PACKAGE LOCATION, in the event you are parsing a repo file
114
- def package_location=(path)
115
- @package_location = path
116
- end
117
-
118
- # Accessor for the UNCOMPRESSED PACKAGE SIZE from the package file
119
- def uncompressed_size
120
- if not(@uncompressed_size.nil?)
121
- return @uncompressed_size
122
- end
123
-
124
- f = File.open(self.path + '/' + self.fullname)
125
- while true
126
- if (f.readline =~ /^UNCOMPRESSED PACKAGE SIZE:\s+(.*)$/)
127
- return $1
128
- end
129
- end
130
- end
131
-
132
- # Setter for the UNCOMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
133
- def uncompressed_size=(size)
134
- @uncompressed_size = size
135
- end
136
-
137
- # Accessor for the COMPRESSED PACKAGE SIZE from the package file
138
- def compressed_size
139
- if not(@compressed_size.nil?)
140
- return @compressed_size
141
- end
142
-
143
- f = File.open(self.path + '/' + self.fullname)
144
- while true
145
- if (f.readline =~ /^COMPRESSED PACKAGE SIZE:\s+(.*)$/)
146
- return $1
147
- end
148
- end
149
- end
150
-
151
- # Setter for the COMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
152
- def compressed_size=(size)
153
- @compressed_size = size
154
- end
155
-
156
- # Accessor for the FILE LIST from the package file
157
- # unless the :owned_files symbol is populated
158
- def get_owned_files
159
- unless self.owned_files.nil?
160
- return self.owned_files
161
- else
162
- f = File.open(self.path + '/' + self.fullname)
163
- files = f.drop_while {|l| not( l =~ /^FILE LIST:/) }[2..-1].map {|l| l.chomp }
164
- f.close
165
- return files
166
- end
167
- end
168
-
169
- # Set the file list in the package object in memory
170
- def set_owned_files
171
- if self.owned_files.nil?
172
- self.owned_files = get_owned_files()
173
- return true
174
- else
175
- return false
176
- end
177
- end
178
-
179
- # populates and returns self.time
180
- def get_time
181
- if (self.time.nil? && self.path)
182
- if (File.exist?(self.path + "/" + self.fullname))
183
- self.time = File.mtime(self.path + "/" + self.fullname)
184
- end
185
- elsif (not(self.path) && (self.time.nil?))
186
- if (File.exist?(DIR_INSTALLED_PACKAGES + "/" + self.fullname))
187
- self.time = File.mtime(DIR_INSTALLED_PACKAGES + "/" + self.fullname)
188
- end
189
- end
190
- return self.time
191
- end
192
-
193
- # Fill in the path information
194
- def get_path
195
- if (self.path.nil? && File.exist?(DIR_INSTALLED_PACKAGES + "/" + self.name))
196
- self.path = DIR_INSTALLED_PACKAGE
197
- return DIR_INSTALLED_PACKAGE
198
- end
199
- end
200
-
201
- def inspect
202
- "#<%s:0x%x name=\"%s\" version=\"%s\" arch=\"%s\" build=%s tag=\"%s\">" % [
203
- self.class.name,
204
- self.object_id,
205
- self.name,
206
- self.version,
207
- self.arch,
208
- self.build,
209
- self.tag
210
- ]
211
- end
212
-
213
- end
214
-
215
- class Script < Package
216
- attr_accessor :script
217
-
218
- def initialize(name = nil)
219
- self.script = true
220
- super
221
- end
222
-
223
- def parse(name)
224
- super
225
- self.script = true
226
- end
227
-
228
- end
101
+ return desc
102
+ end
103
+ end
104
+ end
105
+
106
+ # Setter for the PACKAGE DESCRIPTION, in the event you are parsing a repo file
107
+ def package_description=(desc)
108
+ @package_description = desc
109
+ end
110
+
111
+ # Accessor for the PACKAGE LOCATION from the package file
112
+ def package_location
113
+ if not(@package_location.nil?)
114
+ return @package_location
115
+ end
116
+
117
+ f = File.open(self.path + '/' + self.fullname)
118
+ while true
119
+ if (f.readline =~ RE_PACKAGE_LOCATION)
120
+ return $1
121
+ end
122
+ end
123
+ end
124
+
125
+ # Setter for the PACKAGE LOCATION, in the event you are parsing a repo file
126
+ def package_location=(path)
127
+ @package_location = path
128
+ end
129
+
130
+ # Accessor for the UNCOMPRESSED PACKAGE SIZE from the package file
131
+ def uncompressed_size
132
+ if not(@uncompressed_size.nil?)
133
+ return @uncompressed_size
134
+ end
135
+
136
+ f = File.open(self.path + '/' + self.fullname)
137
+ while true
138
+ if (f.readline =~ RE_UNCOMPRESSED_PACKAGE_SIZE)
139
+ return $1
140
+ end
141
+ end
142
+ end
143
+
144
+ # Setter for the UNCOMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
145
+ def uncompressed_size=(size)
146
+ @uncompressed_size = size
147
+ end
148
+
149
+ # Accessor for the COMPRESSED PACKAGE SIZE from the package file
150
+ def compressed_size
151
+ if not(@compressed_size.nil?)
152
+ return @compressed_size
153
+ end
154
+
155
+ f = File.open(self.path + '/' + self.fullname)
156
+ while true
157
+ if (f.readline =~ RE_COMPRESSED_PACKAGE_SIZE)
158
+ return $1
159
+ end
160
+ end
161
+ end
162
+
163
+ # Setter for the COMPRESSED PACKAGE SIZE, in the event you are parsing a repo file
164
+ def compressed_size=(size)
165
+ @compressed_size = size
166
+ end
167
+
168
+ # Accessor for the FILE LIST from the package file
169
+ # unless the :owned_files symbol is populated
170
+ def get_owned_files
171
+ unless self.owned_files.nil?
172
+ return self.owned_files
173
+ else
174
+ files = []
175
+ File.open(self.path + '/' + self.fullname) do |f|
176
+ while true
177
+ break if f.eof?
178
+ line = f.readline()
179
+ if line.force_encoding("US-ASCII") =~ RE_FILE_LIST # FIXME ArgumentError: invalid byte sequence in US-ASCII
180
+ f.seek(2, IO::SEEK_CUR)
181
+ break
182
+ end
183
+ end
184
+ begin
185
+ files = f.readlines().map {|line| line.rstrip.force_encoding("US-ASCII") }
186
+ rescue ArgumentError
187
+ Log.instance.debug("Slackware::Package") {
188
+ "encoding in : " + self.path + '/' + self.fullname
189
+ }
190
+ end
191
+ end
192
+ return files
193
+ end
194
+ end
195
+
196
+ # Set the file list in the package object in memory
197
+ def set_owned_files
198
+ if self.owned_files.nil?
199
+ self.owned_files = get_owned_files()
200
+ return true
201
+ else
202
+ return false
203
+ end
204
+ end
205
+
206
+ # populates and returns self.time
207
+ def get_time
208
+ if (self.time.nil? && self.path)
209
+ if (File.exist?(self.path + "/" + self.fullname))
210
+ self.time = File.mtime(self.path + "/" + self.fullname)
211
+ end
212
+ elsif (not(self.path) && (self.time.nil?))
213
+ if (File.exist?(Paths::installed_packages() + "/" + self.fullname))
214
+ self.time = File.mtime(Paths::installed_packages() + "/" + self.fullname)
215
+ end
216
+ end
217
+ return self.time
218
+ end
219
+
220
+ # Fill in the path information
221
+ def get_path
222
+ if (self.path.nil? && File.exist?(Paths::installed_packages() + "/" + self.name))
223
+ self.path = Paths::installed_packages()
224
+ return Paths::installed_packages()
225
+ end
226
+ end
227
+
228
+ def inspect
229
+ "#<%s:0x%x name=\"%s\" version=\"%s\" arch=\"%s\" build=%s tag=\"%s\">" % [
230
+ self.class.name,
231
+ self.object_id,
232
+ self.name,
233
+ self.version,
234
+ self.arch,
235
+ self.build,
236
+ self.tag
237
+ ]
238
+ end
239
+
240
+ end
241
+
242
+ class Script < Package
243
+ attr_accessor :script
244
+
245
+ def initialize(name = nil)
246
+ self.script = true
247
+ super
248
+ end
249
+
250
+ def parse(name)
251
+ super
252
+ self.script = true
253
+ end
254
+
255
+ end
229
256
  end
257
+
258
+ # vim:sw=2:sts=2:et: