Bases: Aggregation

Represents a Resource in HydroShare

Source code in hsclient\hydroshare.py
class Resource(Aggregation):
    """Represents a Resource in HydroShare"""

    @property
    def _hsapi_path(self):
        path = urlparse(str(self.metadata.identifier)).path
        return '/hsapi' + path

    def _upload(self, file, destination_path):
        path = urljoin(self._hsapi_path, "files", destination_path.strip("/"))
        self._hs_session.upload_file(path, files={'file': open(file, 'rb')}, status_code=201)

    def _delete_file(self, path) -> None:
        path = urljoin(self._hsapi_path, "files", path)
        self._hs_session.delete(path, status_code=200)

    def _download_file_folder(self, path: str, save_path: str) -> None:
        return self._hs_session.retrieve_zip(path, save_path)

    def _delete_file_folder(self, path: str) -> None:
        path = urljoin(self._hsapi_path, "folders", path)
        self._hs_session.delete(path, status_code=200)

    # system information

    @property
    def resource_id(self) -> str:
        """The resource id (guid) of the HydroShare resource"""
        return self._map.identifier

    @property
    def metadata_file(self):
        """The path to the metadata file"""
        return self.metadata_path.split("/data/", 1)[1]

    def system_metadata(self):
        """
        The system metadata associated with the HydroShare resource
        returns: JSON object
        """
        hsapi_path = urljoin(self._hsapi_path, 'sysmeta')
        return self._hs_session.get(hsapi_path, status_code=200).json()

    # access operations

    def set_sharing_status(self, public: bool):
        """
        Set the sharing status of the resource to public or private
        :param public: bool, set to True for public, False for private
        """
        path = urljoin("hsapi", "resource", "accessRules", self.resource_id)
        data = {'public': public}
        self._hs_session.put(path, status_code=200, data=data)

    @property
    def access_permission(self):
        """
        Retrieves the access permissions of the resource
        :return: JSON object
        """
        path = urljoin(self._hsapi_path, "access")
        response = self._hs_session.get(path, status_code=200)
        return response.json()

    # resource operations

    def new_version(self):
        """
        Creates a new version of the resource on HydroShare
        :return: A Resource object of the newly created resource version
        """
        path = urljoin(self._hsapi_path, "version")
        response = self._hs_session.post(path, status_code=202)
        resource_id = response.text
        return Resource("/resource/{}/data/resourcemap.xml".format(resource_id), self._hs_session)

    def copy(self):
        """
        Copies this Resource into a new resource on HydroShare
        returns: A Resource object of the newly copied resource
        """
        path = urljoin(self._hsapi_path, "copy")
        response = self._hs_session.post(path, status_code=202)
        resource_id = response.text
        return Resource("/resource/{}/data/resourcemap.xml".format(resource_id), self._hs_session)

    def download(self, save_path: str = "") -> str:
        """
        Downloads a zipped bagit archive of the resource from HydroShare
        param save_path: A local path to save the bag to, defaults to the current working directory
        returns: The relative pathname of the download
        """
        return self._hs_session.retrieve_bag(self._hsapi_path, save_path=save_path)

    @refresh
    def delete(self) -> None:
        """
        Deletes the resource on HydroShare
        :return: None
        """
        hsapi_path = self._hsapi_path
        self._hs_session.delete(hsapi_path, status_code=204)

    @refresh
    def save(self) -> None:
        """
        Saves the metadata to HydroShare
        :return: None
        """
        metadata_string = rdf_string(self._retrieved_metadata, rdf_format="xml")
        path = urljoin(self._hsapi_path, "ingest_metadata")
        self._hs_session.upload_file(path, files={'file': ('resourcemetadata.xml', metadata_string)})

    # referenced content operations

    @refresh
    def reference_create(self, file_name: str, url: str, path: str = '') -> None:
        """
        Creates a HydroShare reference object to reference content outside of the resource
        :param file_name: the file name of the resulting .url file
        :param url: the url of the referenced content
        :param path: the path to create the reference in
        :return: None
        """
        request_path = urljoin(self._hsapi_path.replace(self.resource_id, ""), "data-store-add-reference")
        self._hs_session.post(
            request_path,
            data={"res_id": self.resource_id, "curr_path": path, "ref_name": file_name, "ref_url": url},
            status_code=200,
        )

    @refresh
    def reference_update(self, file_name: str, url: str, path: str = '') -> None:
        """
        Updates a HydroShare reference object
        :param file_name: the file name for the .url file
        :param url: the url of the referenced content
        :param path: the path to the directory where the reference is located
        :return: None
        """
        request_path = urljoin(self._hsapi_path.replace(self.resource_id, ""), "data_store_edit_reference_url")
        self._hs_session.post(
            request_path,
            data={"res_id": self.resource_id, "curr_path": path, "url_filename": file_name, "new_ref_url": url},
            status_code=200,
        )

    # file operations

    @refresh
    def folder_create(self, folder: str) -> None:
        """
        Creates a folder on HydroShare
        :param folder: the folder path to create
        :return: None
        """
        path = urljoin(self._hsapi_path, "folders", folder)
        self._hs_session.put(path, status_code=201)

    @refresh
    def folder_rename(self, path: str, new_path: str) -> None:
        """
        Renames a folder on HydroShare
        :param path: the path to the folder to rename
        :param new_path: the new path folder name
        :return: None
        """
        self.file_rename(path=path, new_path=new_path)

    @refresh
    def folder_delete(self, path: str = None) -> None:
        """
        Deletes a folder on HydroShare
        :param path: the path to the folder
        :return: None
        """
        self._delete_file_folder(path)

    def folder_download(self, path: str, save_path: str = ""):
        """
        Downloads a folder from HydroShare
        :param path: The path to folder
        :param save_path: The local path to save the download to, defaults to the current directory
        :return: The path to the download zipped folder
        """
        return self._hs_session.retrieve_zip(
            urljoin(self._resource_path, "data", "contents", path), save_path, params={"zipped": "true"}
        )

    def file_download(self, path: str, save_path: str = "", zipped: bool = False):
        """
        Downloads a file from HydroShare
        :param path: The path to the file
        :param save_path: The local path to save the file to
        :param zipped: Defaults to False, set to True to download the file zipped
        :return: The path to the downloaded file
        """
        if zipped:
            return self._hs_session.retrieve_zip(
                urljoin(self._resource_path, "data", "contents", path), save_path, params={"zipped": "true"}
            )
        else:
            return self._hs_session.retrieve_file(urljoin(self._resource_path, "data", "contents", path), save_path)

    @refresh
    def file_delete(self, path: str = None) -> None:
        """
        Delete a file on HydroShare
        :param path: The path to the file
        :return: None
        """
        self._delete_file(path)

    @refresh
    def file_rename(self, path: str, new_path: str) -> None:
        """
        Rename a file on HydroShare
        :param path: The path to the file
        :param new_path: the renamed path to the file
        :return: None
        """
        rename_path = urljoin(self._hsapi_path, "functions", "move-or-rename")
        self._hs_session.post(rename_path, status_code=200, data={"source_path": path, "target_path": new_path})

    @refresh
    def file_zip(self, path: str, zip_name: str = None, remove_file: bool = True) -> None:
        """
        Zip a file on HydroShare
        :param path: The path to the file
        :param zip_name: The name of the zipped file
        :param remove_file: Defaults to True, set to False to not delete the file that was zipped
        :return: None
        """
        zip_name = basename(path) + ".zip" if not zip_name else zip_name
        data = {"input_coll_path": path, "output_zip_file_name": zip_name, "remove_original_after_zip": remove_file}
        zip_path = urljoin(self._hsapi_path, "functions", "zip")
        self._hs_session.post(zip_path, status_code=200, data=data)

    @refresh
    def file_unzip(self, path: str, overwrite: bool = True, ingest_metadata=True) -> None:
        """
        Unzips a file on HydroShare
        :param path: The path to the file to unzip
        :param overwrite: Defaults to True, set to False to unzip the files into a folder with the zip filename
        :param ingest_metadata: Defaults to True, set to False to not ingest HydroShare RDF metadata xml files
        :return: None
        """
        if not path.endswith(".zip"):
            raise Exception("File {} is not a zip, and cannot be unzipped".format(path))
        unzip_path = urljoin(self._hsapi_path, "functions", "unzip", "data", "contents", path)
        self._hs_session.post(
            unzip_path, status_code=200, data={"overwrite": overwrite, "ingest_metadata": ingest_metadata}
        )

    def file_aggregate(self, path: str, agg_type: AggregationType, refresh: bool = True):
        """
        Aggregate a file to a HydroShare aggregation type.  Aggregating files allows you to specify metadata specific
        to the files associated with the aggregation.  To set a FileSet aggregation, include the path to the folder or
        a file in the folder you would like to create a FileSet aggregation from.
        :param path: The path to the file to aggregate
        :param agg_type: The AggregationType to create
        :param refresh: Defaults True, toggles automatic refreshing of the updated resource in HydroShare
        :return: The newly created Aggregation object if refresh is True
        """
        type_value = agg_type.value
        data = {}
        if agg_type == AggregationType.SingleFileAggregation:
            type_value = 'SingleFile'
        if agg_type == AggregationType.FileSetAggregation:
            if '/' in path:
                relative_path = dirname(path)
            else:
                relative_path = path
            data = {"folder_path": relative_path}

        url = urljoin(self._hsapi_path, "functions", "set-file-type", path, type_value)
        self._hs_session.post(url, status_code=201, data=data)
        if refresh:
            # Only return the newly created aggregation if a refresh is requested
            self.refresh()
            return self.aggregation(file__path=path)

    @refresh
    def file_upload(self, *files: str, destination_path: str = "") -> None:
        """
        Uploads files to a folder in HydroShare
        :param *files: The local file paths to upload
        :param destination_path: The path on HydroShare to upload the files to, defaults to the root contents directory
        :return: None
        """
        if len(files) == 1:
            self._upload(files[0], destination_path=destination_path)
        else:
            with tempfile.TemporaryDirectory() as tmpdir:
                zipped_file = os.path.join(tmpdir, 'files.zip')
                with ZipFile(zipped_file, 'w') as zipped:
                    for file in files:
                        zipped.write(file, os.path.basename(file))
                self._upload(zipped_file, destination_path=destination_path)
                unzip_path = urljoin(
                    self._hsapi_path, "functions", "unzip", "data", "contents", destination_path, 'files.zip'
                )
                self._hs_session.post(
                    unzip_path, status_code=200, data={"overwrite": "true", "ingest_metadata": "true"}
                )
        # TODO, return those files?

    # aggregation operations

    @refresh
    def aggregation_remove(self, aggregation: Aggregation) -> None:
        """
        Removes an aggregation from HydroShare.  This does not remove the files in the aggregation.
        :param aggregation: The aggregation object to remove
        :return: None
        """
        path = urljoin(
            aggregation._hsapi_path,
            "functions",
            "remove-file-type",
            aggregation.metadata.type.value + "LogicalFile",
            aggregation.main_file_path,
        )
        aggregation._hs_session.post(path, status_code=200)
        aggregation.refresh()

    @refresh
    def aggregation_move(self, aggregation: Aggregation, dst_path: str = "") -> None:
        """
        Moves an aggregation from its current location to another folder in HydroShare.
        :param aggregation: The aggregation object to move
        :param  dst_path: The target file path to move the aggregation to - target folder must exist
        :return: None
        """
        path = urljoin(
            aggregation._hsapi_path,
            aggregation.metadata.type.value + "LogicalFile",
            aggregation.main_file_path,
            "functions",
            "move-file-type",
            dst_path,
        )
        response = aggregation._hs_session.post(path, status_code=200)
        json_response = response.json()
        task_id = json_response['id']
        status = json_response['status']
        if status in ("Not ready", "progress"):
            while aggregation._hs_session.check_task(task_id) != 'true':
                time.sleep(CHECK_TASK_PING_INTERVAL)
        aggregation.refresh()

    @refresh
    def aggregation_delete(self, aggregation: Aggregation) -> None:
        """
        Deletes an aggregation from HydroShare.  This deletes the files and metadata in the aggregation.
        :param aggregation: The aggregation object to delete
        :return: None
        """
        aggregation.delete()

    def aggregation_download(self, aggregation: Aggregation, save_path: str = "", unzip_to: str = None) -> str:
        """
        Download an aggregation from HydroShare
        :param aggregation: The aggregation to download
        :param save_path: The local path to save the aggregation to, defaults to the current directory
        :param unzip_to: If set, the resulting download will be unzipped to the specified path
        :return: None
        """
        return aggregation._download(save_path=save_path, unzip_to=unzip_to)

