def main(): arguments = compile_arguments() if arguments.list_modules: list_modules() sys.exit(0) if os.geteuid() != 0: print_error("You must run this script as root!") print_error("Run: sudo -E {0}".format(os.path.basename(__file__))) sys.exit(1) if os.getenv('PWD') is None: print_error( "You have to run this script with 'sudo -E'. You are probably missing the -E parameter." ) sys.exit(1) config_file = arguments.config if arguments.generate: conf = config.Config(None) conf.generate_config(config_file) print_success(f"Configuration file generated: ./{config_file}") sys.exit(0) conf = config.Config(config_file) conf.load_config() conf.argument_overwrite(arguments) install = installer.Installer(conf) if arguments.run_module is None: install.run() else: install.run_one(arguments.run_module)
def main(): config_file_location = None if len(sys.argv) == 2: if sys.argv[1] == '-g': conf = config.Config(None) conf.generate_config('example_config.ini') print_success("Configuration file generated: ./example_config.ini") sys.exit(0) else: config_file_location = sys.argv[1] conf = config.Config(config_file_location) conf.load_config() install = installer.Installer(conf) install.run()
def __init__(self, pin_motor_A, pin_motor_B, channel_speed, speed=50, busnum=None): config = config_i.Config(self.CONFIG_FILE()) self.pin_motor_A = pin_motor_A self.pin_motor_B = pin_motor_B self.channel_speed = channel_speed self.speed = int(config.get("start_speed", "60")) if busnum == None: self.pwm = pca9685.PWM() else: self.pwm = pca9685.PWM(bus_number=busnum) self.pwm.frequency = int(config.get("start_frequency", "60")) GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(self.pin_motor_A, GPIO.OUT) GPIO.setup(self.pin_motor_B, GPIO.OUT)
def __init__(self, name, exec_qtlab_name, **kw): Instrument.__init__(self, name) self._exec_qtlab_name = exec_qtlab_name ins_pars = {'measurement_name' : {'type':types.StringType,'val':'','flags':Instrument.FLAG_GETSET}, 'is_running' : {'type':types.BooleanType,'val':False,'flags':Instrument.FLAG_GETSET}, 'data_path' : {'type':types.StringType,'val':'','flags':Instrument.FLAG_GETSET}, 'script_path' : {'type':types.StringType,'val':'','flags':Instrument.FLAG_GETSET}, 'live_plot_interval' : {'type':types.FloatType, 'val':2,'flags':Instrument.FLAG_GETSET}, 'do_live_plotting' : {'type':types.BooleanType, 'val':False,'flags':Instrument.FLAG_GETSET}, 'completed_reps' : {'type':types.IntType, 'val':0,'flags':Instrument.FLAG_GETSET} } instrument_helper.create_get_set(self,ins_pars) self.add_function('execute_script') self.add_function('get_measurement_params') self.add_function('set_measurement_params') self.add_function('start_adwin_live_plotting') self.add_function('get_adwin_data') self.add_function('plot_adwin_data') self.add_function('stop_adwin_live_plotting') self._measurement_params = {} # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def update_wpcfg(new_position, config_dir=r'D:\measuring\user\config'): if not (os.path.isfile(os.path.join(config_dir, 'wp_position.cfg'))): wpcfg = config.create_config( os.path.join(config_dir, 'wp_position.cfg')) print 'wp_position.cfg created in ' + config_dir else: wpcfg = config.Config(os.path.join(config_dir, 'wp_position.cfg')) print 'wp_position.cfg opened from ' + config_dir try: cur_pos = wpcfg.get_all()['current_position'] except KeyError: cur_pos = wpcfg.set('current_position', 'out') print '\tcurrent_position not a key, set to default value...' if new_position == 'in' or new_position == 'out': wpcfg.set("current_position", new_position) new_pos = wpcfg.get_all()['current_position'] if cur_pos != new_pos: print '\tPosition changed to ' + new_pos else: print '\tPosition not changed' else: print 'new_position input not understood, try in or out' #log the time wpcfg.set("Last update", time.ctime()) return wpcfg
def __init__(self, name, servo_controller='Servo', min_pos=500, max_pos=2500, in_pos=810, out_pos=706): Instrument.__init__(self, name) self._ins_servo = qt.instruments[servo_controller] #print 'servo:', self._ins_servo self.add_parameter('channel', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=0, maxval=15) self.add_parameter('position', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=min_pos, maxval=max_pos) self.add_parameter('speed', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=0, maxval=63) self.add_parameter('in_position', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=min_pos, maxval=max_pos) self.add_parameter('out_position', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=min_pos, maxval=max_pos) self.add_function('move_in') self.add_function('move_out') #defaults self.set_channel(0) self.set_speed(20) self._position = 706 self.set_in_position(in_pos) self.set_out_position(out_pos) # override from config cfg_fn = os.path.abspath( os.path.join(qt.config['ins_cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name, use_adwin='adwin'): Instrument.__init__(self, name) self.add_parameter('channel', type = types.IntType, flags = Instrument.FLAG_GETSET) self.add_parameter('state', type = types.StringType, flags = Instrument.FLAG_GETSET, option_list = ('Open', 'Closed')) #Naar voorbeeld van eerder, Werkt dit? self._ins_adwin=qt.instruments[use_adwin] # set defaults self._channel = 7 # THis is the channel on the second breakout box, does this corespond? self._state = 'Closed' self.get_all() # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
class remote_powersocket(Instrument): """ The socket has to got to be recognized by the energenie software (name: energenie power manager) with a specific name. """ __init__(name,socket_name,**kws): logging.info(__name__ + ' : Initializing remotely controllable powerplug') Instrument.__init__(self, name) self.add_parameter('status', type=types.BooleanType, flags=Instrument.FLAG_GETSET, channels=(1, 2, 3 ,4), channel_prefix='socket%d_',val=False) self.add_function('turn_socket_on') self.add_function('turn_socket_off') self.add_function('get_all') # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.set_socket_name(socket_name) self._ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def test_get(self): """test function _get""" cfg = config.Config("./conf/spider.conf") self.assertEqual(cfg.get("spider", "url_list_file"), "./urls") self.assertEqual(cfg.get("spider", "output_directory"), "./output") self.assertEqual(cfg.getint("spider", "crawl_interval"), 1) self.assertEqual(cfg.getint("spider", "crawl_timeout"), 1) self.assertEqual(cfg.get("spider", "target_url"), ".*.(htm|html)$")
def __init__(self, name, p7889='p7889', physical_adwin=None): Instrument.__init__(self, name) self.name = name self._p7889 = qt.instruments[p7889] if physical_adwin != None: self._physical_adwin = qt.instruments[physical_adwin] else: self._physical_adwin = None self.add_parameter('is_running', type=types.BooleanType, flags=Instrument.FLAG_GETSET) self.add_parameter('integration_time', type=types.FloatType, unit='s', flags=Instrument.FLAG_GETSET, minval=0.1, maxval=10) self.add_parameter('adwin_par', type=types.IntType, flags=Instrument.FLAG_GETSET, minval=1, maxval=80) self.add_parameter('roi_min', unit='ns', type=types.FloatType, flags=Instrument.FLAG_GETSET) self.add_parameter('roi_max', unit='ns', type=types.FloatType, flags=Instrument.FLAG_GETSET) self.add_parameter('countrate', type=types.FloatType, flags=Instrument.FLAG_GET) self.add_function('start') self.add_function('stop') self.set_is_running(False) self.set_integration_time(0.2) self.set_adwin_par(43) self.set_roi_min(1) self.set_roi_max(100) self._total_countrate, self._roi_countrate = 0, 0 self._timer_id = -1 # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name + '.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name): logging.info(__name__ + ' : Initializing instrument') Instrument.__init__(self, name, tags=['physical']) self._LJ = u3.U3() self._LJ.configIO(FIOAnalog=int( '00000011', 2)) #all FIO3-8 set to digital 0-2 analog self.add_parameter('bipolar_dac', flags=Instrument.FLAG_GETSET, type=types.FloatType, units='V', minval=-10., maxval=10., channels=(0, 1, 2, 3, 4, 5), doc='+/-10V dac with 14 bit resolution') self.bipolar_dac_values = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] self.add_parameter('dac', flags=Instrument.FLAG_GETSET, type=types.FloatType, units='V', minval=0.0, maxval=5.0, channels=(0, 1), doc='0-5V dac with 10 bit resolution') self.add_parameter('analog_in', flags=Instrument.FLAG_GET, type=types.FloatType, channels=(0, 1), doc='0-2.4V anolog input with 12 bit resolution') self.dac_modules = {} self.getCalConstants() cfg_fn = os.path.abspath( os.path.join(qt.config['cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._parlist = [ 'bipolar_dac0', 'bipolar_dac1', 'bipolar_dac2', 'bipolar_dac3', 'bipolar_dac4', 'bipolar_dac5' ] self.ins_cfg = config.Config(cfg_fn) self._loaded_cfg = False self.load_cfg() self._loaded_cfg = True self.save_cfg()
def __init__(self, name, adwin, processes={}, process_subfolder='', use_cfg=True, **kw): Instrument.__init__(self, name, tags=['virtual']) self.physical_adwin = adwin self.process_dir = os.path.join(qt.config['adwin_programs'], process_subfolder) self.processes = processes self.default_processes = kw.get('default_processes', []) self.dacs = kw.get('dacs', {}) self.use_cfg = use_cfg self._dac_voltages = {} for d in self.dacs: self._dac_voltages[d] = 0. if kw.get('init', False): self._load_programs() # the accessible functions # initialization self.add_function('boot') self.add_function('load_programs') # tools self.add_function('get_process_status') # automatically generate process functions self._make_process_tools(self.processes) # convenience functions that belong to processes self.add_function('set_dac_voltage') self.add_function('get_dac_voltage') self.add_function('get_dac_channels') self.add_function('get_countrates') self.add_function('set_simple_counting') # set up config file if self.use_cfg: cfg_fn = os.path.abspath( os.path.join(qt.config['ins_cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def get_help_text(): """ compile some kind of error page """ help_html = "<html><head><title>Error</title></head><body>" help_html += "<h1>Avaiable Blocklist Groups</h1>" help_html += "<p>Just append the name of the blocklist to the path like" help_html += " http(s)://blocklist.somewhere.org/social</p><ul>" groups = config.Config().valuelist("Blacklists/Groups/Group") for group in groups: help_html += "<li>" + group.get("name") + "</li>" help_html += "</ul></body>" return help_html
def __init__(self, name, get_freq_yellow=None, get_freq_gate=None, get_freq_newfocus=None): Instrument.__init__(self, name) self._get_freq_yellow = get_freq_yellow self._get_freq_gate = get_freq_gate self._get_freq_newfocus = get_freq_newfocus ins_pars = { 'delta_t': { 'type': types.FloatType, 'val': 1.0, 'flags': Instrument.FLAG_GETSET }, 'log_gate': { 'type': types.BooleanType, 'val': True, 'flags': Instrument.FLAG_GETSET }, 'log_yellow': { 'type': types.BooleanType, 'val': True, 'flags': Instrument.FLAG_GETSET }, 'log_newfocus': { 'type': types.BooleanType, 'val': True, 'flags': Instrument.FLAG_GETSET }, 'is_running': { 'type': types.BooleanType, 'val': False, 'flags': Instrument.FLAG_GETSET } } instrument_helper.create_get_set(self, ins_pars) self.add_function('start') self.add_function('stop') # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name + '.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name): logging.info(__name__ + ' : Initializing instrument') Instrument.__init__(self, name, tags=['physical']) self._LJ = u3.U3() self._LJ.writeRegister( 50590, 15) #Setting FIO0-3 to analog, and the rest to digital... #should be changed if FIO0-3 should be used for sth else self.add_parameter('bipolar_dac', flags=Instrument.FLAG_GETSET, type=types.FloatType, units='V', minval=-10., maxval=10., channels=(0, 1, 2, 3), doc='+/-10V dac with 14 bit resolution') self.bipolar_dac_values = [0.0, 0.0, 0.0, 0.0] self.add_parameter('dac', flags=Instrument.FLAG_GETSET, type=types.FloatType, units='V', minval=0.0, maxval=5.0, channels=(0, 1), doc='0-5V dac with 10 bit resolution') self.add_parameter('analog_in', flags=Instrument.FLAG_GET, type=types.FloatType, channels=(0, 1, 2, 3), doc='0-2.4V anolog input with 12 bit resolution') self.dac_modules = {} self.getCalConstants() cfg_fn = os.path.abspath( os.path.join(qt.config['cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._parlist = [ 'bipolar_dac0', 'bipolar_dac1', 'bipolar_dac2', 'bipolar_dac3' ] self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name): Instrument.__init__(self, name) self.add_function('step_up') self.add_function('step_down') self.add_function('set_zero') ins_pars = { 'channel': { 'type': types.StringType, 'flags': Instrument.FLAG_GETSET, 'val': '' }, 'min_value': { 'type': types.FloatType, 'flags': Instrument.FLAG_GETSET, 'val': 0 }, 'max_value': { 'type': types.FloatType, 'flags': Instrument.FLAG_GETSET, 'val': 2 }, 'step_size': { 'type': types.FloatType, 'flags': Instrument.FLAG_GETSET, 'val': 0 }, } instrument_helper.create_get_set(self, ins_pars) self.add_parameter('current_value', type=types.FloatType, flags=Instrument.FLAG_GETSET) self._parlist = ins_pars.keys() self._adwin = qt.instruments['adwin'] # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name + '.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg() self._do_get_current_value()
def create_app(): app = Flask(__name__) app.jinja_env.auto_reload = True app.config.from_object(config.Config()) CORS(app) # models setup models.setup(app) # security setup Security(app, models.user.USER_DATASTORE,login_form=models.user.ExtendedLoginForm) # register app register_blueprint(app) return app
def __init__(self, name, rotator, rotation_config_name='', waveplates=['zpl_half','zpl_quarter'], get_value_f=None, get_norm_f=None, get_count_f=None, get_msmt_running_f = None): Instrument.__init__(self, name) self._rotator = qt.instruments[rotator] self._waveplates=waveplates self._rotation_cfg=rotcfg.config[rotation_config_name] self._prev_wp_channel='none' self._get_value_f = get_value_f self._get_norm_f = get_norm_f self._get_count_f = get_count_f self._get_msmt_running_f = get_msmt_running_f self._is_running = False self._timer = -1 self._half_direction = 1 self._quarter_direction = 1 self._reject_cycles = 0 ins_pars = { 'integration_time_during_msmt' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':10, 'units': 's'}, 'integration_time' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':0.3, 'units': 's'}, 'good_rejection' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':3}, 'step_size' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':2} } instrument_helper.create_get_set(self,ins_pars) self.add_function('move') self.add_function('get_waveplates') self.add_function('start') self.add_function('stop') self.add_function('get_value') self.add_function('get_noof_reject_cycles') cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name, rotator, adwin, red_laser=None, rotation_config_name='', waveplates=['zpl_half','zpl_quarter']): Instrument.__init__(self, name) self._rotator = qt.instruments[rotator] if red_laser != None: self._red_laser = qt.instruments[red_laser] else: self._red_laser = None self._adwin = qt.instruments[adwin] self._waveplates=waveplates self._rotation_cfg=rotcfg.config[rotation_config_name] self._prev_wp_channel='none' self.add_function('optimize') self.add_function('jog_optimize') self.add_function('optimize_all') self.add_function('first_time_run') self.add_function('move') self.add_function('get_waveplates') self.add_function('reset_wp_channel') self.add_function('nd_optimize') ins_pars = {'opt_range' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':4, 'units': 'deg'}, 'opt_noof_points' : {'type':types.IntType,'flags':Instrument.FLAG_GETSET, 'val':11}, 'opt_red_power' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':10e-9}, 'first_time_range' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':45, 'units': 'deg'}, 'first_time_noof_points' : {'type':types.IntType,'flags':Instrument.FLAG_GETSET, 'val':11}, 'first_time_red_power' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':1e-9, 'units': 'W'}, 'cnt_threshold' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET, 'val':5E5}, 'zpl_counter' : {'type':types.IntType,'flags':Instrument.FLAG_GETSET, 'val':2}, } instrument_helper.create_get_set(self,ins_pars) self._powell_direc=None cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, name, set_half_control_f=None, set_quarter_control_f=None, get_value_f=None, get_norm_f=None,msmt_helper = 'lt3_measurement_helper' , plot_name=''): Instrument.__init__(self, name) if plot_name=='': self._plot_name='optimizer_'+name else: self._plot_name = plot_name self._set_half_control_f = set_half_control_f self._set_quarter_control_f = set_quarter_control_f self._set_control_f = set_quarter_control_f self._get_value_f = get_value_f self._get_norm_f=get_norm_f self._msmt_helper = msmt_helper self._half_direction = 1 self._quarter_direction = 1 self._quarter_first = True ins_pars ={'scan_min' : {'type':types.FloatType, 'val':0.0,'flags':Instrument.FLAG_GETSET}, 'scan_max' : {'type':types.FloatType, 'val':0.0,'flags':Instrument.FLAG_GETSET}, 'control_step_size' : {'type':types.FloatType, 'val':0.0,'flags':Instrument.FLAG_GETSET}, 'min_value' : {'type':types.FloatType, 'val':0.,'flags':Instrument.FLAG_GETSET}, 'min_norm' : {'type':types.FloatType, 'val':200.,'flags':Instrument.FLAG_GETSET}, 'dwell_time' : {'type':types.FloatType, 'val':0.1,'flags':Instrument.FLAG_GETSET}, #s 'do_plot' : {'type':types.BooleanType,'val':True,'flags':Instrument.FLAG_GETSET}, 'dwell_after_set' : {'type':types.BooleanType,'val':True,'flags':Instrument.FLAG_GETSET}, } instrument_helper.create_get_set(self,ins_pars) self.add_function('scan') self.add_function('optimize') self.add_function('get_value') self.add_function('go_one_step') self.add_function('optimize_rejection') # override from config cfg_fn = os.path.join(qt.config['ins_cfg_path'], name+'.cfg') if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg() print 'creating waveplate optimizer'
def __init__(self, name, **kw): Instrument.__init__(self, name) self.add_parameter('save_data', type=types.BooleanType, flags=Instrument.FLAG_GETSET) self.add_parameter('send_email', type=types.BooleanType, flags=Instrument.FLAG_GETSET) self.add_parameter('is_running', type=types.BooleanType, flags=Instrument.FLAG_GETSET) self.add_parameter('read_interval', type=types.FloatType, unit='min', flags=Instrument.FLAG_GETSET) self.add_function('start') self.add_function('stop') self.add_function('manual_update') self.add_function('save_cfg') self.set_is_running(False) self.set_save_data(True) self.set_send_email(True) self.set_read_interval(10) #min # override from config cfg_fn = os.path.abspath( os.path.join(qt.config['ins_cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._parlist = ['save_data', 'send_email', 'read_interval'] self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def __init__(self, config_file): self.conf_file = config_file self.cfg = config.Config(config_file) self.module_name = 'spider' self.max_depth = self.cfg.getint(self.module_name, 'max_depth') self.crawl_interval = self.cfg.getint(self.module_name, 'crawl_interval') self.crawl_timeout = self.cfg.getint(self.module_name, 'crawl_timeout') self.target_url = self.cfg.get(self.module_name, 'target_url') self.output_directory = self.cfg.get(self.module_name, 'output_directory') self.url_list_file = self.cfg.get(self.module_name, 'url_list_file') self.thread_count = self.cfg.getint(self.module_name, 'thread_count') self.target_pattern = re.compile(self.target_url) self.url_queue = queue.Queue() self.handled_set = set() self.lock = threading.Lock()
def main(): configObj = config.Config('../config.json') configAr = configObj.getAllConnfig() bleMylux = ble.BleConnector(configAr['bleName'], configAr['bleUUID']) nums = [4, 8, 15, 16, 23, 42] i = 0 mah = 0 try: while True: print(nums[i]) print(mah) bleMylux.write(configAr['amps'], str(nums[i]) + "\n") bleMylux.write(configAr['mah'], str(mah) + "\n") i = (i + 1) % len(nums) mah += i time.sleep_ms(1000) except KeyboardInterrupt: pass uart.close()
def __init__(self, *args, **kwargs): """ Initialise attributes and register all behaviours """ self.logging = logging self.__log('Starting Assistant') self.db = Database() self.mode = kwargs.get('mode', 'console') self.behaviours = {} self.dir = os.path.dirname(os.path.realpath(__file__)) self.files = self.dir + '/files' self.config = config.Config() self.responder = None self.admin = self.config.get_or_request('Admin') self.register_behaviours() self.register_responders() schedule.clear() schedule.every(5).minutes.do(self.idle)
def run(channel, config_file): cfg = config.Config(filename=config_file) debug = cfg.get_default("debug", False) cr = cfg.get("color", "yellow") lower, upper = color_mask.unpack_range(cr) camera, width, height = util.get_video(channel) while True: hsv, img = util.get_hsv(camera) masked = color_mask.get_mask(hsv, lower, upper) res = cv2.bitwise_and(hsv, hsv, mask=masked) key = cv2.waitKey(1) if util.has_pressed(key, 'q'): break print(target_tracker.single_target(masked, img)) cv2.imshow("image", img) cv2.imshow("res", res) # cv2.imshow("masked", masked) cv2.destroyAllWindows()
def process_request(self, path): """ Process requests - get blocklist urls from config for category name given by request and call aggregator """ try: get_request = urllib.parse.urlparse(path) msg = get_request.path conf = config.Config() try: response = REQINV groups = conf.valuelist("Blacklists/Groups/Group") for group in groups: group_name = group.get("name") if msg[1:] == group_name: response = REQOK lists = conf.valuelist( 'Blacklists/Groups/Group[@name="' + group_name + '"]/list') blocklist = [] for item in lists: blocklist_data = aggregator.normalize( ur.urlopen(item.get("url"))) blocklist.append({ "name": item.get("name"), "data": blocklist_data }) self.result = aggregator.merge(blocklist) return response except Exception as error: self.log_message("Error '{0}' occured." % (error)) return SRCINV except Exception as error: self.log_message("Error '{0}' occured." % (error)) return REQINV else: self.log_message("should not get here") return UNKNOWN
def __init__(self, name, set_eprime_func,get_eprime_func,get_E_func,get_Y_func,set_strain_splitting_func, **kw): Instrument.__init__(self, name) ins_pars = {'read_interval' : {'type':types.FloatType,'flags':Instrument.FLAG_GETSET,'unit':'s', 'val': 1.}, 'is_running' : {'type':types.BooleanType,'flags':Instrument.FLAG_GETSET, 'val': False}, 'E_y' : {'type':types.BooleanType,'flags':Instrument.FLAG_GETSET, 'val': True}, 'offset' : {'type':types.FloatType, 'flags':Instrument.FLAG_GETSET, 'unit':'GHz', 'val': 0.}, 'precision' : {'type':types.FloatType, 'flags':Instrument.FLAG_GETSET, 'unit':'GHz', 'val': 0.05}, 'yellow_z_factor' : {'type':types.FloatType, 'flags':Instrument.FLAG_GETSET, 'unit':'GHz', 'val': 4.2}, 'yellow_x_factor' : {'type':types.FloatType, 'flags':Instrument.FLAG_GETSET, 'unit':'GHz', 'val': 0.2}, 'strain_splitting' : {'type':types.FloatType, 'flags':Instrument.FLAG_GET, 'unit':'GHz', 'val': 0.}, } instrument_helper.create_get_set(self,ins_pars) self.add_function('start') self.add_function('stop') self._get_E_func=get_E_func self._get_Y_func=get_Y_func self._set_eprime_func = set_eprime_func self._get_eprime_func = get_eprime_func self._set_strain_splitting_func = set_strain_splitting_func self._timer=-1 # override from config ---------- cfg_fn = os.path.abspath( os.path.join(qt.config['ins_cfg_path'], name+'.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self._parlist = ['read_interval', 'E_y', 'offset','yellow_z_factor', 'yellow_x_factor','precision'] self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
help= 'Output directory that will overwrite the one from the configuration file') parser.add_argument( '-s', '--source', help= 'Source directory that will overwrite the one from the configuration file') arguments = parser.parse_args() # ################## # # Configuration File # # ################## # # config reading and error parsing try: cfg = config.Config(config_file) # invalid JSON except json.JSONDecodeError as e: print('Cannot parse configuration file. Invalid JSON') sys.exit() # file does not exist except FileNotFoundError as e: print('Configuration file "{config_file}" not found'.format( config_file=config_file)) sys.exit() # missing config option except KeyError as e: print('{key} missing in configuration file "{config_file}"'.format( key=e, config_file=config_file)) sys.exit()
def __init__(self, name, get_matisse_freq_func=None, **kw): Instrument.__init__(self, name) #instruments self._ins_adwin = qt.instruments['adwin'] self._ins_adwin_lt1 = qt.instruments['adwin_lt1'] self._ins_pidmatisse = qt.instruments['pidmatisse'] self._ins_pidnewfocus = qt.instruments['pidnewfocus'] self._ins_pidnewfocus_lt1 = qt.instruments['pidnewfocus_lt1'] self._func_matisse_freq = get_matisse_freq_func self.add_parameter('read_interval', type=types.FloatType, unit='s', flags=Instrument.FLAG_GETSET) self.add_parameter('tpqi_per_sec_min', type=types.FloatType, unit='/s', flags=Instrument.FLAG_GETSET) self.add_parameter('cr_checks_per_sec_min', type=types.FloatType, unit='/s', flags=Instrument.FLAG_GETSET) self.add_parameter('fraction_failed_min', type=types.FloatType, unit='%', flags=Instrument.FLAG_GETSET) self.add_parameter('is_running', type=types.BooleanType, flags=Instrument.FLAG_GETSET) self.add_function('start') self.add_function('stop') self.add_function('optimize_matisse') self.add_function('optimize_newfocus') self.add_function('optimize_gate') self.set_is_running(False) self.set_read_interval(1.0) self.set_tpqi_per_sec_min( 300 ) #if the tpqi starts per second are more than this, no optimisation is done self.set_cr_checks_per_sec_min( 100 ) #if the number of cr_checks per second on a setup is less than this, no optimisation is done on that setup self.set_fraction_failed_min( 0.1 ) #if the fraction of failed cr checks is less than this, no optimisation is done on that setup self._prev_raw_values = zeros(9) self._get_input_values() # override from config cfg_fn = os.path.abspath( os.path.join(qt.config['ins_cfg_path'], name + '.cfg')) if not os.path.exists(cfg_fn): _f = open(cfg_fn, 'w') _f.write('') _f.close() self.ins_cfg = config.Config(cfg_fn) self.load_cfg() self.save_cfg()
def main(): #Config and logging configuration = config.Config('configs/clouderasizer.conf') logfmt = '%(asctime)s - %(levelname)s - %(message)s' datefmt = '%m/%d/%Y %I:%M:%S' logging.basicConfig(filename=configuration.logging_dir + '/clouderasizer.log', level=logging.DEBUG, datefmt=datefmt, format=logfmt) console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logging.Formatter(logfmt)) logging.getLogger('').addHandler(console) #Set defaults based on config file. These will be overriden by any command arguments, or if not specified will be the default arguments. cm_host = configuration.cloudera_manager_name username = configuration.cloudera_username password = configuration.cloudera_password cluster_name = configuration.cloudera_cluster_name current_time = datetime.datetime.fromtimestamp(time.time()) last_year = datetime.datetime.fromtimestamp(time.time() - 31536000) collectionplan_dir = configuration.collectionplan_dir output_dir = configuration.output_dir #CLI Argument Logic - Root parser parser = argparse.ArgumentParser(prog='clouderasizer.py') parser.add_argument( '--username', default=username, help= 'Name of an user with administrative access (defaults to %(default)s)') parser.add_argument( '--password', default=password, help='Password for the administrative user (defaults to %(default)s)') parser.add_argument('--cm_host', help="The hostname/ip of the Cloudera Manager server", default=cm_host) parser.add_argument('--cluster_name', help="The name of the cluster inside of CM", default=cluster_name) parser.add_argument('--output_dir', help="The full path of the output directory", default=output_dir) parser.add_argument('--start_time', help='The start time to collect from', default=last_year) parser.add_argument('--end_time', help='The end time to collect until', default=current_time) subparsers = parser.add_subparsers() #metrics subparser parser_metrics = subparsers.add_parser( 'metrics', help='Find and describe available metrics') parser_metrics.add_argument( '--search', nargs='+', help= 'Find available metrics. Takes one or more words separated by spaces', default='None') parser_metrics.set_defaults(func=do_search) #collector subparser parser_collect = subparsers.add_parser('collect', help='Collect metrics') parser_collect.add_argument( '--metrics', nargs='+', help= 'The names of the metrics to retrieve. Can be a space-separated list', required=True) parser_collect.add_argument( '--entity_name', help= 'The service name or entity to collect the metrics for. By default it will grab at CLUSTER level', default='None') parser_collect.add_argument( '--save_as', help= 'The format to save the metrics in - JSON, CSV, or NONE. Default is NONE', default='None') parser_collect.set_defaults(func=do_collect) #collectionplan subparser parser_collection = subparsers.add_parser( 'collectionplan', help= 'Execute a collection plan for collecting a defined series of metrics') parser_collection.add_argument( '--execute', help='The name of the collection plan to execute') parser_collection.add_argument('--list', action='store_true', help='Shows list of collection plans') parser_collection.add_argument( '--details', help='Shows details for a given collection plan') parser_collection.add_argument( '--output_type', help='The type of output to produce - ZIP is the only current option', default='ZIP') parser_collection.add_argument('--output_path', help='The path to output to', default=configuration.output_dir) parser_collection.add_argument( '--collectionplan_dir', help='The path where collectionplans are kept', default=collectionplan_dir) parser_collection.set_defaults(func=do_collectionplan) #pptplan subparser parser_pptplan = subparsers.add_parser( 'pptplan', help='Generate a PPT from a collection generated from collectionplan') parser_pptplan.add_argument( '--generate', help= 'Generate a PPT from a collection. Takes a collection .zip as argument' ) parser_pptplan.set_defaults(func=do_pptplan) args = parser.parse_args() #call the function as determined by commands args.func(args) print "Invalid options or syntax error" sys.exit(1)