def test_foo(self): excpected = {'connection': {'database': 'name', 'user': '******', 'password': '******', 'host': 'host', 'port': '1234'}, 'date': '20170202'} actual = ConfigFileParser.wrapper("blablabla -c resources/conn.config -d 20170202".split()) self.assertEqual(actual,excpected)
def __init__(self, master): # Init frame tk.Frame.__init__(self, master) #[temp,hum] = grovepi.dht(4,0) self.temp = 21 self.room = ConfigFileParser.ConfigFileParser() self.dagList = [ "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag" ] self.lesList = [ "Les uur / Tijd ", "1 ", "2 ", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" ] self.startList = [ "Start", " 8:30", " 9:20", "10:30", "11:20", "12:10", "13:00", "13:50", "15:00", "15:50", "17:00", "17:50", "18:40", "19:30", "20:20", "21:10" ] self.master = master self.init_buttons() # Init table view self.Fill_outer() self.Fill_inner()
def test_parse_config(self): res = ConfigFileParser._parse_config('resources/conn.config') self.assertEqual(res.database_pass,'pass') self.assertEqual(res.database_user,'user') self.assertEqual(res.database_name,'name') self.assertEqual(res.database_port,'1234')
def setUp(self): self.xmlParser = SimpleXMLParser() self.configFileParser = ConfigFileParser.ConfigFileParser() self.xmlParser.link((self.xmlParser, 'outbox'), (self.configFileParser, 'inbox')) self.xmlParser.link((self.xmlParser, 'signal'), (self.configFileParser, 'control')) self.initializeSystem(self.xmlParser, self.configFileParser)
def test_get_connection_parameters(self): # execute actual = ConfigFileParser.get_connection_parameters('resources/conn.config') # test # self.assertEqual(actual['connection_type'], 'connection_type') self.assertEqual(actual['password'], 'pass') self.assertEqual(actual['user'], 'user') self.assertEqual(actual['database'], 'name') self.assertEqual(actual['port'], '1234') self.assertEqual(actual['host'], 'host')
def ConvertWeekJson(jsonData,booking): room = ConfigFileParser.ConfigFileParser() roomNumber = str(room) # New array of data for json newJsonData = [] # Filters json for the day of the week. if(booking): for data in jsonData: if(data['Classroom'] == roomNumber): newJsonData.append(BookingClass.BookingClass(data)) return newJsonData else: for data in jsonData: newJsonData.append(RoomClass.Rooms(data)) return newJsonData
def ConvertDayJson(day,jsonData,booking): room = ConfigFileParser.ConfigFileParser() roomNumber = str(room) # New array of data for json newJsonData = [] if(booking): for data in jsonData: if (data['WeekDay'] == date.today().isocalendar()[2]): newJsonData.append(BookingClass.BookingClass(data)) return newJsonData # Filters json for the day of the week. else: for data in jsonData: if (data['WeekDay'] == date.today().isocalendar()[2]): newJsonData.append(RoomClass.Rooms(data)) return newJsonData
def client_authenticator(sock): channel = rpyc.Channel(rpyc.SocketStream(sock)) data = channel.recv() data = rpyc.core.brine.load(data) login = data[0] password = data[1] config_parser = ConfigFileParser.ConfigFileParser() expected_login = config_parser.login() expected_password = config_parser.password() if login != expected_login or password != expected_password: channel.send('AUTH_ERROR') raise rpyc.utils.authenticators.AuthenticationError( 'Invalid password from client.') channel.send('AUTH_SUCCESS') return sock, None
def RetrieveData(day, booking, endPoint): try: #requests for data : May take time request = requests endPointString = "http://acceptancetimetable2api.azurewebsites.net/api/" + endPoint room = ConfigFileParser.ConfigFileParser() url = endPointString + str(room) + "/" + str( date.today().isocalendar()[1]) authString = str(base64.b64encode(bytes("Pi:" + str(room), "utf8"))) response = request.get(url, headers={ 'Authorization': 'Basic ' + authString[1:].strip("'") }) jsonData = simplejson.loads(response.content) if (endPoint == "Schedule/Classroom/"): return DataFormer.DataFormer.FormData(jsonData, day, "jsonRoom.txt", booking) else: return DataFormer.DataFormer.FormData(jsonData, day, "jsonBooking.txt", booking) except: if (endPoint == "Schedule/Classroom/"): try: return DataFormer.DataFormer.FormData( TextFileReader.TextFileReader.ReadFromFile( "jsonRoom.txt"), day, "jsonRoom.txt", booking) except: return ["Lost"] else: try: return DataFormer.DataFormer.FormData( TextFileReader.TextFileReader.ReadFromFile( "jsonBooking.txt"), day, "jsonBooking.txt", booking) except: return ["Lost"]
def __init__(self, master): # Init frame tk.Frame.__init__(self, master) #[temp,hum] = grovepi.dht(4,0) self.temp = 21 self.room = ConfigFileParser.ConfigFileParser() self.startList = [ "Start", " 8:30", " 9:20", "10:30", "11:20", "12:10", "13:00", "13:50", "15:00", "15:50", "17:00", "17:50", "18:40", "19:30", "20:20", "21:10" ] # Sets selected item to none self.selected_item = None # Creates variable for the master class FrameController self.master = master # Inits the buttons and pictures self.init_buttons() # Builds foundation of the treeview self.Build_Treeview(self.master)
def generateConfigObj(self): conf = ConfigFileParser.generateGeneralConfigObject() conf.htmlTemplateName.parsedValue += DUMMY_TEMPLATE conf.maxPostNumber.parsedValue += '10' conf.name.parsedValue += PLANET_NAME return conf.generateResultObject()
def generateFeedObj(self, feedUrl): feed = ConfigFileParser.generateFeed() feed.url.parsedValue += feedUrl return feed.generateResultObject()
def __init__( self , NET_TRANS_NODE , SCENEGRAPH , CONFIG_FILE ): # parameters ## @var background_texture # The skymap to be used for all pipelines. self.background_texture = "data/textures/sky.jpg" avango.gua.create_texture(self.background_texture) # references ## @var SCENEGRAPH # Reference to the scenegraph. self.SCENEGRAPH = SCENEGRAPH ## @var NET_TRANS_NODE # Reference to the net transformation node. self.NET_TRANS_NODE = NET_TRANS_NODE # variables ## @var user_list # List of all created user instances. self.user_list = [] ## @var navigation_list # List of all created Navigation instances. self.navigation_list = [] ## @var border_observer_list # List of all created BorderObserver instances. self.border_observer_list = [] # kill all running python processes on display hosts _own_hostname = open('/etc/hostname', 'r').readline().strip(" \n") for _display in displays: if _display.hostname != _own_hostname: _ssh_kill = subprocess.Popen(["ssh", _display.hostname, "killall python"]) ## @var slot_manager # A SlotManager instance in order to handle the shutter timings of users. self.slot_manager = SlotManager() self.slot_manager.my_constructor(self.user_list) # create file parser and load file ## @var config_file_parser # Instance of ConfigFileParser in order to load and parse an XML configuration file. self.config_file_parser = ConfigFileParser(self) self.config_file_parser.parse(CONFIG_FILE) # care for correct slot assignment self.slot_manager.update_slot_configuration() # server control monitor setup # ## @var server_transform # Transform node representing the position and orientation of the server control monitor. self.server_transform = avango.gua.nodes.TransformNode(Name = "server_transform") self.server_transform.Transform.value = avango.gua.make_trans_mat(0, 20, 6) * \ avango.gua.make_rot_mat(-90, 1, 0, 0) self.NET_TRANS_NODE.Children.value.append(self.server_transform) ## @var eye # Transform node representing the server's eye self.eye = avango.gua.nodes.TransformNode(Name = "server_eye") self.eye.Transform.value = avango.gua.make_trans_mat(0, 0, 0) self.server_transform.Children.value.append(self.eye) ## @var screen # Screen node representing the server's screen. self.screen = avango.gua.nodes.ScreenNode(Name = "server_screen") self.screen.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, -0.5) self.screen.Width.value = 160/1.5 * 0.75 self.screen.Height.value = 100/1.5 * 0.75 self.server_transform.Children.value.append(self.screen) ## @var camera # Camera used for the server control monitor. self.camera = avango.gua.nodes.Camera() self.camera.SceneGraph.value = self.SCENEGRAPH.Name.value self.camera.LeftScreen.value = self.screen.Path.value self.camera.RightScreen.value = self.screen.Path.value self.camera.LeftEye.value = self.eye.Path.value self.camera.RightEye.value = self.eye.Path.value self.camera.Mode.value = 1 _render_mask = "!do_not_display_group && !server_do_not_display_group" for i in range(0, 10): _render_mask = _render_mask + " && !platform_group_" + str(i) self.camera.RenderMask.value = _render_mask ## @var window # Window displaying the server control view. self.window = avango.gua.nodes.Window() self.window.Title.value = "Server Control Monitor" self.window.Size.value = avango.gua.Vec2ui(1920, 1080) self.window.LeftResolution.value = avango.gua.Vec2ui(1920, 1080) ## @var pipeline # Pipeline repsonsible for rendering the server control monitor. self.pipeline = avango.gua.nodes.Pipeline() self.pipeline.BackgroundMode.value = avango.gua.BackgroundMode.COLOR self.pipeline.Window.value = self.window self.pipeline.LeftResolution.value = self.window.LeftResolution.value self.pipeline.EnableStereo.value = False self.pipeline.Camera.value = self.camera self.pipeline.EnableFrustumCulling.value = True # add pipeline and scenegraph to viewer self.viewer.Pipelines.value = [self.pipeline] self.viewer.SceneGraphs.value = [self.SCENEGRAPH]
import datetime import unittest import ConfigFileParser import Cruds from concurrent.futures import ThreadPoolExecutor import RealTimeArrivals conn_config = ConfigFileParser.get_connection_parameters('../../../../conn.config') class MyTestCase(unittest.TestCase): def test_read_gtfs(self): # excpect excpected_num_elems = 48 excpected_type_elem = RealTimeArrivals.Stop # exec with Cruds.Connection(**conn_config) as c: crud = Cruds.CrudPostgresql(c) data = crud.read_stops('27782048_310717') # test num elems self.assertEqual(excpected_num_elems, len(data)) # test type elem self.assertTrue(all([isinstance(i, excpected_type_elem) for i in data])) def test_read_records(self): # excpect excpected_num_elems = 1548 excpected_type_elem = RealTimeArrivals.Record
# code that runs when a connection is created # (to init the serivce, if needed) pass def on_disconnect(self): # code that runs when the connection has already closed # (to finalize the service, if needed) pass def exposed_get(self, key): # this is an exposed method #print key return self.mysql.select(key) def exposed_put(self, key, val): # this is an exposed method return self.mysql.insert(key, val) def exposed_update(self, key, val): # this is an exposed method return self.mysql.update(key, val) if __name__ == "__main__": from rpyc.utils.server import ThreadedServer config_parser = ConfigFileParser.ConfigFileParser() port = int(config_parser.port()) t = ThreadedServer(RPCService, port=port, authenticator=client_authenticator) t.start()
class ApplicationManager(): ## @var viewer # The guacamole viewer to be used for rendering. viewer = avango.gua.nodes.Viewer() ## @var shell # The GuaVE shell to be used when the application is running. shell = GuaVE() ## Custom constructor # @param NET_TRANS_NODE Reference to the net transformation node. # @param SCENEGRAPH Reference to the scenegraph. # @param CONFIG_FILE Path to the XML configuration file. def __init__( self , NET_TRANS_NODE , SCENEGRAPH , CONFIG_FILE ): # parameters ## @var background_texture # The skymap to be used for all pipelines. self.background_texture = "data/textures/sky.jpg" avango.gua.create_texture(self.background_texture) # references ## @var SCENEGRAPH # Reference to the scenegraph. self.SCENEGRAPH = SCENEGRAPH ## @var NET_TRANS_NODE # Reference to the net transformation node. self.NET_TRANS_NODE = NET_TRANS_NODE # variables ## @var user_list # List of all created user instances. self.user_list = [] ## @var navigation_list # List of all created Navigation instances. self.navigation_list = [] ## @var border_observer_list # List of all created BorderObserver instances. self.border_observer_list = [] # kill all running python processes on display hosts _own_hostname = open('/etc/hostname', 'r').readline().strip(" \n") for _display in displays: if _display.hostname != _own_hostname: _ssh_kill = subprocess.Popen(["ssh", _display.hostname, "killall python"]) ## @var slot_manager # A SlotManager instance in order to handle the shutter timings of users. self.slot_manager = SlotManager() self.slot_manager.my_constructor(self.user_list) # create file parser and load file ## @var config_file_parser # Instance of ConfigFileParser in order to load and parse an XML configuration file. self.config_file_parser = ConfigFileParser(self) self.config_file_parser.parse(CONFIG_FILE) # care for correct slot assignment self.slot_manager.update_slot_configuration() # server control monitor setup # ## @var server_transform # Transform node representing the position and orientation of the server control monitor. self.server_transform = avango.gua.nodes.TransformNode(Name = "server_transform") self.server_transform.Transform.value = avango.gua.make_trans_mat(0, 20, 6) * \ avango.gua.make_rot_mat(-90, 1, 0, 0) self.NET_TRANS_NODE.Children.value.append(self.server_transform) ## @var eye # Transform node representing the server's eye self.eye = avango.gua.nodes.TransformNode(Name = "server_eye") self.eye.Transform.value = avango.gua.make_trans_mat(0, 0, 0) self.server_transform.Children.value.append(self.eye) ## @var screen # Screen node representing the server's screen. self.screen = avango.gua.nodes.ScreenNode(Name = "server_screen") self.screen.Transform.value = avango.gua.make_trans_mat(0.0, 0.0, -0.5) self.screen.Width.value = 160/1.5 * 0.75 self.screen.Height.value = 100/1.5 * 0.75 self.server_transform.Children.value.append(self.screen) ## @var camera # Camera used for the server control monitor. self.camera = avango.gua.nodes.Camera() self.camera.SceneGraph.value = self.SCENEGRAPH.Name.value self.camera.LeftScreen.value = self.screen.Path.value self.camera.RightScreen.value = self.screen.Path.value self.camera.LeftEye.value = self.eye.Path.value self.camera.RightEye.value = self.eye.Path.value self.camera.Mode.value = 1 _render_mask = "!do_not_display_group && !server_do_not_display_group" for i in range(0, 10): _render_mask = _render_mask + " && !platform_group_" + str(i) self.camera.RenderMask.value = _render_mask ## @var window # Window displaying the server control view. self.window = avango.gua.nodes.Window() self.window.Title.value = "Server Control Monitor" self.window.Size.value = avango.gua.Vec2ui(1920, 1080) self.window.LeftResolution.value = avango.gua.Vec2ui(1920, 1080) ## @var pipeline # Pipeline repsonsible for rendering the server control monitor. self.pipeline = avango.gua.nodes.Pipeline() self.pipeline.BackgroundMode.value = avango.gua.BackgroundMode.COLOR self.pipeline.Window.value = self.window self.pipeline.LeftResolution.value = self.window.LeftResolution.value self.pipeline.EnableStereo.value = False self.pipeline.Camera.value = self.camera self.pipeline.EnableFrustumCulling.value = True # add pipeline and scenegraph to viewer self.viewer.Pipelines.value = [self.pipeline] self.viewer.SceneGraphs.value = [self.SCENEGRAPH] ## Creates a Navigation instance and adds it to the list of navigations. # @param INPUT_DEVICE_TYPE Type of the input device to be associated (e.g. XBoxController" or "OldSpheron") # @param INPUT_DEVICE_NAME Name of the input device values as chosen in daemon. # @param STARTING_MATRIX Initial platform matrix for the new device. # @param PLATFORM_SIZE Physical size of the platform in meters. [width, depth] # @param SCALE Start scaling of the platform. # @param ANIMATE_COUPLING Boolean indicating if an animation should be done when a coupling of Navigations is initiated. # @param MOVEMENT_TRACES Boolean indicating if the platform should leave traces behind. # @param INVERT Boolean indicating if the input values should be inverted. # @param NO_TRACKING_MAT Matrix which should be applied if no tracking is available. # @param GROUND_FOLLOWING_SETTINGS Setting list for the GroundFollowing instance: [activated, ray_start_height] # @param TRANSMITTER_OFFSET The matrix offset that is applied to the values delivered by the tracking system. # @param DISPLAYS The names of the displays that belong to this navigation. # @param AVATAR_TYPE A string that determines what kind of avatar representation is to be used ["joseph", "joseph_table", "kinect"]. # @param CONFIG_FILE The path to the config file that is used. # @param DEVICE_TRACKING_NAME Name of the device's tracking sensor as chosen in daemon if available. def create_navigation( self , INPUT_DEVICE_TYPE , INPUT_DEVICE_NAME , STARTING_MATRIX , PLATFORM_SIZE , SCALE , ANIMATE_COUPLING , MOVEMENT_TRACES , INVERT , NO_TRACKING_MAT , GROUND_FOLLOWING_SETTINGS , TRANSMITTER_OFFSET , DISPLAYS , AVATAR_TYPE , CONFIG_FILE , DEVICE_TRACKING_NAME = None ): # convert list of parsed display strings to the corresponding instances _display_instances = [] _displays_found = list(DISPLAYS) # create bool list if displays were found for _i in range(len(_displays_found)): _displays_found[_i] = False # search for display instances for _i in range(len(DISPLAYS)): for _display_instance in displays: if _display_instance.name == DISPLAYS[_i]: _display_instances.append(_display_instance) _displays_found[_i] = True # check if all display instances were found for _i in range(len(_displays_found)): if _displays_found[_i] == False: print_error("No matching display instance found for " + DISPLAYS[_i], True) # create the navigation instance _navigation = Navigation() _navigation.my_constructor( NET_TRANS_NODE = self.NET_TRANS_NODE , SCENEGRAPH = self.SCENEGRAPH , PLATFORM_SIZE = PLATFORM_SIZE , SCALE = SCALE , STARTING_MATRIX = STARTING_MATRIX , NAVIGATION_LIST = self.navigation_list , INPUT_SENSOR_TYPE = INPUT_DEVICE_TYPE , INPUT_SENSOR_NAME = INPUT_DEVICE_NAME , NO_TRACKING_MAT = NO_TRACKING_MAT , GF_SETTINGS = GROUND_FOLLOWING_SETTINGS , ANIMATE_COUPLING = ANIMATE_COUPLING , MOVEMENT_TRACES = MOVEMENT_TRACES , INVERT = INVERT , SLOT_MANAGER = self.slot_manager , TRANSMITTER_OFFSET = TRANSMITTER_OFFSET , DISPLAYS = _display_instances , AVATAR_TYPE = AVATAR_TYPE , CONFIG_FILE = CONFIG_FILE , TRACKING_TARGET_NAME = DEVICE_TRACKING_NAME ) self.navigation_list.append(_navigation) self.border_observer_list.append(None) ## Create a standard (non-HMD) user. # @param VIP Boolean indicating if the user to be created is a vip. # @param GLASSES_ID ID of the shutter glasses worn by the user. # @param PLATFORM_ID The ID of the platform this user belongs to. # @param HEADTRACKING_TARGET_NAME The headtracking target identifier attached to this user # @param WARNINGS Boolean indicating whether to display warning planes when the user gets close to the platform borders. def create_standard_user( self , VIP , GLASSES_ID , PLATFORM_ID , HEADTRACKING_TARGET_NAME , WARNINGS ): _user = User() _user.my_constructor(self , len(self.user_list) , VIP , GLASSES_ID , HEADTRACKING_TARGET_NAME , PLATFORM_ID , self.navigation_list[PLATFORM_ID].trace_material) self.user_list.append(_user) # init border checker to warn user on platform if WARNINGS: if self.border_observer_list[PLATFORM_ID] == None: _checked_borders = [True, True, True, True] self.create_border_observer(_checked_borders, _user, self.navigation_list[PLATFORM_ID].platform) else: self.border_observer_list[PLATFORM_ID].add_user(_user) ## Creates a BorderObserver instance for a Platform and adds a User to it. # @param CHECKED_BORDERS A list of four booleans to indicate which borders of the platform should be checked: # [display_left_border, display_right_border, display_front_border, display_back_border] # @param USER_INSTANCE A first User to be appended to the new BorderObserver. # @param PLATFORM_INSTANCE The platform to which the BorderObserver should belong to. def create_border_observer(self, CHECKED_BORDERS, USER_INSTANCE, PLATFORM_INSTANCE): _border_observer = BorderObserver() _border_observer.my_constructor(CHECKED_BORDERS, USER_INSTANCE, PLATFORM_INSTANCE) self.border_observer_list[PLATFORM_INSTANCE.platform_id] = _border_observer ## Starts the shell and the viewer. # @param LOCALS Local variables. # @param GLOBALS Global variables. def run(self, LOCALS, GLOBALS): self.shell.start(LOCALS, GLOBALS) self.viewer.run() ## Lists the variables of the shell. def list_variables(self): self.shell.list_variables()
if len(sys.argv) < 2: print "\n\n" print "==========================================================================================" print redColor + "No config file provided." + reset print redColor + "Command : " + reset + blueColor + "./haproxy-log-puller <configFile>" + reset print "==========================================================================================" print "\n\n" exit(-1) #check if pid exists def pid_exists(pid): return os.path.isdir("/proc/"+str(pid)) configFilePath = sys.argv[1] try: CONFIG = ConfigFileParser.parse(configFilePath) except Exception as e: print str(e) exit(-1) if not os.path.isfile(configFilePath): print redColor + "Config file " + blueColor + "[" + configFilePath + "]" + blueColor + redColor + " does not exists." + reset exit(-1) #check if haproxy-log puller process is already running. if os.path.isfile(pullerpidfilename): with open(pullerpidfilename,"r") as file: pullerpid = file.readline() if pid_exists(pullerpid): print redColor + "Puller Process already running with pid " + pullerpid + reset print redColor + "Try killing it first." +reset
def test_get_args_from_cli(self): actual = ConfigFileParser.get_args_from_cli("blablabla -c configurations.config -d 20170202".split()) self.assertEqual( actual.date_for_query, '20170202') self.assertEqual(actual.config_file, 'configurations.config')
def test_configFileReader(self): config = ConfigFileParser.ConfigFileParser() self.assertNotEqual(None, str(config))
formatter = logging.Formatter( '%(asctime)s %(name)-12s %(levelname)-8s %(message)s') fileHandler = logging.FileHandler('log.txt') fileHandler.setFormatter(formatter) fileHandler.setLevel(logging.NOTSET) stdoutHandler = logging.StreamHandler() stdoutHandler.setFormatter(formatter) stdoutHandler.setLevel(logging.DEBUG) logger.addHandler(stdoutHandler) logger.addHandler(fileHandler) configs = ConfigFileParser.wrapper(sys.argv) connection = configs['connection'] date = datetime.datetime.strptime(configs['date'], "%Y-%m-%d").date() with Cruds.Connection(**connection) as c: trips = Cruds.CrudPostgresql(c).get_relevant_trips_from_gtfs(date) for trip in trips: try: results = trip.run() print( "Trip_id: {} trip_date: {} results: {} len errores: {}".format( trip.trip_id, trip.trip_date, results.get('num of real times'), len(results.get('errors'))))