access_permission property

Retrieves the access permissions of the resource :return: JSON object

metadata_file property

The path to the metadata file

resource_id: str property

The resource id (guid) of the HydroShare resource

aggregation_delete(aggregation)

Deletes an aggregation from HydroShare. This deletes the files and metadata in the aggregation. :param aggregation: The aggregation object to delete :return: None

Source code in hsclient\hydroshare.py
@refresh
def aggregation_delete(self, aggregation: Aggregation) -> None:
    """
    Deletes an aggregation from HydroShare.  This deletes the files and metadata in the aggregation.
    :param aggregation: The aggregation object to delete
    :return: None
    """
    aggregation.delete()

aggregation_download(aggregation, save_path='', unzip_to=None)

Download an aggregation from HydroShare :param aggregation: The aggregation to download :param save_path: The local path to save the aggregation to, defaults to the current directory :param unzip_to: If set, the resulting download will be unzipped to the specified path :return: None

Source code in hsclient\hydroshare.py
def aggregation_download(self, aggregation: Aggregation, save_path: str = "", unzip_to: str = None) -> str:
    """
    Download an aggregation from HydroShare
    :param aggregation: The aggregation to download
    :param save_path: The local path to save the aggregation to, defaults to the current directory
    :param unzip_to: If set, the resulting download will be unzipped to the specified path
    :return: None
    """
    return aggregation._download(save_path=save_path, unzip_to=unzip_to)

