Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ENCODE-DCC/submission_sample_scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
vsmalladi committed Oct 2, 2013
2 parents 6724130 + f28a25f commit 86d3366
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
29 changes: 17 additions & 12 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,19 @@ def WriteJSON(new_object,object_file):
# run for each object in objects folder
for object_filename in object_filenames:

# define object parameters
object_type,object_name = object_filename.strip('.json').split('-')
object_file = ('objects/' + object_type + '-' + object_name + '.json')
# define object parameters. SHOULD NOT RELY ON FILENAME. NEED WAY TO IDENTIFY OBJECT TYPE/NAME BY REVIEWING DATA
object_type,object_name = object_filename.strip('.json').split(';')
object_file = ('objects/' + object_type + ';' + object_name + '.json')
object_id = ('/' + object_type + 's/' + object_name + '/')

# load object
json_object = open(object_file)
new_object = json.load(json_object)
json_object.close()


#check to see if object already exists

# check to see if object already exists
# PROBLEM: SHOULD CHECK UUID AND NOT USE ANY SHORTCUT METADATA THAT MIGHT NEED TO CHANGE
# BUT CAN'T USE UUID IF NEW... HENCE PROBLEM
old_object = get_ENCODE(object_id)

# if object is not found, verify and post it
Expand All @@ -96,18 +97,22 @@ def WriteJSON(new_object,object_file):
# get relevant schema
object_schema = get_ENCODE(('/profiles/' + object_type + '.json'))

# test the new object. SHOULD HANDLE ERRORS GRACEFULLY
if jsonschema.validate(new_object,object_schema):

# test the new object. SHOULD HANDLE ERRORS GRACEFULLY
try:
jsonschema.validate(new_object,object_schema)
# did not validate
except Exception as e:
print('Validation of ' + object_id + ' failed.')
print(e)

# did validate
else:
# inform the user of the success
print('Validation of ' + object_id + ' succeeded.')

# post the new object(s). SHOULD HANDLE ERRORS GRACEFULLY
response = new_ENCODE('/users/',new_object)

# inform the user of the failure.
else:
print('Validation of ' + object_id + ' failed.')

# if object is found, check for differences and patch it if needed.
else:
Expand Down

0 comments on commit 86d3366

Please sign in to comment.