--- /usr/lib/python2.7/dist-packages/duplicity/backends/pydrivebackend.py 2015-05-12 16:12:53.000000000 +0100 +++ pydrive2backend.py 2015-05-28 15:57:16.460856110 +0100 @@ -23,7 +23,7 @@ from duplicity.errors import BackendException -class PyDriveBackend(duplicity.backend.Backend): +class PyDrive2Backend(duplicity.backend.Backend): """Connect to remote store using PyDrive API""" def __init__(self, parsed_url): @@ -32,22 +32,38 @@ global pydrive import httplib2 from apiclient.discovery import build - from oauth2client.client import SignedJwtAssertionCredentials from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive except ImportError: - raise BackendException('PyDrive backend requires PyDrive installation' + raise BackendException('PyDrive2 backend requires PyDrive installation. ' 'Please read the manpage to fix.') - if 'GOOGLE_DRIVE_ACCOUNT_KEY' not in os.environ: - raise BackendException('GOOGLE_DRIVE_ACCOUNT_KEY environment variable not set. Please read the manpage to fix.') - account_key = os.environ['GOOGLE_DRIVE_ACCOUNT_KEY'] + if 'GOOGLE_DRIVE_AUTH_DIRECTORY' not in os.environ: + raise BackendException('PyDrive2 backend requires GOOGLE_DRIVE_AUTH_DIRECTORY environment variable to be set.') - credentials = SignedJwtAssertionCredentials(parsed_url.username + '@' + parsed_url.hostname, account_key, scope='https://www.googleapis.com/auth/drive') - credentials.authorize(httplib2.Http()) + try: + auth_dir = os.environ['GOOGLE_DRIVE_AUTH_DIRECTORY'] + os.chdir(auth_dir) + except: + raise BackendException('PyDrive2 backend could not change to auth directory GOOGLE_DRIVE_AUTH_DIRECTORY=' + auth_dir) + + try: + f=open('client_secrets.json') + except: + raise BackendException('PyDrive2 backend failed to open client_secrets.json. ' + 'To generate this file see http://pythonhosted.org/PyDrive/quickstart.html') + + + auth_file = 'auth.json' + + try: gauth = GoogleAuth() - gauth.credentials = credentials + if not gauth.LoadCredentialsFile(auth_file) : + gauth.CommandLineAuth() + gauth.SaveCredentialsFile(auth_file) self.drive = GoogleDrive(gauth) + except: + raise BackendException('PyDrive2 backend authentication using ' + auth_dir + ' failed.') # Dirty way to find root folder id file_list = self.drive.ListFile({'q': "'Root' in parents"}).GetList() @@ -104,5 +120,5 @@ size = -1 return {'size': size} -duplicity.backend.register_backend('pydrive', PyDriveBackend) -duplicity.backend.uses_netloc.extend(['pydrive']) +duplicity.backend.register_backend('pydrive2', PyDrive2Backend) +duplicity.backend.uses_netloc.extend(['pydrive2'])