]> git.itanic.dy.fi Git - emerge-timer/commitdiff
Merge branch 'master' of itanic.dy.fi:/home/git/emerge-timer
authorEsko Kokkonen <esko.kokkonen@gmail.com>
Thu, 5 Apr 2012 13:35:06 +0000 (16:35 +0300)
committerEsko Kokkonen <esko.kokkonen@gmail.com>
Thu, 5 Apr 2012 13:35:06 +0000 (16:35 +0300)
1  2 
emerge-timer.py

diff --combined emerge-timer.py
index cc4d242667ca570e0102d2b298c47c7cc14f07ee,fb610c4f31f2596c66065261ab880c3922d5e4d5..a11acbdb4a8022e42ed8fe64ed119a4e86c0f247
@@@ -30,8 -30,6 +30,8 @@@ class package
          self.versions = []
          self.emerge_time = "infinity"
  
 +        self.plotData = []
 +
  
      def add_version(self, version, emerge_time, emerge_date):
          """Add version to the class version list"""
                  if len(give_time(p[1], True)) > time_length:
                      time_length = len(give_time(p[1], True))
  
 +                # Create the data for plotting in the format (emerge time, emerge date)
 +                self.plotData.append((p[1], p[2]))
 +
              dots =  (version_length + time_length + len(self.name)
                       + len(give_date(self.versions[0][2])) + 14)
  
                "\nIn total spent:\t" + give_time(total) +
                "emerging " + GREEN(self.name))
  
 +    def plotToScreen(self):
 +        dates = []
 +        times = []
 +
 +        for i in self.plotData:
 +            dates.append(datetime.date.fromtimestamp(i[1]))
 +            times.append(i[0])
 +
 +        fig = plt.figure()
 +
 +        plt.plot_date(dates, times, xdate=True, ydate=False)
 +
 +        plt.ylabel("Emerge time [s]")
 +        plt.suptitle(self.name)
 +        plt.grid()
 +        fig.autofmt_xdate()
 +        plt.show()
 +
  
  
  def give_time(time, nocolor=False):
@@@ -350,16 -327,13 +350,14 @@@ def search_log_for_all_packages()
          elif ((":::" in line) and ("completed emerge" in line)):
              for p in all_packages:
                  if p[0] in line:
-                     stop_time = float(line.partition(':')[0])
                      print("\t" + give_date(p[1]) + " >>> " + GREEN(p[0]))
  
-                     total_emerge_time += stop_time - p[1]
                      emerge_number += 1
  
                      all_packages.pop(all_packages.index(p))
  
 -    print("\n" + GREEN(str(emerge_number)) + " packages in total.")
++
 +    print("\n" + GREEN(str(emerge_number)) + " emerges in total found.")
  
  
  
@@@ -522,9 -496,6 +520,9 @@@ def _main(status, user_package=None)
                  pack.print_versions()
                  pack.print_min_max_ave()
  
 +                if matplotWorking:
 +                    pack.plotToScreen()
 +
              else:
                  print("Package " + GREEN(pack.name)
                        + " has never been emerged.")
@@@ -582,8 -553,6 +580,8 @@@ Options
  \t-h, --help \t Show this helpscreen
  \t-q, --quiet \t Be less verbose
  \t--no-color \t Use colorless output
 +\t--plot \t\t Plot emerge times into a 2D scatter plot
 +\t\t\t (needs matlibplot installed for this to work)
  \t--simulate \t Do a simulation run"""
  
      print usage
@@@ -597,7 -566,6 +595,7 @@@ if __name__ == "__main__"
      mode = "package"
      input_packages = None
      simulation = False
 +    matplotWorking = False
  
      for arg in sys.argv[1:]:
  
  
              sys.argv.pop(sys.argv.index(arg))
  
 +        if arg == "--plot":
 +            try:
 +                import matplotlib.pyplot as plt
 +                matplotWorking = True
 +            except ImportError:
 +                print(RED("Cannot initialize matplotlib!"))
 +                print(RED("Check that you have properly installed matplotlib.\n"))
 +                matplotWorking = False
 +
 +            sys.argv.pop(sys.argv.index(arg))
 +
          if arg == "--no-color":
              green_start = ""
              color_stop = ""