def _ImportJSONs(self, paths):

        for path in paths:

            try:

                with open(path, 'r', encoding='utf-8') as f:

                    payload = f.read()

            except Exception as e:

                QW.QMessageBox.critical(self, 'Error', str(e))

                return

            try:

                obj = HydrusSerialisable.CreateFromString(payload)

                self._ImportObject(obj)

            except:

                QW.QMessageBox.critical(
                    self, 'Error',
                    'I could not understand what was encoded in "{}"!'.format(
                        path))

                return
 def _ImportFromClipboard( self ):
     
     try:
         
         raw_text = HG.client_controller.GetClipboardText()
         
     except HydrusExceptions.DataMissing as e:
         
         QW.QMessageBox.critical( self, 'Error', str(e) )
         
         return
         
     
     try:
         
         obj = HydrusSerialisable.CreateFromString( raw_text )
         
         self._ImportObject( obj )
         
     except Exception as e:
         
         QW.QMessageBox.critical( self, 'Error', 'I could not understand what was in the clipboard' )
         
     
     self._listctrl.Sort()
    def _InitCaches(self):

        if self._c.execute('SELECT 1 FROM sqlite_master WHERE name = ?;',
                           ('services', )).fetchone() is not None:

            all_data = self._c.execute(
                'SELECT service_id, service_key, service_type, name, dictionary_string FROM services;'
            ).fetchall()

            for (service_id, service_key, service_type, name,
                 dictionary_string) in all_data:

                dictionary = HydrusSerialisable.CreateFromString(
                    dictionary_string)

                service = ClientServices.GenerateService(
                    service_key, service_type, name, dictionary)

                self._service_ids_to_services[service_id] = service

                self._service_keys_to_service_ids[service_key] = service_id

            self.local_file_service_id = self.GetServiceId(
                CC.LOCAL_FILE_SERVICE_KEY)
            self.local_update_service_id = self.GetServiceId(
                CC.LOCAL_UPDATE_SERVICE_KEY)
            self.trash_service_id = self.GetServiceId(CC.TRASH_SERVICE_KEY)
            self.combined_local_file_service_id = self.GetServiceId(
                CC.COMBINED_LOCAL_FILE_SERVICE_KEY)
            self.combined_file_service_id = self.GetServiceId(
                CC.COMBINED_FILE_SERVICE_KEY)
            self.combined_tag_service_id = self.GetServiceId(
                CC.COMBINED_TAG_SERVICE_KEY)
Exemple #4
0
 def _InitCaches( self ):
     
     if self._Execute( 'SELECT 1 FROM sqlite_master WHERE name = ?;', ( 'services', ) ).fetchone() is not None:
         
         all_data = self._Execute( 'SELECT service_id, service_key, service_type, name, dictionary_string FROM services;' ).fetchall()
         
         for ( service_id, service_key, service_type, name, dictionary_string ) in all_data:
             
             dictionary = HydrusSerialisable.CreateFromString( dictionary_string )
             
             service = ClientServices.GenerateService( service_key, service_type, name, dictionary )
             
             self._service_ids_to_services[ service_id ] = service
             
             self._service_keys_to_service_ids[ service_key ] = service_id
             
         
         self.local_update_service_id = self.GetServiceId( CC.LOCAL_UPDATE_SERVICE_KEY )
         self.trash_service_id = self.GetServiceId( CC.TRASH_SERVICE_KEY )
         self.combined_local_file_service_id = self.GetServiceId( CC.COMBINED_LOCAL_FILE_SERVICE_KEY )
         self.combined_file_service_id = self.GetServiceId( CC.COMBINED_FILE_SERVICE_KEY )
         
         try:
             
             self.combined_deleted_file_service_id = self.GetServiceId( CC.COMBINED_DELETED_FILE_SERVICE_KEY )
             self.combined_local_media_service_id = self.GetServiceId( CC.COMBINED_LOCAL_MEDIA_SERVICE_KEY )
             
         except HydrusExceptions.DataMissing:
             
             # version 465/486 it might not be in yet
             
             pass
             
         
         self.combined_tag_service_id = self.GetServiceId( CC.COMBINED_TAG_SERVICE_KEY )
Exemple #5
0
def ConvertToNewAccountType(account_type_key, title,
                            dictionary_string) -> HydrusNetwork.AccountType:

    dictionary = HydrusSerialisable.CreateFromString(dictionary_string)

    permissions = dict(dictionary['permissions'])
    bandwidth_rules = dictionary['bandwidth_rules']

    return HydrusNetwork.AccountType(account_type_key=account_type_key,
                                     title=title,
                                     permissions=permissions,
                                     bandwidth_rules=bandwidth_rules)
    def _dump_and_load_and_test(self, obj, test_func):

        serialisable_tuple = obj.GetSerialisableTuple()

        self.assertIsInstance(serialisable_tuple, tuple)

        if isinstance(obj, HydrusSerialisable.SerialisableBaseNamed):

            (serialisable_type, name, version,
             serialisable_info) = serialisable_tuple

        elif isinstance(obj, HydrusSerialisable.SerialisableBase):

            (serialisable_type, version,
             serialisable_info) = serialisable_tuple

        self.assertEqual(serialisable_type, obj.SERIALISABLE_TYPE)
        self.assertEqual(version, obj.SERIALISABLE_VERSION)

        dupe_obj = HydrusSerialisable.CreateFromSerialisableTuple(
            serialisable_tuple)

        self.assertIsNot(obj, dupe_obj)

        test_func(obj, dupe_obj)

        #

        json_string = obj.DumpToString()

        self.assertIsInstance(json_string, str)

        dupe_obj = HydrusSerialisable.CreateFromString(json_string)

        self.assertIsNot(obj, dupe_obj)

        test_func(obj, dupe_obj)

        #

        network_bytes = obj.DumpToNetworkBytes()

        self.assertIsInstance(network_bytes, bytes)

        dupe_obj = HydrusSerialisable.CreateFromNetworkBytes(network_bytes)

        self.assertIsNot(obj, dupe_obj)

        test_func(obj, dupe_obj)
    def _ImportJSONs(self, paths):

        have_shown_load_error = False

        for path in paths:

            try:

                with open(path, 'r', encoding='utf-8') as f:

                    payload = f.read()

            except Exception as e:

                QW.QMessageBox.critical(self, 'Error', str(e))

                return

            try:

                obj = HydrusSerialisable.CreateFromString(
                    payload, raise_error_on_future_version=True)

                self._ImportObject(obj)

            except HydrusExceptions.SerialisationException as e:

                if not have_shown_load_error:

                    message = str(e)

                    if len(paths) > 1:

                        message += os.linesep * 2
                        message += 'If there are more objects in this import with similar load problems, they will now be skipped silently.'

                    QW.QMessageBox.critical(self, 'Problem loading', str(e))

                    have_shown_load_error = True

            except:

                QW.QMessageBox.critical(
                    self, 'Error',
                    'I could not understand what was encoded in "{}"!'.format(
                        path))

                return