예제 #1
0
def CheckHydrusVersion(service_key, service_type, response_headers):

    service_string = HC.service_string_lookup[service_type]

    if 'server' not in response_headers or service_string not in response_headers[
            'server']:

        HydrusGlobals.client_controller.Write(
            'service_updates', {
                service_key: [
                    HydrusData.ServiceUpdate(HC.SERVICE_UPDATE_ACCOUNT,
                                             HydrusData.GetUnknownAccount())
                ]
            })

        raise HydrusExceptions.WrongServiceTypeException('Target was not a ' +
                                                         service_string + '!')

    server_header = response_headers['server']

    (service_string_gumpf, network_version) = server_header.split('/')

    network_version = int(network_version)

    if network_version != HC.NETWORK_VERSION:

        if network_version > HC.NETWORK_VERSION:
            message = 'Your client is out of date; please download the latest release.'
        else:
            message = 'The server is out of date; please ask its admin to update to the latest release.'

        raise HydrusExceptions.NetworkVersionException(
            'Network version mismatch! The server\'s network version was ' +
            str(network_version) + ', whereas your client\'s is ' +
            str(HC.NETWORK_VERSION) + '! ' + message)
예제 #2
0
    def _recordDataUsage(self, request):

        path = request.path[1:]  # /account -> account

        if request.method == 'GET': method = HC.GET
        else: method = HC.POST

        if (HC.LOCAL_BOORU, method, path) in HC.BANDWIDTH_CONSUMING_REQUESTS:

            num_bytes = request.hydrus_request_data_usage

            HydrusGlobals.client_controller.pub(
                'service_updates_delayed', {
                    CC.LOCAL_BOORU_SERVICE_KEY: [
                        HydrusData.ServiceUpdate(
                            HC.SERVICE_UPDATE_REQUEST_MADE, num_bytes)
                    ]
                })
예제 #3
0
def DAEMONSynchroniseAccounts(controller):

    services = controller.GetServicesManager().GetServices(
        HC.RESTRICTED_SERVICES)

    options = controller.GetOptions()

    do_notify = False

    for service in services:

        service_key = service.GetServiceKey()
        service_type = service.GetServiceType()

        account = service.GetInfo('account')
        credentials = service.GetCredentials()

        if service_type in HC.REPOSITORIES:

            if options['pause_repo_sync']: continue

            info = service.GetInfo()

            if info['paused']: continue

        if account.IsStale() and credentials.HasAccessKey(
        ) and not service.HasRecentError():

            try:

                response = service.Request(HC.GET, 'account')

                account = response['account']

                account.MakeFresh()

                controller.WriteSynchronous(
                    'service_updates', {
                        service_key: [
                            HydrusData.ServiceUpdate(HC.SERVICE_UPDATE_ACCOUNT,
                                                     account)
                        ]
                    })

                do_notify = True

            except HydrusExceptions.NetworkException as e:

                HydrusData.Print('Failed to refresh account for ' +
                                 service.GetName() + ':')

                HydrusData.Print(e)

            except Exception:

                HydrusData.Print('Failed to refresh account for ' +
                                 service.GetName() + ':')

                HydrusData.Print(traceback.format_exc())

    if do_notify:

        controller.pub('notify_new_permissions')