def setUpClass( self ): self._first_key = os.urandom( 32 ) self._second_key = os.urandom( 32 ) self._third_key = os.urandom( 32 ) tag_siblings = collections.defaultdict( HC.default_dict_set ) first_dict = HC.default_dict_set() first_dict[ HC.CURRENT ] = { ( 'ishygddt', 'i sure hope you guys don\'t do that' ), ( 'character:rei ayanami', 'character:ayanami rei' ), ( 'tree_1', 'tree_3' ), ( 'tree_2', 'tree_3' ), ( 'tree_3', 'tree_5' ), ( 'tree_4', 'tree_5' ), ( 'tree_5', 'tree_6' ), ( 'current_a', 'current_b' ), ( 'chain_a', 'chain_b' ), ( 'chain_b', 'chain_c' ), ( 'closed_loop', 'closed_loop' ), ( 'loop_a', 'loop_b' ), ( 'loop_b', 'loop_c' ) } first_dict[ HC.DELETED ] = { ( 'deleted_a', 'deleted_b' ) } second_dict = HC.default_dict_set() second_dict[ HC.CURRENT ] = { ( 'loop_c', 'loop_a' ) } second_dict[ HC.DELETED ] = { ( 'current_a', 'current_b' ) } second_dict[ HC.PENDING ] = { ( 'pending_a', 'pending_b' ) } second_dict[ HC.PETITIONED ] = { ( 'petitioned_a', 'petitioned_b' ) } third_dict = HC.default_dict_set() third_dict[ HC.CURRENT ] = { ( 'petitioned_a', 'petitioned_b' ) } third_dict[ HC.DELETED ] = { ( 'pending_a', 'pending_b' ) } tag_siblings[ self._first_key ] = first_dict tag_siblings[ self._second_key ] = second_dict tag_siblings[ self._third_key ] = third_dict HC.app.SetRead( 'tag_siblings', tag_siblings ) self._tag_siblings_manager = HydrusTags.TagSiblingsManager()
def setUpClass( self ): self._first_key = os.urandom( 32 ) self._second_key = os.urandom( 32 ) self._third_key = os.urandom( 32 ) first_dict = HC.default_dict_set() first_dict[ HC.CURRENT ] = { ( 'current_a', 'current_b' ), ( 'child', 'mother' ), ( 'child', 'father' ), ( 'sister', 'mother' ), ( 'sister', 'father' ), ( 'brother', 'mother' ), ( 'brother', 'father' ), ( 'mother', 'grandmother' ), ( 'mother', 'grandfather' ), ( 'aunt', 'grandmother' ), ( 'aunt', 'grandfather' ), ( 'cousin', 'aunt' ), ( 'cousin', 'uncle' ), ( 'closed_loop', 'closed_loop' ), ( 'loop_a', 'loop_b' ), ( 'loop_b', 'loop_c' ) } first_dict[ HC.DELETED ] = { ( 'deleted_a', 'deleted_b' ) } second_dict = HC.default_dict_set() second_dict[ HC.CURRENT ] = { ( 'loop_c', 'loop_a' ) } second_dict[ HC.DELETED ] = { ( 'current_a', 'current_b' ) } second_dict[ HC.PENDING ] = { ( 'pending_a', 'pending_b' ) } second_dict[ HC.PETITIONED ] = { ( 'petitioned_a', 'petitioned_b' ) } third_dict = HC.default_dict_set() third_dict[ HC.CURRENT ] = { ( 'petitioned_a', 'petitioned_b' ) } third_dict[ HC.DELETED ] = { ( 'pending_a', 'pending_b' ) } tag_parents = collections.defaultdict( HC.default_dict_set ) tag_parents[ self._first_key ] = first_dict tag_parents[ self._second_key ] = second_dict tag_parents[ self._third_key ] = third_dict HC.app.SetRead( 'tag_parents', tag_parents ) self._tag_parents_manager = HydrusTags.TagParentsManager()
def RefreshAllAccounts(self): with self._lock: self._service_keys_to_sessions = collections.defaultdict(dict) self._account_keys_to_session_keys = HC.default_dict_set() self._account_keys_to_accounts = {} # existing_sessions = HC.app.Read('sessions') for (session_key, service_key, account, expires) in existing_sessions: account_key = account.GetAccountKey() self._service_keys_to_sessions[service_key][session_key] = ( account, expires) self._account_keys_to_session_keys[account_key].add( session_key) self._account_keys_to_accounts[account_key] = account
def setUpClass(self): self._first = TestConstants.GenerateClientServiceIdentifier( HC.LOCAL_TAG) self._third = TestConstants.GenerateClientServiceIdentifier( HC.TAG_REPOSITORY) self._second = TestConstants.GenerateClientServiceIdentifier( HC.TAG_REPOSITORY) tag_service_precedence = [self._first, self._second, self._third] tag_siblings = collections.defaultdict(HC.default_dict_set) first_dict = HC.default_dict_set() first_dict[HC.CURRENT] = { ('ishygddt', 'i sure hope you guys don\'t do that'), ('character:rei ayanami', 'character:ayanami rei'), ('tree_1', 'tree_3'), ('tree_2', 'tree_3'), ('tree_3', 'tree_5'), ('tree_4', 'tree_5'), ('tree_5', 'tree_6'), ('current_a', 'current_b'), ('chain_a', 'chain_b'), ('chain_b', 'chain_c'), ('closed_loop', 'closed_loop'), ('loop_a', 'loop_b'), ('loop_b', 'loop_c') } first_dict[HC.DELETED] = {('deleted_a', 'deleted_b')} second_dict = HC.default_dict_set() second_dict[HC.CURRENT] = {('loop_c', 'loop_a'), ('deleted_a', 'deleted_b')} second_dict[HC.DELETED] = {('current_a', 'current_b')} second_dict[HC.PENDING] = {('pending_a', 'pending_b')} second_dict[HC.PETITIONED] = {('petitioned_a', 'petitioned_b')} third_dict = HC.default_dict_set() third_dict[HC.CURRENT] = {('petitioned_a', 'petitioned_b')} third_dict[HC.DELETED] = {('pending_a', 'pending_b')} tag_siblings[self._first] = first_dict tag_siblings[self._second] = second_dict tag_siblings[self._third] = third_dict HC.app.SetRead('tag_service_precedence', tag_service_precedence) HC.app.SetRead('tag_siblings', tag_siblings) self._tag_siblings_manager = ClientConstants.TagSiblingsManager()
def _RefreshParents(self): service_keys_to_statuses_to_pairs = HC.app.Read('tag_parents') # first collapse siblings sibling_manager = HC.app.GetManager('tag_siblings') collapsed_service_keys_to_statuses_to_pairs = collections.defaultdict( HC.default_dict_set) for (service_key, statuses_to_pairs) in service_keys_to_statuses_to_pairs.items(): if service_key == HC.COMBINED_TAG_SERVICE_KEY: continue for (status, pairs) in statuses_to_pairs.items(): pairs = sibling_manager.CollapsePairs(pairs) collapsed_service_keys_to_statuses_to_pairs[service_key][ status] = pairs # now collapse current and pending service_keys_to_pairs_flat = HC.default_dict_set() for (service_key, statuses_to_pairs ) in collapsed_service_keys_to_statuses_to_pairs.items(): pairs_flat = statuses_to_pairs[HC.CURRENT].union( statuses_to_pairs[HC.PENDING]) service_keys_to_pairs_flat[service_key] = pairs_flat # now create the combined tag service combined_pairs_flat = set() for pairs_flat in service_keys_to_pairs_flat.values(): combined_pairs_flat.update(pairs_flat) service_keys_to_pairs_flat[ HC.COMBINED_TAG_SERVICE_KEY] = combined_pairs_flat # service_keys_to_simple_children_to_parents = BuildServiceKeysToSimpleChildrenToParents( service_keys_to_pairs_flat) self._service_keys_to_children_to_parents = BuildServiceKeysToChildrenToParents( service_keys_to_simple_children_to_parents)
def BuildSimpleChildrenToParents(pairs): simple_children_to_parents = HC.default_dict_set() for (child, parent) in pairs: if child == parent: continue if LoopInSimpleChildrenToParents(simple_children_to_parents, child, parent): continue simple_children_to_parents[child].add(parent) return simple_children_to_parents
def MergeTagsManagers(tags_managers): def CurrentAndPendingFilter(items): for (service_key, statuses_to_tags) in items: filtered = { status: tags for (status, tags) in statuses_to_tags.items() if status in (HC.CURRENT, HC.PENDING) } yield (service_key, filtered) # [[( service_key, statuses_to_tags )]] s_k_s_t_t_tupled = (CurrentAndPendingFilter( tags_manager.GetServiceKeysToStatusesToTags().items()) for tags_manager in tags_managers) # [(service_key, statuses_to_tags)] flattened_s_k_s_t_t = itertools.chain.from_iterable(s_k_s_t_t_tupled) # service_key : [ statuses_to_tags ] s_k_s_t_t_dict = HC.BuildKeyToListDict(flattened_s_k_s_t_t) # now let's merge so we have service_key : statuses_to_tags merged_service_keys_to_statuses_to_tags = collections.defaultdict( HC.default_dict_set) for (service_key, several_statuses_to_tags) in s_k_s_t_t_dict.items(): # [[( status, tags )]] s_t_t_tupled = (s_t_t.items() for s_t_t in several_statuses_to_tags) # [( status, tags )] flattened_s_t_t = itertools.chain.from_iterable(s_t_t_tupled) statuses_to_tags = HC.default_dict_set() for (status, tags) in flattened_s_t_t: statuses_to_tags[status].update(tags) merged_service_keys_to_statuses_to_tags[service_key] = statuses_to_tags return TagsManagerSimple(merged_service_keys_to_statuses_to_tags)