Example #1
0
    def service(self):
        if self._service is not None:
            return self._service

        storage = self._getCredentialStorage()
        if storage is not None:
            credentials = storage.get()
        else:
            credentials = None

        if credentials is None:
            credentials = self._obtainCredentials()

        debug("Authenticating")
        import httplib2

        if debug.enabled():
            httplib2.debuglevel = 4

        http = credentials.authorize(
            httplib2.Http(cache = self._getConfigDir("http_cache"))
        )

        debug("Loading Google Drive service from config")

        from apiclient.discovery import build_from_document, DISCOVERY_URI
        
        debug("Downloading API service")

        import uritemplate
        url = uritemplate.expand(DISCOVERY_URI, {
            'api': 'drive',
            'apiVersion': 'v2'
        })
        res, content = http.request(url)

        apistr = None
        if res.status in [ 200, 202 ]:
            # API expires every minute.
            apistr = str(content)

        if not apistr:
            return None

        debug("Building Google Drive service from document")
        self._service = build_from_document(
            apistr, http = http, base = DISCOVERY_URI
        )

        return self._service
Example #2
0
from oauth2client.client import OAuth2Credentials
from libgsync.output import verbose, debug
from libgsync.drive.mimetypes import MimeTypes
from libgsync.drive.file import DriveFile

# Set to True for strict positional parameter exceptions in oauth2client
try:
    import gflags
    if False:
        gflags.FLAGS['positional_parameters_enforcement'].value = 'EXCEPTION'
    else:
        gflags.FLAGS['positional_parameters_enforcement'].value = 'IGNORE'
except Exception:
    pass

if debug.enabled():
    import logging
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

class ENoTTY(Exception):
    pass

class EGetAuthURL(Exception):
    pass

class EExchange(Exception):
    pass

class EInvalidRequest(Exception):
    pass
Example #3
0
try:
    import simplejson as json
except ImportError: # pragma: no cover
    import json

import oauth2client.util
oauth2client.util.positional_parameters_enforcement = \
    oauth2client.util.POSITIONAL_IGNORE

from oauth2client.client import OAuth2Credentials
from apiclient.http import MediaUploadProgress
from libgsync.output import verbose, debug
from libgsync.drive.mimetypes import MimeTypes
from libgsync.drive.file import DriveFile

if debug.enabled(): # pragma: no cover
    import logging
    logging.getLogger().setLevel(logging.DEBUG)


class NoTTYError(Exception): # pragma: no cover
    """Raised for non-tty based terminal exceptions"""
    pass

class ExchangeError(Exception): # pragma: no cover
    """Step2_Exchange based exception type"""
    pass

class FileNotFoundError(Exception): # pragma: no cover
    """Raised when expected files/directories are not found"""
    def __init__(self, filename):
Example #4
0
try:
    import simplejson as json
except ImportError: # pragma: no cover
    import json

import oauth2client.util
oauth2client.util.positional_parameters_enforcement = \
    oauth2client.util.POSITIONAL_IGNORE

from oauth2client.client import OAuth2Credentials
from apiclient.http import MediaUploadProgress
from libgsync.output import verbose, debug
from libgsync.drive.mimetypes import MimeTypes
from libgsync.drive.file import DriveFile

if debug.enabled(): # pragma: no cover
    import logging
    logging.getLogger().setLevel(logging.DEBUG)


class NoTTYError(Exception): # pragma: no cover
    """Raised for non-tty based terminal exceptions"""
    pass

class ExchangeError(Exception): # pragma: no cover
    """Step2_Exchange based exception type"""
    pass

class FileNotFoundError(Exception): # pragma: no cover
    """Raised when expected files/directories are not found"""
    def __init__(self, filename):