Example #1
0
 def _pithos_add(self, path):
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         uploader = PithosUploader(path, dm.get_service_root("Pithos"))
     except IOError:
         self.pending_uploads["Pithos"][id] = {"error": "File not found", "status": "Error-2", "path": path}
     else:
         self.pending_uploads["Pithos"][id] = {"uploader": uploader, "status": "Starting", "conflict": "KeepBoth"}
     return (id, self.pending_uploads["Pithos"][id])
Example #2
0
 def _dropbox_add(self, path):
     """
     path: localpath to the file.
     The identifier for each upload will be an id generated by simpleflake.
     """
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         uploader = DropboxUploader(path, dm.get_service_root("Dropbox"))
     except IOError:
         self.pending_uploads["Dropbox"][id] = {"error": "File not found", "status": "Error-2", "path": path}
     else:
         self.pending_uploads["Dropbox"][id] = {"uploader": uploader, "status": "Starting", "conflict": "KeepBoth"}
     return (id, self.pending_uploads["Dropbox"][id])
Example #3
0
    def _googledrive_auth(self):
        credentials = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        credentials = dataManager.get_credentials('GoogleDrive')

        credentials = Credentials.new_from_json(credentials)
        http = credentials.authorize(httplib2.Http())
        try:
            drive_service = build('drive', 'v2', http=http)
        except httplib2.ServerNotFoundError:
            raise faults.NetworkError('No internet.')

        try:
            #Check whether the target folder exists
            container = dataManager.get_service_root('GoogleDrive')
            if container:
                arguments = [
                    'title = "{}"'.format(container),
                    'mimeType = "application/vnd.google-apps.folder"',
                    'trashed = False'
                ]
                q = ' and '.join(arguments)
                response = drive_service.files().list(q=q).execute()
                if not response['items']:
                    #Create the folder
                    self.logger.info(
                        'GoogleDrive folder changed:{}'.format(container))
                    body = {
                        'title': container,
                        'mimeType': 'application/vnd.google-apps.folder'
                    }
                    response = drive_service.files().insert(
                        body=body).execute()
                    dataManager.set_folder_id(response['id'])
                else:
                    dataManager.set_folder_id(response['items'][0]['id'])
        except errors.HttpError as e:
            #raise
            raise faults.NetworkError('No internet.')
        except AccessTokenRefreshError:
            raise faults.InvalidAuth('GoogleDrive')

        dataManager.set_credentials('GoogleDrive', credentials)
        return drive_service
Example #4
0
 def _googledrive_add(self, path):
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         with open(path, "rb"):
             pass
         uploader = GoogleDriveUploader(path, dm.get_service_root("GoogleDrive"), dm.get_folder_id())
     except IOError:
         self.pending_uploads["GoogleDrive"][id] = {"error": "File not found", "status": "Error-2", "path": path}
     else:
         self.pending_uploads["GoogleDrive"][id] = {
             "uploader": uploader,
             "status": "Starting",
             "conflict": "KeepBoth",
         }
     return (id, self.pending_uploads["GoogleDrive"][id])
Example #5
0
    def _dropbox_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Dropbox')

        dropboxClient = DropboxClient(access_token)

        try:
            dropboxClient.account_info()
        except rest.ErrorResponse as e:
            if e.status == 401:
                raise faults.InvalidAuth('Dropbox-Auth')
        except rest.RESTSocketError as e:
            raise faults.NetworkError('No internet-Auth')

        return dropboxClient
Example #6
0
    def _dropbox_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Dropbox')

        dropboxClient = DropboxClient(access_token)

        try:
            dropboxClient.account_info()
        except rest.ErrorResponse as e:
            if e.status == 401:
                raise faults.InvalidAuth('Dropbox-Auth')
        except rest.RESTSocketError as e:
            raise faults.NetworkError('No internet-Auth')

        return dropboxClient
Example #7
0
 def _pithos_add(self, path):
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         uploader = PithosUploader(path, dm.get_service_root('Pithos'))
     except IOError:
         self.pending_uploads['Pithos'][id] = {
             'error': 'File not found',
             'status': 'Error-2',
             'path': path
         }
     else:
         self.pending_uploads['Pithos'][id] = {
             'uploader': uploader,
             'status': 'Starting',
             'conflict': 'KeepBoth'
         }
     return (id, self.pending_uploads['Pithos'][id])
Example #8
0
 def _dropbox_add(self, path):
     '''
     path: localpath to the file.
     The identifier for each upload will be an id generated by simpleflake.
     '''
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         uploader = DropboxUploader(path, dm.get_service_root('Dropbox'))
     except IOError:
         self.pending_uploads['Dropbox'][id] = {
             'error': 'File not found',
             'status': 'Error-2',
             'path': path
         }
     else:
         self.pending_uploads['Dropbox'][id] = {
             'uploader': uploader,
             'status': 'Starting',
             'conflict': 'KeepBoth'
         }
     return (id, self.pending_uploads['Dropbox'][id])
