Example #1
0
  def rename_label(self, label_id, label_name):

    Validation.require(label_id not in RESERVED_IDS and
        label_id in self._labels, "Unknown Label")

    label_name = label_name.strip()
    self._validate_name(Label.get_parent(label_id), label_name)

    obj = self._labels[label_id]
    obj["name"] = label_name

    self._clear_subtree_ancestry(label_id)

    if obj["data"]["move_data_completed_mode"] == "subfolder":
      path = os.path.join(self.get_parent_path(label_id), label_name)
      obj["data"]["move_data_completed_path"] = path

      self._apply_data_completed_path(label_id)
      self._propagate_path_to_descendents(label_id)

    self._last_modified = datetime.datetime.now()
    self._config.save()

    if (obj["data"]["move_data_completed_mode"] == "subfolder" and
        self._prefs["options"]["move_on_changes"]):
      self._subtree_move_completed(label_id)
Example #2
0
  def set_options(self, label_id, options_in):

    Validation.require(label_id not in RESERVED_IDS and
        label_id in self._labels, "Unknown Label")

    retroactive = options_in.get("tmp_auto_retroactive", False)
    unlabeled_only = options_in.get("tmp_auto_unlabeled", True)

    options = self._labels[label_id]["data"]

    old_download = options["download_settings"]
    old_move = options["move_data_completed"]
    old_move_path = options["move_data_completed_path"]

    self._normalize_label_data(options_in)
    options.update(options_in)

    self._config.save()

    for id in self._index[label_id]["torrents"]:
      self._apply_torrent_options(id)

    if label_id in self._shared_limit_index:
      self._shared_limit_index.remove(label_id)

    if options["bandwidth_settings"] and options["shared_limit_on"]:
      self._shared_limit_index.append(label_id)

    # Make sure descendent labels are updated if path changed
    if old_move_path != options["move_data_completed_path"]:
      self._propagate_path_to_descendents(label_id)

      self._config.save()

      if self._prefs["options"]["move_on_changes"]:
        self._subtree_move_completed(label_id)
    else:
      # If move completed was just turned on...
      if (options["download_settings"] and
          options["move_data_completed"] and
          (not old_download or not old_move) and
          self._prefs["options"]["move_on_changes"]):
        self._do_move_completed(label_id, self._index[label_id]["torrents"])

    if options["auto_settings"] and retroactive:
      autolabel = []
      for torrent_id in self._torrents:
        if not unlabeled_only or torrent_id not in self._mappings:
          if self._has_auto_apply_match(label_id, torrent_id):
            autolabel.append(torrent_id)

      if autolabel:
        self.set_torrent_labels(label_id, autolabel)

    self._last_modified = datetime.datetime.now()
    self._config.save()
Example #3
0
  def get_parent_path(self, label_id):

    Validation.require(label_id not in RESERVED_IDS and
        label_id in self._labels, "Unknown Label")

    parent_id = Label.get_parent(label_id)
    if parent_id == NULL_PARENT:
      path = self._get_default_save_path()
    else:
      path = self._labels[parent_id]["data"]["move_data_completed_path"]

    return path
Example #4
0
  def remove_label(self, label_id):

    Validation.require(label_id not in RESERVED_IDS and
        label_id in self._labels, "Unknown Label")

    self._remove_label(label_id)

    parent_id = Label.get_parent(label_id)
    self._index[parent_id]["children"].remove(label_id)

    self._last_modified = datetime.datetime.now()
    self._config.save()
Example #5
0
  def set_torrent_labels(self, label_id, torrent_list):

    Validation.require((label_id not in RESERVED_IDS and
        label_id in self._labels) or (not label_id), "Unknown Label")

    torrents = [t for t in torrent_list if t in self._torrents]
    for id in torrents:
      self._set_torrent_label(id, label_id)

    self._last_modified = datetime.datetime.now()
    self._config.save()

    self._do_move_completed(label_id, torrents)
Example #6
0
  def set_torrent_labels(self, label_id, torrent_list):

    if not label_id:
      label_id = ID_NONE

    Validation.require(label_id == ID_NONE or (label_id not in RESERVED_IDS and
        label_id in self._labels), "Unknown Label")

    torrents = [t for t in torrent_list if t in self._torrents]
    for id in torrents:
      self._set_torrent_label(id, label_id)

    self._last_modified = datetime.datetime.now()
    self._config.save()

    if self._prefs["options"]["move_on_changes"]:
      self._do_move_completed(label_id, torrents)
Example #7
0
  def get_label_bandwidth_usage(self, label_id, sublabels=False):

    Validation.require((label_id not in RESERVED_IDS and
        label_id in self._labels) or (not label_id or label_id == ID_NONE),
        "Unknown Label")

    if not label_id:
      label_id = ID_NONE

    labels = [label_id]

    if label_id != ID_NONE and sublabels:
      labels += self._get_descendent_labels(label_id)

    active_torrents = self._get_labeled_torrents_status(
      labels, {"state": ["Seeding", "Downloading"]},
      ["download_payload_rate", "upload_payload_rate"])

    return self._get_bandwidth_usage(active_torrents)
Example #8
0
  def add_label(self, parent_id, label_name):

    Validation.require(parent_id in self._labels, "Unknown Label")

    label_name = label_name.strip()
    self._validate_name(parent_id, label_name)

    id = self._get_unused_id(parent_id)
    self._index[parent_id]["children"].append(id)

    self._labels[id] = {
      "name": label_name,
      "data": dict(self._prefs["defaults"]),
    }

    self._index[id] = {
      "children": [],
      "torrents": [],
    }

    options = self._labels[id]["data"]
    mode = options["move_data_completed_mode"]
    if mode != "folder":
      path = self.get_parent_path(id)

      if mode == "subfolder":
        path = os.path.join(path, label_name)

      options["move_data_completed_path"] = path

    self._build_label_ancestry(id)

    self._last_modified = datetime.datetime.now()
    self._config.save()

    return id
Example #9
0
  def wrap(*args, **kwargs):

    if len(args) > 0 and isinstance(args[0], Core):
      Validation.require(args[0].initialized, "Plugin not initialized")

    return func(*args, **kwargs)
Example #10
0
  def _validate_name(self, parent_id, label_name):

    Validation.validate_name(label_name)

    names = self._get_children_names(parent_id)
    Validation.require(label_name not in names, "Label already exists")
Example #11
0
  def get_options(self, label_id):

    Validation.require(label_id not in RESERVED_IDS and
        label_id in self._labels, "Unknown Label")

    return self._labels[label_id]["data"]