Beispiel #1
0
    def do_POST(self):
        """Handles a POST request, which is assumed to be from the GUI."""
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={
                                    'REQUEST_METHOD': 'POST',
                                    'CONTENT_TYPE':
                                    self.headers['Content-Type']
                                })

        outfiles = dict()
        for key in ['outfile_settings', 'outfile_data', 'outfile_scripts']:
            outfiles[key[8:]] = "genxml/" + form.getfirst(key)

        # Settings
        sroot = ETree.Element('settings')
        for key in form:
            if (key.startswith('/')):
                for path in key.split(','):
                    addXml(sroot, path, form.getfirst(key))
        stree = ETree.ElementTree(element=sroot)
        with open(outfiles['settings'], 'w') as sfile:
            stree.write(sfile, encoding='utf-8', xml_declaration=True)

        # Data
        with open(outfiles['data'], 'w') as dfile:
            fileitemlist = form['data_files']
            if (not isinstance(fileitemlist, list)):
                fileitemlist = [fileitemlist]
            filelist = []
            for fileitem in fileitemlist:
                filelist.append(fileitem.file)
            if (form.getfirst('data_file_type') == 'csv'):
                csvToXmlData(filelist, dfile)
            elif (form.getfirst('data_file_type') == 'xml'):
                combineXmlData(filelist, dfile)

        # Scripts
        with open(outfiles['scripts'], 'w') as cfile:
            scriptnames = []
            for key in form:
                if (key.startswith('script_')):
                    scriptnames.append(key[7:])
            builtinScripts(scriptnames, cfile)

        try:
            self.send_response(200)
            self.send_header('Content-type', 'image/svg+xml')
            self.end_headers()
            getChart(None, outfiles['settings'],
                     outfiles['data'], outfiles['scripts'], self.wfile,
                     form.getfirst('type'), False, ',,,')
        except:
            self.wfile.write("""<?xml version='1.0' encoding='utf-8'?>
			<svg verson='1.1' xmlns='http://www.w3.org/2000/svg'>
				<text x='10' y='25'>An error occured during chart generation. Please use your browser's Back
				button to return to the previous page and make sure that all input is valid.</text>
			</svg>
			""")
Beispiel #2
0
    def do_GET(self):

        # Parse the query out of the path
        query = urlparse.urlparse(self.path).query
        form = urlparse.parse_qs(query)

        # Make sure at least some input is specified
        if "infile" not in form and "settings" not in form and "data" not in form:
            self.send_response(200)
            self.send_header('Content-type', 'text/html')
            self.end_headers()

            getGUI(self.wfile)
            return
        else:
            if "infile" in form:
                infile = form["infile"][0]
            else:
                infile = None

            if "settings" in form:
                settings = form["settings"][0]
            else:
                settings = None

            if "data" in form:
                data = form["data"][0]
            else:
                data = None

            if "scripts" in form:
                scripts = form["scripts"][0]
            else:
                scripts = None

            if "type" in form:
                type = form["type"][0]
            else:
                type = 'scatter'

            if "range" in form:
                range = form["range"][0]
            else:
                range = ',,,'

            pretty = "pretty" in form

            # Send success headers and the SVG MIME type
            self.send_response(200)
            self.send_header('Content-type', 'image/svg+xml')
            self.end_headers()

            # Gets the chart and writes directly to the client
            getChart(infile, settings, data, scripts, self.wfile, type, pretty,
                     range)
Beispiel #3
0
	def do_GET(self):
		
		# Parse the query out of the path
		query = urlparse.urlparse(self.path).query
		form = urlparse.parse_qs(query)
		
		# Make sure at least some input is specified
		if "infile" not in form and "settings" not in form and "data" not in form:
			self.send_response(200)
			self.send_header('Content-type','text/html')
			self.end_headers()

			getGUI(self.wfile)
			return
		else:
			if "infile" in form:
				infile = form["infile"][0]
			else:
				infile = None
			
			if "settings" in form:
				settings = form["settings"][0]
			else:
				settings = None
			
			if "data" in form:
				data = form["data"][0]
			else:
				data = None
				
			if "scripts" in form:
				scripts = form["scripts"][0]
			else:
				scripts = None
			
			if "type" in form:
				type = form["type"][0]
			else:
				type = 'scatter'
			
			if "range" in form:
				range = form["range"][0]
			else:
				range = ',,,'
			
			pretty = "pretty" in form
			
			# Send success headers and the SVG MIME type
			self.send_response(200)
			self.send_header('Content-type', 'image/svg+xml')
			self.end_headers()
			
			# Gets the chart and writes directly to the client
			getChart(infile, settings, data, scripts, self.wfile, type, pretty, range)
Beispiel #4
0
	def do_POST(self):
		"""Handles a POST request, which is assumed to be from the GUI."""
		form = cgi.FieldStorage(fp=self.rfile,headers=self.headers,
								environ={'REQUEST_METHOD':'POST','CONTENT_TYPE':self.headers['Content-Type']})

		outfiles = dict()
		for key in ['outfile_settings','outfile_data','outfile_scripts']:
			outfiles[key[8:]] = "genxml/" + form.getfirst(key)

		# Settings
		sroot = ETree.Element('settings')
		for key in form:
			if (key.startswith('/')):
				for path in key.split(','):
					addXml(sroot,path,form.getfirst(key))
		stree = ETree.ElementTree(element=sroot)
		with open(outfiles['settings'],'w') as sfile:
			stree.write(sfile,encoding='utf-8',xml_declaration=True)

		# Data
		with open(outfiles['data'],'w') as dfile:
			fileitemlist = form['data_files']
			if (not isinstance(fileitemlist,list)):
				fileitemlist = [fileitemlist]
			filelist = []
			for fileitem in fileitemlist:
				filelist.append(fileitem.file)
			if (form.getfirst('data_file_type') == 'csv'):
				csvToXmlData(filelist,dfile)
			elif (form.getfirst('data_file_type') == 'xml'):
				combineXmlData(filelist,dfile)

		# Scripts
		with open(outfiles['scripts'],'w') as cfile:
			scriptnames = []
			for key in form:
				if (key.startswith('script_')):
					scriptnames.append(key[7:])
			builtinScripts(scriptnames,cfile)

		try:
			self.send_response(200)
			self.send_header('Content-type','image/svg+xml')
			self.end_headers()
			getChart(None, outfiles['settings'], outfiles['data'], outfiles['scripts'], self.wfile, form.getfirst('type'), False, ',,,')
		except:
			self.wfile.write("""<?xml version='1.0' encoding='utf-8'?>
			<svg verson='1.1' xmlns='http://www.w3.org/2000/svg'>
				<text x='10' y='25'>An error occured during chart generation. Please use your browser's Back
				button to return to the previous page and make sure that all input is valid.</text>
			</svg>
			""")