def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() directory = self.local_directory_line_edit.text() backup = Backup() backup.name = name backup.location = "Local Directory" backup.password = password backup.local_directory = directory self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), (directory, ), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
class ConfigAzureDialog(QDialog, Ui_ConfigAzureDialog): def __init__(self, window, just_save): QDialog.__init__(self) Ui_ConfigAzureDialog.__init__(self) self.setupUi(self) self.window = window self.backup = None self.just_save = just_save if self.just_save: self.confirm_password_line_edit.hide() self.label_3.hide() def command_done(self, res): self.setEnabled(True) ret, message = res if not ret: QMessageBox.warning(self.window, "Invalid details", message) return if self.just_save: Backups.save(self.backup) super().accept() def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() connection = self.connection_line_edit.text().strip() container = self.container_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Microsoft Azure" backup.password = password backup.azure_conn_str = connection backup.azure_container = container backup.cloud_prefix = prefix self.backup = backup fs = [Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo] args = [(name, ), (password, confirm_password), ("Connection String", connection), ("Container", container), ("Prefix", prefix), ("Container", container), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() connection = self.connection_line_edit.text().strip() container = self.container_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Microsoft Azure" backup.password = password backup.azure_conn_str = connection backup.azure_container = container backup.cloud_prefix = prefix self.backup = backup fs = [Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo] args = [(name, ), (password, confirm_password), ("Connection String", connection), ("Container", container), ("Prefix", prefix), ("Container", container), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() cred_file = self.cred_file_line_edit.text() project = self.project_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Google Cloud" backup.password = password backup.gcp_cred_file = cred_file backup.gcp_project = project backup.gcp_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo] args = [(name, ), (password, confirm_password), (cred_file, ), ("Project", project), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() private_key = self.private_key_line_edit.text() username = self.username_line_edit.text().strip() sftp_password = self.sftp_password_line_edit.text().strip() server = self.server_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "SFTP" backup.password = password if len(private_key) is not 0: backup.sftp_private_key = private_key backup.sftp_username = username if len(sftp_password) is not 0: backup.sftp_password = sftp_password backup.sftp_server = server backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("Username", username), ("Server", server), ("Prefix", prefix), ("Server", server), ("Prefix", prefix), ("Username", username), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() url = self.s3_url_line_edit.text().strip() key_id = self.key_id_line_edit.text().strip() key = self.key_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "S3 Storage" backup.password = password backup.s3_url = url backup.aws_key_id = key_id backup.aws_key = key backup.aws_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("AWS Key Id", key_id), ("S3 URL", url), ("AWS Key", key), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): self.backup.name = self.backup_name_line_edit.text().strip() self.backup.paths = self.paths self.backup.exclude_rules = self.exclude_rules self.backup.retention = None if self.forever_radio_button.isChecked( ) else self.days_spin_box.value() self.backup.backup_daily_time = None if not self.daily_radio_button.isChecked( ) else self.schedule_time_edit.time() self.backup.backup_days = None if not self.daily_radio_button.isChecked( ) else ",".join(self.days_checked) self.backup.every_hour = None if not self.backup_every_radio_button.isChecked( ) else self.hourly_spinbox.value() self.backup.every_min = None if not self.backup_every_radio_button.isChecked( ) else self.mins_spinbox.value() self.backup.thread_count = self.thread_count_spin_box.value() self.backup.compression_level = self.compression_level_spin_box.value() if self.backup.name == "": QMessageBox.warning(self.window, "Invalid details", "Please provide a backup name") return if self.backup.backup_days == "": QMessageBox.warning(self.window, "Invalid details", "Please select some days of the week") return if self.backup.location == "Local Directory" and not os.path.isdir( self.backup.local_directory): QMessageBox.warning( self.window, "Invalid details", f"The backup source '{self.backup.local_directory}' does not exists.\nPlease mount or plug the drive." ) return self.setEnabled(False) self.thread = CommandThread(self.worker, {}) self.thread.result.connect(self.command_done) self.thread.start()
class ConfigSFTPDialog(QDialog, Ui_ConfigSFTPDialog): def __init__(self, window, just_save): QDialog.__init__(self) Ui_ConfigSFTPDialog.__init__(self) self.setupUi(self) self.window = window self.backup = None self.just_save = just_save if self.just_save: self.confirm_password_line_edit.hide() self.label_3.hide() self.browse_button.pressed.connect(self.browse) def browse(self): path, _ = QFileDialog.getOpenFileName() self.private_key_line_edit.setText(path) def command_done(self, res): self.setEnabled(True) ret, message = res if not ret: QMessageBox.warning(self.window, "Invalid details", message) return if self.just_save: Backups.save(self.backup) super().accept() def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() private_key = self.private_key_line_edit.text() username = self.username_line_edit.text().strip() sftp_password = self.sftp_password_line_edit.text().strip() server = self.server_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "SFTP" backup.password = password if len(private_key) is not 0: backup.sftp_private_key = private_key backup.sftp_username = username if len(sftp_password) is not 0: backup.sftp_password = sftp_password backup.sftp_server = server backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("Username", username), ("Server", server), ("Prefix", prefix), ("Server", server), ("Prefix", prefix), ("Username", username), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
class ConfigAwsDialog(QDialog, Ui_ConfigAwsDialog): def __init__(self, window, just_save=False): QDialog.__init__(self) Ui_ConfigAwsDialog.__init__(self) self.setupUi(self) self.window = window self.backup = None self.just_save = just_save if self.just_save: self.confirm_password_line_edit.hide() self.label_3.hide() def command_done(self, res): self.setEnabled(True) ret, message = res if not ret: QMessageBox.warning(self.window, "Invalid details", message) return if self.just_save: Backups.save(self.backup) super().accept() def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() key_id = self.key_id_line_edit.text().strip() key = self.key_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Amazon AWS" backup.password = password backup.aws_key_id = key_id backup.aws_key = key backup.aws_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("AWS Key Id", key_id), ("AWS Key", key), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
class ConfigLocalDialog(QDialog, Ui_ConfigLocalDialog): def __init__(self, window, just_save=False): QDialog.__init__(self) Ui_ConfigLocalDialog.__init__(self) self.setupUi(self) self.window = window self.backup = None self.just_save = just_save if self.just_save: self.confirm_password_line_edit.hide() self.label_3.hide() self.browse_button.pressed.connect(self.browse) def browse(self): directory = QFileDialog.getExistingDirectory() self.local_directory_line_edit.setText(directory) def command_done(self, res): self.setEnabled(True) ret, message = res if not ret: QMessageBox.warning(self.window, "Invalid details", message) return if self.just_save: Backups.save(self.backup) super().accept() def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() directory = self.local_directory_line_edit.text() backup = Backup() backup.name = name backup.location = "Local Directory" backup.password = password backup.local_directory = directory self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), (directory, ), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
class BackupSettings(QDialog, Ui_BackupSettingsDialog): def __init__(self, backup, window, edit=False): QDialog.__init__(self) Ui_BackupSettingsDialog.__init__(self) self.setupUi(self) self.backup = backup self.original_backup_name = self.backup.name self.window = window self.edit = edit self.paths = set() self.exclude_rules = set() self.map = { "mon": self.mon_checkbox, "tue": self.tue_checkbox, "wed": self.wed_checkbox, "thu": self.thu_checkbox, "fri": self.fri_checkbox, "sat": self.sat_checkbox, "sun": self.sun_checkbox } self.days_checked = set() prefix = self.backup.cloud_prefix if self.backup.cloud_prefix is not None else self.backup.local_directory window_title = f"{self.backup.location}: {self.backup.name} ({prefix})" # Hiding unsupported add file button for now self.add_file_button.hide() self.add_button.pressed.connect(self.add_folder) self.add_file_button.pressed.connect(self.add_file) self.remove_button.pressed.connect(self.remove_folder) self.add_exclude_rule.pressed.connect(self.add_rule) self.remove_exclude_rule.pressed.connect(self.remove_rule) self.group_schedule = QButtonGroup() self.group_schedule.addButton(self.manual_radio_button) self.group_schedule.addButton(self.backup_every_radio_button) self.group_schedule.addButton(self.daily_radio_button) self.group_retention = QButtonGroup() self.group_retention.addButton(self.forever_radio_button) self.group_retention.addButton(self.keep_last_radio_button) self.forever_radio_button.setChecked(True) self.manual_radio_button.setChecked(True) self.daily_radio_button.pressed.connect(self.daily_radio_pressed) self.backup_every_radio_button.pressed.connect( self.backup_every_pressed) self.manual_radio_button.pressed.connect(self.manual_radio_pressed) self.forever_radio_button.pressed.connect( lambda: self.days_spin_box.setEnabled(False)) self.keep_last_radio_button.pressed.connect( lambda: self.days_spin_box.setEnabled(True)) self.mon_checkbox.clicked.connect( lambda: self.state_changed("mon", self.mon_checkbox)) self.tue_checkbox.clicked.connect( lambda: self.state_changed("tue", self.tue_checkbox)) self.wed_checkbox.clicked.connect( lambda: self.state_changed("wed", self.wed_checkbox)) self.thu_checkbox.clicked.connect( lambda: self.state_changed("thu", self.thu_checkbox)) self.fri_checkbox.clicked.connect( lambda: self.state_changed("fri", self.fri_checkbox)) self.sat_checkbox.clicked.connect( lambda: self.state_changed("sat", self.sat_checkbox)) self.sun_checkbox.clicked.connect( lambda: self.state_changed("sun", self.sun_checkbox)) self.activation_label.hide() self.setWindowTitle(window_title) self.thread_count_spin_box.setValue(DEFAULT_THREAD_COUNT) self.compression_level_spin_box.setValue(DEFAULT_COMPRESSION_LEVEL) self.populate() def daily_radio_pressed(self): self.set_days(True) self.set_every(False) def backup_every_pressed(self): self.set_every(True) self.set_days(False) def manual_radio_pressed(self): self.set_days(False) self.set_every(False) def state_changed(self, day, checkbox): if checkbox.isChecked(): self.days_checked.add(day) else: self.days_checked.remove(day) def set_every(self, status): self.hourly_spinbox.setEnabled(status) self.mins_spinbox.setEnabled(status) self.label_2.setEnabled(status) self.label_3.setEnabled(status) def set_days(self, status): self.schedule_time_edit.setEnabled(status) self.mon_checkbox.setEnabled(status) self.tue_checkbox.setEnabled(status) self.wed_checkbox.setEnabled(status) self.thu_checkbox.setEnabled(status) self.fri_checkbox.setEnabled(status) self.sat_checkbox.setEnabled(status) self.sun_checkbox.setEnabled(status) def populate(self): if self.backup.paths is not None: self.paths = self.backup.paths self.reload_paths() if self.backup.exclude_rules is not None: self.exclude_rules = self.backup.exclude_rules self.reload_exclude_rules() self.set_days(False) if self.backup.backup_daily_time is not None: self.set_days(True) self.daily_radio_button.setChecked(True) self.schedule_time_edit.setTime(self.backup.backup_daily_time) self.set_every(False) if self.backup.every_hour is not None and self.backup.every_min is not None: self.set_every(True) self.backup_every_radio_button.setChecked(True) self.hourly_spinbox.setValue(self.backup.every_hour) self.mins_spinbox.setValue(self.backup.every_min) self.days_spin_box.setEnabled(False) if self.backup.retention is not None: self.days_spin_box.setEnabled(True) self.keep_last_radio_button.setChecked(True) self.days_spin_box.setValue(self.backup.retention) if self.backup.backup_days is not None: days = self.backup.backup_days.split(",") for checkbox in self.map.values(): checkbox.setChecked(False) for day in days: self.days_checked.add(day) self.map[day].setChecked(True) self.backup_name_line_edit.setText(self.backup.name) self.thread_count_spin_box.setValue(self.backup.thread_count) self.compression_level_spin_box.setValue(self.backup.compression_level) def reload_exclude_rules(self): self.exclude_rules_list_widget.clear() for rule in self.exclude_rules: self.exclude_rules_list_widget.addItem(rule) def reload_paths(self): self.paths_list_widget.clear() for path in self.paths: self.paths_list_widget.addItem(path) def add_rule(self): input = QInputDialog(self.window) input.setWindowTitle("Add exclude rule") input.setLabelText("Exclude rule (eg: C:\\Users\\*\\Volumes\\*.iso)") if input.exec_(): exclude_rule = input.textValue() exclude_rule = exclude_rule.replace(os.sep, "/") self.exclude_rules.add(exclude_rule) self.reload_exclude_rules() def remove_rule(self): selected_item = self.exclude_rules_list_widget.currentItem() if selected_item is None: return rule = selected_item.text() self.exclude_rules.remove(rule) self.reload_exclude_rules() def add_file(self): path, _ = QFileDialog.getOpenFileName(self, dir=os.path.expanduser("~")) if len(path) is 0: return self.paths.add(path) self.reload_paths() def add_folder(self): path = QFileDialog.getExistingDirectory(self, dir=os.path.expanduser("~")) if len(path) is 0: return self.paths.add(path) self.reload_paths() def remove_folder(self): selected_item = self.paths_list_widget.currentItem() if selected_item is None: return path = selected_item.text() self.paths.remove(path) self.reload_paths() def worker(self, args): is_initialized = Repo(Utils.get_backend(self.backup)).is_initialized() if self.edit: if not is_initialized: return False else: Repo(Utils.get_backend(self.backup)).init( self.backup.password.encode()) return True def command_done(self, ret): self.setEnabled(True) if not ret: QMessageBox.warning( self.window, "Invalid details", f"Backup {self.backup.name} has not been initialized") return Backups.save(self.backup) if self.backup.name != self.original_backup_name: Backups.change_name(self.original_backup_name, self.backup.name) self.window.app.scheduler.reload() super().accept() def accept(self): self.backup.name = self.backup_name_line_edit.text().strip() self.backup.paths = self.paths self.backup.exclude_rules = self.exclude_rules self.backup.retention = None if self.forever_radio_button.isChecked( ) else self.days_spin_box.value() self.backup.backup_daily_time = None if not self.daily_radio_button.isChecked( ) else self.schedule_time_edit.time() self.backup.backup_days = None if not self.daily_radio_button.isChecked( ) else ",".join(self.days_checked) self.backup.every_hour = None if not self.backup_every_radio_button.isChecked( ) else self.hourly_spinbox.value() self.backup.every_min = None if not self.backup_every_radio_button.isChecked( ) else self.mins_spinbox.value() self.backup.thread_count = self.thread_count_spin_box.value() self.backup.compression_level = self.compression_level_spin_box.value() if self.backup.name == "": QMessageBox.warning(self.window, "Invalid details", "Please provide a backup name") return if self.backup.backup_days == "": QMessageBox.warning(self.window, "Invalid details", "Please select some days of the week") return if self.backup.location == "Local Directory" and not os.path.isdir( self.backup.local_directory): QMessageBox.warning( self.window, "Invalid details", f"The backup source '{self.backup.local_directory}' does not exists.\nPlease mount or plug the drive." ) return self.setEnabled(False) self.thread = CommandThread(self.worker, {}) self.thread.result.connect(self.command_done) self.thread.start()
class ConfigGcpDialog(QDialog, Ui_ConfigGcpDialog): def __init__(self, window, just_save): QDialog.__init__(self) Ui_ConfigGcpDialog.__init__(self) self.setupUi(self) self.window = window self.backup = None self.just_save = just_save if self.just_save: self.confirm_password_line_edit.hide() self.label_3.hide() self.browse_button.pressed.connect(self.browse) def browse(self): path, _ = QFileDialog.getOpenFileName() self.cred_file_line_edit.setText(path) def command_done(self, res): self.setEnabled(True) ret, message = res if not ret: QMessageBox.warning(self.window, "Invalid details", message) return if self.just_save: Backups.save(self.backup) super().accept() def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() cred_file = self.cred_file_line_edit.text() project = self.project_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Google Cloud" backup.password = password backup.gcp_cred_file = cred_file backup.gcp_project = project backup.gcp_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo] args = [(name, ), (password, confirm_password), (cred_file, ), ("Project", project), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()