def do_POST(self): """ POST Handler """ if self.path.startswith("/setup"): data = json.loads( self.rfile.read(int(self.headers['content-length']))) for field in ['gps', 'imu', 'lidar', 'lpcm']: CONFIG[field].update(data[field]) util.DONE = True util.write_config(CONFIG) content_type = "application/json" output = json.dumps({ "message": "Stored. Rebooting...", }) os.system("shutdown --reboot +1") else: self.send_error(http.client.NOT_FOUND, self.path) return # If we made it this far, then send output to the browser output = output.encode('utf-8') self.send_response(http.client.OK) self.send_header("Content-type", content_type) self.send_header("Content-length", str(len(output))) self.end_headers() self.wfile.write(output)
def prepare_gals(self, dir): config.set('Dir', 'dirprj', dir) write_config() path = pathlib.Path(dir) self.dbname = path.joinpath(path.name + '.db') # self.dbname = os.path.join(dir, os.path.split(dir)[-1] + '.db') # dir + '.db' # self.ch_state(('btn', 'b_db'), ()) # self.ch_state(('btn', ), ()) self.tol_bar.num_gals.set(f"{' ':^19}") self.flag_gals = False self.b['bgals'].config(state='normal')
def test_launchd_service_with_token(self, tmp_path, component_tests_config): log_file = tmp_path / test_logging.default_log_file additional_config = { "logfile": str(log_file), } config = component_tests_config(additional_config=additional_config) # service install doesn't install the config file but in this case we want to use some default settings # so we write the base config without the tunnel credentials and ID write_config(pathlib.Path(default_config_dir()), config.base_config()) self.launchd_service_scenario(config, use_token=True)
def new_prj__(self, arg=None): if arg: path = pathlib.Path(arg) prj_name = path.name prj_path = path.joinpath(os.path.abspath('.'), 'Проекты') path_prj = path.joinpath(prj_path, prj_name) # if prj_name in (i.name for i in os.scandir(prj_path)): if prj_name in os.listdir(prj_path): box.showwarning('!', 'Проект с таким именем уже существует!') return self.pr_name.set(f'{prj_name:^{len(prj_name)+4}}') config.set('Dir', 'dirprj', f'{path_prj}') write_config() self.master.prepare_gals(str(path_prj)) try: os.mkdir(path_prj) os.mkdir(path.joinpath(path_prj, 'Исходные данные')) # 'base_data' os.mkdir(path.joinpath(path_prj, 'Обработанные данные')) # 'processed_data' os.mkdir(path.joinpath(path_prj, 'Конвертированные данные')) # 'converted_data' os.mkdir(path.joinpath(path_prj, 'Конвертированные данные NMEA')) # 'converted_nmea_data' except Exception: box.showerror('?', 'Ошибка создания проекта!')
def test_sysv_service_with_token(self, tmp_path, component_tests_config): additional_config = { "loglevel": "debug", } config = component_tests_config(additional_config=additional_config) # service install doesn't install the config file but in this case we want to use some default settings # so we write the base config without the tunnel credentials and ID config_path = write_config(tmp_path, config.base_config()) subprocess.run(["sudo", "cp", config_path, "/etc/cloudflared/config.yml"], check=True) self.sysv_service_scenario(config, tmp_path, use_token=True)
def post(self, slug): """ POST request of /configs/update query param: 'module_name' http body: json changes the config of the module given by module_name to the json in the http body """ if self.current_user: if slug == "update": module = self.get_argument( "module_name", None) # TODO handle input of wrong module name config_path = get_config_path(module) new_config = tornado.escape.json_decode(self.request.body) write_config(config_path, new_config) else: self.set_status(401) self.write({ "status": 401, "reason": "no_token", "redirect_suggestions": ["/login"] })
def expect_address_connections(self, tmp_path, component_tests_config, protocol, edge_ip_version, assert_address_type): config = component_tests_config( self._extra_config(protocol, edge_ip_version)) config_path = write_config(tmp_path, config.full_config) LOGGER.debug(config) with CloudflaredCli(config, config_path, LOGGER): wait_tunnel_ready(tunnel_url=config.get_url(), require_min_connections=4) cfd_cli = CloudflaredCli(config, config_path, LOGGER) tunnel_id = config.get_tunnel_id() info = cfd_cli.get_tunnel_info(tunnel_id) connector_id = get_tunnel_connector_id() connector = next( (c for c in info["conns"] if c["id"] == connector_id), None) assert connector, f"Expected connection info from get tunnel info for the connected instance: {info}" conns = connector["conns"] assert conns == None or len( conns) == 4, f"There should be 4 connections registered: {conns}" for conn in conns: origin_ip = conn["origin_ip"] assert origin_ip, f"No available origin_ip for this connection: {conn}" assert_address_type(origin_ip)
if not group_id in old_groups: old_groups[group_id] = {"id": group["id"], "name": group["name"]} new_config["groups"] = old_groups print("Group ID written to config") if not "simulation_id" in old_groups[group_id]: print("Creating the simulation group") data = {"name": group["name"] + " Simulation"} headers = {"Content-Type": "application/json"} res = util.post_rest('groups', data=data, headers=headers) if res is None: print("Creating simulation groupme failed") else: old_groups[group_id]["simulation_id"] = res["id"] util.write_config(new_config) if not os.path.exists("groups"): os.mkdir("groups") if not os.path.exists("groups/" + group_id): os.mkdir("groups/" + group_id) os.mkdir("groups/" + group_id + '/members') print("Loading group information for first run") load_messages.main(group_id, "reset") print("Done loading group information") print("Setup Complete") run = input("Would you like to run the simulation? (y/n): ") if run == 'y': simulate.main(group_id)
def main(): #Parsing level from parameters: level = 0 user_supplied_level = False parse_config() if len(sys.argv) > 1: for arg in sys.argv: if level == -1: try: level = int(arg) user_supplied_level = True except: print "Error: incorrect level number" level = 0 elif arg == "-l": level = -1 #Initializing pygame and screen pygame.init() print "Which way is up starting up." screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) pygame.display.set_caption("Which way is up?") if (pygame.joystick.get_count() > 0): joystick = pygame.joystick.Joystick(0) joystick.init() else: joystick = None score = Score(0) done = False if (Variables.vdict["unlocked"] == 0) or user_supplied_level: # Go straight to the game end_trigger = END_NEXT_LEVEL menu_choice = -2 else: # Go to the menu first end_trigger = END_MENU menu_choice = 0 #Menu and level changing loop, actual game code is in game.py: while not done: if end_trigger == END_NEXT_LEVEL: if level < TOTAL_LEVELS or user_supplied_level: end_trigger = game.run(screen, level, score, joystick) level += 1 if end_trigger == END_QUIT: end_trigger = END_MENU else: end_trigger = END_WIN if end_trigger == END_LOSE: display_bg("lose", screen) end_trigger = END_MENU elif end_trigger == END_WIN: display_bg("victory", screen) end_trigger = END_MENU elif end_trigger == END_QUIT or end_trigger == END_HARD_QUIT: done = True elif end_trigger == END_MENU: prev_score = score.score score = Score(0) if prev_score != 0: menu = Menu(screen, prev_score) else: menu = Menu(screen) menu_choice = menu.run(menu_choice) if menu_choice == MENU_QUIT: end_trigger = END_QUIT elif menu_choice == MENU_SOUND: Variables.vdict["sound"] = not Variables.vdict["sound"] end_trigger = END_MENU elif menu_choice == MENU_DIALOGUE: Variables.vdict["dialogue"] = not Variables.vdict["dialogue"] end_trigger = END_MENU else: level = menu_choice end_trigger = END_NEXT_LEVEL else: if user_supplied_level: user_supplied_level = False end_trigger = END_WIN else: if Variables.vdict["unlocked"] < level: Variables.vdict["unlocked"] = level print "Unlocked level " + str(Variables.vdict["unlocked"]) write_config() return
def vz(self, value): """Изменение скорости звука""" self._vz = value # int self.head.set_v(value) config.set('System', 'vz', f'{value}') write_config()
def zg(self, value): """Изменение заглубления""" self._zg = value self.head.set_z(value) config.set('System', 'zagl', f'{value}') write_config()
def zona(self, value): self._zona = value self.head.set_utc(t=True) config.set('System', 'vzona', f'{value}') write_config()
time = 0 cur_puzzle = [] if app.bRecordLastPuzzle and app.lastPuzzle: _id = app.lastPuzzle['id'] time = app.lastPuzzle['time'] puzzle = util.str2puzzle(app.lastPuzzle['puzzleDefault']) cur_puzzle = util.str2puzzle(app.lastPuzzle['puzzleCurrent']) logger.info('RecordLastPuzzle! id=%d, time=%s', _id, util.time_format(time)) logger.info('puzzle=%s', app.lastPuzzle['puzzleDefault']) logger.info('cur puzzle=%s', app.lastPuzzle['puzzleCurrent']) else: #puzzle loader _id, puzzle = get_puzzle_loader().pick(mode) #anim anim.InitAnimManager() #frame frame = MainFrame(None, 'Sudoku Boxer') frame.setDefault(_id, puzzle, cur_puzzle) if user: frame._setUser(user) if time: frame.setSpendTime(time) mainApp.MainLoop() app.SetConfig() util.write_config()
def SaveBtnClk(self): print self.src.text() self.config.set('main', 'source_dir', str(self.src.text())) self.config.set('main', 'dest_dir', str(self.dst.text())) write_config(self.config) self.close()
def main(): #Parsing level from parameters and parsing main config: level_name = None world_index = 0 world = World(WORLDS[world_index]) user_supplied_level = False parse_config() getlevel = False Variables.vdict["devmode"] = False if len(sys.argv) > 1: for arg in sys.argv: if getlevel: try: level_name = arg user_supplied_level = True end_trigger = END_NEXT_LEVEL menu_choice = MENU_QUIT except: error_message("Incorrect command line parameters") level_name = None elif arg == "-l": getlevel = True elif arg == "-dev": Variables.vdict["devmode"] = True Variables.vdict["verbose"] = True elif arg == "-v": Variables.vdict["verbose"] = True #Initializing pygame and screen pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT)) caption = "Which way is up?" if (Variables.vdict["devmode"]): caption = caption + " - developer mode" pygame.display.set_caption(caption) apply_fullscreen_setting(screen) if (pygame.joystick.get_count() > 0): joystick = pygame.joystick.Joystick(0) joystick.init() else: joystick = None score = Score(0) done = False if not user_supplied_level: if (Variables.vdict["unlocked" + WORLDS[0]] == 0): # Nothing unlocked, go straight to the game end_trigger = END_NEXT_LEVEL menu_choice = MENU_QUIT level_name = world.get_level() else: # Go to the menu first end_trigger = END_MENU menu_choice = 0 bgscreen = None #Menu and level changing loop, actual game code is in game.py: while not done: if end_trigger == END_NEXT_LEVEL: if user_supplied_level: end_trigger = game.run(screen, level_name, world.index, score, joystick) if end_trigger == END_NEXT_LEVEL: user_supplied_level = False end_trigger = END_WIN else: end_trigger = game.run(screen, level_name, world.index, score, joystick) if end_trigger == END_NEXT_LEVEL: if world.is_next_level(): level_name = world.get_level() else: end_trigger = END_WIN elif end_trigger == END_QUIT: display_bg("quit", screen) end_trigger = END_MENU bgscreen = screen.copy() if end_trigger == END_LOSE: display_bg("lose", screen) end_trigger = END_MENU menu_choice = world.index - 1 bgscreen = screen.copy() elif end_trigger == END_WIN: display_bg("victory", screen) end_trigger = END_MENU menu_choice = 0 bgscreen = screen.copy() elif end_trigger == END_QUIT or end_trigger == END_HARD_QUIT: done = True elif end_trigger == END_MENU: prev_score = score.score prev_time = score.time prev_levels = score.levels score = Score(0) if prev_score != 0: menu = Mainmenu(screen, prev_score, world, bgscreen, prev_time, prev_levels) else: menu = Mainmenu(screen, None, world, bgscreen) menu_choice = menu.run(menu_choice) if menu_choice == MENU_QUIT: end_trigger = END_QUIT elif menu_choice == MENU_SOUND: Variables.vdict["sound"] = not Variables.vdict["sound"] end_trigger = END_MENU elif menu_choice == MENU_DIALOGUE: Variables.vdict["dialogue"] = not Variables.vdict["dialogue"] end_trigger = END_MENU elif menu_choice == MENU_FULLSCREEN: Variables.vdict["fullscreen"] = not Variables.vdict["fullscreen"] end_trigger = END_MENU apply_fullscreen_setting(screen) elif menu_choice == MENU_WORLD: world_index += 1 if world_index >= len(WORLDS): world_index = 0 world = World(WORLDS[world_index]) end_trigger = END_MENU else: level_name = world.get_level(menu_choice) end_trigger = END_NEXT_LEVEL write_config() write_log() return
def opgl(self, value): self._opgl = value self.board.show_opgl() # вывести на холст оп. глуб. config.set('System', 'opgl', f'{value}') write_config()
def _write_config(self, config): util.write_config(config, os.path.join(self.app_data_dir, self.email, CFG_FILE_NAME))
def save_(*arg): """Сохранить настройки в конфиге""" config.set('Preferens', 'T', f'{arg[0]}') config.set('Preferens', 'h', f'{arg[1]}') config.set('Preferens', 'D', f'{arg[2]}') write_config()
call("/bin/bash %s/zops_agent.sh start" % app_abs_path('bin'), shell=True) return log.logger.info('backup zops_agent done') os.chdir(os.path.join(prog_dir(), '..')) # commands.getstatusoutput("chattr +i %s" % app_abs_path('conf/client.conf')) ret_code, ret_msg = commands.getstatusoutput("tar xf %s --exclude=agent/conf/client.conf" % os.path.basename(update_fn)) log.logger.info('tar update file done') # commands.getstatusoutput("chattr -i %s" % app_abs_path('conf/client.conf')) commands.getstatusoutput("rm -f %s" % os.path.basename(update_fn)) log.logger.info('remove update package done') os.chdir(prog_dir()) if ret_code != 0: log.logger.error(ret_msg) call("/bin/bash %s/zops_agent.sh start" % app_abs_path('bin'), shell=True) return write_config('version', new_version) ret_code, ret_msg = commands.getstatusoutput("/bin/bash %s/zops_agent.sh restart" % app_abs_path('bin')) if ret_code != 0: log.logger.error("restart agent fail %s" % ret_msg) return log.logger.info('update zops_agent done') def backup_agent(self): app_dir = os.path.join(prog_, '..') src = "%s/agent" % app_dir dst = "%s/agent.%s" % (app_dir, int(time.time())) backup_list = glob.glob('%s/agent.[0-9]*' % app_dir) max_backup = int(self.opts['max_backup']) if len(backup_list) >= max_backup: for bak in sorted(backup_list, key=lambda x: -int(os.path.basename(x).split('.')[1]))[max_backup - 1:]: shutil.rmtree(bak)