From ad859741a01bc1b3138f59aa39a9bc692652bfea Mon Sep 17 00:00:00 2001 From: John L Long Date: Fri, 7 Jul 2017 11:24:43 -0600 Subject: [PATCH] Missed a file; reving version --- pysb/SbSessionCompatibility.py | 121 ++++++++++++++++++++++++--------- setup.py | 2 +- 2 files changed, 88 insertions(+), 35 deletions(-) diff --git a/pysb/SbSessionCompatibility.py b/pysb/SbSessionCompatibility.py index 9f71c0d..dd38c5d 100644 --- a/pysb/SbSessionCompatibility.py +++ b/pysb/SbSessionCompatibility.py @@ -11,24 +11,45 @@ class SbSessionCompatibility: _sb = None def __init__(self, env=None): - _sb = SbSession(env) + self._sb = SbSession(env) + + def login(self, username, password): + """Log into ScienceBase + + :param username: The ScienceBase user to log in as + :param password: The ScienceBase password for the given user + :return: The SbSession object with the user logged in + """ + return self._sb.login(username, password) + + def loginc(self, username): + """Log into ScienceBase, prompting for the password + + :param username: The ScienceBase user to log in as + :return: The SbSession object with the user logged in + """ + return self._sb.loginc(username, password) + + def ping(self): + """Ping ScienceBase. A very low-cost operation to determine whether ScienceBase is available. + + :return: JSON response from ScienceBase Catalog + """ + return self._sb.ping() - # - # Backwards compatibility section. May be removed in future releases. - # def isLoggedIn(self): """Determine whether the SbSession is logged in and active in ScienceBase :return: Whether the SbSession is logged in and active in ScienceBase. """ - return _sb.is_logged_in() + return self._sb.is_logged_in() def getSessionInfo(self): """Get the JOSSO session information for the current session :return: ScienceBase Josso session info """ - return _sb.get_session_info() + return self._sb.get_session_info() def getSbItem(self, item_id): """Get the ScienceBase Item JSON with the given ID @@ -36,7 +57,7 @@ def getSbItem(self, item_id): :param params: Allows you to specify query params, such as {'fields':'title,ancestors'} for ?fields=title,ancestors :return: JSON for the ScienceBase Item with the given ID """ - return _sb.get_item(item_id) + return self._sb.get_item(item_id) def createSbItem(self, item_json): """Create a new Item in ScienceBase @@ -44,7 +65,7 @@ def createSbItem(self, item_json): :param item_json: JSON representing the ScienceBase Catalog item to create :return: Full item JSON from ScienceBase Catalog after creation """ - return _sb.create_item(item_json) + return self._sb.create_item(item_json) def updateSbItem(self, item_json): """Update an existing ScienceBase Item @@ -52,7 +73,7 @@ def updateSbItem(self, item_json): :param item_json: JSON representing the ScienceBase Catalog item to update :return: Full item JSON from ScienceBase Catalog after update """ - return _sb.update_item(item_json) + return self._sb.update_item(item_json) def deleteSbItem(self, item_json): """Delete an existing ScienceBase Item @@ -60,14 +81,14 @@ def deleteSbItem(self, item_json): :param item_json: JSON representing the ScienceBase Catalog item to delete :return """ - return _sb.delete_item(item_json) + return self._sb.delete_item(item_json) def undeleteSbItem(self, item_id): """Undelete a ScienceBase Item :param itemid: ID of the Item to undelete :return: JSON of the undeleted Item """ - return _sb.undelete_item(item_id) + return self._sb.undelete_item(item_id) def deleteSbItems(self, item_ids): """Delete multiple ScienceBase Items. This is much more efficient than using delete_item() for mass @@ -76,7 +97,7 @@ def deleteSbItems(self, item_ids): :param itemIds: List of Item IDs to delete :return: True if the items were successfully deleted """ - return _sb.delete_items(item_ids) + return self._sb.delete_items(item_ids) def moveSbItem(self, item_id, parent_id): """Move an existing ScienceBase Item under a new parent @@ -85,7 +106,7 @@ def moveSbItem(self, item_id, parent_id): :param parentid: ID of the new parent Item :return """ - return _sb.move_item(item_id, parent_id) + return self._sb.move_item(item_id, parent_id) def moveSbItems(self, item_ids, parent_id): """Move ScienceBase Items under a new parent @@ -94,7 +115,7 @@ def moveSbItems(self, item_ids, parent_id): :param parentid: ScienceBase Catalog Item ID of the new parent Item :return: A count of the number of Items moved """ - return _sb.move_items(item_ids, parent_id) + return self._sb.move_items(item_ids, parent_id) def uploadFileToItem(self, item, filename): """Upload a file to an existing Item in ScienceBase @@ -104,7 +125,7 @@ def uploadFileToItem(self, item, filename): :param scrape_file: Whether to scrape metadata and create extensions from special files :return """ - return _sb.upload_file_to_item(item, filename) + return self._sb.upload_file_to_item(item, filename) def uploadFileAndCreateItem(self, parent_id, filename): """Upload a file and create a new Item in ScienceBase @@ -114,7 +135,7 @@ def uploadFileAndCreateItem(self, parent_id, filename): :param scrape_file: Whether to scrape metadata and create extensions from special files :return: The ScienceBase Catalog Item JSON of the new Item """ - return _sb.upload_file_and_create_item(parent_id, filename) + return self._sb.upload_file_and_create_item(parent_id, filename) def uploadFilesAndCreateItem(self, parent_id, filenames): """Upload multiple files and create a new Item in ScienceBase @@ -122,10 +143,10 @@ def uploadFilesAndCreateItem(self, parent_id, filenames): :param parentid: ScienceBase Catalog Item JSON of the Item under which to create the new Item :param filenames: Filename of the files to upload :param scrape_file: Whether to scrape metadata and create extensions from special files - :return: The - return _sb.upload_files_and_create_item(parent_id, filenames) + :return: ScienceBase Catalog Item JSON of the new Item """ - + return self._sb.upload_files_and_create_item(parent_id, filenames) + def uploadFilesAndUpdateItem(self, item, filenames): """Upload multiple files and update an existing Item in ScienceBase @@ -134,7 +155,7 @@ def uploadFilesAndUpdateItem(self, item, filenames): :param scrape_file: Whether to scrape metadata and create extensions from special files :return: The ScienceBase Catalog Item JSON of the updated Item """ - return _sb.upload_files_and_update_item(item, filenames) + return self._sb.upload_files_and_update_item(item, filenames) def uploadFilesAndUpsertItem(self, item, filenames): """Upload multiple files and create or update an Item in ScienceBase @@ -144,7 +165,7 @@ def uploadFilesAndUpsertItem(self, item, filenames): :param scrape_file: Whether to scrape metadata and create extensions from special files :return: The ScienceBase Catalog Item JSON of the updated Item """ - return _sb.upload_files_and_upsert_item(item, filenames) + return self._sb.upload_files_and_upsert_item(item, filenames) def uploadFile(self, filename, mimetype=None): """ADVANCED USE -- USE OTHER UPLOAD METHODS IF AT ALL POSSIBLE. Upload a file to ScienceBase. The file will @@ -155,7 +176,7 @@ def uploadFile(self, filename, mimetype=None): :param mimetype: MIME type of the file :return: JSON response from ScienceBase """ - return _sb.upload_file(filename, mimetype) + return self._sb.upload_file(filename, mimetype) def replaceFile(self, filename, item): """Replace a file on a ScienceBase Item. This method will replace all files named @@ -165,7 +186,7 @@ def replaceFile(self, filename, item): :param item: ScienceBase Catalog Item JSON of the Item on which to replace the file :return: ScienceBase Catalog Item JSON of the updated Item """ - return _sb.replace_file(filename, item) + return self._sb.replace_file(filename, item) def getItemFilesZip(self, item, destination='.'): """Download all files from a ScienceBase Item as a zip. The zip is created server-side @@ -175,7 +196,7 @@ def getItemFilesZip(self, item, destination='.'): :param destination: Destination directory in which to store the zip file :return: The full name and path of the downloaded file """ - return _sb.get_item_files_zip(item, destination) + return self._sb.get_item_files_zip(item, destination) def getItemFileInfo(self, item): """Retrieve file information from a ScienceBase Item @@ -184,7 +205,7 @@ def getItemFileInfo(self, item): :return: A list of dictionaries containing url, name and size of each file """ - return _sb.get_item_file_info(item) + return self._sb.get_item_file_info(item) def downloadFile(self, url, local_filename, destination='.'): """Download file from URL @@ -194,7 +215,7 @@ def downloadFile(self, url, local_filename, destination='.'): :param destination: Destination directory in which to store the files :return: The full name and path of the downloaded file """ - return _sb.download_file(url, local_filename, destination) + return self._sb.download_file(url, local_filename, destination) def getItemFiles(self, item, destination='.'): """Download the individual files attached to a ScienceBase Item @@ -203,14 +224,14 @@ def getItemFiles(self, item, destination='.'): :param destination: Destination directory in which to store the files :return: The ScienceBase Catalog file info JSON response """ - return _sb.get_item_files(item, destination) + return self._sb.get_item_files(item, destination) def getMyItemsId(self): """Get the ID of the logged-in user's My Items :return: The ScienceBase Catalog Item ID of the logged in user's My Items folder """ - return _sb.get_my_items_id() + return self._sb.get_my_items_id() def getChildIds(self, parent_id): """Get IDs of all immediate children for a given parent @@ -218,7 +239,7 @@ def getChildIds(self, parent_id): :param parentid: ScienceBase Catalog Item ID of the item for which to look for children :return: A List of ScienceBase Catalog Item IDs of the direct children """ - return _sb.get_child_ids(parent_id) + return self._sb.get_child_ids(parent_id) def getNetCDFOPeNDAPInfoFacet(self, url): """Given an OPeNDAP URL, create a NetCDFOPeNDAP facet from the return data @@ -226,7 +247,7 @@ def getNetCDFOPeNDAPInfoFacet(self, url): :param url: OPeNDAP URL to query :return: ScienceBase Catalog Item facet JSON with information on the OPeNDAP service """ - return _sb.get_NetCDFOPeNDAP_info_facet(url) + return self._sb.get_NetCDFOPeNDAP_info_facet(url) def findSbItems(self, params): """Search for ScienceBase items @@ -234,7 +255,7 @@ def findSbItems(self, params): :param params: ScienceBase Catalog search parameters :return: ScienceBase Catalog search response object containing the next page of results for the search """ - return _sb.find_items(params) + return self._sb.find_items(params) def findSbItemsByAnytext(self, text): """Search for ScienceBase items by free text @@ -242,7 +263,7 @@ def findSbItemsByAnytext(self, text): :param text: Text to search for in all searchable fields of ScienceBase Catalog Items :return: ScienceBase Catalog search response containing results """ - return _sb.find_items_by_any_text(text) + return self._sb.find_items_by_any_text(text) def findSbItemsByTitle(self, text): """Search for ScienceBase items by title @@ -250,7 +271,7 @@ def findSbItemsByTitle(self, text): :param text: Text to search for in the title field :return: ScienceBase Catalog search response containing results """ - return _sb.find_items_by_title(text) + return self._sb.find_items_by_title(text) def getJson(self, response): """Get the JSON response of the given URL @@ -258,4 +279,36 @@ def getJson(self, response): :param url: URL to request via HTTP GET :return: JSON response """ - return _sb.get_json(response) \ No newline at end of file + return self._sb.get_json(response) + + def next(self, items): + """Get the next set of items from the search + + :param items: ScienceBase Catalog search response object from a prior search + :return: ScienceBase Catalog search response object containing the next page of results for the search + """ + return self._sb.next(items) + + def previous(self, items): + """Get the previous set of items from the search + + :param items: ScienceBase Catalog search response object from a prior search + :return: ScienceBase Catalog search response object containing the previous page of results for the search + """ + return self._sb.previous(items) + + def get(self, url): + """Get the text response of the given URL + + :param url: URL to request via HTTP GET + :return: TEXT response + """ + return self._sb.get(url) + + def debug(self): + """Turn on HTTP logging for debugging purposes. + This enables debugging at httplib level (requests->urllib3->httplib) + You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA. + The only thing missing will be the response.body which is not logged. + """ + self._sb.debug() diff --git a/setup.py b/setup.py index 655c20b..25c54b6 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from distutils.core import setup setup(name='pysb', - version='1.4.1', + version='1.5.0', packages=['pysb',], description="Python ScienceBase Utilities", author="ScienceBase Development Team",