class Upman::Service::InstallHistory
Attributes
since[RW]
Public Instance Methods
get(since)
click to toggle source
# File lib/upman/services/install_history.rb, line 7 def get(since) @since = since result = [] lines = fetch_history.split("\n") lines.each do |line| fill_up(result, line) end result.reverse! end
Private Instance Methods
fetch_history()
click to toggle source
# File lib/upman/services/install_history.rb, line 21 def fetch_history command = 'for x in $(ls -1t /var/log/dpkg.log*); do zcat -f $x |tac |grep -e " install " -e " upgrade " -e " remove "; done |awk -F ":a" \'{print $1 " :a" $2}\' |column -t' `#{command}` end
fill_up(result, line)
click to toggle source
# File lib/upman/services/install_history.rb, line 26 def fill_up(result, line) command = parse_command(line) return nil if command.empty? if @since.instance_of?(DateTime) if DateTime.parse(command[:datetime]) >= @since result.append command end else result.append command end end
parse_command(command_line)
click to toggle source
# File lib/upman/services/install_history.rb, line 39 def parse_command(command_line) package = {} regexp = /([0-9]{4}-[0-9]{2}-[0-9]{2})\s+([0-9]{2}:[0-9]{2}:[0-9]{2})\s+(upgrade|install|remove)\s+([\w\-+\.]+)\s+\:([a-z0-9]+)\s+([\w+:\.\-~<>]+)\s+([\w+:\.\-~<>]+)/ unless !(matches = command_line.match(regexp)) package[:datetime] = "#{matches[1]} #{matches[2]}" package[:action] = matches[3] package[:package] = matches[4] package[:architecture] = matches[5] package[:old_version] = (%w[<keine> <none>].include? matches[6]) ? nil : matches[6] package[:target_version] = (%w[<keine> <none>].include? matches[7]) ? nil : matches[7] end package end