aggregation_move(aggregation, dst_path='')

Moves an aggregation from its current location to another folder in HydroShare. :param aggregation: The aggregation object to move :param dst_path: The target file path to move the aggregation to - target folder must exist :return: None

Source code in hsclient\hydroshare.py
@refresh
def aggregation_move(self, aggregation: Aggregation, dst_path: str = "") -> None:
    """
    Moves an aggregation from its current location to another folder in HydroShare.
    :param aggregation: The aggregation object to move
    :param  dst_path: The target file path to move the aggregation to - target folder must exist
    :return: None
    """
    path = urljoin(
        aggregation._hsapi_path,
        aggregation.metadata.type.value + "LogicalFile",
        aggregation.main_file_path,
        "functions",
        "move-file-type",
        dst_path,
    )
    response = aggregation._hs_session.post(path, status_code=200)
    json_response = response.json()
    task_id = json_response['id']
    status = json_response['status']
    if status in ("Not ready", "progress"):
        while aggregation._hs_session.check_task(task_id) != 'true':
            time.sleep(CHECK_TASK_PING_INTERVAL)
    aggregation.refresh()

aggregation_remove(aggregation)

Removes an aggregation from HydroShare. This does not remove the files in the aggregation. :param aggregation: The aggregation object to remove :return: None