Example #9
0
 def _googledrive_add(self, path):
     id = self._new_id()
     uploader = None
     dm = LocalDataManager()
     try:
         with open(path, 'rb'):
             pass
         uploader = GoogleDriveUploader(path,
                                        dm.get_service_root('GoogleDrive'),
                                        dm.get_folder_id())
     except IOError:
         self.pending_uploads['GoogleDrive'][id] = {
             'error': 'File not found',
             'status': 'Error-2',
             'path': path
         }
     else:
         self.pending_uploads['GoogleDrive'][id] = {
             'uploader': uploader,
             'status': 'Starting',
             'conflict': 'KeepBoth'
         }
     return (id, self.pending_uploads['GoogleDrive'][id])
Example #10
0
    def _pithos_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Pithos')
        try:
            dm = LocalDataManager()
            s = AstakosClient(access_token, local.Pithos_AUTHURL)
            auth_data = s.authenticate()
            pithos_url = self._get_pithos_public_url(auth_data)
            uuid = auth_data['access']['user']['id']
            pithosClient = CloudyPithosClient(pithos_url, access_token, uuid)
            pithosClient.container = dm.get_service_root('Pithos')

            #Check if the container saved in the settings exists.
            self._call_exceptional(pithosClient)
        except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
            raise faults.InvalidAuth('Pithos-Auth')
        except (AstakosErrors.AstakosClientException, faults.NetworkError) as e:
            raise faults.NetworkError('No internet-Auth')

        return pithosClient
Example #11
0
    def _googledrive_auth(self):
        credentials = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        credentials = dataManager.get_credentials('GoogleDrive')

        credentials = Credentials.new_from_json(credentials)
        http = credentials.authorize(httplib2.Http())
        try:
            drive_service = build('drive', 'v2', http=http)
        except httplib2.ServerNotFoundError:
            raise faults.NetworkError('No internet.')

        try:
            #Check whether the target folder exists
            container = dataManager.get_service_root('GoogleDrive')
            if container:
                arguments = ['title = "{}"'.format(container),
                             'mimeType = "application/vnd.google-apps.folder"',
                             'trashed = False']
                q = ' and '.join(arguments)
                response = drive_service.files().list(q=q).execute()
                if not response['items']:
                    #Create the folder
                    self.logger.info('GoogleDrive folder changed:{}'.format(container))
                    body = {'title':container, 'mimeType':'application/vnd.google-apps.folder'}
                    response = drive_service.files().insert(body=body).execute()
                    dataManager.set_folder_id(response['id'])
                else:
                    dataManager.set_folder_id(response['items'][0]['id'])
        except errors.HttpError as e:
            #raise
            raise faults.NetworkError('No internet.')
        except AccessTokenRefreshError:
            raise faults.InvalidAuth('GoogleDrive')

        dataManager.set_credentials('GoogleDrive', credentials)
        return drive_service
Example #12
0
    def _pithos_auth(self):
        access_token = None
        dataManager = LocalDataManager()

        #A KeyError will be raised if there is no token.
        access_token = dataManager.get_credentials('Pithos')
        try:
            dm = LocalDataManager()
            s = AstakosClient(access_token, local.Pithos_AUTHURL)
            auth_data = s.authenticate()
            pithos_url = self._get_pithos_public_url(auth_data)
            uuid = auth_data['access']['user']['id']
            pithosClient = CloudyPithosClient(pithos_url, access_token, uuid)
            pithosClient.container = dm.get_service_root('Pithos')

            #Check if the container saved in the settings exists.
            self._call_exceptional(pithosClient)
        except (AstakosErrors.Unauthorized, faults.InvalidAuth) as e:
            raise faults.InvalidAuth('Pithos-Auth')
        except (AstakosErrors.AstakosClientException,
                faults.NetworkError) as e:
            raise faults.NetworkError('No internet-Auth')

        return pithosClient
Example #13
0
 def _pithos_add_user(self, key):
     dataManager = LocalDataManager()
     dataManager.set_credentials('Pithos', key)
     return self._pithos_auth()
Example #14
0
 def _dropbox_add_user(self, key):
     dataManager = LocalDataManager()
     dataManager.set_credentials('Dropbox', key)
     return self._dropbox_auth()
Example #15
0
 def _googledrive_add_user(self, credentials):
     dataManager = LocalDataManager()
     dataManager.set_credentials('GoogleDrive', credentials)
     return self._googledrive_auth()
Example #16
0
 def add_and_authenticate(self, key):
     dataManager = LocalDataManager()
     dataManager.set_credentials('Pithos', key)
     return self._pithos_auth()
Example #17
0
 def _pithos_add_user(self, key):
     dataManager = LocalDataManager()
     dataManager.set_credentials('Pithos', key)
     return self._pithos_auth()
Example #18
0
 def _dropbox_add_user(self, key):
     dataManager = LocalDataManager()
     dataManager.set_credentials('Dropbox', key)
     return self._dropbox_auth()
Example #19
0
 def _googledrive_add_user(self, credentials):
     dataManager = LocalDataManager()
     dataManager.set_credentials('GoogleDrive', credentials)
     return self._googledrive_auth()