def _build_index(self): index = {} for id in self._labels: children = [] torrents = [] for child_id in self._labels: if child_id == id: continue if Label.get_parent(child_id) == id: children.append(child_id) for torrent_id in self._mappings: if self._mappings[torrent_id] == id: torrents.append(torrent_id) index[id] = { "children": children, "torrents": torrents, } self._index = index for id in self._labels: self._build_label_ancestry(id)
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)
def _build_index(self): index = {} shared_limit_index = [] for id in self._labels: if id not in RESERVED_IDS and ( self._labels[id]["data"]["bandwidth_settings"] and self._labels[id]["data"]["shared_limit_on"]): shared_limit_index.append(id) children = [] torrents = [] for child_id in self._labels: if child_id == id: continue if Label.get_parent(child_id) == id: children.append(child_id) for torrent_id in self._mappings: if self._mappings[torrent_id] == id: torrents.append(torrent_id) index[id] = { "children": children, "torrents": torrents, } self._index = index self._shared_limit_index = shared_limit_index for id in self._labels: self._build_label_ancestry(id)
def _remove_orphans(self): removals = [] for id in self._labels: if id == NULL_PARENT: continue parent_id = Label.get_parent(id) if not self._labels.get(parent_id): removals.append(id) for id in removals: self._remove_label(id)
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
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()
def _build_label_ancestry(self, label_id): members = [] member = label_id while member and member != NULL_PARENT: ancestry_str = self._index[member].get("ancestry") if ancestry_str: members.append(ancestry_str) break members.append(self._labels[member]["name"]) member = Label.get_parent(member) ancestry_str = "/".join(reversed(members)) self._index[label_id]["ancestry"] = ancestry_str return ancestry_str