Source code in hsclient\hydroshare.py
@refresh
def aggregation_remove(self, aggregation: Aggregation) -> None:
    """
    Removes an aggregation from HydroShare.  This does not remove the files in the aggregation.
    :param aggregation: The aggregation object to remove
    :return: None
    """
    path = urljoin(
        aggregation._hsapi_path,
        "functions",
        "remove-file-type",
        aggregation.metadata.type.value + "LogicalFile",
        aggregation.main_file_path,
    )
    aggregation._hs_session.post(path, status_code=200)
    aggregation.refresh()

copy()

Copies this Resource into a new resource on HydroShare returns: A Resource object of the newly copied resource

Source code in hsclient\hydroshare.py
def copy(self):
    """
    Copies this Resource into a new resource on HydroShare
    returns: A Resource object of the newly copied resource
    """
    path = urljoin(self._hsapi_path, "copy")
    response = self._hs_session.post(path, status_code=202)
    resource_id = response.text
    return Resource("/resource/{}/data/resourcemap.xml".format(resource_id), self._hs_session)

delete()

Deletes the resource on HydroShare :return: None

Source code in hsclient\hydroshare.py
@refresh
def delete(self) -> None:
    """
    Deletes the resource on HydroShare
    :return: None
    """
    hsapi_path = self._hsapi_path
    self._hs_session.delete(hsapi_path, status_code=204)

