Esempio n. 1
0
def get_open_port():
    """
    Resolves an available port for socket messages
    Returns: available port number
    """

    environment.getEnvironmentVars()
    try:
        # get the port number from the settings file
        port = int(os.environ['APP_CONSOLE_SOCKET'])
    except KeyError:
        # set the port to 0 if it is not found in the settings file.  This will make the socket library find an open port.
        port = 0

    try:
        s = socket(AF_INET, SOCK_DGRAM)

        # attempt to bind to the port
        s.bind(("localhost", port))

        # get the port number from the socket
        port = s.getsockname()[1]

        # always close the socket.  This allows the gui console to bind to it later (see caveat below)
        s.close()

        # save this port back to the environment vars
        environment.setEnvironmentVar('APP', 'CONSOLE_SOCKET', port)
    except:
        # an error is raised if the gui has bound to this address before the engine tries to.
        # ignore this error for now, however we should wait until sprint has resolved socket
        # ports before allowing the gui to bind to it.
        pass

    return port
Esempio n. 2
0
    def OnInit(self):

        # load environment variables
        environment.getEnvironmentVars()

        # Don't delete this line, instantiating the Borg Engine main thread here
        engine = engineManager.Engine()

        # We are terminating dependency logging errors, We may want this in the future but it
        # tends to add clutter to our console.
        wx.Log.SetLogLevel(0)

        self.logicEmit = EMITCtrl(None)
        return True
Esempio n. 3
0
    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        self.engine = Coordinator()
        sprint.PrintTarget.CONSOLE = 1134

        self.g = n.DiGraph()
Esempio n. 4
0
    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        self.engine = Coordinator()
        sprint.PrintTarget.CONSOLE = 1134

        self.g = n.DiGraph()
Esempio n. 5
0
    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        sprint.PrintTarget.CONSOLE = 1134

        self._engine = Coordinator()
        self.basepath = os.path.dirname(__file__)
Esempio n. 6
0
    def setUp(self):

        # initialize environment variables
        environment.getEnvironmentVars()

        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()

        sprint.PrintTarget.CONSOLE = 1134

        self._engine = Coordinator()
        self.basepath = os.path.dirname(__file__)
Esempio n. 7
0
    def setUp(self):

        # define the paths for the empty and populated temp databases
        dirpath = os.path.dirname(os.path.abspath(__file__))
        self.empty_db_path = os.path.join(dirpath,'data/temp_empty.db')
        self.pop_db_path = os.path.join(dirpath, 'data/temp_pop.db')


        # remove temp databases
        if os.path.exists(self.empty_db_path):
            os.remove(self.empty_db_path)
        if os.path.exists(self.pop_db_path):
            os.remove(self.pop_db_path)

        # connect to each database
        empty_connection = dbconnection.createConnection('sqlite', self.empty_db_path)
        pop_connection = dbconnection.createConnection('sqlite', self.pop_db_path)

        self.emptysqlite = sqlite(empty_connection)
        self.popsqlite = sqlite(pop_connection)

        # initialize the in-memory database, loop through each command (skip first and last lines)
        empty_dump_script = open( os.path.join(dirpath, 'data/empty_dump.sql'),'r').read()
        for line in empty_dump_script.split(';\n'):
            self.emptysqlite.cursor.execute(line)

        populated_dump_script = open(os.path.join(dirpath, 'data/populated_dump.sql'),'r').read()
        for line in populated_dump_script.split(';\n'):
            self.popsqlite.cursor.execute(line)

        # initialize environment variables
        environment.getEnvironmentVars()
        if sys.gettrace():
            print 'Detected Debug Mode'
            # initialize debug listener (reroute messages to console)
            self.d = sprint.DebugListener()
        sprint.PrintTarget.CONSOLE = 1134
Esempio n. 8
0
def get_open_port():
    """
    Resolves an available port for socket messages
    Returns: available port number
    """


    environment.getEnvironmentVars()
    try:
        # get the port number from the settings file
        port = int(os.environ['APP_CONSOLE_SOCKET'])
    except KeyError:
        # set the port to 0 if it is not found in the settings file.  This will make the socket library find an open port.
        port = 0

    try:
        s = socket(AF_INET, SOCK_DGRAM)

        # attempt to bind to the port
        s.bind(("localhost", port))

        # get the port number from the socket
        port = s.getsockname()[1]

        # always close the socket.  This allows the gui console to bind to it later (see caveat below)
        s.close()

        # save this port back to the environment vars
        environment.setEnvironmentVar('APP','CONSOLE_SOCKET',port)
    except:
        # an error is raised if the gui has bound to this address before the engine tries to.
        # ignore this error for now, however we should wait until sprint has resolved socket
        # ports before allowing the gui to bind to it.
        pass

    return port