def processSerialPort(): """ This function handles serial port and listens for data arriving from Arduino uController. The function reads configuration file to obtain configuration for opening the serial port. Once serial port is opened it listens for incoming messages. When incoming message is 1 that means that Arduino detected laser interruption. This function then notifies the data module via the laserRegistration() function. If serial port is down for some reason (i.e. unplugged cable) the function attempts to re-read the config file and reopen serial connection, notifying the user in the web ui. This function is meant to be run in thread. :return: None """ global _serial_ok while True: try: while True: conf.read_config_file() ARDUINO_COM_PORT = conf.ARDUINO_COM_PORT ARDUINO_BAUD_RATE = conf.ARDUINO_BAUD_RATE ser = serial.Serial(ARDUINO_COM_PORT, ARDUINO_BAUD_RATE) _serial_ok = True while True: result = (int(ser.readline())) if result == 1: data.laserRegistration() except KeyboardInterrupt: return except: time.sleep(1) _serial_ok = False
def __init__(self, command=None): GObject.GObject.__init__(self) config.read_config_file() self.music_list = [] self.swift = Swift() self.dbc = config.prefs['dbc'] # database container self.dbo = config.prefs['dbo'] # database object if command != "generate-new-db": if not self.swift.container_exists(self.dbc): exit("There should be a container called '%s'" % self.dbc) head, contents = self.swift.get_db_file(self.dbc, self.dbo) db = open(self.dbo, "w") db.write(contents) db.close() self.sqlconn = sqlite3.connect(self.dbo) with self.sqlconn: self.sqlcur = self.sqlconn.cursor() self.sqlcur.execute('SELECT SQLITE_VERSION()') data = self.sqlcur.fetchone() print "SQLite version: %s" % data
def __init__(self, command=None): Gst.init(None) # Move somewhere more particular config.read_config_file() self.url = config.prefs['url'] self.authurl = config.prefs['url'] + config.prefs['authurl'] self.user = config.prefs['user'] self.key = config.prefs['key'] self.temp_url_key = config.prefs['temp_url_key'] self.conn = client.Connection(authurl=self.authurl, user=self.user, key=self.key, retries=5, auth_version='1.0') print "Connection successful to the account: ", self.conn.user
def __init__(self, command=None): Gst.init(None) # Move somewhere more particular config.read_config_file() self.url = config.prefs['url'] self.authurl = config.prefs['url'] + config.prefs['authurl'] self.user = config.prefs['user'] self.key = config.prefs['key'] self.temp_url_key = config.prefs['temp_url_key'] self.conn = client.Connection( authurl=self.authurl, user=self.user, key=self.key, retries=5, auth_version='1.0') print "Connection successful to the account: ", self.conn.user
try: o_idx = sys.argv.index('-out_dir') _output_path = sys.argv[o_idx + 1] except (ValueError, IndexError): _output_path = None return _config_file, _input, _output_path if __name__ == '__main__': config_file, input_arg, output_path = __get_arguments__() logging.config.fileConfig(fname=config_file) params = read_config_file(_config_file=config_file) logging.info(str(params)) commands, abs_output_path = generate_parser_commands(_params=params) logging.info('commands = ' + str(commands)) if sys.platform.find('win') != -1: platform = 'win' elif sys.platform.find('linux') != -1: platform = 'linux' else: logging.info('OS unsupported') sys.exit() logging.info('platform = ' + platform)
def main(): args = parse_config() supported_backbones = [ 'resnet', 'vgg', 'inception', 'xception', 'efficientnet' ] # create object that stores backbone information if "resnet" in args.backbone: backbone = ResNetBackbone(args.backbone) elif "vgg" in args.backbone: backbone = VGGBackbone(args.backbone) elif "inception" in args.backbone: backbone = InceptionBackbone(args.backbone) elif "xception" in args.backbone: backbone = XceptionBackbone(args.backbone) elif "efficientnet" in args.backbone: backbone = EfficientNetBackbone(args.backbone) else: raise ValueError( f"Backbone '{args.backbone}' currently not supported. Supported backbones: {supported_backbones}" ) # # make sure keras and tensorflow are the minimum required version # check_keras_version() # check_tf_version() # optionally choose specific GPU if args.gpu is not None: setup_gpu(args.gpu) if not "config" in dir(args): args.config = None # # optionally load config parameters elif args.config and args.anchor_generation_method == "multiple": args.config = read_config_file(args.config) # create the generators train_generator, validation_generator = create_generator( args, backbone.preprocess_image) # create the model if args.snapshot is not None: print('Loading model, this may take a second...') model = load_model(args.snapshot, backbone_name=args.backbone) training_model = model # anchor_params = None if args.config and 'anchor_parameters' in args.config: anchor_params = parse_anchor_parameters(args.config) else: anchor_params = get_anchor_config(args) prediction_model = retinanet_bbox(model=model, anchor_params=anchor_params) else: weights = args.weights # default to imagenet if nothing else is specified if weights is None and args.imagenet_weights: weights = ResNetBackbone.download_imagenet() print('Creating model, this may take a second...') model, training_model, prediction_model = create_models( args=args, backbone_retinanet=backbone.retinanet, num_classes=train_generator.num_classes(), weights=weights, multi_gpu=args.multi_gpu, freeze_backbone=args.freeze_backbone, lr=args.lr, config=args.config, backbone_name=args.backbone) # layer_dict = dict([(layer.name, layer) for layer in model.layers]) # print model summary # print(model.summary()) # this lets the generator compute backbone layer shapes using the actual backbone model if 'vgg' in args.backbone or 'densenet' in args.backbone: train_generator.compute_shapes = make_shapes_callback(model) if validation_generator: validation_generator.compute_shapes = train_generator.compute_shapes # create the callbacks callbacks = create_callbacks( model, training_model, prediction_model, validation_generator, args, ) if not args.compute_val_loss: validation_generator = None # start training return training_model.fit_generator( generator=train_generator, steps_per_epoch=args.steps, epochs=args.epochs, verbose=1, callbacks=callbacks, workers=args.workers, use_multiprocessing=args.multiprocessing, max_queue_size=args.max_queue_size, validation_data=validation_generator, initial_epoch=args.initial_epoch)
builder.build_component(arguments.component) def noop(*__): pass def run(arguments): runner = { 'list': list_version, 'build': build, 'package': package, 'switch': switch_version } runner.get(arguments.action, noop)(arguments) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('action') parser.add_argument('component') parser.add_argument('-c', '--config', dest='config_file') parser.add_argument('--to', dest='target_version') arguments = parser.parse_args() if arguments.config_file is not None: config.read_config_file(arguments.config_file) else: config.read_config_file() run(arguments);
def get_configurations(): # read the configurations (file names, values, etc.) config = read_config_file("config.ini") return config
# === MAIN ==================================================================== if __name__ == '__main__': app = QApplication(sys.argv) # Splash screen pixmap = QPixmap(os.path.join(RESOURCE_PATH, "splash.jpg")) splash = QSplashScreen(pixmap) splash.show() splash.showMessage("Loading configs ... ") # Import custom libraries sys.path.append(LIBRARY_PATH) from config import read_config_file from console import Console c = Console() configs = read_config_file(CONFIG_FILE) if len(configs) > 0: logger.info("Read %d configs from %s" %(len(configs), CONFIG_FILE )) else: message = "No configs read from %s" %CONFIG_FILE c.write_warning(message) logger.warning(message) # app.processEvents() # Show the main window and close the splash screen windowMain = MainWindow() splash.finish(windowMain) windowMain.show() # Application executions and clean exit sys.exit(app.exec_())
def noop(*__): pass def run(arguments): runner = { 'list': list_version, 'build': build, 'package': package, 'switch': switch_version } runner.get(arguments.action, noop)(arguments) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('action') parser.add_argument('component') parser.add_argument('-c', '--config', dest='config_file') parser.add_argument('--to', dest='target_version') arguments = parser.parse_args() if arguments.config_file is not None: config.read_config_file(arguments.config_file) else: config.read_config_file() run(arguments)