Ejemplo n.º 1
0
def archive_delete(model, iterator):
    archive = model[iterator][2].archive

    dialog = Gtk.MessageDialog(
        common.win, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING,
        Gtk.ButtonsType.CANCEL,
        'Are you sure you want to delete the archive <b>%s</b>?' %
        GLib.markup_escape_text(archive.name))

    dialog.set_property('use-markup', True)
    dialog.add_button('_Delete', Gtk.ResponseType.ACCEPT)
    dialog.set_default_response(Gtk.ResponseType.CANCEL)

    accepted = dialog.run() == Gtk.ResponseType.ACCEPT

    dialog.destroy()

    if accepted:
        transitions.to_load()
        dialog = Gtk.MessageDialog(common.win, Gtk.DialogFlags.MODAL,
                                   Gtk.MessageType.INFO, Gtk.ButtonsType.NONE,
                                   '<i>Deleting</i>')
        dialog.set_property('use-markup', True)
        dialog.show_all()

        def idle_func():
            archive.delete(borg.helpers.Statistics())
            common.cur_rep_manifest.write()
            common.cur_repository.commit()
            common.cur_rep_cache.commit()
            model.remove(iterator)
            dialog.hide()
            transitions.unload()

        GLib.idle_add(idle_func)
Ejemplo n.º 2
0
def back_button_callback():
    def idle_func():
        common.reload_cur_repository()
        transitions.unload()
        transitions.to_rep()

    transitions.to_load()
    GLib.idle_add(idle_func)
Ejemplo n.º 3
0
def create_repository(caller):
	#validate entries
	reset_error()
	valid = True
	name = directory_name_entry.get_text()
	if name == '':
		common.set_error(directory_name_entry)
		directory_name_entry.empty_popover.show_all()
		valid = False

	args = argparse.Namespace()
	args.encryption = 'none'
	if not encryption_disable_checkbox.get_active():
		passwd = encryption_passphrase_entry.get_text()
		if passwd == '':
			common.set_error(encryption_passphrase_entry)
			common.set_error(encryption_passphrase_again_entry)
			encryption_passphrase_entry.popover.show_all()
			valid = False
		elif passwd != encryption_passphrase_again_entry.get_text():
			common.set_error(encryption_passphrase_entry)
			common.set_error(encryption_passphrase_again_entry)
			encryption_passphrase_again_entry.popover.show_all()
			valid = False
		elif valid:
			repository.set_pass(passwd)
			if encryption_store_key_checkbox.get_active():
				args.encryption = 'keyfile'
			else:
				args.encryption = 'repokey'

	directory = directory_path_button.get_filename()
	if directory:
		path = os.path.join(directory_path_button.get_filename(), name)
		if os.path.exists(path) and valid:
			dialog = Gtk.MessageDialog(common.win, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE,
			                           'The file [' + path + '] already exists. Choose a different location or name')
			dialog.run()
			dialog.destroy()
			valid = False
	else:
		common.set_error(directory_path_button)
		directory_path_button.popover.show_all()
		valid = False

	if valid:
		transitions.to_load()

		def idle_func():
			common.cur_path = os.path.join(directory_path_button.get_filename(), name)
			common.prepare()

			#Simulate do_init, Create repository, cache and manifest and lock them
			common.cur_repository = borg.repository.Repository(common.cur_path, create=True, exclusive=True, lock_wait=1)
			common.cur_repository.__enter__()
			borg.archiver.logger.info('Initializing repository at "%s"' % common.cur_path)
			common.cur_rep_key = borg.key.key_creator(common.cur_repository, args)
			common.cur_rep_manifest = borg.helpers.Manifest(common.cur_rep_key, common.cur_repository)
			common.cur_rep_manifest.key = common.cur_rep_key
			common.cur_rep_manifest.write()
			common.cur_repository.commit()
			common.cur_rep_cache = borg.cache.Cache(common.cur_repository, common.cur_rep_key, common.cur_rep_manifest, lock_wait=1,
			                                 warn_if_unencrypted=False)
			common.cur_rep_cache.__enter__()

			repository.start()

		GLib.idle_add(idle_func)
Ejemplo n.º 4
0
 def enter_pass(caller):
     set_pass(pass_entry.get_text())
     transitions.to_load()
     GLib.idle_add(idle_func)
