コード例 #1
0
ファイル: ClientGUIListCtrl.py プロジェクト: HOZHENWAI/hydrus
 def _GetExportObject( self ):
     
     if self._custom_get_callable is None:
         
         to_export = HydrusSerialisable.SerialisableList()
         
         for obj in self._listctrl.GetData( only_selected = True ):
             
             to_export.append( obj )
             
         
     else:
         
         to_export = [ self._custom_get_callable() ]
         
     
     if len( to_export ) == 0:
         
         return None
         
     elif len( to_export ) == 1:
         
         return to_export[0]
         
     else:
         
         return to_export
コード例 #2
0
    def _GetSerialisableInfo(self):

        serialisable_tag_display_types_to_service_keys_to_tag_filters = []

        for (
                tag_display_type, service_keys_to_tag_filters
        ) in self._tag_display_types_to_service_keys_to_tag_filters.items():

            serialisable_service_keys_to_tag_filters = [
                (service_key.hex(), tag_filter.GetSerialisableTuple())
                for (service_key,
                     tag_filter) in service_keys_to_tag_filters.items()
            ]

            serialisable_tag_display_types_to_service_keys_to_tag_filters.append(
                (tag_display_type, serialisable_service_keys_to_tag_filters))

        serialisable_tag_autocomplete_options = HydrusSerialisable.SerialisableList(
            self._tag_service_keys_to_tag_autocomplete_options.values(
            )).GetSerialisableTuple()

        serialisable_info = [
            serialisable_tag_display_types_to_service_keys_to_tag_filters,
            serialisable_tag_autocomplete_options
        ]

        return serialisable_info
コード例 #3
0
 def Compact( self, compact_before_this_source_time ):
     
     with self._lock:
         
         if len( self._gallery_seeds ) <= self.COMPACT_NUMBER:
             
             return
             
         
         new_gallery_seeds = HydrusSerialisable.SerialisableList()
         
         for gallery_seed in self._gallery_seeds[:-self.COMPACT_NUMBER]:
             
             still_to_do = gallery_seed.status == CC.STATUS_UNKNOWN
             still_relevant = gallery_seed.created > compact_before_this_source_time
             
             if still_to_do or still_relevant:
                 
                 new_gallery_seeds.append( gallery_seed )
                 
             
         
         new_gallery_seeds.extend( self._gallery_seeds[-self.COMPACT_NUMBER:] )
         
         self._gallery_seeds = new_gallery_seeds
         self._gallery_seeds_to_indices = { gallery_seed : index for ( index, gallery_seed ) in enumerate( self._gallery_seeds ) }
         
         self._SetStatusDirty()
コード例 #4
0
    def test_basics(self):
        def test(obj, dupe_obj):

            self.assertEqual(len(list(obj.items())),
                             len(list(dupe_obj.items())))

            for (key, value) in list(obj.items()):

                self.assertEqual(value, dupe_obj[key])

        #

        d = HydrusSerialisable.SerialisableDictionary()

        d[1] = 2
        d[3] = 'test1'

        d['test2'] = 4
        d['test3'] = 5

        d[6] = HydrusSerialisable.SerialisableDictionary(
            {i: 'test' + str(i)
             for i in range(20)})
        d[ClientSearch.Predicate(ClientSearch.PREDICATE_TYPE_TAG,
                                 'test pred 1')] = 56

        d[ClientSearch.Predicate(
            ClientSearch.PREDICATE_TYPE_TAG,
            'test pred 2')] = HydrusSerialisable.SerialisableList([
                ClientSearch.Predicate(ClientSearch.PREDICATE_TYPE_TAG,
                                       'test' + str(i)) for i in range(10)
            ])

        self.assertEqual(len(list(d.keys())), 7)

        for (key, value) in list(d.items()):

            self.assertEqual(d[key], value)

        self._dump_and_load_and_test(d, test)

        #

        db = HydrusSerialisable.SerialisableBytesDictionary()

        db[HydrusData.GenerateKey()] = HydrusData.GenerateKey()
        db[HydrusData.GenerateKey()] = [
            HydrusData.GenerateKey() for i in range(10)
        ]
        db[1] = HydrusData.GenerateKey()
        db[2] = [HydrusData.GenerateKey() for i in range(10)]

        self.assertEqual(len(list(db.keys())), 4)

        for (key, value) in list(db.items()):

            self.assertEqual(db[key], value)

        self._dump_and_load_and_test(db, test)