download(save_path='')

Downloads a zipped bagit archive of the resource from HydroShare param save_path: A local path to save the bag to, defaults to the current working directory returns: The relative pathname of the download

Source code in hsclient\hydroshare.py
def download(self, save_path: str = "") -> str:
    """
    Downloads a zipped bagit archive of the resource from HydroShare
    param save_path: A local path to save the bag to, defaults to the current working directory
    returns: The relative pathname of the download
    """
    return self._hs_session.retrieve_bag(self._hsapi_path, save_path=save_path)

file_aggregate(path, agg_type, refresh=True)

Aggregate a file to a HydroShare aggregation type. Aggregating files allows you to specify metadata specific to the files associated with the aggregation. To set a FileSet aggregation, include the path to the folder or a file in the folder you would like to create a FileSet aggregation from. :param path: The path to the file to aggregate :param agg_type: The AggregationType to create :param refresh: Defaults True, toggles automatic refreshing of the updated resource in HydroShare :return: The newly created Aggregation object if refresh is True

Source code in hsclient\hydroshare.py
def file_aggregate(self, path: str, agg_type: AggregationType, refresh: bool = True):
    """
    Aggregate a file to a HydroShare aggregation type.  Aggregating files allows you to specify metadata specific
    to the files associated with the aggregation.  To set a FileSet aggregation, include the path to the folder or
    a file in the folder you would like to create a FileSet aggregation from.
    :param path: The path to the file to aggregate
    :param agg_type: The AggregationType to create
    :param refresh: Defaults True, toggles automatic refreshing of the updated resource in HydroShare
    :return: The newly created Aggregation object if refresh is True
    """
    type_value = agg_type.value
    data = {}
    if agg_type == AggregationType.SingleFileAggregation:
        type_value = 'SingleFile'
    if agg_type == AggregationType.FileSetAggregation:
        if '/' in path:
            relative_path = dirname(path)
        else:
            relative_path = path
        data = {"folder_path": relative_path}

    url = urljoin(self._hsapi_path, "functions", "set-file-type", path, type_value)
    self._hs_session.post(url, status_code=201, data=data)
    if refresh:
        # Only return the newly created aggregation if a refresh is requested
        self.refresh()
        return self.aggregation(file__path=path)

file_delete(path=None)

Delete a file on HydroShare :param path: The path to the file :return: None

Source code in hsclient\hydroshare.py
@refresh
def file_delete(self, path: str = None) -> None:
    """
    Delete a file on HydroShare
    :param path: The path to the file
    :return: None
    """
    self._delete_file(path)

file_download(path, save_path='', zipped=False)

Downloads a file from HydroShare :param path: The path to the file :param save_path: The local path to save the file to :param zipped: Defaults to False, set to True to download the file zipped :return: The path to the downloaded file

Source code in hsclient\hydroshare.py
def file_download(self, path: str, save_path: str = "", zipped: bool = False):
    """
    Downloads a file from HydroShare
    :param path: The path to the file
    :param save_path: The local path to save the file to
    :param zipped: Defaults to False, set to True to download the file zipped
    :return: The path to the downloaded file
    """
    if zipped:
        return self._hs_session.retrieve_zip(
            urljoin(self._resource_path, "data", "contents", path), save_path, params={"zipped": "true"}
        )
    else:
        return self._hs_session.retrieve_file(urljoin(self._resource_path, "data", "contents", path), save_path)

file_rename(path, new_path)

Rename a file on HydroShare :param path: The path to the file :param new_path: the renamed path to the file :return: None

Source code in hsclient\hydroshare.py
@refresh
def file_rename(self, path: str, new_path: str) -> None:
    """
    Rename a file on HydroShare
    :param path: The path to the file
    :param new_path: the renamed path to the file
    :return: None
    """
    rename_path = urljoin(self._hsapi_path, "functions", "move-or-rename")
    self._hs_session.post(rename_path, status_code=200, data={"source_path": path, "target_path": new_path})

file_unzip(path, overwrite=True, ingest_metadata=True)