Ejemplo n.º 5
0
def start_with_path(path):
    transitions.to_load()

    def idle_func():
        common.cur_path = path
        try:
            common.prepare()
            #Get repository, cache and manifest and lock them
            common.set_cur_repository(common.cur_path, False)
            start()
        except borg.key.PassphraseWrong as e:
            common.unset_cur_repository(e)
            transitions.unload()
            global pass_not_setup, pass_again, msg_label, pass_entry
            if pass_not_setup:
                builder = Gtk.Builder.new_from_file('../data/ui/passphrase.ui')

                grid = builder.get_object('grid')
                common.stack.add_named(grid, 'pass')

                msg_label = builder.get_object('msg_label')

                pass_entry = builder.get_object('entry')

                button = builder.get_object('button')

                def enter_pass(caller):
                    set_pass(pass_entry.get_text())
                    transitions.to_load()
                    GLib.idle_add(idle_func)

                builder.connect_signals({
                    'click_button':
                    lambda caller: button.clicked(),
                    'enter_pass':
                    enter_pass
                })

                pass_not_setup = False

            common.stack.set_visible_child_full(
                'pass', Gtk.StackTransitionType.CROSSFADE)
            common.addrep_button.hide()
            common.back_button.show()
            common.win.set_title('Passphrase')
            common.back_button.disconnect(common.back_button_signal_id)

            def callback(caller):
                pass_again = False
                transitions.to_replist()

            common.back_button_signal_id = common.back_button.connect(
                'clicked', callback)
            if pass_again:
                msg_label.set_text('Passphrase Incorrect. Try again')
            else:
                msg_label.set_text(
                    'Passphrase needed to read or modify the contents of this repository'
                )
            pass_again = True

    GLib.idle_add(idle_func)
Ejemplo n.º 6
0
def archive_selected(selection):
    global select_grid
    model, iterator = selection.get_selected()
    if iterator:
        global stack
        archive_name = model[iterator][1]

        def set_info_labels():
            obj = model[iterator][2]

            builder.get_object('fingerprint').set_markup('<small>' +
                                                         obj.fingerprint +
                                                         '</small>')

            for key, value in obj.info.items():
                builder.get_object(key).set_text(value)

            for key, value in model.all_info.items():
                builder.get_object(key).set_text(value)

            select_name_label.set_markup('<big><b>' + archive_name +
                                         '</b></big>')

        if model[iterator][2]:
            set_info_labels()
        else:
            transitions.to_load()

            def idle_func():
                new_obj = GObject.Object()
                new_obj.archive = common.get_archive(archive_name, False)
                stats = new_obj.archive.calc_stats(common.cur_rep_cache)
                new_obj.fingerprint = binascii.hexlify(
                    new_obj.archive.id).decode('ascii')
                new_obj.info = {
                    'hostname':
                    new_obj.archive.metadata[b'hostname'],
                    'username':
                    new_obj.archive.metadata[b'username'],
                    'time_start':
                    borg.helpers.format_time(
                        borg.helpers.to_localtime(new_obj.archive.ts)),
                    'time_end':
                    borg.helpers.format_time(
                        borg.helpers.to_localtime(new_obj.archive.ts_end)),
                    'command':
                    ' '.join(new_obj.archive.metadata[b'cmdline']),
                    'n_files':
                    str(stats.nfiles),
                    'original_size':
                    stats.osize_fmt,
                    'compressed_size':
                    stats.csize_fmt,
                    'deduplicated_size':
                    stats.usize_fmt
                }
                model[iterator][2] = new_obj

                if not hasattr(model, 'all_info'):
                    summary = common.cur_rep_cache.chunks.summarize()
                    model.all_info = {
                        'all_original_size':
                        borg.helpers.format_file_size(summary[0]),
                        'all_compressed_size':
                        borg.helpers.format_file_size(summary[1]),
                        'all_deduplicated_size':
                        borg.helpers.format_file_size(summary[3]),
                        'unique_chunks':
                        str(summary[4]),
                        'total_chunks':
                        str(summary[5])
                    }

                set_info_labels()

                select_grid.show_all()
                transitions.unload()

            GLib.idle_add(idle_func)
    else:
        select_grid.hide()