Exemple #1
0
def validate_name(label_name):

    if not label_name:
        raise LabelPlusError(ERR_EMPTY_LABEL)

    if RE_INVALID_CHARS.search(label_name):
        raise LabelPlusError(ERR_INVALID_CHARS)
Exemple #2
0
    def on_timeout():

      log.error("%s: %s", STR_UPDATE, LabelPlusError(ERR_TIMED_OUT))

      if self._status_item:
        self._tries += 1
        if self._tries < MAX_TRIES:
          self._calls.append(twisted.internet.reactor.callLater(
            THROTTLED_INTERVAL, self._update_loop))
        else:
          log.error("%s: %s", STR_UPDATE, LabelPlusError(ERR_MAX_RETRY))
Exemple #3
0
  def set_torrent_labels(self, torrent_ids, label_id):

    log.debug("Setting torrent labels to %r", label_id)

    if (label_id != labelplus.common.label.ID_NONE and
        label_id not in self._labels):
      raise LabelPlusError(ERR_INVALID_LABEL)

    existing_torrent_ids = [x for x in set(torrent_ids) if x in self._torrents]

    for t in set(torrent_ids):
      if t not in existing_torrent_ids:
        self.__pending_labels[t] = label_id

    if not existing_torrent_ids:
      return

    torrent_ids = existing_torrent_ids

    for id in torrent_ids:
      self._set_torrent_label(id, label_id)

    if self._prefs["options"]["move_on_changes"]:
      self._move_torrents(torrent_ids)

    self._timestamp["mappings_changed"] = datetime.datetime.now()
    def __init__(self, plugin, label_id):

        if label_id in RESERVED_IDS:
            raise LabelPlusError(ERR_INVALID_LABEL)

        super(RenameLabelDialog, self).__init__(plugin, self.TYPE_RENAME,
                                                label_id)
Exemple #5
0
  def wrap(*args, **kwargs):

    if args and isinstance(args[0], Core):
      if not args[0]._initialized:
        raise LabelPlusError(ERR_CORE_NOT_INITIALIZED)

    return func(*args, **kwargs)
Exemple #6
0
  def set_torrent_labels(self, torrent_ids, label_id):

    log.debug("Setting torrent labels to %r", label_id)

    if (label_id != labelplus.common.label.ID_NONE and
        label_id not in self._labels):
      raise LabelPlusError(ERR_INVALID_LABEL)

    existing_torrent_ids = [x for x in set(torrent_ids) if x in self._torrents]

    for t in set(torrent_ids):
      if t not in existing_torrent_ids:
        self.__pending_labels[t] = label_id

    if not existing_torrent_ids:
      return

    torrent_ids = existing_torrent_ids

    for id in torrent_ids:
      self._set_torrent_label(id, label_id)
    if 'Label' in component.get("CorePluginManager").get_enabled_plugins():
          label = component.get("CorePlugin.Label")
          if lower(label_id) != label._status_get_label(id):
              label.set_torrent(id, lower(label_id))
    if self._prefs["options"]["move_on_changes"]:
      self._move_torrents(torrent_ids)

    self._timestamp["mappings_changed"] = datetime.datetime.now()
Exemple #7
0
  def set_label_options(self, label_id, options_in, apply_to_all=None):

    log.debug("Setting label options for %r", label_id)

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    self._set_label_options(label_id, options_in, apply_to_all)
Exemple #8
0
  def get_label_options(self, label_id):

    log.debug("Getting label options for %r", label_id)

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    return self._labels[label_id]["options"]
    def __init__(self, plugin, dialog_type, label_id):

        self._plugin = plugin
        self._type = dialog_type

        if self._type == self.TYPE_ADD:
            self._parent_id = label_id
        elif self._type == self.TYPE_RENAME:
            if label_id in plugin.store:
                self._parent_id = labelplus.common.label.get_parent_id(
                    label_id)
                self._label_id = label_id
                self._label_name = plugin.store[label_id]["name"]
                self._label_fullname = plugin.store[label_id]["fullname"]
            else:
                raise LabelPlusError(ERR_INVALID_LABEL)
        else:
            raise LabelPlusError(ERR_INVALID_TYPE)

        self._store = None
        self._menu = None

        super(NameInputDialog, self).__init__(self.GLADE_FILE,
                                              self.ROOT_WIDGET, "_")

        try:
            self._store = plugin.store.copy()
            self._set_parent_label(self._parent_id)

            # Keep window alive with cyclic reference
            self._root_widget.set_data("owner", self)

            self._setup_widgets()

            self._load_state()

            self._create_menu()

            self._refresh()

            self._plugin.register_update_func(self.update_store)
            self._plugin.register_cleanup_func(self.destroy)
        except:
            self.destroy()
            raise
Exemple #10
0
  def rename_label(self, label_id, label_name):

    log.debug("Renaming name of label %r to %r", label_id, label_name)

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    self._rename_label(label_id, label_name)

    self._timestamp["labels_changed"] = datetime.datetime.now()
