Skip to content

Commit 5e33c6e

Browse files
committed
Merge branch 'master' of https://github.com/hydroshare/hsclient into fix-ResourcePreview-model
2 parents b7076aa + e38970e commit 5e33c6e

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# hsclient
2-
A python client for interacting with HydroShare in an object oriented way.
2+
A python client for interacting with HydroShare in an object oriented way. The hsclient Python package can be use to create, modify, and interact with HydroShare resources. It was designed to allow you to write code to do pretty much everything you can do through HydroShare's web user interface.
33

44
## Jupyter Notebooks
5-
HydroShare has a resource with example notebooks. Click [here](https://www.hydroshare.org/resource/7561aa12fd824ebb8edbee05af19b910/) then click the blue `Open with...` dropdown and select `Cuahsi Jupyterhub` to launch the notebooks into a Jupyter Environment to start using this project.
5+
HydroShare has a resource with example Jupyter notebooks for using hsclient. Click [here](https://www.hydroshare.org/resource/7561aa12fd824ebb8edbee05af19b910/) then click the blue `Open with...` dropdown at the top of the page and select `Cuahsi Jupyterhub` to launch the notebooks into HydroShare's linked Jupyter Environment. [Click here](https://help.hydroshare.org/apps/CUAHSI-JupyterHub/) for information on how to access the HydroShare linked JupyterHub environment.
66

77

8-
## Install the HS RDF HydroShare Python Client
9-
The HS RDF Python Client for HydroShare won't be installed by default, so it has to be installed first before you can work with it. Use the following command to install the Python Client from the GitHub repository. Eventually we will distribute this package via the Python Package Index (PyPi) so that it can be installed via pip from PyPi.
8+
## Install the hsclient HydroShare Python Client
9+
The hsclient package is installed already in HydroShare's linked JupyterHub Python environment. However, if you want to use hsclient outside of that Python environment, hsclient won't be installed by default. You'll need to install it before you can work with it. Use the following command to pip install hsclient from the Python Package Index (PyPI). You can also use the package manager for your interactive development environment to do this.
1010

1111
```bash
1212
pip install hsclient
1313
```
1414

15-
## Authenticate with HydroShare
15+
## Getting Started and Documentation
16+
17+
The following are quick examples of how to get started with hsclient. Refer to the Jupyter notebooks above for more extensive examples. [Click here](https://hydroshare.github.io/hsclient/) to access documentation for hsclient.
18+
19+
### Authenticate with HydroShare
1620
Before you start interacting with resources in HydroShare you will need to authenticate.
1721
```python
1822
from hsclient import HydroShare
@@ -21,7 +25,7 @@ hs = HydroShare()
2125
hs.sign_in()
2226
```
2327

24-
## Create a New Empty Resource
28+
### Create a New Empty Resource
2529
A "resource" is a container for your content in HydroShare. Think of it as a "working directory" into which you are going to organize the code and/or data you are using and want to share. The following code can be used to create a new, empty resource within which you can create content and metadata.
2630

2731
This code creates a new resource in HydroShare. It also creates an in-memory object representation of that resource in your local environmment that you can then manipulate with further code.
@@ -37,12 +41,12 @@ print('The HydroShare Identifier for your new resource is: ' + resIdentifier)
3741
print('Your new resource is available at: ' + new_resource.metadata.url)
3842
```
3943

40-
# Creating and Editing Resource Metadata Elements
44+
### Creating and Editing Resource Metadata Elements
4145
Editing metadata elements for a resource can be done in an object oriented way. You can specify all of the metadata elements in code, which will set their values in memory in your local environment. Values of metadata elements can be edited, removed, or replaced by setting them to a new value, appending new values (in the case where the metadata element accepts a list), or by removing the value entirely.
4246

4347
When you are ready to save edits to metadata elements from your local environment to the resource in HydroShare, you can call the save() function on your resource and all of the new metadata values you created/edited will be saved to the resource in HydroShare.
4448

45-
## Resource Title and Abstract
49+
### Resource Title and Abstract
4650
The Title and Abstract metadata elements can be specified as text strings. To modify the Title or Abstract after it has been set, just set them to a different value.
4751

4852
```python
@@ -64,3 +68,8 @@ new_resource.save()
6468
print('Title: ' + new_resource.metadata.title)
6569
print('Abstract: ' + new_resource.metadata.abstract)
6670
```
71+
72+
## Funding and Acknowledgements
73+
74+
This material is based upon work supported by the National Science Foundation (NSF) under awards [1931278](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1931278) and [1931297](https://www.nsf.gov/awardsearch/showAward?AWD_ID=1931297). Any opinions, findings, conclusions, or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the NSF.
75+

hsclient/hydroshare.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
from hsclient.oauth2_model import Token
5454
from hsclient.utils import attribute_filter, encode_resource_url, is_aggregation, main_file_type
5555

56+
CHECK_TASK_PING_INTERVAL = 10
57+
5658

5759
class File(str):
5860
"""
@@ -1274,7 +1276,7 @@ def aggregation_move(self, aggregation: Aggregation, dst_path: str = "") -> None
12741276
status = json_response['status']
12751277
if status in ("Not ready", "progress"):
12761278
while aggregation._hs_session.check_task(task_id) != 'true':
1277-
time.sleep(1)
1279+
time.sleep(CHECK_TASK_PING_INTERVAL)
12781280
aggregation.refresh()
12791281

12801282
@refresh
@@ -1368,7 +1370,7 @@ def retrieve_bag(self, path, save_path=""):
13681370
file = self.get(path, status_code=200, allow_redirects=True)
13691371

13701372
if file.headers['Content-Type'] != "application/zip":
1371-
time.sleep(1)
1373+
time.sleep(CHECK_TASK_PING_INTERVAL)
13721374
return self.retrieve_bag(path, save_path)
13731375
return self.retrieve_file(path, save_path)
13741376

@@ -1386,7 +1388,7 @@ def retrieve_zip(self, path, save_path="", params=None):
13861388
zip_status = json_response['zip_status']
13871389
if zip_status == "Not ready":
13881390
while self.check_task(task_id) != 'true':
1389-
time.sleep(1)
1391+
time.sleep(CHECK_TASK_PING_INTERVAL)
13901392
return self.retrieve_file(download_path, save_path)
13911393

13921394
def upload_file(self, path, files, status_code=204):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
setup(
77
name='hsclient',
8-
version='1.0.1',
8+
version='1.0.4',
99
packages=find_packages(include=['hsclient', 'hsclient.*'],
1010
exclude=("tests",)),
1111
install_requires=[
12-
'hsmodels>=1.0.3',
12+
'hsmodels>=1.0.4',
1313
'requests',
1414
'requests_oauthlib',
1515
],

0 commit comments

Comments
 (0)