Top Level Namespace

Defined Under Namespace

Modules: Slackware

Instance Method Summary collapse

Instance Method Details

#build_packages(opts = {}, args = []) ⇒ Object

This is base builder of the packe list



39
40
41
42
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/slackware/utils.rb', line 39

def build_packages(opts = {}, args = [])
  pkgs = Slackware::System.installed_packages
  
  # separated this little thing out, since it adds a little more time
  if (opts[:time])
    pkgs = pkgs.each {|p| p.get_time }
  end

  if (opts[:all])
    if (args.count > 0)
      args.each {|arg|
        # about 0.012s performance improvement,
        # by compiling it here, instead of inside the iteration.
        if (opts[:case_insensitive])
          re = /#{arg}/i
        else
          re = /#{arg}/
        end

        pkgs = pkgs.find_all {|pkg| pkg.fullname =~ re }
      }
    end
    re = nil
  end
  if (opts[:pkg])
    if (opts[:case_insensitive])
      re = /#{opts[:pkg]}/i
    else
      re = /#{opts[:pkg]}/
    end
    pkgs = pkgs.map {|p|
      if p.name =~ re
        if (opts[:color])
          p.name = p.name.gsub(re, "#{@st}\\&#{@en}")
        end
        p
      end
    }.compact
    re = nil
  end
  if (opts[:Version])
    if (opts[:case_insensitive])
      re = Regexp.new(Regexp.escape(opts[:Version]), Regexp::IGNORECASE)
    else
      re = Regexp.new(Regexp.escape(opts[:Version]))
    end
    pkgs = pkgs.map {|p|
      if p.version =~ re
        if (opts[:color])
          p.version = p.version.gsub(re, "#{@st}\\&#{@en}")
        end
        p
      end
    }.compact
    re = nil
  end
  if (opts[:arch])
    if (opts[:case_insensitive])
      re = /#{opts[:arch]}/i
    else
      re = /#{opts[:arch]}/
    end
    pkgs = pkgs.map {|p|
      if p.arch =~ re
        if (opts[:color])
          p.arch = p.arch.gsub(re, "#{@st}\\&#{@en}")
        end
        p
      end
    }.compact
    re = nil
  end
  if (opts[:build])
    if (opts[:case_insensitive])
      re = /#{opts[:build]}/i
    else
      re = /#{opts[:build]}/
    end
    pkgs = pkgs.map {|p|
      if p.build =~ re
        if (opts[:color])
          p.build = p.build.gsub(re, "#{@st}\\&#{@en}")
        end
        p
      end
    }.compact
    re = nil
  end
  if (opts[:tag])
    if (opts[:case_insensitive])
      re = /#{opts[:tag]}/i
    else
      re = /#{opts[:tag]}/
    end
    pkgs = pkgs.map {|p|
      if p.tag =~ re
        if (opts[:color])
          p.tag = p.tag.gsub(re, "#{@st}\\&#{@en}")
        end
        p
      end
    }.compact
    re = nil
  end

  return pkgs
end

#find_linked(file_to_find) ⇒ Object

XXX This is a work in progress It works, but is pretty darn slow … It would be more efficient to break this out to a separate Class, and use a sqlite database for caching linked dependencies. Categorized by pkg, file, links. based on mtime of the package file, or maybe even mtime of the shared objects themselves. That way, those entries alone could be updated if they are newer, otherwise it’s just a query.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/slackware/utils.rb', line 296

def find_linked(file_to_find)
  require 'find'

  dirs = %w{ /lib /lib64 /usr/lib /usr/lib64 /bin /sbin /usr/bin /usr/sbin }
  re_so = /ELF.*shared object/
  re_exec = /ELF.*executable/

  if File.exist?(file_to_find)
    file_to_find = File.expand_path(file_to_find)
  end
  if not(filemagic(File.dirname(file_to_find) + "/" + File.readlink(file_to_find)) =~ re_so)
    printf("%s is not a shared object\n",file_to_find)
    return nil
  end

  includes_linked = []
  printf("Searching through ... ")
  dirs.each {|dir|
    printf("%s ", dir)
    Find.find(dir) {|file|
      if File.directory?(file)
        next
      end
      file_magic = filemagic(file)
      if (file_magic =~ re_so || file_magic =~ re_exec)
        l = `/usr/bin/ldd #{file} 2>/dev/null `
        if l.include?(file_to_find)
          printf(".")
          l = l.sub(/\t/, '').split(/\n/)
          includes_linked << {:file => file, :links => l}
        end
      end
    }
  }
  printf("\n")
  return includes_linked
end

#find_orphaned_config_filesObject

find orpaned files from /etc/

* build a list of files from removed_packages
* check the list to see if they are currently owned by a package
* check the unowned members, to see if they still exist on the filesystem
* return existing files


233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/slackware/utils.rb', line 233