Exemple #11
0
  def _validate_name(self, parent_id, label_name):

    assert(parent_id == labelplus.common.label.ID_NULL or
      parent_id in self._labels)

    labelplus.common.label.validate_name(label_name)

    names = self._get_children_names(parent_id)
    if label_name in names:
      raise LabelPlusError(ERR_LABEL_EXISTS)
    def _request_options(self, label_id):
        def on_timeout():

            if self.valid:
                self._wnd_label_options.set_sensitive(True)
                self._report_error(STR_LOAD_OPTIONS,
                                   LabelPlusError(ERR_TIMED_OUT))

        def process_result(result):

            if self.valid:
                self._wnd_label_options.set_sensitive(True)

                for success, data in result:
                    if not success:
                        error = labelplus.common.extract_error(data)
                        if error:
                            self._report_error(STR_LOAD_OPTIONS, error)
                        else:
                            self.destroy()
                        return

                self._label_defaults = result[0][1]
                self._path_options = result[1][1]
                self._label_options = result[2][1]

                self._load_options(self._label_options)
                self._enable_options()

        self._clear_options()
        self._disable_options()
        self._set_label(label_id)
        self._refresh()

        if not label_id in self._store:
            self._report_error(STR_LOAD_OPTIONS,
                               LabelPlusError(ERR_INVALID_LABEL))
            return

        self._set_error(None)

        log.info("Loading options for %r", self._label_fullname)

        deferreds = []
        deferreds.append(client.labelplus.get_label_defaults())
        deferreds.append(client.labelplus.get_path_options(label_id))
        deferreds.append(client.labelplus.get_label_options(label_id))

        deferred = twisted.internet.defer.DeferredList(deferreds,
                                                       consumeErrors=True)

        self._wnd_label_options.set_sensitive(False)

        labelplus.common.deferred_timeout(deferred, self.REQUEST_TIMEOUT,
                                          on_timeout, process_result, None)
    def _validate(self):

        if self._parent_id != ID_NULL and self._parent_id not in self._store:
            raise LabelPlusError(ERR_INVALID_PARENT)

        if self._type == self.TYPE_RENAME:
            if self._label_id not in self._store:
                raise LabelPlusError(ERR_INVALID_LABEL)

            if (self._label_id == self._parent_id
                    or labelplus.common.label.is_ancestor(
                        self._label_id, self._parent_id)):
                raise LabelPlusError(ERR_INVALID_PARENT)

        name = unicode(self._txt_name.get_text(), "utf8")
        labelplus.common.label.validate_name(name)

        for id in self._store.get_descendent_ids(self._parent_id, max_depth=1):
            if name == self._store[id]["name"]:
                raise LabelPlusError(ERR_LABEL_EXISTS)
Exemple #14
0
  def remove_label(self, label_id):

    log.debug("Removing label %r", label_id)

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    self._remove_label(label_id)

    self._timestamp["labels_changed"] = datetime.datetime.now()
    self._timestamp["mappings_changed"] = datetime.datetime.now()
Exemple #15
0
  def move_label(self, label_id, dest_id, dest_name):

    log.debug("Moving label %r to %r with name %r", label_id, dest_id,
      dest_name)

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    if dest_id != labelplus.common.label.ID_NULL and (
        label_id == dest_id or dest_id not in self._labels or
        labelplus.common.label.is_ancestor(label_id, dest_id)):
      raise LabelPlusError(ERR_INVALID_PARENT)

    parent_id = labelplus.common.label.get_parent_id(label_id)
    if parent_id == dest_id:
      self._rename_label(label_id, dest_name)
    else:
      self._move_label(label_id, dest_id, dest_name)

    self._timestamp["labels_changed"] = datetime.datetime.now()
Exemple #16
0
  def add_label(self, parent_id, label_name):

    log.debug("Adding %r to label %r", label_name, parent_id)

    if (parent_id != labelplus.common.label.ID_NULL and
        parent_id not in self._labels):
      raise LabelPlusError(ERR_INVALID_PARENT)

    id = self._add_label(parent_id, label_name)

    self._timestamp["labels_changed"] = datetime.datetime.now()

    return id
    def _save_options(self):
        def on_timeout(options):

            if self.valid:
                self._wnd_label_options.set_sensitive(True)
                self._report_error(STR_SAVE_OPTIONS,
                                   LabelPlusError(ERR_TIMED_OUT))

        def process_result(result, options):

            if self.valid:
                self._wnd_label_options.set_sensitive(True)

                if isinstance(result, Failure):
                    error = labelplus.common.extract_error(result)
                    if error:
                        self._report_error(STR_SAVE_OPTIONS, error)
                    else:
                        self.destroy()
                        return result
                else:
                    self._label_options = options

        if not self._label_id in self._store:
            self._report_error(STR_SAVE_OPTIONS,
                               LabelPlusError(ERR_INVALID_LABEL))
            return

        self._set_error(None)

        log.info("Saving options for %r", self._label_fullname)

        options = self._get_options()
        same = labelplus.common.dict_equals(options, self._label_options)

        if self._chk_autolabel_retroactive.get_active():
            apply_to_all = not self._chk_autolabel_unlabeled_only.get_active()
        else:
            apply_to_all = None

        if not same or apply_to_all is not None:
            deferred = client.labelplus.set_label_options(
                self._label_id, options, apply_to_all)

            self._wnd_label_options.set_sensitive(False)

            labelplus.common.deferred_timeout(deferred, self.REQUEST_TIMEOUT,
                                              on_timeout, process_result,
                                              process_result, options)
        else:
            log.info("No options were changed")