Unzips a file on HydroShare :param path: The path to the file to unzip :param overwrite: Defaults to True, set to False to unzip the files into a folder with the zip filename :param ingest_metadata: Defaults to True, set to False to not ingest HydroShare RDF metadata xml files :return: None

Source code in hsclient\hydroshare.py
@refresh
def file_unzip(self, path: str, overwrite: bool = True, ingest_metadata=True) -> None:
    """
    Unzips a file on HydroShare
    :param path: The path to the file to unzip
    :param overwrite: Defaults to True, set to False to unzip the files into a folder with the zip filename
    :param ingest_metadata: Defaults to True, set to False to not ingest HydroShare RDF metadata xml files
    :return: None
    """
    if not path.endswith(".zip"):
        raise Exception("File {} is not a zip, and cannot be unzipped".format(path))
    unzip_path = urljoin(self._hsapi_path, "functions", "unzip", "data", "contents", path)
    self._hs_session.post(
        unzip_path, status_code=200, data={"overwrite": overwrite, "ingest_metadata": ingest_metadata}
    )

file_upload(*files, destination_path='')

Uploads files to a folder in HydroShare :param *files: The local file paths to upload :param destination_path: The path on HydroShare to upload the files to, defaults to the root contents directory :return: None

Source code in hsclient\hydroshare.py
@refresh
def file_upload(self, *files: str, destination_path: str = "") -> None:
    """
    Uploads files to a folder in HydroShare
    :param *files: The local file paths to upload
    :param destination_path: The path on HydroShare to upload the files to, defaults to the root contents directory
    :return: None
    """
    if len(files) == 1:
        self._upload(files[0], destination_path=destination_path)
    else:
        with tempfile.TemporaryDirectory() as tmpdir:
            zipped_file = os.path.join(tmpdir, 'files.zip')
            with ZipFile(zipped_file, 'w') as zipped:
                for file in files:
                    zipped.write(file, os.path.basename(file))
            self._upload(zipped_file, destination_path=destination_path)
            unzip_path = urljoin(
                self._hsapi_path, "functions", "unzip", "data", "contents", destination_path, 'files.zip'
            )
            self._hs_session.post(
                unzip_path, status_code=200, data={"overwrite": "true", "ingest_metadata": "true"}
            )

file_zip(path, zip_name=None, remove_file=True)

Zip a file on HydroShare :param path: The path to the file :param zip_name: The name of the zipped file :param remove_file: Defaults to True, set to False to not delete the file that was zipped :return: None

Source code in hsclient\hydroshare.py
@refresh
def file_zip(self, path: str, zip_name: str = None, remove_file: bool = True) -> None:
    """
    Zip a file on HydroShare
    :param path: The path to the file
    :param zip_name: The name of the zipped file
    :param remove_file: Defaults to True, set to False to not delete the file that was zipped
    :return: None
    """
    zip_name = basename(path) + ".zip" if not zip_name else zip_name
    data = {"input_coll_path": path, "output_zip_file_name": zip_name, "remove_original_after_zip": remove_file}
    zip_path = urljoin(self._hsapi_path, "functions", "zip")
    self._hs_session.post(zip_path, status_code=200, data=data)

folder_create(folder)

Creates a folder on HydroShare :param folder: the folder path to create :return: None

Source code in hsclient\hydroshare.py
@refresh
def folder_create(self, folder: str) -> None:
    """
    Creates a folder on HydroShare
    :param folder: the folder path to create
    :return: None
    """
    path = urljoin(self._hsapi_path, "folders", folder)
    self._hs_session.put(path, status_code=201)

folder_delete(path=None)

Deletes a folder on HydroShare :param path: the path to the folder :return: None

Source code in hsclient\hydroshare.py
@refresh
def folder_delete(self, path: str = None) -> None:
    """
    Deletes a folder on HydroShare
    :param path: the path to the folder
    :return: None
    """
    self._delete_file_folder(path)

folder_download(path, save_path='')

Downloads a folder from HydroShare :param path: The path to folder :param save_path: The local path to save the download to, defaults to the current directory :return: The path to the download zipped folder

