#!python3 ''' Created on Sep 21, 20-16 author: tpweis file name: manifesttest.py This function writes a manifest file for sleds. The purpose if testing the writemanifest algorithm and results. ''' import os, time import datetime import subprocess import shutil import subprocess import sys import json def writemanifest(target_dir, fullname): "function writemanifest" filename, file_ext = os.path.splitext(fullname) manifest = dict() originator = dict() originator["ipAddress"] = "127.0.0.1" originator["jobId"] = filename packages = dict() packages["package_name"] = filename packages["files"] = [fullname] manifest["data"] = {} createtime = datetime.datetime.utcnow().isoformat() manifest["dateCreated"] = createtime manifest["jobType"] = "loan" manifest["originator"] = originator manifest["packages"] = [packages] manifest["type"] = "SNT_JOB" manifest["workOrderName"] = "BENCHMARK_TEST_WORKORDER" # Save the manifest in the target directory newname = os.path.normpath(target_dir + "/" +filename + ".json") print("Manifest: " + newname) f = open(newname, 'w') json.dump(manifest, f, sort_keys=True, indent=4) f.close() print(json.dumps(manifest, sort_keys = True, indent=4)) # We added the source_dir to the manifest file open, to ensure it is written in # the correct location. However, subsequent processing of the manifest file will # control the directories. Thuse, return only the basename. return filename + ".json" def main(): "function main" arglist = sys.argv[1:] if(len(arglist)< 1): print("Missing Target Directory argument. Try again") sys.exit(3) else: TARGETdir = arglist[0] if(len(arglist) < 2): print("Missing filename argument. Try again") sys.exit(4) else: filename =arglist[1] manifest = writemanifest(TARGETdir,filename) print("Saved new manifest as " + manifest) sys.exit(0) if __name__ == '__main__': # execute only if run as a script main()