def put(self, site_name): default_path = "/etc/nginx" args = self.reqparse.parse_args() path = args['path'] if path is None: path = default_path IO.set_nginx_dir(path) return { 'state': 1 }
def put(self, site_name): default_path = "/etc/nginx" args = self.reqparse.parse_args() path = args['path'] if path is None: path = default_path IO.set_nginx_dir(path) return {'state': 1}
def put(self, site_name): """ @api {put} /config/site/:site_name Update a configuration. @apiName UpdateSiteConfig @apiDescription Replace a configuration for a site. @apiGroup Configuration @apiParam {String} site_name Name of the site. @apiParam {String} config Configuration of the site. @apiParam {String} enable Activate the configuration. @apiSuccess (200) {int} state Status of the operation, 1 if everything went well. @apiExample Example: PUT /config/site/default @apiParamExample {json} Configuration example: { 'config': "Configuration...", 'enable': "True" } @apiSuccessExample Success response HTTP/1.1 200 OK { 'state': 1 } """ args = self.reqparse.parse_args() config = args['config'] enable = args['enable'] if enable is not None: enable = enable.lower() == "true" else: enable = False result = IO.update_site_config(site_name, config) if result is not True: raise UnableToPushConfiguration() print(enable) if enable: IO.enable_config(site_name) else: IO.disable_config(site_name) reload_nginx() return {'state': 1}
def __init__(self, communicationMode=None, logLevel=logging.DEBUG, logFile='logs.log'): self.isSuccessfullyInitialized = True try: self.io = IO(*communicationMode, storagePath="storage\\", storageFilename=None, logFile=logFile, logLevel=logLevel) self.io.loggerWrapper.logInfo("MainAutoControll ctor started") self.initGpsPathFinder() except Exception as e: # todo: error handling! self.isSuccessfullyInitialized = False self.io.loggerWrapper.logError("Unknown error during autoRover starting: " + str(e))
def __init__(self): """ Initialize console, level, UI. """ self.console = IO() # Create a console self.ui = UI() # Create user interface self.rng = RNG() self.noise = Noise(self.rng.rand) self.console.cprint(((W - len(G_LEVEL_MSG)) / 2, H / 2), G_LEVEL_MSG) # Print generating level msg self.console.flush() # And flush it self.dungeon = Dungeon(None) self.dungeon.levels[0] = Level((self.noise.getNoise, self.noise.getNoise1d), self.rng.rand, self.dungeon) self.dungeon.level = self.dungeon.levels[0] self.level = self.dungeon.level self.level.num = 0 self.player = Player((PLAYERX, PLAYERY), self.level) # Create player self.level.setPlayer(self.player) # And put it into the level for x in range(self.level.w + 1): for y in range(self.level.h + 1): if self.level[x][y].retChar() == "<": self.player.move((x, y), True, False) break
def get(self): """ @api {get} /config/site Get the list of the sites. @apiName GetListSites @apiDescription Get the list of the sites on the Agent, either activated (= in 'enabled' directory) or not (= in 'available' directory). @apiGroup Sites @apiParam {Boolean} [allAvailable=False] Should list all the available (not necessarily enabled) sites. @apiSuccess (200) {List} sites List of the available or enabled sites. @apiSuccess (200) {Boolean} allAvailable Copy of the paramater 'allAvailable' received in the query. @apiExample Example: GET /config/site?allAvailable=True @apiSuccessExample Success response, retrieving all the sites HTTP/1.1 200 OK { 'sites': ['default', 'site1', 'site2'], 'allAvailable': true } @apiSuccessExample Success response, retrieving only the enabled sites HTTP/1.1 200 OK { 'sites': ['default'], 'allAvailable': false } """ args = self.reqparse.parse_args() list_all_sites_available = args['allAvailable'] if list_all_sites_available is not None: list_all_sites_available = list_all_sites_available.lower( ) == 'true' else: list_all_sites_available = False status, sites = IO.list_available_sites( ) if list_all_sites_available else IO.list_enabled_sites() if status is False: raise SiteListNotAvailable() return {'sites': sites, 'allAvailable': list_all_sites_available}
def get(self): """ @api {get} /config/site Get the list of the sites. @apiName GetListSites @apiDescription Get the list of the sites on the Agent, either activated (= in 'enabled' directory) or not (= in 'available' directory). @apiGroup Sites @apiParam {Boolean} [allAvailable=False] Should list all the available (not necessarily enabled) sites. @apiSuccess (200) {List} sites List of the available or enabled sites. @apiSuccess (200) {Boolean} allAvailable Copy of the paramater 'allAvailable' received in the query. @apiExample Example: GET /config/site?allAvailable=True @apiSuccessExample Success response, retrieving all the sites HTTP/1.1 200 OK { 'sites': ['default', 'site1', 'site2'], 'allAvailable': true } @apiSuccessExample Success response, retrieving only the enabled sites HTTP/1.1 200 OK { 'sites': ['default'], 'allAvailable': false } """ args = self.reqparse.parse_args() list_all_sites_available = args['allAvailable'] if list_all_sites_available is not None: list_all_sites_available = list_all_sites_available.lower() == 'true' else: list_all_sites_available = False status, sites = IO.list_available_sites() if list_all_sites_available else IO.list_enabled_sites() if status is False: raise SiteListNotAvailable() return {'sites': sites, 'allAvailable': list_all_sites_available}
def get(self, site_name): """ @api {get} /config/site/:site_name Get a configuration. @apiName GetSiteConfig @apiDescription Retrieve the configuration of a site. @apiGroup Configuration @apiParam {String} site_name Name of the site. @apiSuccess (200) {String} config Configuration of the site. @apiExample Example: GET /config/site/default @apiSuccessExample Success response HTTP/1.1 200 OK { 'config': "Configuration of the site" } @apiError SiteNotFound The configuration does not exist. @apiErrorExample {json} Error-Response: HTTP/1.1 404 Not Found { "status": 404 "message": "Site not found." } """ status, config = IO.site_config(site_name) if status is False: raise SiteNotFound() return {'config': config}
class MainAutoControll: missionCords = [] def __init__(self, communicationMode=None, logLevel=logging.DEBUG, logFile='logs.log'): self.isSuccessfullyInitialized = True try: self.io = IO(*communicationMode, storagePath="storage\\", storageFilename=None, logFile=logFile, logLevel=logLevel) self.io.loggerWrapper.logInfo("MainAutoControll ctor started") self.initGpsPathFinder() except Exception as e: # todo: error handling! self.isSuccessfullyInitialized = False self.io.loggerWrapper.logError("Unknown error during autoRover starting: " + str(e)) def initGpsPathFinder(self): # gps path finder self.gpsPathFinder = GpsPathFinder("map.osm", "foot") # ustalanie trasy dla danego przejazdu self.gpsPathFinder.definePath([50.01824, 21.98584], [50.01837921142578, 21.986557006835984]) self.routeOSM, self.routeLocation = self.gpsPathFinder.GetRouteToTravel() # todo: MOVE TO GPS SERVICE! def moveByGPS(self, gps): # Here is place to get current location from gps lat = gps[1][1] lon = gps[1][0] print("lat: " + str(lat) + " | lon: " + str(lon)) nearestNode = self.gpsPathFinder.GetNearestNodeToCurrentLocation([float(lat), float(lon)]) try: gpsSensorResult = self.gpsPathFinder.CheckCurrentPositionAtRoute([lat, lon], nearestNode) if gpsSensorResult.status == ResultStatus.Success: distanceToGoalPoint = gpsSensorResult.data[0] distanceToNearestNode = gpsSensorResult.data[1] angle = gpsSensorResult.data[2] print("Arithmetic Distance to goal is" + str(distanceToGoalPoint)) print("Distance to current nearest node in road is ", distanceToNearestNode) print("angle: " + str(angle)) angle *= 5000 # Temp TODO MOVE DECISION OF ROVER DRIVING TO "COMMON SENSOR GUARDIAN" (Name is temp) isGoalReached = distanceToGoalPoint <= 0.00004 if not isGoalReached: print("Goal is not reached") self.io.communicationService.sendPacket(PacketsSend.RightLeftDriving, ( 50.0 - 50 * angle, 55.0 + 50 * angle)) # right/left levels (-100, 100) except Exception as e: # todo: error handling! print(e) def mainLoop(self): if not self.isSuccessfullyInitialized: return while True: time.sleep(0.001) if not self.io.communicationService.isCommunicationRunning: if not self.io.start(communication=True, storage=not self.io.storageService.isStorageInitialized()): self.io.loggerWrapper.logError("Cannot connect to rover!") continue self.io.communicationService.sendPacket(PacketsSend.RightLeftDriving, (50.0, 55.0)) # right/left levels (-100, 100) gps = self.io.readGPS() if gps is None: continue else: self.moveByGPS(gps)
class Game: """ Main game class. Some basic functions. etc. """ def __init__(self): """ Initialize console, level, UI. """ self.console = IO() # Create a console self.ui = UI() # Create user interface self.rng = RNG() self.noise = Noise(self.rng.rand) self.console.cprint(((W - len(G_LEVEL_MSG)) / 2, H / 2), G_LEVEL_MSG) # Print generating level msg self.console.flush() # And flush it self.dungeon = Dungeon(None) self.dungeon.levels[0] = Level((self.noise.getNoise, self.noise.getNoise1d), self.rng.rand, self.dungeon) self.dungeon.level = self.dungeon.levels[0] self.level = self.dungeon.level self.level.num = 0 self.player = Player((PLAYERX, PLAYERY), self.level) # Create player self.level.setPlayer(self.player) # And put it into the level for x in range(self.level.w + 1): for y in range(self.level.h + 1): if self.level[x][y].retChar() == "<": self.player.move((x, y), True, False) break def mainLoop(self): """ Main loop of game. """ play = True # The game started while play: self.level.draw(self.console) # Draw level on self.console self.ui.draw(self.console) # Draw UI self.console.flush() # Flush console key = self.console.rkey() # Read one key # From the console if key.c == 0: # If no key was pressed for cell in self.level.redrawcells: # Then redraw animated self.level.drawCell(cell[0], cell[1], cell[2], cell[3], False) # cells else: move = self.console.keyparse(key) # Ask keyparser for move if move: # Player has moved... self.player.move(move) elif chr(key.c) == "x": # ...Or hasn't. # Build something self.level[self.player.x][self.player.y].setType(False, False) # Update cell self.level.update((self.player.x, self.player.y)) elif chr(key.c) == "z": # Or dig coords = self.console.askDirection() # Get direction if coords: # Keyparser returned coordinates (x, y) = coords (x, y) = (x + self.player.x, y + self.player.y) if self.level[x][y].isWall() and self.level[x][y].isDiggable(): # If you can dig that wall self.level[x][y].setType(True, True) # Dig it self.level.update((x, y)) # And update elif chr(key.c) == "m": # Show map for one _turn_ self.level.draw(self.console, forced=True) # Draw level self.console.flush() # Ignoring FOV. self.console.readKey() # And wait for keypress elif chr(key.c) == "q": # Quit play = False elif chr(key.c) == "S": self.save() elif chr(key.c) == "L": self.console.cprint((5, 5), "%d" % self.level.num) self.console.flush() self.console.readKey() elif chr(key.c) == ">": if self.level[self.player.x][self.player.y].retChar() == ">": if self.level.num + 1 >= len(self.dungeon.levels): self.dungeon.levels.append( Level((self.noise.getNoise, self.noise.getNoise1d), self.rng.rand, self.dungeon) ) self.level = self.dungeon.levels[self.player.level.num + 1] self.level.setPlayer(self.player) self.player.level = self.level for x in range(self.level.w + 1): for y in range(self.level.h + 1): if self.level[x][y].retChar() == "<": self.player.move((x, y), True, False) break elif chr(key.c) == "<": if self.level[self.player.x][self.player.y].retChar() == "<": if self.level.num != 0: self.level = self.dungeon.levels[self.player.level.num - 1] self.level.setPlayer(self.player) self.player.level = self.level for x in range(self.level.w + 1): for y in range(self.level.h + 1): if self.level[x][y].retChar() == ">": self.player.move((x, y), True, False) break for x in range(self.level.w): for y in range(self.level.h): if self.level[x][y].mob != None: self.level[x][y].mob.ai() # This line is useful for stress testing the game. # self.player.move((random.randint(-1,1),random.randint(-1,1))) # End game if window is closed play = not libtcod.console_is_window_closed() and play def load(): pass def save(): pass