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])
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])
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])
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
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])
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
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])
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])
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