本文整理汇总了Python中hs_restclient.HydroShare类的典型用法代码示例。如果您正苦于以下问题:Python HydroShare类的具体用法?Python HydroShare怎么用?Python HydroShare使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HydroShare类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resource_move_or_rename
def test_resource_move_or_rename(self):
hs = HydroShare(prompt_auth=False)
response = hs.resource('511debf8858a4ea081f78d66870da76c').functions.move_or_rename({
"source_path": "/source/path",
"target_path": "/target/path"
})
self.assertEqual(response.status_code, 200)
示例2: test_referenced_update
def test_referenced_update(self):
hs = HydroShare(prompt_auth=False)
response = hs.updateReferencedFile(pid='511debf8858a4ea081f78d66870da76c', path='data/contents', name='file.url',
ref_url='https://www.cuahsi.org')
self.assertEqual(response['status'], 'success')
示例3: test_resource_scimeta_custom
def test_resource_scimeta_custom(self):
hs = HydroShare(prompt_auth=False)
response = hs.resource('511debf8858a4ea081f78d66870da76c').scimeta.custom({
"foo": "bar",
"foo2": "bar2"
})
self.assertEqual(response.status_code, 200)
示例4: test_get_resource_list
def test_get_resource_list(self):
hs = HydroShare()
res_list = hs.getResourceList()
for (i, r) in enumerate(res_list):
self.assertEquals(r['resource_title'], self.resource_titles[i])
self.assertEquals(r['resource_id'], self.resource_ids[i])
示例5: home
def home(request):
"""
Controller for the app home page.
"""
logger = logging.getLogger('django')
logger.error('Entering controller.py...')
res_output = ""
client_id = getattr(settings, "SOCIAL_AUTH_HYDROSHARE_KEY", "None")
client_secret = getattr(settings, "SOCIAL_AUTH_HYDROSHARE_SECRET", "None")
token = request.user.social_auth.get(provider='hydroshare').extra_data['token_dict']
token_dict_str = "Token: {0}".format(str(token))
logger.error(token_dict_str)
auth = HydroShareAuthOAuth2(client_id, client_secret, token=token)
try:
logger.error("Fetching resource list from playground.hydroshare.org")
hs = HydroShare(auth=auth, hostname='playground.hydroshare.org')
for resource in hs.getResourceList():
res_output += str(resource)
context = {"res_output": res_output, "token_dict_str": token_dict_str}
return render(request, 'oauth_user_demo/home.html', context)
except TokenExpiredError as e:
# TODO: redirect back to login view, giving this view as the view to return to
logger.error("TokenExpiredError: TODO: redirect to login view")
raise e
示例6: test_get_user_info
def test_get_user_info(self):
hs = HydroShare()
user_info = hs.getUserInfo()
self.assertEquals(user_info['username'], 'username')
self.assertEquals(user_info['first_name'], 'First')
self.assertEquals(user_info['last_name'], 'Last')
self.assertEquals(user_info['email'], '[email protected]')
示例7: test_get_resource_file_list
def test_get_resource_file_list(self):
hs = HydroShare()
res_list = hs.getResourceFileList('511debf8858a4ea081f78d66870da76c')
for (i, r) in enumerate(res_list):
self.assertEquals(r['url'], self.urls[i])
self.assertEquals(r['size'], self.sizes[i])
self.assertEquals(r['content_type'], self.content_types[i])
示例8: test_resource_zip_folder
def test_resource_zip_folder(self):
hs = HydroShare(prompt_auth=False)
response = hs.resource('511debf8858a4ea081f78d66870da76c').functions.zip({
"input_coll_path": "/source/path",
"output_zip_fname": "filename.zip",
"remove_original_after_zip": True
})
self.assertEqual(response.status_code, 200)
示例9: test_get_folder_contents
def test_get_folder_contents(self):
hs = HydroShare(prompt_auth=False)
folder_contents = hs.getResourceFolderContents('511debf8858a4ea081f78d66870da76c', pathname='model/initial/')
self.assertEqual(folder_contents['resource_id'], '511debf8858a4ea081f78d66870da76c')
self.assertEqual(folder_contents['path'], 'model/initial')
self.assertEqual(folder_contents['files'], ["model.exe", "param.txt"])
self.assertEqual(folder_contents['folders'], ["run/1", "run/2"])
示例10: get_resource_list
def get_resource_list():
hs = HydroShare()
resource_list = []
for resource in hs.getResourceList(types=['RasterResource']):
res_name = '{} [creator: {}]'.format(resource['resource_title'], resource['creator'])
resource_list.append((res_name, resource['resource_id']))
return resource_list
示例11: test_resource_list_by_bounding_box
def test_resource_list_by_bounding_box(self):
hs = HydroShare(prompt_auth=False)
res_list = hs.resources(coverage_type="box",
north="50",
south="30",
east="40",
west="20")
for (i, r) in enumerate(res_list):
self.assertEquals(True, True)
示例12: handle
def handle(self, *args, **options): # (f,fileid, databeginson,columnheaderson, cmd):
# cmdline = bool(options['cmdline'][0])
username = str(options['username'][0])
password = str(options['password'][0])
hs_client_id = settings.SOCIAL_AUTH_HYDROSHARE_UP_KEY
hs_client_secret = settings.SOCIAL_AUTH_HYDROSHARE_UP_SECRET
auth = HydroShareAuthOAuth2(hs_client_id, hs_client_secret,
username=username, password=password)
# print(username)
# print(password)
export_complete = True
resource_link = ''
user = str(options['django_user_name'][0])
datasettitle = str(options['datasettitle'][0])
startdate = str(options['startdate'][0])
enddate = str(options['enddate'][0])
datafile = str(options['datafile'][0])
dbfilename = str(options['dbfilename'][0])
# print(request.POST['hydroshareusername'])
# hs = get_oauth_hs(request)
# userInfo = hs.getUserInfo()
#
hs = HydroShare(auth=auth)
# username = hs.getUserInfo()
# print(username)
abstracttext = ''
title = ''
abstracttext += 'ODM2 Admin dataset: ' + str(datasettitle)
title += 'ODM2 Admin dataset ' + str(datasettitle)
abstract = abstracttext
keywords = ['ODM2']
rtype = 'GenericResource'
fpath = datafile # str(exportdb.DATABASES['default']['NAME'])
# # print(fpath)
# #metadata = '[{"coverage":{"type":"period", "value":{"start":"'+entered_start_date +'", "end":"'+ entered_end_date +'"}}}, {"creator":{"name":"Miguel Leon"}}]'
metadata = '[{"coverage":{"type":"period", "value":{"start":"' + str(startdate) + '", "end":"' + str(
enddate) + '"}}}, ' \
'{"creator":{"name":"' + user + '"}}]'
extra_metadata = '{"key-1": "value-1", "key-2": "value-2"}'
# #abstract = 'My abstract'
# #title = 'My resource'
# #keywords = ('my keyword 1', 'my keyword 2')
# #rtype = 'GenericResource'
# #fpath = 'C:/Users/leonmi/Google Drive/ODM2AdminLT2/ODM2SQliteBlank.db'
# #metadata = '[{"coverage":{"type":"period", "value":{"start":"01/01/2000", "end":"12/12/2010"}}}, {"creator":{"name":"John Smith"}}, {"creator":{"name":"Lisa Miller"}}]'
# #extra_metadata = '{"key-1": "value-1", "key-2": "value-2"}'
# messages.success(request, 'Profile details updated.')
resource_id = hs.createResource(rtype, title, resource_file=datafile,
resource_filename=dbfilename, keywords=keywords,
abstract=abstract, metadata=metadata, extra_metadata=extra_metadata)
print('resource created')
print(resource_id)
示例13: start_file_download
def start_file_download(request):
global temp_dir, prediction_data, rp_data, total_prediction_comids, total_rp_comids, sorted_prediction_comids, \
sorted_rp_comids, time
if request.method == 'GET':
get_data = request.GET
this_script_path = inspect.getfile(inspect.currentframe())
try:
if get_data['res_id'] is not None:
temp_dir = tempfile.mkdtemp()
file_path = get_data['res_id']
if get_data['src'] == 'iRODS':
download = requests.get(file_path, stream=True)
filename = os.path.basename(file_path)
local_file_path = os.path.join(temp_dir, filename)
with open(local_file_path, 'wb') as fd:
for chunk in download.iter_content(1024):
fd.write(chunk)
prediction_data = nc.Dataset(local_file_path, mode="r")
elif get_data['src'] == 'hs':
auth = HydroShareAuthBasic(username='username', password='*****')
hs = HydroShare(auth=auth, hostname="playground.hydroshare.org", use_https=False)
resource_data = hs.getSystemMetadata(file_path)
filename = resource_data['resource_title']
# this will only work if there is only one file in the resource and if
# the resource title is the same as filename
hs.getResourceFile(file_path, filename, destination=temp_dir)
local_file_path = temp_dir + "/" + filename
prediction_data = nc.Dataset(local_file_path, mode="r")
else:
testfile_path = this_script_path.replace('controllers.py', 'public/data/test.nc')
prediction_data = nc.Dataset(testfile_path, mode="r")
# Sort the RAPID netCDF file by COMID
qout_dimensions = prediction_data.variables['Qout'].dimensions
if qout_dimensions[0].lower() == 'comid' and qout_dimensions[1].lower() == 'time':
sorted_prediction_comids = sorted(enumerate(prediction_data.variables['COMID'][:]),
key=lambda comid: comid[1])
total_prediction_comids = len(sorted_prediction_comids)
else:
return JsonResponse({'error': "Invalid netCDF file"})
variables = prediction_data.variables.keys()
if 'time' in variables:
time = [t * 1000 for t in prediction_data.variables['time'][:]]
else:
return JsonResponse({'error': "Invalid netCDF file"})
rp_data_path = this_script_path.replace('controllers.py', 'public/data/return_period_data.nc')
rp_data = nc.Dataset(rp_data_path, mode="r")
sorted_rp_comids = sorted(enumerate(rp_data.variables['COMID'][:]), key=lambda comid: comid[1])
total_rp_comids = len(sorted_rp_comids)
return JsonResponse({'success': "The file is ready to go."})
except Exception, err:
return JsonResponse({'error': err})
示例14: test_get_resource_types
def test_get_resource_types(self):
hs = HydroShare()
res_type_proto = {'GenericResource',
'ModelInstanceResource',
'ModelProgramResource',
'NetcdfResource',
'RasterResource',
'RefTimeSeries',
'SWATModelInstanceResource',
'TimeSeriesResource',
'ToolResource'}
res_types = hs.getResourceTypes()
self.assertSetEqual(res_type_proto, res_types)
示例15: upload_to_hydroshare
def upload_to_hydroshare(request):
try:
if request.method == 'GET':
get_data = request.GET
download_path = str(get_data['download_path'])
hs_username = str(get_data['hs_username'])
hs_password = str(get_data['hs_password'])
r_title = str(get_data['r_title'])
r_type = str(get_data['r_type'])
r_abstract = str(get_data['r_abstract'])
r_keywords_raw = str(get_data['r_keywords'])
r_keywords = r_keywords_raw.split(',')
#startup a Hydroshare instance with user's credentials
auth = HydroShareAuthBasic(username=hs_username, password=hs_password)
hs = HydroShare(auth=auth, hostname="dev.hydroshare.org", use_https=True)
# try to download a tiny file simply to test the user's credentials
# test_id = '49d01b5b0d0a41b6a5a31d8aace0a36e'
# hs.getResource(test_id, destination=None, unzip=False)
#download the iRODS file to a temp directory
temp_dir = tempfile.mkdtemp()
filename = os.path.basename(download_path)
download_file_path = os.path.join(temp_dir, filename)
download = requests.get(download_path, stream=True)
with open(download_file_path, 'wb') as fd:
for chunk in download.iter_content(1024):
fd.write(chunk)
#upload the temp file to HydroShare
if os.path.exists(download_file_path):
resource_id = hs.createResource(r_type, r_title, resource_file=download_file_path, keywords=r_keywords, abstract=r_abstract)
else:
if temp_dir:
# remove the temp directory/file
shutil.rmtree(temp_dir)
return JsonResponse({'error': 'An error occurred with the file upload.'})
except Exception, err:
if temp_dir:
# remove the temp directory/file
shutil.rmtree(temp_dir)
if "401 Unauthorized" in str(err):
return JsonResponse({'error': 'Username or password invalid.'})
elif "400 Bad Request" in str(err):
return JsonResponse({'error': 'File uploaded successfully despite 400 Bad Request Error.'})
else:
traceback.print_exc()
return JsonResponse({'error': 'HydroShare rejected the upload for some reason.'})