Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump future from 0.18.2 to 0.18.3 #42

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ colorlog==4.4.0
coverage==5.3
flake8==3.8.4
flake8-polyfill==1.0.2
future==0.18.2
future==0.18.3
gitdb==4.0.5
GitPython==3.1.11
idna==2.10
Expand Down
149 changes: 102 additions & 47 deletions sciencebasepy/SbSession.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,60 +1273,115 @@ def remove_acl_role_write(self, role_name, item_id):
"""
return self._update_acls(self.ACL_REMOVE, self.ACL_WRITE, "ROLE:%s" % role_name, item_id)

def publish_to_public_bucket(self, item_id):
""" call publish end point from catalog
this should publish all files to public s3 publish bucket
TODO: Fix documentation
"""
return self._session.post(self._base_item_url + item_id + "/publishFilesToS3")

def publish_array_to_public_bucket(self, item_id, filenames):
""" publish a list of files on an item to the public s3 publish bucket
"""publish a list of files on an item from the public s3 publish bucket

:param item_id: The ID of the ScienceBase item
:param filenames: a list of filenames to be published
:param filenames: a list of filenames to be unpublished
"""
for filename in filenames:
if not self._sbSessionEx.is_logged_in():
print(f'{self._username} not logged into Keycloak -- cloud services not available')
else:
item = self.get_item(item_id)
pathOnDisk = ""
cuid = ""

if 'files' in item:
for f in item['files']:
if 'name' in f:
if f['name'] == filename:
if 'pathOnDisk' in f:
pathOnDisk = f['pathOnDisk']
if 'cuid' in f:
cuid = f['cuid']
break
if pathOnDisk == "":
if 'facets' in item:
for facet in item['facets']:
if 'files' in facet:
for f in facet['files']:
if f['name'] == filename:
if 'pathOnDisk' in f:
pathOnDisk = f['pathOnDisk']
if 'cuid' in f:
cuid = f['cuid']
break

publishDict = {
"filename": filename,
"actionValue": "publish",
"cuid": cuid,
"pathOnDisk": pathOnDisk
}

response = self._session.post(self._base_item_url + item_id + "/publishSingleFileToS3",
data=json.dumps(publishDict))
print(response)
for filename in filenames:
cuid = ""
key = ""
pathOnDisk = ""

if response:
print("Successfully published filename " + filename + " to public S3 bucket")
else:
print("Failed to publish file " + filename + " to public S3 bucket")
if 'files' in item:
for f in item['files']:
if 'name' in f:
if f['name'] == filename:
if 'pathOnDisk' in f:
pathOnDisk = f['pathOnDisk']
if 'cuid' in f:
cuid = f['cuid']
if 'key' in f:
key = f['key']
break

if cuid == "":
if 'facets' in item:
for facet in item['facets']:
if 'files' in facet:
for f in facet['files']:
if f['name'] == filename:
if 'pathOnDisk' in f:
pathOnDisk = f['pathOnDisk']
if 'cuid' in f:
cuid = f['cuid']
if 'key' in f:
key = f['key']
break

if cuid is None:
cuid = ""

input = {"itemId": item_id, "filename": filename, "action": "publish", "pathOnDisk": pathOnDisk}

response = self._sbSessionEx.publish_to_public_bucket(input)
print(response)
if response:
print("Successfully published filename " + filename + " from public S3 bucket")
else:
print("Failed to publish file " + filename + " from public S3 bucket")


# def publish_to_public_bucket(self, item_id):
# """ call publish end point from catalog
# this should publish all files to public s3 publish bucket
# TODO: Fix documentation
# """
# return self._session.post(self._base_item_url + item_id + "/publishFilesToS3")

# def publish_array_to_public_bucket(self, item_id, filenames):
# """ publish a list of files on an item to the public s3 publish bucket

# :param item_id: The ID of the ScienceBase item
# :param filenames: a list of filenames to be published
# """
# for filename in filenames:
# item = self.get_item(item_id)
# pathOnDisk = ""
# cuid = ""

# if 'files' in item:
# for f in item['files']:
# if 'name' in f:
# if f['name'] == filename:
# if 'pathOnDisk' in f:
# pathOnDisk = f['pathOnDisk']
# if 'cuid' in f:
# cuid = f['cuid']
# break
# if pathOnDisk == "":
# if 'facets' in item:
# for facet in item['facets']:
# if 'files' in facet:
# for f in facet['files']:
# if f['name'] == filename:
# if 'pathOnDisk' in f:
# pathOnDisk = f['pathOnDisk']
# if 'cuid' in f:
# cuid = f['cuid']
# break

# publishDict = {
# "filename": filename,
# "actionValue": "publish",
# "cuid": cuid,
# "pathOnDisk": pathOnDisk
# }

# response = self._session.post(self._base_item_url + item_id + "/publishSingleFileToS3",
# data=json.dumps(publishDict))
# print(response)

# if response:
# print("Successfully published filename " + filename + " to public S3 bucket")
# else:
# print("Failed to publish file " + filename + " to public S3 bucket")

def unpublish_array_from_public_bucket(self, item_id, filenames):
"""unpublish a list of files on an item from the public s3 publish bucket
Expand Down