Ejemplo n.º 1
0
 def __init__(self):
     self.c = Communicate()
     self.d = Detection()
     self.m = Measure()
     self.msg_list = MSG_LIST  # 提示消息字典
     self.cmd_dict = {}  # 命令字典
     self._func_dict()  # 填充cmd_dict,将类方法名中后缀为'_(\d+)'的方法添加进命令字典
Ejemplo n.º 2
0
    def __init__(self, callbackFunc, hostname, messagetosend, endchar, timeout, attempts=1):
        '''Constructor'''
        Thread.__init__(self)
        self._name = "ClientCommThread"
        self._portname = None




        if callbackFunc != None:
            self._callback = Communicate()
            self._callback.myGUI_signal.connect(callbackFunc)

        if hostname != None:
            self._hostname = hostname

        if timeout != None:
            self._timeout = timeout


        if not StringUtils.isNoneOrEmpty(messagetosend):
            self._messagetosend = messagetosend

        if not StringUtils.isNoneOrEmpty(endchar):
            self._end_char = endchar

        if attempts != None:
            self._attemps = attempts

        self._stopevent = Event()
        self._stopevent.clear()

        self._wasStopped = Event()
        self._wasStopped.clear()
Ejemplo n.º 3
0
    def __init__(self,
                 callbackFunc,
                 serialport,
                 baudrate,
                 messagetosend,
                 endchar,
                 timeout,
                 attempts=2):
        '''Constructor'''
        Thread.__init__(self)
        self._name = "SerialCommThread"
        self._portname = None

        if callbackFunc != None:
            self._callback = Communicate()
            self._callback.myGUI_signal.connect(callbackFunc)

        if baudrate != None:
            self._baudrate = baudrate

        if timeout != None:
            self._timeout = timeout

        if serialport != None and baudrate != None:
            self._serialport = serialport
            self._serialport.baudrate = self._baudrate
            self._serialport.rtscts = False
            self._serialport.dsrdtr = False
            self._serialport.timeout = 10
            self._serialport.writeTimeout = 1
            self._serialport.stopbits = serial.STOPBITS_ONE
            self._serialport.parity = serial.PARITY_NONE
            self._serialport.bytesize = serial.EIGHTBITS
            self._serialport.xonxoff = True

            self._serialport.setDTR(True)
            self._serialport.setRTS(False)

            self._portname = self._serialport.name

            if timeout > 0:
                self._serialport.timeout = 0.25

        if not StringUtils.isNoneOrEmpty(messagetosend):
            self._messagetosend = messagetosend

        if not StringUtils.isNoneOrEmpty(endchar):
            self._end_char = endchar

        if attempts != None:
            self._attemps = attempts

        self._stopevent = Event()
        self._stopevent.clear()

        self._wasStopped = Event()
        self._wasStopped.clear()
Ejemplo n.º 4
0
 def test_lamp_simple_print(self):
     lamp = Communicate(self.lampExecutable, self.lampPrompt, self.lampExitCommand)
     
     output,errors = lamp.communicate('print, "%s"'%self.stringToPrint, waitTimeForTheCommandToGiveOutput=0.2)
     
     self.assertEqual(output.strip(),self.stringToPrint)
     self.assertEqual(errors.strip(),"")
     
     lamp.exit();
    def __init__(self, args):
        '''Constructor'''
        Thread.__init__(self)
        self._args = args
        self._name = "DataListenerServer Thread"
        if args != None:
            self.mySrc = Communicate()
            self.mySrc.myGUI_signal.connect(args)

        self._stop_event = Event()
        self._stop_event.clear()
Ejemplo n.º 6
0
    def __init__(self,comm):
        '''Constructor'''
        Thread.__init__(self)
        self._comm = comm
        self._name = "UpdateFile Thread"
        
        if comm != None:
            self._src = Communicate()
            self._src.myGUI_signal.connect(comm)

        self._stopEvent = Event()
        self._stopEvent.clear() 
Ejemplo n.º 7
0
 def test_lamp_print_with_process_relaunch(self):
     lamp = Communicate(self.lampExecutable, self.lampPrompt, self.lampExitCommand)
     #time.sleep(0.2)
     output,errors = lamp.communicate('print, "%s"'%self.stringToPrint, waitTimeForTheCommandToGiveOutput=0.2)
     
     self.assertEqual(output.strip(),self.stringToPrint)
     self.assertEqual(errors.strip(),"")
     
     lamp.exit();
     
     output,errors = lamp.communicate('print, "%s"'%self.stringToPrint, waitTimeForTheCommandToGiveOutput=0.2)
     
     self.assertEqual(output.strip(),self.stringToPrint)
     self.assertEqual(errors.strip(),"")
     
     lamp.exit();
Ejemplo n.º 8
0
    def test_python_simple_print(self):
        '''
        To run just this test:
        python -m unittest -q testCommunicate.TestCommunicate.test_python_simple_print
        '''

        pyshell = Communicate(self.pythonExecutable, self.pythonPrompt, self.pythonExitCommand)
        time.sleep(0.2)
        output,errors = pyshell.communicate('print "%s"'%self.stringToPrint, waitTimeForTheCommandToGiveOutput=0)
        
        print 'O', output
        print 'E', errors
        
        self.assertEqual(output.strip(),self.stringToPrint)
        self.assertEqual(errors.strip(),"")
        
        pyshell.exit();
Ejemplo n.º 9
0
def executeProcess(manifest,
                   role_name,
                   script,
                   function,
                   extension_id,
                   user_id,
                   argv,
                   timeout,
                   stdin=None,
                   rlimit_rss=256):
    flavor = manifest.flavor

    if manifest.flavor not in configuration.extensions.FLAVORS:
        flavor = configuration.extensions.DEFAULT_FLAVOR

    executable = configuration.extensions.FLAVORS[flavor]["executable"]
    library = configuration.extensions.FLAVORS[flavor]["library"]

    process_argv = [executable, os.path.join(library, "critic-launcher.js")]

    stdin_data = "%s\n" % json_encode({
        "criticjs_path":
        os.path.join(library, "critic.js"),
        "rlimit": {
            "rss": rlimit_rss
        },
        "hostname":
        configuration.base.HOSTNAME,
        "dbname":
        configuration.database.PARAMETERS["database"],
        "dbuser":
        configuration.database.PARAMETERS["user"],
        "git":
        configuration.executables.GIT,
        "python":
        configuration.executables.PYTHON,
        "python_path":
        "%s:%s" %
        (configuration.paths.CONFIG_DIR, configuration.paths.INSTALL_DIR),
        "repository_work_copy_path":
        configuration.extensions.WORKCOPY_DIR,
        "changeset_address":
        configuration.services.CHANGESET["address"],
        "branchtracker_pid_path":
        configuration.services.BRANCHTRACKER["pidfile_path"],
        "maildelivery_pid_path":
        configuration.services.MAILDELIVERY["pidfile_path"],
        "is_development":
        configuration.debug.IS_DEVELOPMENT,
        "extension_path":
        manifest.path,
        "extension_id":
        extension_id,
        "user_id":
        user_id,
        "role":
        role_name,
        "script_path":
        script,
        "fn":
        function,
        "argv":
        argv
    })

    if stdin is not None:
        stdin_data += stdin

    process = subprocess.Popen(process_argv,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               cwd=manifest.path)

    communicate = Communicate(process)
    communicate.setInput(stdin_data)
    communicate.setTimeout(timeout)

    return communicate.run()[0]