Example #1
0
 def run_all(self, location=None):
     if location is None:
         backups = Backups.load_all()
     else:
         backups = [
             name for name, val in Backups.load_all().items()
             if val.location == location
         ]
     if len(backups) is 0:
         QMessageBox.information(self, "No backups", "No backups to run")
         return
     backups_str = ',\n'.join(backups)
     reply = QMessageBox.question(
         self, "Run all?",
         f"You are about to run {len(backups)} backups: \n\n{backups_str}\n\nContinue?",
         QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
     if reply is QMessageBox.No:
         return
     for backup_name in backups:
         self.go_backup(backup_name=backup_name)
Example #2
0
 def populate(self, backup_name=None):
     self.backups_tree_widget.clear()
     self.original_item_texts = {}
     plans = Backups.load_all()
     if len(plans) is 0:
         self.hide_regular_widgets()
         self.welcome_widget.show()
         return
     self.show_regular_widgets()
     self.welcome_widget.hide()
     selected_item = None
     for plan in plans.values():
         schedule = "Manual"
         daily = plan.backup_daily_time
         if daily is not None and plan.backup_days is not None:
             days_order = {
                 "mon": 0,
                 "tue": 1,
                 "wed": 2,
                 "thu": 3,
                 "fri": 4,
                 "sat": 5,
                 "sun": 6
             }
             days_map = {
                 "mon": "M",
                 "tue": "T",
                 "wed": "W",
                 "thu": "Th",
                 "fri": "F",
                 "sat": "S",
                 "sun": "Su"
             }
             time_str = datetime.datetime.strptime(
                 f"{daily.hour()}:{daily.minute()}",
                 "%H:%M").strftime("%I:%M %p")
             schedule = f"{time_str} | {','.join(days_map[d] for d in sorted(plan.backup_days.split(','), key=lambda x: days_order[x]))}"
         if plan.every_hour is not None and plan.every_min is not None:
             schedule = f"Every {plan.every_hour} hour(s) ({plan.every_min} mins)"
         item = QTreeWidgetItem(
             [plan.name, plan.location, "Idle", schedule])
         item.setWhatsThis(0, plan.name)
         if backup_name is None:
             if selected_item is None:
                 selected_item = item
         else:
             if plan.name == backup_name:
                 selected_item = item
         self.backups_tree_widget.addTopLevelItem(item)
     self.log_file_thread.reset = True
     self.backups_tree_widget.setCurrentItem(selected_item)
     self.update_logs(force=True)
Example #3
0
 def reload(self):
     self.remove_all_jobs()
     backups = Backups.load_all()
     for backup in backups.values():
         trigger = None
         if backup.backup_daily_time is not None:
             trigger = CronTrigger(hour=backup.backup_daily_time.hour(),
                                   minute=backup.backup_daily_time.minute(),
                                   day_of_week=backup.backup_days)
         if backup.every_hour is not None and backup.every_min is not None:
             trigger = CronTrigger(hour=f'*/{backup.every_hour}',
                                   minute=backup.every_min)
         if self.get_job(backup.name) is not None and trigger is not None:
             self.reschedule_job(backup.name, trigger=trigger)
         elif trigger is not None:
             self.add_job(func=self.app.start_backup.emit,
                          args=(False, backup.name),
                          trigger=trigger,
                          id=backup.name,
                          misfire_grace_time=180)
         elif self.get_job(backup.name) is not None and trigger is None:
             self.remove_job(backup.name)
Example #4
0
 def validate_plan_name(name):
     if len(name) is 0:
         return False, "Backup name must not be empty"
     if name in Backups.load_all():
         return False, "Backup name is already in use"
     return True, None