Esempio n. 1
0
 def _import_logs(self, filename):
     progress = self.main_widget().get_progress_dialog()
     progress.set_text(_("Importing history..."))
     parser = ScienceLogParser(self.database(),
         ids_to_parse=self.items_by_id)
     log_dir = os.path.join(os.path.dirname(filename), "history")
     if not os.path.exists(log_dir):
         self.main_widget().information_box(\
             _("No history found to import."))
         return
     filenames = [os.path.join(log_dir, logname) for logname in \
         sorted(os.listdir(unicode(log_dir))) if logname.endswith(".bz2")]       
     # log.txt can also contain data we need to import, especially on the
     # initial upgrade from 1.x. 'ids_to_parse' will make sure we only pick
     # up the relevant events. (If we do the importing after having used
     # 2.x for a while, there could be duplicate load events, etc, but these
     # don't matter.)
     filenames.append(os.path.join(os.path.dirname(filename), "log.txt"))
     progress.set_range(0, len(filenames))
     for count, filename in enumerate(filenames):
         progress.set_value(count)
         try:
             parser.parse(filename)
         except:
             self.main_widget().information_box(\
                 _("Ignoring unparsable file:") + " " + filename)
     progress.set_value(len(filenames))