Source code in hsclient\hydroshare.py
def folder_download(self, path: str, save_path: str = ""):
    """
    Downloads a folder from HydroShare
    :param path: The path to folder
    :param save_path: The local path to save the download to, defaults to the current directory
    :return: The path to the download zipped folder
    """
    return self._hs_session.retrieve_zip(
        urljoin(self._resource_path, "data", "contents", path), save_path, params={"zipped": "true"}
    )

folder_rename(path, new_path)

Renames a folder on HydroShare :param path: the path to the folder to rename :param new_path: the new path folder name :return: None

Source code in hsclient\hydroshare.py
@refresh
def folder_rename(self, path: str, new_path: str) -> None:
    """
    Renames a folder on HydroShare
    :param path: the path to the folder to rename
    :param new_path: the new path folder name
    :return: None
    """
    self.file_rename(path=path, new_path=new_path)

new_version()

Creates a new version of the resource on HydroShare :return: A Resource object of the newly created resource version

Source code in hsclient\hydroshare.py
def new_version(self):
    """
    Creates a new version of the resource on HydroShare
    :return: A Resource object of the newly created resource version
    """
    path = urljoin(self._hsapi_path, "version")
    response = self._hs_session.post(path, status_code=202)
    resource_id = response.text
    return Resource("/resource/{}/data/resourcemap.xml".format(resource_id), self._hs_session)

reference_create(file_name, url, path='')

Creates a HydroShare reference object to reference content outside of the resource :param file_name: the file name of the resulting .url file :param url: the url of the referenced content :param path: the path to create the reference in :return: None

Source code in hsclient\hydroshare.py
@refresh
def reference_create(self, file_name: str, url: str, path: str = '') -> None:
    """
    Creates a HydroShare reference object to reference content outside of the resource
    :param file_name: the file name of the resulting .url file
    :param url: the url of the referenced content
    :param path: the path to create the reference in
    :return: None
    """
    request_path = urljoin(self._hsapi_path.replace(self.resource_id, ""), "data-store-add-reference")
    self._hs_session.post(
        request_path,
        data={"res_id": self.resource_id, "curr_path": path, "ref_name": file_name, "ref_url": url},
        status_code=200,
    )

reference_update(file_name, url, path='')

Updates a HydroShare reference object :param file_name: the file name for the .url file :param url: the url of the referenced content :param path: the path to the directory where the reference is located :return: None

Source code in hsclient\hydroshare.py
@refresh
def reference_update(self, file_name: str, url: str, path: str = '') -> None:
    """
    Updates a HydroShare reference object
    :param file_name: the file name for the .url file
    :param url: the url of the referenced content
    :param path: the path to the directory where the reference is located
    :return: None
    """
    request_path = urljoin(self._hsapi_path.replace(self.resource_id, ""), "data_store_edit_reference_url")
    self._hs_session.post(
        request_path,
        data={"res_id": self.resource_id, "curr_path": path, "url_filename": file_name, "new_ref_url": url},
        status_code=200,
    )

save()

Saves the metadata to HydroShare :return: None

Source code in hsclient\hydroshare.py
@refresh
def save(self) -> None:
    """
    Saves the metadata to HydroShare
    :return: None
    """
    metadata_string = rdf_string(self._retrieved_metadata, rdf_format="xml")
    path = urljoin(self._hsapi_path, "ingest_metadata")
    self._hs_session.upload_file(path, files={'file': ('resourcemetadata.xml', metadata_string)})

set_sharing_status(public)

Set the sharing status of the resource to public or private :param public: bool, set to True for public, False for private

Source code in hsclient\hydroshare.py
def set_sharing_status(self, public: bool):
    """
    Set the sharing status of the resource to public or private
    :param public: bool, set to True for public, False for private
    """
    path = urljoin("hsapi", "resource", "accessRules", self.resource_id)
    data = {'public': public}
    self._hs_session.put(path, status_code=200, data=data)

system_metadata()

The system metadata associated with the HydroShare resource returns: JSON object

Source code in hsclient\hydroshare.py
def system_metadata(self):
    """
    The system metadata associated with the HydroShare resource
    returns: JSON object
    """
    hsapi_path = urljoin(self._hsapi_path, 'sysmeta')
    return self._hs_session.get(hsapi_path, status_code=200).json()