Exemple #1
0
    def validate_new_sync_inputs(self, event):
        # step 1
        label = self.label
        path = self.path

        # Always allow to go back
        if not event.GetDirection():
            return True

        # Validate the inputs
        if not gui_utils.is_valid_input(label):
            gui_utils.show_error_dialog(message=_('%s is not a valid label') %
                                        label,
                                        title=_('Invalid Label'))
            event.Veto()
            return

        if not gui_utils.is_valid_input(path):
            gui_utils.show_error_dialog(message=_('%s is not a valid path') %
                                        path,
                                        title=_('Invalid Path'))
            event.Veto()
            return

        # Check if the label of the directory are already in the Syncs
        if not SyncsController().check_uniq_label(label):
            gui_utils.show_error_dialog(
                message=_('Label "%s" already exists') % label,
                title=_('Invalid Label'))
            event.Veto()
            return

        try:
            SyncsController().check_uniq_path(path)

        except PathDoesntExistsException as e:
            msg = _("Path '{}' doesn't exist").format(e.path)

            gui_utils.show_error_dialog(message=msg, title=_('Invalid Path'))

            event.Veto()
            return

        except PathColisionException as e:
            msg = _("Path '{}' collides with path '{}' of sync {}").format(
                e.path, e.sync_label, e.sync_path)

            gui_utils.show_error_dialog(message=msg, title=_('Path Collision'))
            event.Veto()
            return

        #self.label = self.parent.box_label
        self.parent.box_label = label
        self.parent.path = path
        self.parent.localbox_client.authenticator.label = self.label
        self.parent.localbox_client.label = self.label
        self.parent.localbox_client.authenticator.save_client_data()
Exemple #2
0
    def __init__(self, parent):
        super(LocalboxListCtrl, self).__init__(parent, style=wx.LC_REPORT)

        self.ctrl = SyncsController()

        # Add three columns to the list
        self.InsertColumn(0, _("Label"))
        self.InsertColumn(1, _("Path"))
        self.InsertColumn(2, _("URL"))

        self.SetColumnWidth(0, 100)
        self.SetColumnWidth(1, 250)
        self.SetColumnWidth(2, 200)
Exemple #3
0
def get_syncers():
    """
    returns a list of Syncers. One per configured localbox instance.
    """
    syncs_ctrl = SyncsController()

    sites = []
    for sync_item in syncs_ctrl:
        getLogger(__name__).info("Syncing %s", sync_item.label)
        try:
            url = sync_item.url
            path = sync_item.path
            direction = sync_item.direction
            label = sync_item.label
            localbox_client = LocalBox(url, label)

            syncer = Syncer(localbox_client,
                            path,
                            direction,
                            name=sync_item.label)
            sites.append(syncer)
        except NoOptionError as error:
            getLogger(__name__).exception(error)
            string = "Skipping '%s' due to missing option '%s'" % \
                     (sync_item, error.option)
            getLogger(__name__).info(string)
        except URLError as error:
            getLogger(__name__).exception(error)
            string = "Skipping '%s' because it cannot be reached" % \
                     (sync_item)
            getLogger(__name__).info(string)

    return sites
Exemple #4
0
    def create_popup_menu(self):
        """
        This method is called by the base class when it needs to popup
        the menu for the default EVT_RIGHT_DOWN event.  Just create
        the menu how you want it and return it from this function,
        the base class takes care of the rest.
        """
        getLogger(__name__).debug("create_popup_menu")
        menu = wx.Menu()

        # settings item
        self.item_start_gui = menu.Append(ID_ANY, _("Settings"))

        # sync item
        menu.AppendSeparator()
        if self._main_syncing_thread.is_running():
            self.item_sync = menu.Append(ID_ANY, _("Sync in progress"))
            menu.Enable(id=self.item_sync.Id, enable=False)
        else:
            self.item_sync = menu.Append(ID_ANY, _("Force Sync"))
            # only enable option if label list is not empty
            menu.Enable(id=self.item_sync.Id,
                        enable=len(SyncsController().list) > 0)

        # stop item
        self.item_sync_stop = menu.Append(ID_ANY, _('Stop'))
        menu.Enable(id=self.item_sync_stop.Id,
                    enable=self._main_syncing_thread.is_running())

        # delete decrypted item
        menu.AppendSeparator()
        self.item_del = menu.Append(ID_ANY, _("Delete decrypted files"))
        if not openfiles_ctrl.load():
            menu.Enable(id=self.item_del.Id, enable=False)

        # version item
        menu.AppendSeparator()
        item_version = menu.Append(ID_ANY, _("Version: %s") % VERSION_STRING)
        menu.Enable(id=item_version.Id, enable=False)

        # quit item
        menu.AppendSeparator()
        self.item_close = menu.Append(ID_ANY, _("Quit"))

        self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.item_close.Id)
        self.Bind(wx.EVT_MENU, self.start_gui, id=self.item_start_gui.Id)
        self.Bind(wx.EVT_MENU, self.start_sync, id=self.item_sync.Id)
        self.Bind(wx.EVT_MENU, self.stop_sync, id=self.item_sync_stop.Id)
        self.Bind(wx.EVT_MENU, self.delete_decrypted, id=self.item_del.Id)

        return menu
Exemple #5
0
 def select_dir(self, wx_event):
     try:
         path = gui_utils.select_directory(cwd=self.localbox_path)
         if path:
             path = get_localbox_path(
                 SyncsController().get(self.selected_localbox).path, path)
             # get meta to verify if path is a valid LocalBox path
             # this will later problems, because for the sharing to work the files must exist in the server
             self.localbox_client.get_meta(path)
             self._selected_dir.SetValue(path)
     except InvalidLocalBoxPathError:
         gui_utils.show_error_dialog(
             _('Invalid LocalBox path. Please make sure that you are selecting a directory inside LocalBox and '
               'that the directory has been uploaded. Or try a different directory.'
               ), 'Error')