コード例 #5
0
 def _UpdateSerialisableInfo( self, version, old_serialisable_info ):
     
     if version == 1:
         
         serialisable_tag_display_types_to_service_keys_to_tag_filters = old_serialisable_info
         
         tag_autocomplete_options_list = HydrusSerialisable.SerialisableList()
         
         new_serialisable_info = [
             serialisable_tag_display_types_to_service_keys_to_tag_filters,
             tag_autocomplete_options_list.GetSerialisableTuple()
         ]
         
         return ( 2, new_serialisable_info )
         
     
     if version == 2:
         
         [
             serialisable_tag_display_types_to_service_keys_to_tag_filters,
             serialisable_tag_autocomplete_options
         ] = old_serialisable_info
         
         service_keys_to_ordered_sibling_service_keys = collections.defaultdict( list )
         service_keys_to_ordered_parent_service_keys = collections.defaultdict( list )
         
         serialisable_service_keys_to_ordered_sibling_service_keys = HydrusSerialisable.SerialisableBytesDictionary( service_keys_to_ordered_sibling_service_keys ).GetSerialisableTuple()
         serialisable_service_keys_to_ordered_parent_service_keys = HydrusSerialisable.SerialisableBytesDictionary( service_keys_to_ordered_parent_service_keys ).GetSerialisableTuple()
         
         new_serialisable_info = [
             serialisable_tag_display_types_to_service_keys_to_tag_filters,
             serialisable_tag_autocomplete_options,
             serialisable_service_keys_to_ordered_sibling_service_keys,
             serialisable_service_keys_to_ordered_parent_service_keys
         ]
         
         return ( 3, new_serialisable_info )
         
     
     if version == 3:
         
         # took it out again lmao, down to the db
         
         [
             serialisable_tag_display_types_to_service_keys_to_tag_filters,
             serialisable_tag_autocomplete_options,
             serialisable_service_keys_to_ordered_sibling_service_keys,
             serialisable_service_keys_to_ordered_parent_service_keys
         ] = old_serialisable_info
         
         
         new_serialisable_info = [
             serialisable_tag_display_types_to_service_keys_to_tag_filters,
             serialisable_tag_autocomplete_options
         ]
         
         return ( 4, new_serialisable_info )
コード例 #6
0
    def __init__(self, name, page_containers=None):

        GUISessionContainerPage.__init__(self, name)

        if page_containers is None:

            page_containers = []

        self._page_containers = HydrusSerialisable.SerialisableList(
            page_containers)
コード例 #7
0
 def _threadDoGETJob( self, request ):
     
     updates = HG.server_controller.Read( 'immediate_update', self._service_key, request.hydrus_account )
     
     updates = HydrusSerialisable.SerialisableList( updates )
     
     body = HydrusNetwork.DumpHydrusArgsToNetworkBytes( { 'updates' : updates } )
     
     response_context = HydrusServerResources.ResponseContext( 200, body = body )
     
     return response_context
