import mdcs

"""
Explanation: Populate local MDCS instance with student data and metadata
Import MDCS API tool module
End of explanation
"""


user='admin'
pswd='admin'
host='http://127.0.0.1:8000'
template_name='DiffusionDemo'

"""
Explanation: Host and user information
End of explanation
"""


name_list=[
    "GE-DiffusionCouple-IN100-IN718",
    "GE-DiffusionCouple-IN718-R95",
    "GE-DiffusionCouple-R95-R88",
    "GE-DiffusionCouple-R88-IN100"
]

"""
Explanation: List of file prefixes for micrograph images and XML metadata
End of explanation
"""


for name in name_list:
    xml_name=name+".xml"
    tif_name=name+".tif"
    
    print "Uploading:",tif_name
    url = mdcs.blob.upload(tif_name,host,user,pswd)
    
    print "Reading:",xml_name
    with open(xml_name, 'r') as f: 
        content = f.read()
    content = content.replace("http://127.0.0.1:8000/rest/blob?id=REPLACE-ME-BLOB-ID",url)
    
    print "Uploading:",xml_name
    response = mdcs.curate_as(xml_name,name,host,user,pswd,template_title=template_name,content=content)
    print "Response:",response

"""
Explanation: For each name in the list:

Upload micrograph
Read XML metadata
Replace generic URL with unique URL for micrograph
Upload XML metadata record
End of explanation
"""