def find_orphaned_config_files
  # build a list of config files currently installed
  installed_config_files = Slackware::System.installed_packages.map {|pkg|
    pkg.get_owned_files.map {|file|
      if not(file =~ /\/$/)
        if (file =~ /^etc\//)
          file
        end
      end
    }
  }.flatten.compact

  # this Array is where we'll stash removed packages that have config file to check
  pkgs = Array.new
  Slackware::System.removed_packages.each {|r_pkg|
    # find config files for this removed package
    config = r_pkg.get_owned_files.grep(/^etc\/.*[\w|\d]$/)
    # continue if there are none
    if (config.count > 0)
      # remove config files that are owned by a currently installed package
      config = config.map {|file|
        if not(installed_config_files.include?(file))
          if not(installed_config_files.include?(file + ".new"))
            file
          end
        end
      }.compact
      # check again, and continue if there are no config files left
      if (config.count > 0)
        # otherwise add this package, and its files, to the stack
        pkgs << {:pkg => r_pkg, :files => config}
      end
    end
  }

  # setup list of files to check whether they still exist on the filesystem
  files = []
  pkgs.map {|pkg| files << pkg[:files] }
  files.flatten!.uniq!

  orphaned_config_files = []
  files.each {|file|
    if (File.exist?("/" + file))
      orphaned_config_files << file
    end
  }

  return orphaned_config_files

end

#packages_of_linked_files(linked_files_arr) ⇒ Object

This is intended to take the return of the find_linked() method



335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/slackware/utils.rb', line 335

def packages_of_linked_files(linked_files_arr)
  pkgs = Slackware::System.installed_packages
  owned_pkgs = []
  pkgs.map {|pkg|
    files.each {|file|
      if pkg.owned_files.include?(file)
        owned_pkgs << {:pkg => pkg, :file => file}
      end
    }
  }
  return owned_pkgs
end

Pretty print the output of find_linked()



349
350
351
352
353
354
355
# File 'lib/slackware/utils.rb', line 349

def print_find_linked(file_to_find)
  files = find_linked(file_to_find)
  printf("files linked to '%s' include:\n", file_to_find)
  files.each {|file|
    printf("  %s\n", file)
  }
end


284
285
286
# File 'lib/slackware/utils.rb', line 284

def print_orphaned_files(files)
  puts files
end

package file listing



204
205
206
207
208
209
210
211
212
213
214
# File 'lib/slackware/utils.rb', line 204

def print_package_file_list(pkgs)
  if (pkgs.count > 1)
    pkgs.each {|pkg|
      pkg.get_owned_files.each {|line|
        puts pkg.name + ": " + line
      }
    }
  else
    pkgs.each {|pkg| puts pkg.get_owned_files }
  end
end

search Array of Slackware::Package’s for files and print the items found



218
219
220
221
222
223
224
225
226
# File 'lib/slackware/utils.rb', line 218

def print_package_searched_files(pkgs, files)
  found_files = []
  files.each {|file|
    found_files += Slackware::System.owns_file(file)
  }
  found_files.each {|file|
    puts file[0].fullname + ": " + file[1]
  }
end


175
176
177
178
179
180
181
# File 'lib/slackware/utils.rb', line 175

def print_packages(pkgs)
  if (pkgs.count > 0 && pkgs.first.class == Slackware::Package)
    pkgs.each {|pkg|
      printf("%s\n", pkg.fullname )
    }
  end
end


191
192
193
194
195
196
197
198
199
200
201
# File 'lib/slackware/utils.rb', line 191

def print_packages_description(pkgs)
  if (pkgs.count > 0 && pkgs.first.class == Slackware::Package)
    pkgs.each {|pkg|
      printf("%s: COMPRESSED SIZE: %s\n", pkg.fullname, pkg.compressed_size )
      printf("%s: UNCOMPRESSED SIZE: %s\n", pkg.fullname, pkg.uncompressed_size )
      pkg.package_description.each {|line|
        printf("%s: %s\n", pkg.fullname, line )
      }
    }
  end
end


183
184
185
186
187
188
189
# File 'lib/slackware/utils.rb', line 183

def print_packages_times(pkgs, epoch = false)
  if (epoch == true)
    pkgs.each {|pkg| printf("%s : %s\n", pkg.fullname, pkg.time.to_i) }
  else
    pkgs.each {|pkg| printf("%s : %s\n", pkg.fullname, pkg.time.to_s) }
  end
end


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/slackware/utils.rb', line 147

def print_upgrades(pkgs)
  count = 1
  p_count = pkgs.count
  pkgs.each do |pkg|
    if (Slackware::System.is_upgraded?(pkg.name))
      puts '"%s" (current version %s build %s%s) has been upgraded before' % [pkg.name,
                                                                        pkg.version,
                                                                        pkg.build,
                                                                        pkg.tag]
      Slackware::System.upgrades(pkg.name).each do |up|
        puts "  %s build %s%s upgraded on  %s" % [up.version,
                                            up.build,
                                            up.tag,
                                            up.upgrade_time]
      end
    else
      puts '"%s" (current version %s build %s%s) has not been upgraded' % [pkg.name,
                                                                     pkg.version,
                                                                     pkg.build,
                                                                     pkg.tag]
    end
    if count < p_count
      puts
    end
    count += 1
  end
end