Example #1
0
    def __init__(self, app):
        Gtk.Window.__init__(self, title="Bups", application=app)
        self.set_default_size(800, 400)
        self.set_icon_name("drive-harddisk")
        self.set_position(Gtk.WindowPosition.CENTER)

        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.add(vbox)

        if hasattr(Gtk, "HeaderBar"):  # Use HeaderBar if available
            hb = Gtk.HeaderBar(title="Bups")
            hb.set_show_close_button(True)
            self.set_titlebar(hb)

            # Add/remove
            box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
            Gtk.StyleContext.add_class(box.get_style_context(), "linked")

            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="list-add-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Add a directory"))
            button.connect("clicked", self.on_add_clicked)
            box.add(button)

            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="list-remove-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Remove this directory"))
            button.connect("clicked", self.on_remove_clicked)
            box.add(button)

            if hasattr(Gtk, "Revealer"):
                button = Gtk.ToggleButton()
            else:
                button = Gtk.Button()
            icon = Gio.ThemedIcon(name="document-properties-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Properties"))
            button.connect("clicked", self.on_properties_clicked)
            box.add(button)
            self.sidebar_btn = button

            hb.pack_start(box)

            # Backup/browse/restore
            box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
            Gtk.StyleContext.add_class(box.get_style_context(), "linked")

            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="drive-harddisk-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Backup now"))
            button.connect("clicked", self.on_backup_clicked)
            box.add(button)

            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="view-refresh-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Restore a backup"))
            button.connect("clicked", self.on_restore_clicked)
            box.add(button)

            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="document-open-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Browse backups"))
            button.connect("clicked", self.on_mount_clicked)
            box.add(button)

            hb.pack_start(box)

            # Settings
            button = Gtk.Button()
            icon = Gio.ThemedIcon(name="emblem-system-symbolic")
            image = Gtk.Image.new_from_gicon(icon, Gtk.IconSize.BUTTON)
            button.add(image)
            button.set_tooltip_text(_("Settings"))
            button.connect("clicked", self.on_settings_clicked)
            hb.pack_end(button)
        else:  # Fallback to Toolbar if HeaderBar is not available
            tb = Gtk.Toolbar()
            tb.set_style(Gtk.ToolbarStyle.ICONS)
            vbox.pack_start(tb, False, False, 0)

            button = Gtk.ToolButton(Gtk.STOCK_ADD)
            button.set_tooltip_text(_("Add a directory"))
            button.connect("clicked", self.on_add_clicked)
            tb.add(button)

            button = Gtk.ToolButton(Gtk.STOCK_REMOVE)
            button.set_tooltip_text(_("Remove this directory"))
            button.connect("clicked", self.on_remove_clicked)
            tb.add(button)

            sep = Gtk.SeparatorToolItem()
            tb.add(sep)

            button = Gtk.ToolButton(Gtk.STOCK_HARDDISK)
            button.set_tooltip_text(_("Backup now"))
            button.connect("clicked", self.on_backup_clicked)
            tb.add(button)

            button = Gtk.ToolButton(Gtk.STOCK_REFRESH)
            button.set_tooltip_text(_("Restore a backup"))
            button.connect("clicked", self.on_restore_clicked)
            tb.add(button)

            button = Gtk.ToolButton(Gtk.STOCK_OPEN)
            button.set_tooltip_text(_("Browse backups"))
            button.connect("clicked", self.on_mount_clicked)
            tb.add(button)

            sep = Gtk.SeparatorToolItem()
            sep.set_draw(False)
            sep.set_expand(True)
            tb.add(sep)

            button = Gtk.ToolButton(Gtk.STOCK_PROPERTIES)
            button.set_tooltip_text(_("Settings"))
            button.connect("clicked", self.on_settings_clicked)
            tb.add(button)

        self.liststore = Gtk.ListStore(str, str)

        self.treeview = Gtk.TreeView(model=self.liststore)

        renderer_text = Gtk.CellRendererText()
        column = Gtk.TreeViewColumn(_("Directory"), renderer_text, text=0)
        column.set_sort_column_id(0)
        self.treeview.append_column(column)

        renderer_text = Gtk.CellRendererText()
        renderer_text.set_property("editable", True)
        renderer_text.connect("edited", self.on_backup_name_edited)
        column = Gtk.TreeViewColumn(_("Name"), renderer_text, text=1)
        column.set_sort_column_id(1)
        self.treeview.append_column(column)

        hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
        vbox.pack_start(hbox, True, True, 0)

        scrolled = Gtk.ScrolledWindow()
        scrolled.add(self.treeview)

        hbox.pack_start(scrolled, True, True, 0)

        self.sidebar = None
        if hasattr(Gtk,
                   "Revealer"):  # Gtk.Revealer is available since GTK 3.10
            self.sidebar = Gtk.Revealer()
            self.sidebar.set_transition_type(
                Gtk.RevealerTransitionType.SLIDE_LEFT)

            self.create_properties(self.sidebar)

            hbox.pack_start(self.sidebar, False, False, 0)

            selection = self.treeview.get_selection()
            selection.connect("changed", self.on_treeview_selection_changed)

        self.config = None
        self.load_config()
        for dirpath in self.config["dirs"]:
            self.add_dir_ui(dirpath)

        sudo_worker = SudoWorker()
        self.manager = BupManager(self.load_config(), sudo_worker)
Example #2
0
#!/usr/bin/env python2

import sys
import config
from manager import BupManager

manager = BupManager(config.read(sys.argv[1]))


def onstatus(status, ctx):
    print(status)


def onerror(err, ctx):
    sys.stderr.write(err + "\n")


callbacks = {"onstatus": onstatus, "onerror": onerror}

manager.backup(callbacks)
Example #3
0
#!/usr/bin/env python2

import sys
import config
from manager import BupManager

manager = BupManager(config.read(sys.argv[1]))

def onstatus(status, ctx):
	print(status)

def onerror(err, ctx):
	sys.stderr.write(err+"\n")

callbacks = {
	"onstatus": onstatus,
	"onerror": onerror
}

manager.backup(callbacks)
Example #4
0
#!/usr/bin/env python2

import sys
import config
import json
from manager import BupManager

manager = BupManager(config.read(sys.argv[1]))

while True:
    try:
        cmd = raw_input()
    except EOFError, e:
        cmd = 'quit'

    res = {"success": True, "output": ""}

    def onerror(err, ctx):
        res["output"] += err + "\n"

    callbacks = {"onerror": onerror}

    if cmd == 'quit':
        sys.exit()
    if cmd == 'mount':
        res["success"] = manager.mount_parents(callbacks)
        res["bup_path"] = manager.bup.get_dir()
    if cmd == 'unmount':
        res["success"] = manager.unmount_parents(callbacks)

    sys.stdout.write(json.dumps(res) + "\n")
Example #5
0
#!/usr/bin/env python2

import sys
import config
import json
from manager import BupManager

manager = BupManager(config.read(sys.argv[1]))

while True:
	try:
		cmd = raw_input()
	except EOFError, e:
		cmd = 'quit'

	res = {
		"success": True,
		"output": ""
	}

	def onerror(err, ctx):
		res["output"] += err+"\n"

	callbacks = {
		"onerror": onerror
	}

	if cmd == 'quit':
		sys.exit()
	if cmd == 'mount':
		res["success"] = manager.mount_parents(callbacks)