コード例 #1
0
ファイル: umnio.py プロジェクト: titasroy89/Calibration_HE
def send_commands(ts=None, crate=None, slot=None, ip=None, control_hub=None, cmds=cmds_default, script=False):
        # Sends commands to "uHTRtool.exe" and returns the raw output and a log. The input is a teststand object and a list of commands.
        # Arguments and variables:
        raw = ""
        results = {}                # Results will be indexed by uHTR IP unless a "ts" has been specified, in which case they'll be indexed by (crate, slot).
        
        ## Parse ip argument:
        ips = meta.parse_args_ip(ts=ts, crate=crate, slot=slot, ip=ip)
        if ips:
                ## Parse control_hub argument:
                control_hub = meta.parse_args_hub(ts=ts, control_hub=control_hub)
        
                ## Parse cmds:
                if isinstance(cmds, str):
                        print 'WARNING (umnio.send_commands): You probably didn\'t intend to run "uMNioTool.exe" with only one command: {0}'.format(cmds)
                        cmds = [cmds]
                cmds_str = ""
                for c in cmds:
                        cmds_str += "{0}\n".format(c)

                # Send the commands:
                for uhtr_ip, crate_slot in ips.iteritems():
                        # Prepare the uHTRtool arguments:
                        uhtr_cmd = "uMNioTool.exe {0}".format(uhtr_ip)
                        if control_hub:
                                uhtr_cmd += " -o {0}".format(control_hub)
                        # Send commands and organize results:
                        if script:
                                with open("umnio_script.cmd", "w") as out:
                                        out.write(cmds_str)
#                                print uhtr_cmd
                                raw_output = Popen(['{0} < umnio_script.cmd'.format(uhtr_cmd)], shell = True, stdout = PIPE, stderr = PIPE).communicate()
                        else:
                                raw_output = Popen(['printf "{0}" | {1}'.format(cmds_str, uhtr_cmd)], shell = True, stdout = PIPE, stderr = PIPE).communicate()                # This puts the output of the command into a list called "raw_output" the first element of the list is stdout, the second is stderr.
                        raw += raw_output[0] + raw_output[1]
                        if crate_slot:
                                results[crate_slot] = raw
                        else:
                                results[uhtr_ip] = raw
                return results
        else:
                return False
コード例 #2
0
ファイル: ngfec.py プロジェクト: titasroy89/Calibration_HE
def send_commands(
    ts=None, control_hub=None, port=port_default, cmds=cmds_default, script=False, raw=False, time_out=30
):
    # Arguments and variables
    output = []
    raw_output = ""
    ## Parse ngFEC server port:
    port = meta.parse_args_port(ts=ts, port=port)  # Uses "ts.ngfec_port" unless a ts is not specified.
    ## Parse control_hub argument:
    control_hub = meta.parse_args_hub(
        ts=ts, control_hub=control_hub
    )  # Uses "ts.control_hub" unless a ts is not specified.
    if control_hub != False and port:  # Potential bug if "port=0" ... (Control_hub should be allowed to be None.)
        ## Parse commands:
        if isinstance(cmds, str):
            cmds = [cmds]
        if not script:
            if "quit" not in cmds:
                cmds.append("quit")
        else:
            cmds = [c for c in cmds if c != "quit"]  # "quit" can't be in a ngFEC script.
            cmds_str = ""
            for c in cmds:
                cmds_str += "{0}\n".format(c)
            file_script = "ngfec_script"
            with open(file_script, "w") as out:
                out.write(cmds_str)

                # Prepare the ngfec arguments:
        ngfec_cmd = "/home/hep/ChargeInjector/ccmServerConnect.sh"
        # ngfec_cmd = 'ngFEC.exe -t -c -p {0}'.format(port)
        # if not script:
        # 	ngfec_cmd = 'ngFEC.exe -t -z -c -p {0}'.format(port)
        # if control_hub != None:
        # 	ngfec_cmd += " -H {0}".format(control_hub)

        # Send the ngfec commands:
        # 		print ngfec_cmd
        p = pexpect.spawn(ngfec_cmd, timeout=time_out)
        # 		print p.pid
        if not script:
            for i, c in enumerate(cmds):
                # 				print c
                p.sendline(c)
                if c != "quit":
                    t0 = time()
                    p.expect("{0}\s?#((\s|E)[^\r^\n]*)".format(escape(c)))
                    t1 = time()
                    # 					print [p.match.group(0)]
                    output.append({"cmd": c, "result": p.match.group(1).strip().replace("'", ""), "times": [t0, t1]})
                    raw_output += p.before + p.after
        else:
            p.sendline("< {0}".format(file_script))
            for i, c in enumerate(cmds):
                # Deterimine how long to wait until the first result is expected:
                if i == 0:
                    timeout = max([time_out, int(0.0075 * len(cmds))])
                # 					print i, c, timeout
                else:
                    timeout = time_out  # pexpect default
                # 					print i, c, timeout
                # 				print i, c, timeout

                # Send commands:
                t0 = time()
                p.expect("{0}\s?#((\s|E)[^\r^\n]*)".format(escape(c)), timeout=timeout)
                t1 = time()
                # 				print [p.match.group(0)]
                output.append({"cmd": c, "result": p.match.group(1).strip().replace("'", ""), "times": [t0, t1]})
                raw_output += p.before + p.after
            p.sendline("quit")
        p.expect(pexpect.EOF)
        raw_output += p.before
        # 		sleep(1)		# I need to make sure the ngccm process is killed.
        p.close()
        # 		print "closed"
        # 		killall()
        if raw:
            return raw_output
        else:
            return output
