import os LOG = system.util.logger("HMI Setup") def upload(): system.gui.messageBox("Please provide the file location of the Description of Operations...") path = system.file.openFile('pdf') if path == None: system.gui.messageBox("No path given!") else: # Load file contents as csv: tags = {} try: project = system.util.getProjectName() print "Opening file..." with open(path, 'rb') as pdf: payload = { "data": pdf.read() } print "Uploading file..." system.util.sendMessage(project, "setup-doo", payload, "G") print "Done!" except: # In case the csv file is corrupt or in a bad format, ignore it: system.gui.messageBox("Failed to open file!") def store(data): path = os.path.join(os.getcwd(), "webserver", "webapps", "main", "pdfs") if not os.path.exists(path): os.makedirs(path) path = os.path.join(path, "Description of Operations.pdf") with open(path, 'wb') as pdf: pdf.write(data) LOG.info("Uploaded new Description of Operations: /pdfs/Description of Operations.pdf")