Exemple #18
0
  def get_move_path_options(self, label_id):

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    parent_path = self._get_parent_path(label_id,
      labelplus.common.config.PATH_MOVE_COMPLETED)

    options = {
      "parent": parent_path,
      "subfolder": os.path.join(parent_path, self._labels[label_id]["name"]),
    }

    return options
  def _set_torrent_label(self, torrent_id, label_id):

    if label_id not in RESERVED_IDS and label_id in self._store:
      log.info("Setting label for %s to %r", torrent_id,
        self._store[label_id]["fullname"])
      self._mappings[torrent_id] = label_id
    else:
      log.info("Removing label from %s", torrent_id)

      if label_id not in self._store:
        log.error("%s", LabelPlusError(ERR_INVALID_LABEL))

      if torrent_id in self._mappings:
        del self._mappings[torrent_id]
Exemple #20
0
  def get_path_options(self, label_id):

    if label_id not in self._labels:
      raise LabelPlusError(ERR_INVALID_LABEL)

    options = {}

    for path_type in labelplus.common.config.PATH_TYPES:
      parent_path = self._get_parent_path(label_id, path_type)
      options[path_type] = {
        "parent": parent_path,
        "subfolder": os.path.join(parent_path, self._labels[label_id]["name"]),
      }

    return options
Exemple #21
0
        def process_result(result):

            if isinstance(result, Failure):
                if failure.check(LabelPlusError):
                    log.error("%s: %s", STR_UPDATE,
                              LabelPlusError(result.value.message))
                    interval = THROTTLED_INTERVAL
                else:
                    return result
            else:
                self._tries = 0
                interval = UPDATE_INTERVAL
                self._update_store(result)

            if self.initialized:
                self._calls.append(
                    twisted.internet.reactor.callLater(interval,
                                                       self._update_loop))
Exemple #22
0
    def process_result(result):

      if isinstance(result, Failure):
        if (isinstance(result.value, DelugeRPCError) and
            result.value.exception_type == "LabelPlusError"):
          log.error("%s: %s", STR_UPDATE,
            LabelPlusError(result.value.exception_msg))
          interval = THROTTLED_INTERVAL
        else:
          return result
      else:
        self._tries = 0
        interval = UPDATE_INTERVAL
        self._update_status_bar(result)

      if self._status_item:
        self._calls.append(twisted.internet.reactor.callLater(interval,
          self._update_loop))
    def __init__(self, plugin, label_id, page=0):

        self._plugin = plugin

        if label_id in RESERVED_IDS or label_id not in plugin.store:
            raise LabelPlusError(ERR_INVALID_LABEL)

        self._store = None
        self._menu = None

        self._label_defaults = {}
        self._path_options = {}
        self._label_options = {}

        for path_type in PATH_TYPES:
            self._path_options[path_type] = {}

        super(LabelOptionsDialog, self).__init__(self.GLADE_FILE,
                                                 self.ROOT_WIDGET, "_")

        try:
            self._store = plugin.store.copy()
            self._set_label(ID_NULL)

            # Keep window alive with cyclic reference
            self._root_widget.set_data("owner", self)

            self._setup_widgets()
            self._index_widgets()

            self._load_state()
            self._nb_tabs.set_current_page(page)

            self._create_menu()

            self._request_options(label_id)

            self._plugin.register_update_func(self.update_store)
            self._plugin.register_cleanup_func(self.destroy)
        except:
            self.destroy()
            raise
        def on_timeout(options):

            if self.valid:
                self._wnd_label_options.set_sensitive(True)
                self._report_error(STR_SAVE_OPTIONS,
                                   LabelPlusError(ERR_TIMED_OUT))
        def on_timeout():

            if self.valid:
                self._wnd_name_input.set_sensitive(True)
                self._report_error(LabelPlusError(ERR_TIMED_OUT))
        def on_timeout(prefs):

            if self.valid:
                self._sw_settings.set_sensitive(True)
                self._report_error(STR_SAVE_PREFS,
                                   LabelPlusError(ERR_TIMED_OUT))