コード例 #3
0
def send_commands(ts=None,
                  crate=None,
                  slot=None,
                  ip=None,
                  control_hub=None,
                  cmds=cmds_default,
                  script=False):
    # Sends commands to "uHTRtool.exe" and returns the raw output and a log. The input is a teststand object and a list of commands.
    # Arguments and variables:
    raw = ""
    results = {
    }  # Results will be indexed by uHTR IP unless a "ts" has been specified, in which case they'll be indexed by (crate, slot).

    ## Parse ip argument:
    ips = meta.parse_args_ip(ts=ts, crate=crate, slot=slot, ip=ip)
    if ips:
        ## Parse control_hub argument:
        control_hub = meta.parse_args_hub(ts=ts, control_hub=control_hub)

        ## Parse cmds:
        if isinstance(cmds, str):
            print 'WARNING (umnio.send_commands): You probably didn\'t intend to run "uMNioTool.exe" with only one command: {0}'.format(
                cmds)
            cmds = [cmds]
        cmds_str = ""
        for c in cmds:
            cmds_str += "{0}\n".format(c)

        # Send the commands:
        for uhtr_ip, crate_slot in ips.iteritems():
            # Prepare the uHTRtool arguments:
            uhtr_cmd = "uMNioTool.exe {0}".format(uhtr_ip)
            if control_hub:
                uhtr_cmd += " -o {0}".format(control_hub)
            # Send commands and organize results:
            if script:
                with open("umnio_script.cmd", "w") as out:
                    out.write(cmds_str)


#                                print uhtr_cmd
                raw_output = Popen(['{0} < umnio_script.cmd'.format(uhtr_cmd)],
                                   shell=True,
                                   stdout=PIPE,
                                   stderr=PIPE).communicate()
            else:
                raw_output = Popen(
                    ['printf "{0}" | {1}'.format(cmds_str, uhtr_cmd)],
                    shell=True,
                    stdout=PIPE,
                    stderr=PIPE
                ).communicate(
                )  # This puts the output of the command into a list called "raw_output" the first element of the list is stdout, the second is stderr.
            raw += raw_output[0] + raw_output[1]
            if crate_slot:
                results[crate_slot] = raw
            else:
                results[uhtr_ip] = raw
        return results
    else:
        return False
コード例 #4
0
ファイル: ngfec.py プロジェクト: titasroy89/Calibration_HE
def send_commands(ts=None, control_hub=None, port=port_default, cmds=cmds_default, script=False, raw=False, time_out=30):
	# Arguments and variables
	output = []
	raw_output = ""
	## Parse ngFEC server port:
	port = meta.parse_args_port(ts=ts, port=port)		# Uses "ts.ngfec_port" unless a ts is not specified.
	## Parse control_hub argument:
	control_hub = meta.parse_args_hub(ts=ts, control_hub=control_hub)		# Uses "ts.control_hub" unless a ts is not specified.
	if control_hub != False and port:		# Potential bug if "port=0" ... (Control_hub should be allowed to be None.)
		## Parse commands:
		if isinstance(cmds, str):
			cmds = [cmds]
		if not script:
			if "quit" not in cmds:
				cmds.append("quit")
		else:
			cmds = [c for c in cmds if c != "quit"]		# "quit" can't be in a ngFEC script.
			cmds_str = ""
			for c in cmds:
				cmds_str += "{0}\n".format(c)
			file_script = "ngfec_script"
			with open(file_script, "w") as out:
				out.write(cmds_str)
		
		# Prepare the ngfec arguments:
		ngfec_cmd = '/home/hep/ChargeInjector/ccmServerConnect.sh'
		# ngfec_cmd = 'ngFEC.exe -t -c -p {0}'.format(port)
		# if not script:
		# 	ngfec_cmd = 'ngFEC.exe -t -z -c -p {0}'.format(port)
		# if control_hub != None:
		# 	ngfec_cmd += " -H {0}".format(control_hub)
		
		# Send the ngfec commands:
#		print ngfec_cmd
		p = pexpect.spawn(ngfec_cmd, timeout=time_out)
#		print p.pid
		if not script:
			for i, c in enumerate(cmds):
#				print c
				p.sendline(c)
				if c != "quit":
					t0 = time()
					p.expect("{0}\s?#((\s|E)[^\r^\n]*)".format(escape(c)))
					t1 = time()
#					print [p.match.group(0)]
					output.append({
						"cmd": c,
						"result": p.match.group(1).strip().replace("'", ""),
						"times": [t0, t1],
					})
					raw_output += p.before + p.after
		else:
			p.sendline("< {0}".format(file_script))
			for i, c in enumerate(cmds):
				# Deterimine how long to wait until the first result is expected:
				if i == 0:
					timeout = max([time_out, int(0.0075*len(cmds))])
#					print i, c, timeout
				else:
					timeout = time_out		# pexpect default
#					print i, c, timeout
#				print i, c, timeout
				
				# Send commands:
				t0 = time()
				p.expect("{0}\s?#((\s|E)[^\r^\n]*)".format(escape(c)), timeout=timeout)
				t1 = time()
#				print [p.match.group(0)]
				output.append({
					"cmd": c,
					"result": p.match.group(1).strip().replace("'", ""),
					"times": [t0, t1],
				})
				raw_output += p.before + p.after
			p.sendline("quit")
		p.expect(pexpect.EOF)
		raw_output += p.before
#		sleep(1)		# I need to make sure the ngccm process is killed.
		p.close()
#		print "closed"
#		killall()
		if raw:
			return raw_output
		else:
			return output