From bc8a76513db6603dd4fa853ea176cfad38029c3e Mon Sep 17 00:00:00 2001 From: David Shakaryan Date: Mon, 29 Sep 2008 16:20:28 -0700 Subject: [PATCH] pint.rb: Do not create a new environment for each dependency spec. --- pint.rb | 18 ++++++++---------- 1 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pint.rb b/pint.rb index d82e9fa..e190203 100755 --- a/pint.rb +++ b/pint.rb @@ -3,7 +3,7 @@ # Copyright 2007-2008 David Shakaryan # Distributed under the terms of the GNU General Public License v2. # -# pint.rb [version 0.6] +# pint.rb [version 0.10] # # Parse a Paludis log file and output install times of one or more packages, # defaulting to all packages if none are specified. @@ -20,8 +20,8 @@ getopt = GetoptLong.new( ['--current', '-c', GetoptLong::NO_ARGUMENT], ['--no-colour', '-C', GetoptLong::NO_ARGUMENT], ['--file', '-f', GetoptLong::REQUIRED_ARGUMENT], - ['--help', '-h', GetoptLong::NO_ARGUMENT], - ['--version', '-v', GetoptLong::NO_ARGUMENT]) + ['--version', '-v', GetoptLong::NO_ARGUMENT], + ['--help', '-h', GetoptLong::NO_ARGUMENT]) $opts = Hash['file' => '/var/log/paludis.log', 'repository' => '\S+'] getopt.each do |opt, arg| $opts[opt.sub('--', '')] = arg end @@ -31,9 +31,9 @@ if $opts.has_key?('no-colour') def colour_date(str); return str; end def colour_time(str); return str; end else + $env = Paludis::EnvironmentFactory.instance.create '' def colour_name(str) - env = Paludis::EnvironmentFactory.instance.create "" - depspec = Paludis::parse_user_package_dep_spec('=' + str, env, Array.new) + depspec = Paludis::parse_user_package_dep_spec('=' + str, $env, Array.new) name = depspec.package version = depspec.version_requirements.first[:spec] @@ -48,10 +48,8 @@ end # Format time from seconds to a readable string. def format_time(s) # Calculate hours, minutes and seconds. - h = s / 3600 - s = s % 3600 - m = s / 60 - s = s % 60 + h, s = s.divmod(3600) + m, s = s.divmod(60) # Convert numbers to a string. str = '' @@ -103,7 +101,7 @@ end # Program version. if $opts.has_key?('version') - puts "pint.rb 0.6" + puts 'pint.rb 0.10' exit end -- 1.6.0.2