Exemple #6
0
    def __init__(self, parent, event, main_syncing_thread):
        super(Gui, self).__init__(parent,
                                  title=MAIN_TITLE,
                                  size=MAIN_FRAME_SIZE,
                                  style=wx.CLOSE_BOX | wx.CAPTION)

        # Attributes
        self._main_syncing_thread = main_syncing_thread
        self.event = event
        self.toolbar_panels = dict()
        self.panel_syncs = SyncsPanel(self, event, main_syncing_thread)
        self.panel_shares = SharePanel(self)
        self.panel_account = AccountPanel(self)
        self.panel_preferences = PreferencesPanel(self)
        self.panel_bottom = BottomPanel(self)
        self.panel_line = wx.Panel(self)

        line_sizer = wx.BoxSizer(wx.VERTICAL)
        line_sizer.Add(wx.StaticLine(self.panel_line, -1),
                       0,
                       wx.ALL | wx.EXPAND,
                       border=10)
        self.panel_line.SetSizer(line_sizer)

        self.ctrl = self.panel_syncs.ctrl

        bSizer1 = wx.BoxSizer(wx.VERTICAL)
        bSizer1.Add(self.panel_line, 0, wx.EXPAND, border=10)
        bSizer1.Add(self.panel_syncs, 0, wx.EXPAND, 10)
        bSizer1.Add(self.panel_shares, 0, wx.EXPAND, 10)
        bSizer1.Add(self.panel_account, 0, wx.EXPAND, 10)
        bSizer1.Add(self.panel_preferences, 0, wx.EXPAND, 10)
        bSizer1.Add(self.panel_bottom, 0, wx.ALIGN_BOTTOM, 10)

        self.SetSizer(bSizer1)

        self.InitUI()

        self.show_first_panels()

        self.SetAutoLayout(True)
        self.SetSizer(bSizer1)
        self.Layout()

        self.Bind(wx.EVT_CLOSE, self.on_close)

        for i in SyncsController().load():
            PassphraseDialog(self, username=i.user, label=i.label).Show()
Exemple #7
0
    def load_invites(self):
        invite_list = []
        for item in SyncsController().load():
            try:
                localbox_client = LocalBox(url=item.url,
                                           label=item.label,
                                           path=item.path)

                result = localbox_client.get_invite_list(user=item.user)

                for invite in result:
                    invite_list.append(invite)
            except URLError:
                getLogger(__name__).exception(
                    'failed to get_share_list (%s, %s)' %
                    (item.url, item.label))
        return invite_list
Exemple #8
0
class LocalboxListCtrl(wx.ListCtrl):
    """
    This class behaves like a bridge between the GUI components and the real syncs controller.
    """
    def __init__(self, parent):
        super(LocalboxListCtrl, self).__init__(parent, style=wx.LC_REPORT)

        self.ctrl = SyncsController()

        # Add three columns to the list
        self.InsertColumn(0, _("Label"))
        self.InsertColumn(1, _("Path"))
        self.InsertColumn(2, _("URL"))

        self.SetColumnWidth(0, 100)
        self.SetColumnWidth(1, 250)
        self.SetColumnWidth(2, 200)

    def populate_list(self):
        """
        Read the syncs list from the controller
        """
        for item in self.ctrl.load():
            self.Append((item.label, item.path, item.url))

    def add(self, item):
        getLogger(__name__).debug('%s: Add item %s' %
                                  (self.__class__.__name__, item))
        self.Append((item.label, item.path, item.url))
        self.ctrl.add(item)

    def delete(self):
        idx = 0
        labels_removed = []
        while idx > -1:
            idx = self.GetNextSelected(-1)

            if idx > -1:
                getLogger(__name__).debug('%s: Delete item #%d' %
                                          (self.__class__.__name__, idx))
                self.DeleteItem(idx)
                label = self.ctrl.delete(idx)
                labels_removed.append(label)

        map(lambda l: SharesController().delete_for_label(l), labels_removed)
        self.save()
        return labels_removed

    def save(self):
        getLogger(__name__).info('%s: ctrl save()' % self.__class__.__name__)
        SharesController().save()
        self.ctrl.save()
Exemple #9
0
    def load(self):
        self._list = []
        for item in SyncsController().load():
            try:
                localbox_client = LocalBox(url=item.url, label=item.label)

                for share in localbox_client.get_share_list(user=item.user):
                    share_item = ShareItem(user=share['user'],
                                           path='/' + share['path'],
                                           url=item.url,
                                           label=item.label,
                                           id=share['id'])
                    self._list.append(share_item)
            except URLError:
                getLogger(__name__).exception(
                    'failed to get_share_list (%s, %s)' %
                    (item.url, item.label))

        return self._list
Exemple #10
0
    def do_heartbeat(self, labels=None, force_gui_notif=False):
        syncs_ctrl = SyncsController()

        for sync_item in syncs_ctrl:
            if labels is None or labels == [] or sync_item.label in labels:
                url = sync_item.url
                path = sync_item.path
                direction = sync_item.direction
                label = sync_item.label

                try:
                    localbox_client = LocalBox(url, label, path)
                    results = localbox_client.do_heartbeat()

                    if results:
                        Notifs().syncHeartbeatUp(label, force_gui_notif)
                    else:
                        Notifs().syncHeartbeatDown(label, force_gui_notif)

                except URLError as error:
                    Notifs().syncHeartbeatDown(sync_item.label, force_gui_notif)
Exemple #11
0
def run_event_daemon():
    for sync_item in SyncsController():
        create_watchdog(sync_item)