def post(self, res_id): if not resource_manager.is_authenticated(): self.write({ 'success': False, 'error': HYDROSHARE_AUTHENTICATION_ERROR, }) return hs_data = ResourceHydroShareData(resource_manager.hs_api_conn, res_id) data = json.loads(self.request.body.decode('utf-8')) file_and_folder_paths = data.get('files') filesChanged = 'sync' if file_and_folder_paths is None: self.set_status(400) # Bad Request self.write('Could not find "files" in request body.') return for item_path in file_and_folder_paths: # Remove any leading / if item_path.startswith('/'): item_path = item_path[1:] local_data = ResourceLocalData(res_id) # resource_manager.save_file_locally(res_id, item_path) hs_data.download_to_local(local_data, Path(item_path), Path(item_path)) self.write({ 'readMe': local_data.get_readme(), 'rootDir': local_data.get_files_and_folders(), })
def get(self, res_id): local_data = ResourceLocalData(res_id) if not local_data.is_downloaded(): resource_manager.save_resource_locally(res_id) self.write({ 'readMe': local_data.get_readme(), 'rootDir': local_data.get_files_and_folders(), })
def get(self, res_id): # Handling authentication first to ensure local data if not present is downloaded from Hydroshare if not resource_manager.is_authenticated(): self.write({ 'success': False, 'error': HYDROSHARE_AUTHENTICATION_ERROR, }) return local_data = ResourceLocalData(res_id) if not local_data.is_downloaded(): resource_manager.save_resource_locally(res_id) self.write({ 'readMe': local_data.get_readme(), 'rootDir': local_data.get_files_and_folders(), })
def get(self, res_id): if not resource_manager.is_authenticated(): self.write({ 'success': False, 'error': HYDROSHARE_AUTHENTICATION_ERROR, }) return local_data = ResourceLocalData(res_id) if not local_data.is_downloaded(): self.write({ 'success': False, 'error': WORKSPACE_FILES_ERROR, # 'error' : 'HydroShare files not present in Workspace', }) return else: local_file_data = local_data.get_files_and_folders() # checkFileSyncStatus(temporaryRoot, res_id) checkHydroShareSyncStatus(local_file_data, res_id, True) self.write({ 'readMe': local_data.get_readme(), 'rootDir': local_file_data, })
def post(self, res_id): if not resource_manager.is_authenticated(): self.write({ 'success': False, 'error': HYDROSHARE_AUTHENTICATION_ERROR, }) return data = json.loads(self.request.body.decode('utf-8')) file_and_folder_paths = data.get('files') myList = [] if file_and_folder_paths is None: self.set_status(400) # Bad Request self.write('Could not find "files" in request body.') return for item_path in file_and_folder_paths: # file_path = item_path # Remove any leading / if item_path.startswith('/'): file_name = item_path[1:] local_data = ResourceLocalData(res_id) CheckSyncStatusFilesRequestHandler.modified_time_local = local_data.get_md5_files( file_name) # appending local modified time to list hs_data = ResourceHydroShareData(resource_manager.hs_api_conn, res_id) CheckSyncStatusFilesRequestHandler.modified_time_hs = hs_data.get_md5_files( res_id, file_name) if CheckSyncStatusFilesRequestHandler.modified_time_hs < CheckSyncStatusFilesRequestHandler.modified_time_local: CheckSyncStatusFilesRequestHandler.filesChanged = 'local' myDict = { 'resourceId': res_id, 'filesChanged': CheckSyncStatusFilesRequestHandler.filesChanged, 'modified_time_local': CheckSyncStatusFilesRequestHandler.modified_time_local, 'file_name': file_name, 'file_path': item_path } myList.append(myDict) myJson = json.dumps(myList) elif CheckSyncStatusFilesRequestHandler.modified_time_hs > CheckSyncStatusFilesRequestHandler.modified_time_local: myDict = { 'resourceId': res_id, 'filesChanged': CheckSyncStatusFilesRequestHandler.filesChanged, 'modified_time_local': CheckSyncStatusFilesRequestHandler.modified_time_hs, 'file_name': file_name, 'file_path': item_path } myList.append(myDict) myJson = json.dumps(myList) temporaryRoot = local_data.get_files_and_folders() self.write({ 'readMe': local_data.get_readme(), 'rootDir': temporaryRoot, 'myJson': myJson })
def get(self, res_id): local_data = ResourceLocalData(res_id) self.write({ 'readMe': local_data.get_readme(), 'rootDir': local_data.get_files_and_folders(), })