Skip to content

Commit

Permalink
get the rest of create sample data working #43
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed May 10, 2024
1 parent 789c940 commit 8bfeea4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions create_sample_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyDataverse.api import NativeApi
from pyDataverse.models import Datafile
import json
import dvconfig
import os
Expand All @@ -16,15 +17,13 @@
api = NativeApi(base_url, api_token)
print(api.get_info_version())
# TODO limit amount of recursion
def check_dataset_lock(dataset_dbid):
query_str = '/datasets/' + str(dataset_dbid) + '/locks'
params = {}
resp = api.get_request(query_str, params=params, auth=True)
def check_dataset_lock(dataset_pid):
resp = api.get_dataset_lock(dataset_pid)
locks = resp.json()['data']
if (locks):
print('Lock found for dataset id ' + str(dataset_dbid) + '... sleeping...')
print('Lock found for dataset id ' + str(dataset_pid) + '... sleeping...')
time.sleep(2)
check_dataset_lock(dataset_dbid)
check_dataset_lock(dataset_pid)
resp = api.get_dataverse(':root')
buff = StringIO("")
if (resp.status_code == 401):
Expand Down Expand Up @@ -72,12 +71,15 @@ def check_dataset_lock(dataset_dbid):
relpath = os.path.relpath(filepath,files_dir)
# "directoryLabel" is used to populate "File Path"
directoryLabel, filename = os.path.split(relpath)
resp = api.upload_file(dataset_pid, "'" + filepath + "'")
df = Datafile()
df_filename = filepath
df.set({"pid": dataset_pid, "filename": df_filename})
resp = api.upload_datafile(dataset_pid, df_filename, df.json())
print(resp)
file_id = resp['data']['files'][0]['dataFile']['id']
file_id = resp.json()['data']['files'][0]['dataFile']['id']
## This lock check and sleep is here to prevent the dataset from being permanently
## locked because a tabular file was uploaded first.
check_dataset_lock(dataset_dbid)
check_dataset_lock(dataset_pid)
# TODO: Think more about where the description comes from. A "sidecar" file as proposed at https://github.com/IQSS/dataverse/issues/5924#issuecomment-499605672 ?
# L.A.: I implemented something along these lines - an (optional) directory called ".filemetadata"
# in the dataset directory, where files containing extra json filemetadata records may be
Expand Down

0 comments on commit 8bfeea4

Please sign in to comment.