コード例 #8
0
def DumpHydrusArgsToNetworkBytes(args):

    if not isinstance(args, HydrusSerialisable.SerialisableBase):

        args = HydrusSerialisable.SerialisableDictionary(args)

    for param_name in BYTE_PARAMS:

        if param_name in args:

            args[param_name] = args[param_name].hex()

    for param_name in JSON_BYTE_LIST_PARAMS:

        if param_name in args:

            args[param_name] = [item.hex() for item in args[param_name]]

    if 'account_types' in args:

        args['account_types'] = HydrusSerialisable.SerialisableList(
            args['account_types'])

    if 'account' in args:

        args[
            'account'] = HydrusNetwork.Account.GenerateSerialisableTupleFromAccount(
                args['account'])

    if 'accounts' in args:

        args['accounts'] = list(
            map(HydrusNetwork.Account.GenerateSerialisableTupleFromAccount,
                args['accounts']))

    if 'service_keys_to_access_keys' in args:

        args['service_keys_to_access_keys'] = [
            (service_key.hex(), access_key.hex())
            for (service_key, access_key
                 ) in list(args['service_keys_to_access_keys'].items())
        ]

    if 'services' in args:

        args['services'] = [
            service.ToSerialisableTuple() for service in args['services']
        ]

    network_bytes = args.DumpToNetworkBytes()

    return network_bytes
コード例 #9
0
 def RemoveGallerySeeds( self, gallery_seeds ):
     
     with self._lock:
         
         gallery_seeds_to_delete = set( gallery_seeds )
         
         self._gallery_seeds = HydrusSerialisable.SerialisableList( [ gallery_seed for gallery_seed in self._gallery_seeds if gallery_seed not in gallery_seeds_to_delete ] )
         
         self._gallery_seeds_to_indices = { gallery_seed : index for ( index, gallery_seed ) in enumerate( self._gallery_seeds ) }
         
         self._SetStatusDirty()
         
     
     self.NotifyGallerySeedsUpdated( gallery_seeds_to_delete )
コード例 #10
0
 def __init__( self ):
     
     HydrusSerialisable.SerialisableBase.__init__( self )
     
     self._gallery_seeds = HydrusSerialisable.SerialisableList()
     
     self._gallery_seeds_to_indices = {}
     
     self._gallery_seed_log_key = HydrusData.GenerateKey()
     
     self._status_cache = None
     
     self._status_dirty = True
     
     self._lock = threading.Lock()
コード例 #11
0
ファイル: ClientTags.py プロジェクト: 106FaceEater106/hydrus
    def _UpdateSerialisableInfo(self, version, old_serialisable_info):

        if version == 1:

            serialisable_tag_display_types_to_service_keys_to_tag_filters = old_serialisable_info

            tag_autocomplete_options_list = HydrusSerialisable.SerialisableList(
            )

            new_serialisable_info = [
                serialisable_tag_display_types_to_service_keys_to_tag_filters,
                tag_autocomplete_options_list.GetSerialisableTuple()
            ]

            return (2, new_serialisable_info)
コード例 #12
0
    def __init__(self, url=None):

        HydrusSerialisable.SerialisableBase.__init__(self)

        self._lock = threading.Lock()

        self._page_key = 'initialising page key'

        self._watchers = HydrusSerialisable.SerialisableList()

        self._highlighted_watcher_url = None

        self._checker_options = HG.client_controller.new_options.GetDefaultWatcherCheckerOptions(
        )
        self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions(
            'loud')
        self._tag_import_options = ClientImportOptions.TagImportOptions(
            is_default=True)

        self._watcher_keys_to_watchers = {}

        self._watcher_keys_to_added_timestamps = {}
        self._watcher_keys_to_already_in_timestamps = {}

        self._watchers_repeating_job = None

        self._status_dirty = True
        self._status_cache = None
        self._status_cache_generation_time = 0

        #

        if url is not None:

            watcher = WatcherImport()

            watcher.SetURL(url)

            self._AddWatcher(watcher)

        self._last_time_watchers_changed = HydrusData.GetNowPrecise()

        self._last_pubbed_value_range = (0, 0)
        self._next_pub_value_check_time = 0
コード例 #13
0
ファイル: ClientStrings.py プロジェクト: pianomanx/hydrus
    def _GetSerialisableInfo(self):

        return HydrusSerialisable.SerialisableList(
            self._processing_steps).GetSerialisableTuple()