def main(): args = parse_args() if args.input: lat = load_lattice(args.input) else: lat = generate_lattice(args.generator, args.generator_args) if args.labels: labelLat = fileio.read(args.labels) if not labelLat.check_consistency(): print("Label lattice is inconsistent") sys.exit(1) labels = labelLat.label_graph(args.method) if args.plot_labels: show_lattice(labelLat, labels) lat.relabel(labels) if args.plot: if args.labels: show_lattice(lat, labels) else: show_lattice(lat, np.arange(len(lat))) if args.plot_adjacency: show_adjacency_matrix(lat) if args.output: fileio.write(args.output, lat) if args.plot or args.plot_labels or args.plot_adjacency: plt.show()
def upload_file(): upload_directory = request.form.get('upload_directory') uploaded_file = request.files['uploaded_file'] uploaded_file_path = upload_directory + uploaded_file.filename uploaded_file_extension = os.path.splitext(uploaded_file.filename)[1] uploaded_file_content = uploaded_file.read() if not uploaded_file: return expected_response({ 'success': False, 'message': 'Please choose .json or .py file to upload' }) if uploaded_file_extension != ".py" and uploaded_file_extension != ".json": return expected_response({ 'success': False, 'message': "Can't upload this file. Currently only supports .json or .py file" }) upload_status, upload_message = fileio.write(uploaded_file_path, uploaded_file_content) if upload_status is False: return expected_response({'success': False, 'message': upload_message}) events.master_new_file_uploaded.fire( new_file={ "full_path": uploaded_file_path, "name": uploaded_file.filename, "content": uploaded_file_content }) runners.locust_runner.reload_tests() return expected_response({'success': True, 'message': ""})
def worker(self): while True: msg = self.client.recv() if msg.type == "hatch": self.client.send(Message("hatching", None, self.client_id)) job = msg.data self.hatch_rate = job["hatch_rate"] #self.num_clients = job["num_clients"] self.num_requests = job["num_requests"] self.host = job["host"] self.client_index = job["client_index"] self.hatching_greenlet = gevent.spawn( lambda: self.start_hatching(locust_count=job["num_clients" ], hatch_rate=job["hatch_rate"])) elif msg.type == "stop": self.stop() self.client.send( Message("client_stopped", None, self.client_id)) self.client.send(Message("client_ready", None, self.client_id)) elif msg.type == "quit": logger.info("Got quit message from master, shutting down...") self.stop() self.greenlet.kill(block=True) elif msg.type == "switch": logger.info("Test file switch to %s", self.available_locustfiles[msg.data].values()) self.locust_classes = self.available_locustfiles[ msg.data].values() elif msg.type == "config": logger.info( "Got new config from master, updating this slave config") fileio.write(configuration.CONFIG_PATH, msg.data['config']) events.master_new_configuration.fire( new_config=msg.data['config']) elif msg.type == "python_file": logger.info( "Uploaded test file from master detected, writing now") new_file = msg.data upload_status, upload_message = fileio.write( new_file['full_path'], new_file['content']) if upload_status is False: logger.info("error while creating new file: " + upload_message) self.reload_tests()
def save_json(): assert request.method == "POST" config_json = str(request.form["final_json"]) try: success, message = fileio.write(configuration.CONFIG_PATH, config_json) events.master_new_configuration.fire(new_config=config_json) response = make_response( json.dumps({ 'success': success, 'message': message })) except Exception as err: response = make_response( json.dumps({ 'success': success, 'message': message })) response.headers["Content-type"] = "application/json" return response
#!/usr/bin/env python from event import Event from fileio import write import gzip f = gzip.open("test.odf.gz","wb") ev = Event() ev.runID = 1009322 ev.year = 2007 ev.startTime = long(10908290809370) ev.eventLength = 100000. ev.triggers = [(10000.00,"BLEH")] ev.hits = [(1.0,1000.4,100.,-100.,255.)] write(f,ev)
def log(path='../logs/', message='', level='Warning'): mkdir(path) ctime = time.time() write(path + level + '/', format_time(ctime, "%Y-%m-%d"), format_time(ctime) + " " + message + "\r\n", 'a')
print('Travel undefined') continue follower.update(args.flat, args.offset, args.fradius) cam.gen(args.radius, args.ccw) elif args.target == 'conj': if not cam(): print('Cam undefined') continue cam.gen_conjugated(args.breadth) # LOAD elif args.command == 'load': if args.target == 'travel': travel.load(args.file) elif args.target == 'cam': fileio.write(args.file, travel.x, travel.y) # SAVE elif args.command == 'save': if args.target == 'travel': if not travel(): print('Travel undefined') continue fileio.write(args.file, travel.x, travel.y) elif args.target == 'cam': if not cam(): print('Cam undefined') continue fileio.write(args.file, cam.pcoords[0], cam.pcoords[1]) # DRAW
def _write_json(data, fname): text = json.dumps(data, indent=2) fileio.write(text, fname)