def onBackupDirsBtnClicked(self, widget): dialog = Gtk.FileChooserDialog( "Choose Another Folder: ", None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK)) dialog.set_default_size(800, 600) response = dialog.run() filename = "" if response == Gtk.ResponseType.OK: print(dialog.get_filename()) filename = dialog.get_filename() elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") if config.get_value('folderstobak').strip() == "": config.set_value('folderstobak', filename.strip()) else: config.set_value( 'folderstobak', config.get_value("folderstobak").strip() + ";" + filename.strip()) builder.get_object("entry").set_text(config.get_value("folderstobak")) dialog.destroy()
def __init__(self, parent): Gtk.Dialog.__init__(self, "Select Backup to Restore", parent, 0) self.set_default_size(600, 100) self.response_vbox = Gtk.VBox(spacing=5) self.selected_backup = "" self.response_boxes = {} self.button_mapper = {} print(config.get_value('backuploc')) for folder in glob.glob(config.get_value('backuploc') + "/*"): folder_name_array = folder.split("_") readable_name = "Backup on " + folder_name_array[ 2] + "/" + folder_name_array[3] + "/" + folder_name_array[ 1] + " at " + folder_name_array[ 4] + ":" + folder_name_array[5] backup_box = Gtk.Box(spacing=10) backup_label = Gtk.Label(readable_name) select_button = Gtk.Button("Select") select_button.connect('clicked', self.log_selected_backup) backup_box.pack_start(backup_label, True, True, 0) backup_box.pack_start(select_button, True, True, 1) self.response_boxes[backup_box] = folder self.button_mapper[select_button] = folder box_index = 0 for box, folder in self.response_boxes.items(): self.vbox.pack_start(box, True, True, box_index) box_index += 1 put = self.get_content_area() put.add(self.response_vbox) self.show_all()
def __init__(self): self.restore_dir = config.get_value('folderstobak') self.backups_dir = config.get_value('backuploc') self.restore_dirmapper = {} for dir in self.restore_dir.split(';'): dir = dir.strip() print(dir) self.restore_dirmapper[os.path.basename(dir)] = dir print(self.restore_dirmapper)
def __init__(self): self.backup_dir = config.get_value("backuploc") self.folders_to_backup = config.get_value('folderstobak').strip().split(';') self.backup_time = strftime('%Y_%m_%d_%H_%M_%S', localtime()) self.back_path = self.backup_dir.strip() + "/backup_" + self.backup_time #print(self.back_path) if os.path.exists(self.back_path): sys.stderr.write('FATAL: The directory to back up to exists.\n') else: print("DEBUG: creating directory " + self.back_path) os.makedirs(self.back_path)
def run(): script_running_in_full = os.path.dirname(os.path.realpath(__file__)) print("DEBUG: os.getcwd basename is: " + script_running_in_full) builder.add_from_file(script_running_in_full + "/Preferences.glade") builder.connect_signals(Handlers()) builder.get_object("prefswin").connect('destroy', Gtk.main_quit) builder.get_object("entry").set_text( config.get_value("folderstobak").strip()) builder.get_object("entry1").set_text( config.get_value("backuploc").strip()) window = builder.get_object("prefswin") window.show_all() Gtk.main()
def run(): if os.path.basename(os.getcwd()) == "Interface": builder.add_from_file("Preferences.glade") elif os.path.basename(os.getcwd()) == "ImageBak": builder.add_from_file("Interface/Preferences.glade") builder.connect_signals(Handlers()) builder.get_object("prefswin").connect('destroy', Gtk.main_quit) builder.get_object("entry").set_text( config.get_value("folderstobak").strip()) builder.get_object("entry1").set_text( config.get_value("backuploc").strip()) window = builder.get_object("prefswin") window.show_all() Gtk.main()
def onBackupDirsBtnClicked(self, widget): dialog = Gtk.FileChooserDialog( "Choose Another Folder: ", None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK)) dialog.set_default_size(800, 600) response = dialog.run() filename = "" if response == Gtk.ResponseType.OK: print(dialog.get_filename()) filename = dialog.get_filename() if filename in config.get_value('folderstobak').split(';'): print("DEBUG: Already added, skipping...") else: if config.get_value('folderstobak').strip() == "": config.set_value('folderstobak', filename.strip()) #foldertobak previously set else: config.set_value( 'folderstobak', config.get_value("folderstobak").strip() + ";" + filename.strip()) filename_label = Gtk.Label(filename) label_dict[filename] = filename_label filler_listboxrow = Gtk.ListBoxRow() filler_listboxrow.add(filename_label) print("DEBUG: adding filler listboxrow to folders listbox") builder.get_object("folders_listbox").add(filler_listboxrow) builder.get_object("folders_listbox").show_all() #update dicts lbr_dict[filler_listboxrow] = filename_label label_dict[filename] = filename_label elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") dialog.destroy()
def run(): script_running_in_full = os.path.dirname(os.path.realpath(__file__)) print("DEBUG: os.getcwd basename is: " + script_running_in_full) builder.add_from_file(script_running_in_full + "/Preferences.glade") builder.connect_signals(Handlers()) builder.get_object("prefswin").connect('destroy', Gtk.main_quit) folderstobak_list = config.get_value('folderstobak').strip().split(';') for folder in folderstobak_list: label_to_insert = Gtk.Label(folder) label_dict[folder] = label_to_insert temp_gtklistboxrow = Gtk.ListBoxRow() lbr_dict[temp_gtklistboxrow] = label_to_insert temp_gtklistboxrow.add(label_to_insert) builder.get_object('folders_listbox').add(temp_gtklistboxrow) #builder.get_object("entry").set_text(config.get_value("folderstobak").strip()) builder.get_object("entry1").set_text( config.get_value("backuploc").strip()) window = builder.get_object("prefswin") window.show_all() Gtk.main()
def compress_dir(dirname, target): """Compress a directory to a bzip2 image""" # Make the archive as temp file shutil.make_archive('tmp', 'zip', dirname) # COmpress zip file with bz2 compression level with open('tmp.zip', 'rb') as data: bz2_compress = bz2.compress(data.read(), int(config.get_value('compression_level'))) with open(target, 'wb') as writedata: writedata.write(bz2_compress) # Delete temporary file os.remove('tmp.zip')
def onSelectBackupLocationBtnClicked(self, widget): dialog = Gtk.FileChooserDialog( "Choose a Folder: ", None, Gtk.FileChooserAction.SELECT_FOLDER, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, "Select", Gtk.ResponseType.OK)) dialog.set_default_size(800, 600) response = dialog.run() filename = "" if response == Gtk.ResponseType.OK: print(dialog.get_filename()) filename = dialog.get_filename() config.set_value('backuploc', filename) elif response == Gtk.ResponseType.CANCEL: print("Cancel clicked") builder.get_object("entry1").set_text(config.get_value("backuploc")) dialog.destroy()