def first_run(userCfg): x = raw_input("Would you like to install supervisor and supervisor entry ? (y/N) ") psw = getpass.getpass() if x.lower() == "y": sts, ret = cmd("echo " + psw + " | sudo -S apt-get install supervisor") if sts != 0: print "Error installing supervisor - aborting" print "[" + ret + "]" return sudo(psw, "touch /etc/supervisor/conf.d/restplayer.conf") sudo(psw, "chown " + getpass.getuser() + " /etc/supervisor/conf.d/restplayer.conf") with open("/etc/supervisor/conf.d/restplayer.conf", "w") as f: cfg = default_supervisor_config current_path = os.path.abspath(inspect.getfile(inspect.currentframe())) cfg = cfg.replace("COMMANDLINE", current_path) cfg = cfg.replace("USER", getpass.getuser()) f.write(cfg) userConfig.write() sts, ret = cmd("supervisorctl reload") if ret != 0: print "Error loading supervisor, trying as root" sts, ret = sudo(psw, "supervisorctl reload") if sts != 0: print "Error also with root[ " + str(ret) + "]" return sts, ret = cmd("supervisorctl restart restplayer") if ret != 0: print "Error running supervisor, trying as root" sts, ret = sudo(psw, "supervisorctl restart restplayer") if sts != 0: print "Error also with root[ " + str(ret) + "]" return
def detect_ipmi(hw_lst): 'Detect IPMI interfaces.' modprobe("ipmi_smb") modprobe("ipmi_si") modprobe("ipmi_devintf") if os.path.exists('/dev/ipmi0') or os.path.exists('/dev/ipmi/0') \ or os.path.exists('/dev/ipmidev/0'): for channel in range(0, 16): status, _ = cmd('ipmitool channel info %d 2>&1 | grep -sq Volatile' % channel) if status == 0: hw_lst.append(('system', 'ipmi', 'channel', '%s' % channel)) break status, output = cmd('ipmitool lan print') if status == 0: ipmi.parse_lan_info(output, hw_lst) else: # do we need a fake ipmi device for testing purpose ? status, _ = cmd('grep -qi FAKEIPMI /proc/cmdline') if status == 0: # Yes ! So let's create a fake entry hw_lst.append(('system', 'ipmi-fake', 'channel', '0')) sys.stderr.write('Info: Added fake IPMI device\n') return True else: sys.stderr.write('Info: No IPMI device found\n') return False
def detect_ipmi(hw_lst): 'Detect IPMI interfaces.' modprobe("ipmi_smb") modprobe("ipmi_si") modprobe("ipmi_devintf") if os.path.exists('/dev/ipmi0') or os.path.exists('/dev/ipmi/0') \ or os.path.exists('/dev/ipmidev/0'): for channel in range(0, 16): status, _ = cmd( 'ipmitool channel info %d 2>&1 | grep -sq Volatile' % channel) if status == 0: hw_lst.append(('system', 'ipmi', 'channel', '%s' % channel)) break status, output = cmd('ipmitool lan print') if status == 0: ipmi.parse_lan_info(output, hw_lst) else: # do we need a fake ipmi device for testing purpose ? status, _ = cmd('grep -qi FAKEIPMI /proc/cmdline') if status == 0: # Yes ! So let's create a fake entry hw_lst.append(('system', 'ipmi-fake', 'channel', '0')) sys.stderr.write('Info: Added fake IPMI device\n') return True else: sys.stderr.write('Info: No IPMI device found\n') return False
def closefp(fp): f = tempfile.mktemp() + ".gdb" x = open(f,"w") x.write("call close(" + fp + ")\nquit\n\n") x.close() print f print cmd("cat " + f) print cmd("gdb -p " + pid + " --command=" + f + " --batch")
def makePDF(currentDir, error=False): os.chdir(currentDir + '/fig/') if error: st, out = cmd('pdflatex test_err_results.tex') st, out = cmd('rm test_err_results.{aux,log}') else: st, out = cmd('pdflatex test_results.tex') st, out = cmd('rm test_results.{aux,log}') os.chdir(currentDir)
def ib_global_info(card_drv): '''Return global info of a IB card in a python dict. (take in argument a card_drv (ex: mlx4_0)). ''' global_card_info = {} global_info = cmd('ibstat %s -s' % card_drv) for line in global_info.split('\n'): re_dev = re.search('CA type: (.*)', line) if re_dev is not None: global_card_info['device_type'] = re_dev.group(1) re_nb_ports = re.search('Number of ports: (.*)', line) if re_nb_ports is not None: global_card_info['nb_ports'] = re_nb_ports.group(1) re_fw_ver = re.search('Firmware version: (.*)', line) if re_fw_ver is not None: global_card_info['fw_ver'] = re_fw_ver.group(1) re_hw_ver = re.search('Hardware version: (.*)', line) if re_hw_ver is not None: global_card_info['hw_ver'] = re_hw_ver.group(1) re_node_guid = re.search('Node GUID: (.*)', line) if re_node_guid is not None: global_card_info['node_guid'] = re_node_guid.group(1) re_sys_guid = re.search('System image GUID: (.*)', line) if re_sys_guid is not None: global_card_info['sys_guid'] = re_sys_guid.group(1) return global_card_info
def compConf(fname='conf.log', mpi='', hdf='/', cdf='/', fcc='gfortran' \ , oacc=0, pro='shock_tube', ndim=1, iso=0): try: with open(fname) as logfile: st, out = cmd("ls Makefile") if st != 0: return 0 else: logline = logfile.read() args = logline.split(" --") args = args[1:] larg = ['with-mpi', 'with-phdf5', 'with-pnetcdf' \ , 'with-fortran-compiler', 'with-openacc', 'problem' \ , 'ndim', 'isothermal'] linp = ['' for i in range(len(larg))] linp[larg.index('with-openacc')] = 0 for i in range(len(args)): if args[i] != "with-openacc": targ, tinp = args[i].split('=') else: targ = "with-openacc"; tinp=1 linp[larg.index(targ)] = tinp linp[-1] = linp[-1].split('\n')[0] lnew = np.array([mpi, hdf, cdf, fcc, oacc, pro, ndim, iso]) if np.array(lnew == linp).all(): return 1 else: return 0 except IOError: print("File 'conf.log' does not exist") return 0
def ib_global_info(card_drv): '''Return global info of a IB card in a python dict. (take in argument a card_drv (ex: mlx4_0)).''' global_card_info = {} global_info = cmd('ibstat %s -s' % card_drv) for line in global_info.split('\n'): re_dev = re.search('CA type: (.*)', line) if re_dev is not None: global_card_info['device_type'] = re_dev.group(1) re_nb_ports = re.search('Number of ports: (.*)', line) if re_nb_ports is not None: global_card_info['nb_ports'] = re_nb_ports.group(1) re_fw_ver = re.search('Firmware version: (.*)', line) if re_fw_ver is not None: global_card_info['fw_ver'] = re_fw_ver.group(1) re_hw_ver = re.search('Hardware version: (.*)', line) if re_hw_ver is not None: global_card_info['hw_ver'] = re_hw_ver.group(1) re_node_guid = re.search('Node GUID: (.*)', line) if re_node_guid is not None: global_card_info['node_guid'] = re_node_guid.group(1) re_sys_guid = re.search('System image GUID: (.*)', line) if re_sys_guid is not None: global_card_info['sys_guid'] = re_sys_guid.group(1) return global_card_info
def ib_port_info(card_drv, port): '''Return port infos of a IB card_drv in a python dict. (take in argument the card_drv name and the port number (ex: mlx4_0,1)) ''' port_infos = {} port_desc = cmd('ibstat %s %i' % (card_drv, port)) for line in port_desc.split('\n'): re_state = re.search('State: (.*)', line) if re_state is not None: port_infos['state'] = re_state.group(1) re_phy_state = re.search('State: (.*)', line) if re_phy_state is not None: port_infos['physical_state'] = re_phy_state.group(1) re_rate = re.search('Rate: (.*)', line) if re_rate is not None: port_infos['rate'] = re_rate.group(1) re_blid = re.search('Base lid: (.*)', line) if re_blid is not None: port_infos['base_lid'] = re_blid.group(1) re_lmc = re.search('LMC: (.*)', line) if re_lmc is not None: port_infos['lmc'] = re_lmc.group(1) re_smlid = re.search('SM lid: (.*)', line) if re_smlid is not None: port_infos['sm_lid'] = re_smlid.group(1) re_pguid = re.search('Port GUID: (.*)', line) if re_pguid is not None: port_infos['port_guid'] = re_pguid.group(1) return port_infos
def ib_port_info(card_drv, port): '''Return port infos of a IB card_drv in a python dict. (take in argument the card_drv name and the port number (ex: mlx4_0,1))''' port_infos = {} port_desc = cmd('ibstat %s %i' % (card_drv, port)) for line in port_desc.split('\n'): re_state = re.search('State: (.*)', line) if re_state is not None: port_infos['state'] = re_state.group(1) re_phy_state = re.search('State: (.*)', line) if re_phy_state is not None: port_infos['physical_state'] = re_phy_state.group(1) re_rate = re.search('Rate: (.*)', line) if re_rate is not None: port_infos['rate'] = re_rate.group(1) re_blid = re.search('Base lid: (.*)', line) if re_blid is not None: port_infos['base_lid'] = re_blid.group(1) re_lmc = re.search('LMC: (.*)', line) if re_lmc is not None: port_infos['lmc'] = re_lmc.group(1) re_smlid = re.search('SM lid: (.*)', line) if re_smlid is not None: port_infos['sm_lid'] = re_smlid.group(1) re_pguid = re.search('Port GUID: (.*)', line) if re_pguid is not None: port_infos['port_guid'] = re_pguid.group(1) return port_infos
def get_token(username, password, token=None): # TODO: implement oauth2 logic #if username is not None and password is not None: # token = oauth2 if token is None: # TODO: error if token not found in .gitconfig token = cmd('git config github.token') return token
def ping(self): status, output = cmd("ping %s -c5 -W5 -i0.2" % self.target) if status == 0: self.failedCount = 0 else: self.failedCount += 1 return '\n'.join(output.split('\n')[-3:]) + ' failedCount=' + str( self.failedCount)
def callback(self, recognizer, audio): """ Callback funtion to recognize noise in the background :return: None """ # attempt to recognize words being said, check for errors try: # convert speech to text self.text = recognizer.recognize_google(audio, language='en-US') print("Randor Assistant thinks you said: ", self.text) except sr.UnknownValueError: # if the audio could not be understood self.text = None print("Randor Assistant Could Not Understand You") except sr.RequestError as e: # if there is an internal error with Google or # no internet connection self.text = None print("Could not request results form Google services; {0}".format( e)) if self.command: # respond to a command if platform == 'linux' or platform == 'linux2': if self.count == 1: response = cmd(self.text) response.result() self.command = False else: self.count = self.count + 1 else: response = cmd(self.text) response.result() self.command = False commonNameSpells = ['randor', 'ran door', 'randeur'] if self.text is not None and (any( x in self.text for x in commonNameSpells)) and not self.command: # Check if randor was called and it is not in command mode self.command = True self.count = 0 speakResponse = random.choice(self.speakingStartResponses) self.speaker.respond(speakResponse) playsound.playsound('beep.mp3')
def get_payload_kerberos_exe(url, query): from commands import getstatusoutput as cmd script_path = path_join(dirname(abspath(__file__)), 'get_pl_krb.py') e, o = cmd( "eval `scram unset -sh`; python '%s' '%s' '%s' 2>&1 | grep JSON_OUT= | sed 's|.*JSON_OUT= *||'" % (script_path, url, query)) #print e, o return json.loads(o)
def setup_user(channel, username, password): sys.stderr.write('Info: ipmi_setup_user: Setting user="******", ' 'password="******" on channel %s\n' % (username, password, channel)) cmd('ipmitool user set name 1 %s' % username) cmd('ipmitool user set password 1 %s' % password) cmd('ipmitool user priv 1 4 %s' % channel) cmd('ipmitool user enable') state, _ = cmd('ipmitool user test 1 16 %s' % password) if state == 0: sys.stderr.write('Info: ipmi_setup_user: Setting user successful !\n') else: sys.stderr.write('Err: ipmi_setup_user: Setting user failed !\n') return False
def main(): try: os.makedirs('./bin') except OSError: pass tree = FileTree('./src') tree.processAllFiles() editMakefile() st, out = cmd('make') print out
def runConfigure(mpi='/', hdf='/', cdf='/', fcc='gfortran', oacc=0 \ , pro='shock_tube', ndim=1, iso=0): st, out = cmd('./configure' + ('' if mpi == '' else ' --with-mpi=' + mpi) \ + ('' if hdf == '' else ' --with-phdf5=' + hdf) \ + ('' if cdf == '' else ' --with-pnetcdf=' + cdf) \ + ('' if fcc == '' else ' --with-fortran-compiler=' + fcc) \ + ('' if oacc == 0 else ' --with-openacc') \ + ('' if pro == '' else ' --problem=' + pro) \ + ('' if ndim == '' else ' --ndim=%d' %ndim) \ + ('' if iso == '' else ' --iso=%d' %iso)) return st, out
def launchTest(self): """Launch a GPU configuration test for a given maxregcount and a maximum block dimension. Store the log of the run in 'log_rc[maxregcount].dat', all the elapsed times in 'save_all_rc[maxregcount].pkl' and the reduced elapsed times in 'save_time_rc[maxregcount].pkl'. Return a dictionary with the reduced results.""" firstPass = True for couple in self.geneCouple(): currentKey = '{}x{}'.format(couple[0], couple[1]) self.cresults[currentKey] = {} print("Computing time for {} with maxregcount={}".format( currentKey, self.mrc)) self.geneDict(x=couple[0], y=couple[1]) self.rewriteFile() st, out = cmd('pwd') localdir = out os.chdir(self.rootdir) if firstPass: st, out = cmd('./configure --problem=magnetic_loop -o') self.rewriteMakefile() st, out = cmd('./make.py') st, out = cmd('cp src/problem/magnetic_loop/input ' + localdir + '/.') self.rewriteInput(localdir) else: st, out = cmd('make shallow_clean; make') st, out = cmd('cp bin/dumses ' + localdir + '/.') os.chdir(localdir) st, out = cmd('./dumses') if firstPass: with open(self.logfile, 'w') as f: f.write(out) else: with open(self.logfile, "a") as f: f.write("\n") f.write(out) if firstPass: firstPass = False self.cresults[currentKey] = self.getTimes(out.split('\n')) with open(self.allfile, 'a') as f: pickle.dump({currentKey: self.cresults[currentKey]}, f) for key in self.cresults[currentKey].iterkeys(): if self.cresults[currentKey][key]: self.cresults[currentKey][key] = sum( self.cresults[currentKey][key]) / len( self.cresults[currentKey][key]) else: self.cresults[currentKey][key] = None with open(self.picklefile, 'w') as f: pickle.dump(self.cresults, f)
def run(): github = Github(username=GITHUB_USER, api_token=GITHUB_TOKEN) os.chdir(GITHUB_SYNC_DIR) repos = [] for path_to_repo in cmd('find {0} -name ".git"'.format(GITHUB_SYNC_DIR)).split("\n"): # Receive repositories repos.append(path_to_repo[0:-4]) for repo in repos: os.chdir(repo) try: # Receive current branch name branch = [br.split()[1] for br in cmd('git branch').split('\n') if br.split()[0] == "*"][0] except: puts(colored.yellow('Unkown branch in repository "{0}"!'.format(repo))) for remote in cmd('git remote -v').split('\n'): # Receive all remotes for repository remote = remote.split() if remote and remote[2] == "(fetch)" and 'github.com:' in remote[1]: puts(colored.green('Updating repo:')) puts(colored.cyan('> {0}'.format(repo))) puts(colored.cyan('> {0} ({1})'.format(remote[0], remote[1]))) os.system('git pull {0} {1}'.format(remote[0], branch))
def checkStatus(): master = {'host': argv[1], 'user': argv[2], 'pass': argv[3]} slave = {'user': argv[4], 'pass': argv[5]} io = cmd("mysql -u" + slave['user'] + " -p" + slave['pass'] + " -e \"show slave status\G;\" | grep -i Slave_SQL_Running") sql = cmd("mysql -u" + slave['user'] + " -p" + slave['pass'] + " -e \"show slave status\G;\" | grep Slave_IO_Running") # Checks if the replication is running fine if "Yes" in io and "Yes" in sql: master_pos = cmd("mysql -u" + master['user'] + " -p" + master['pass'] + " -h " + master['host'] + " -e \"show master status\G;\"\ | grep Position") master_pos = int(re.findall(r'\d+', str(master_pos))[0]) slave_pos = cmd("mysql -u" + slave['user'] + " -p" + slave['pass'] + " -e \"show slave status\G;\"\ | grep Read_Master_Log_Pos") slave_pos = int(re.findall(r'\d+', str(slave_pos))[0]) while master_pos != slave_pos: slave_pos = int(re.findall(r'\d+', cmd("mysql -u" + slave['user'] + " -p" + slave['pass'] + " -e \"show slave status\G;\"\ | grep Read_Master_Log_Pos"))) print('Syncing...') print("All fine!") return 1 else: print("There are errors") restoreReplication() return -1
def createInput(inputfile="input", problem="magnetic_loop" \ , tlim="1.", verbose=".false.", debug=".false." \ , bdtypex="'zero_gradient'", bdtypey="'zero_gradient'" \ , bdtypez="'zero_gradient'", riemann="'hlld'", riemann2d="'hlld'"\ , slope_type="2", courant="0.7", nx="32", ny="32", nz="32" \ , xmin="-1.d0", xmax="1.d0", ymin="-1.d0", ymax="1.d0" \ , zmin="0.d0", zmax="1.d0", Omega0="0.d0", ciso="0.d0" \ , gamma="1.001d0", dtdump=".1", io_type="'binary'" \ , nxslice="1", nyslice="1", nzslice="1", direction='x'): st, out = cmd('cp input.template ' + inputfile) template = open(inputfile, 'rt').read() data = { "tlim": tlim, "verbose": verbose, "debug": debug, "bdtypex": bdtypex, "bdtypey": bdtypey, "bdtypez": bdtypez, "riemann": riemann, "riemann2d": riemann2d, "slope_type": slope_type, "courant": courant, "nx": nx, "ny": ny, "nz": nz, "xmin": xmin, "xmax": xmax, "ymin": ymin, "ymax": ymax, "zmin": zmin, "zmax": zmax, "Omega0": Omega0, "ciso": ciso, "gamma": gamma, "dtdump": dtdump, "io_type": io_type, "nxslice": nxslice, "nyslice": nyslice, "nzslice": nzslice } with open(inputfile, 'wt') as output: output.write(template % data) lproDirect = ['shock_tube', 'orszag_tang', 'magnetic_loop', 'wind_tunnel'] if problem in lproDirect: f = open(inputfile, 'a') initparam="\n&init_params\n direction = '%s'\n /\n" \ %direction f.write(initparam) f.close()
def checkExe(problem="magnetic_loop", exedir="$HOME/dumses_hybrid/bin/", force=False): st, out = cmd("grep PRBDIR " + exedir + "../Makefile") probMakefile = out.split()[2].split("/")[-1] if not force: if probMakefile != problem: print( bold + "Warning! " + reset + "The problem specified is different from the problem in " + exedir + "../Makefile.\n If you know what you are doing, please reexecute the script with the '-f, --force' option" ) sys.exit(1)
def detect_infiniband(hw_lst): '''Detect Infiniband devinces. To detect if an IB device is present, we search for a pci device. This pci device shall be from vendor Mellanox (15b3) form class 0280 Class 280 stands for a Network Controller while ethernet device are 0200''' status, _ = cmd("lspci -d 15b3: -n|awk '{print $2}'|grep -q '0280'") if status == 0: ib_card = 0 for devices in range(ib_card, len(ib.ib_card_drv())): card_type = ib.ib_card_drv()[devices] ib_infos = ib.ib_global_info(card_type) nb_ports = ib_infos['nb_ports'] hw_lst.append( ('infiniband', 'card%i' % ib_card, 'card_type', card_type)) hw_lst.append(('infiniband', 'card%i' % ib_card, 'device_type', ib_infos['device_type'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'fw_version', ib_infos['fw_ver'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'hw_version', ib_infos['hw_ver'])) hw_lst.append( ('infiniband', 'card%i' % ib_card, 'nb_ports', nb_ports)) hw_lst.append(('infiniband', 'card%i' % ib_card, 'sys_guid', ib_infos['sys_guid'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'node_guid', ib_infos['node_guid'])) for port in range(1, int(nb_ports) + 1): ib_port_infos = ib.ib_port_info(card_type, port) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'state', ib_port_infos['state'])) hw_lst.append( ('infiniband', 'card%i_port%i' % (ib_card, port), 'physical_state', ib_port_infos['physical_state'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'rate', ib_port_infos['rate'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'base_lid', ib_port_infos['base_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'lmc', ib_port_infos['lmc'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'sm_lid', ib_port_infos['sm_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'port_guid', ib_port_infos['port_guid'])) return True else: sys.stderr.write('Info: No Infiniband device found\n') return False
def detect_infiniband(hw_lst): '''Detect Infiniband devinces. To detect if an IB device is present, we search for a pci device. This pci device shall be from vendor Mellanox (15b3) form class 0280 Class 280 stands for a Network Controller while ethernet device are 0200''' status, _ = cmd("lspci -d 15b3: -n|awk '{print $2}'|grep -q '0280'") if status == 0: ib_card = 0 for devices in range(ib_card, len(ib.ib_card_drv())): card_type = ib.ib_card_drv()[devices] ib_infos = ib.ib_global_info(card_type) nb_ports = ib_infos['nb_ports'] hw_lst.append(('infiniband', 'card%i' % ib_card, 'card_type', card_type)) hw_lst.append(('infiniband', 'card%i' % ib_card, 'device_type', ib_infos['device_type'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'fw_version', ib_infos['fw_ver'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'hw_version', ib_infos['hw_ver'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'nb_ports', nb_ports)) hw_lst.append(('infiniband', 'card%i' % ib_card, 'sys_guid', ib_infos['sys_guid'])) hw_lst.append(('infiniband', 'card%i' % ib_card, 'node_guid', ib_infos['node_guid'])) for port in range(1, int(nb_ports)+1): ib_port_infos = ib.ib_port_info(card_type, port) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'state', ib_port_infos['state'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'physical_state', ib_port_infos['physical_state'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'rate', ib_port_infos['rate'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'base_lid', ib_port_infos['base_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'lmc', ib_port_infos['lmc'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'sm_lid', ib_port_infos['sm_lid'])) hw_lst.append(('infiniband', 'card%i_port%i' % (ib_card, port), 'port_guid', ib_port_infos['port_guid'])) return True else: sys.stderr.write('Info: No Infiniband device found\n') return False
def es_krb_query_exe(index, query, start_time, end_time, page_start=0, page_size=10000, timestamp_field="@timestamp", lowercase_expanded_terms='false', es_host='https://es-cmssdt.cern.ch/krb'): from commands import getstatusoutput as cmd script_path = path_join(dirname(abspath(__file__)), 'es_query_krb.py') e, o = cmd( "eval `scram unset -sh`; python '%s' '%s' '%s' '%s' '%s' 2>&1 | grep JSON_OUT= | sed 's|.*JSON_OUT= *||'" % (script_path, index, query, start_time, end_time)) #print e, o return json.loads(o)
def runmodel(params): folder = params['level'] cmd('mkdir {0}/'.format(folder)) cmd('mkdir {0}/input'.format(folder)) cmd('mkdir {0}/output'.format(folder)) fname = '{0}/input/params.p'.format(folder) pickle.dump(params, open(fname, "wb")) if os.getcwd().split('/')[1] == 'global': print 'savio run' print 'python build_model.py {0} 0'.format(folder) a = cmd('python build_model.py {0} 0'.format(folder)) else: print 'local run' print 'python build_model.py {0} 1'.format(folder) a = cmd('python build_model.py {0} 1'.format(folder)) print a
def createInput(tlim="1.", verbose=".false.", debug=".false." \ , bdtypex="'zero_gradient'", bdtypey="'zero_gradient'" \ , bdtypez="'zero_gradient'", riemann="'hlld'", riemann2d="'hlld'"\ , slope_type="2", courant="0.7", nx="32", ny="32", nz="32" \ , xmin="-1.d0", xmax="1.d0", ymin="-1.d0", ymax="1.d0" \ , zmin="0.d0", zmax="1.d0", Omega0="0.d0", ciso="0.d0" \ , gamma="1.001d0", dtdump=".1", dthist="-1", io_type="'binary'" \ , nxslice="1", nyslice="1", nzslice="1"): st, out = cmd('cp ../input.template input') template = open('input', 'rt').read() data = {"tlim": tlim, "verbose": verbose, "debug": debug, "bdtypex": bdtypex, "bdtypey": bdtypey, "bdtypez": bdtypez, "riemann": riemann, "riemann2d": riemann2d, "slope_type": slope_type, "courant": courant, "nx": nx, "ny": ny, "nz": nz, "xmin": xmin, "xmax": xmax, "ymin": ymin, "ymax": ymax, "zmin": zmin, "zmax": zmax, "Omega0": Omega0, "ciso": ciso, "gamma": gamma, "dtdump": dtdump, "dthist": dthist, "io_type": io_type, "nxslice": nxslice, "nyslice": nyslice, "nzslice": nzslice } with open('input', 'wt') as output: output.write(template %data)
def createJobLL(jobfile="job.ll", inputfile="input", jobname="test_hybrid" \ , wallclock="30:00", rundir="$WORKDIR/loop" \ , exedir="$HOME/dumses_hybrid/bin/", bg_size="64" \ , rankpernode="16", omp_num_threads="1"): st, out = cmd('cp job_ll.template ' + jobfile) template = open(jobfile, 'rt').read() data = { "jobname": jobname, "wallclock": wallclock, "bg_size": bg_size, "rankpnode": rankpernode, "omp_num_threads": omp_num_threads, "rundir": rundir, "exedir": exedir, "inputfile": inputfile, "jobfile": jobfile } with open(jobfile, 'wt') as output: output.write(template % data)
def backgroundListener(self): """ Start listening from the background and call a callback function in order to allow for the assistant to communicate :return: Return the text that is sent from the background noise """ print("Starting up") stop_audio = self.r.listen_in_background(self.source, self.callback, phrase_time_limit=5) print("Go ahead and speak! Randor is listening! ") while self.text is None or 'exit' not in self.text: # Loop until told to stop looping time.sleep(0.1) # time pause to not overload CPU print("Exiting...") byeCommand = cmd('bye') byeCommand.result() stop_audio(wait_for_stop=False) # Stop the audio listener for i in range(50): # give 5 seconds to stop background proccess time.sleep(0.1)
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: hw_lst.append( (sys_cls, sys_type, sys_subtype, elt[0].attrib[attrib])) return elt[0].attrib[attrib] else: hw_lst.append((sys_cls, sys_type, sys_subtype, elt[0].text)) return elt[0].text return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') for elt in xml.findall(".//node[@id='memory']"): name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') bank_count = 0 for bank_list in elt.findall(".//node[@id]"): if ('bank:') in bank_list.get('id'): bank_count = bank_count + 1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): find_element(bank, 'size', 'size', bank_list.get('id'), 'memory') find_element(bank, 'clock', 'clock', bank_list.get('id'), 'memory') find_element(bank, 'description', 'description', bank_list.get('id'), 'memory') find_element(bank, 'vendor', 'vendor', bank_list.get('id'), 'memory') find_element(bank, 'serial', 'serial', bank_list.get('id'), 'memory') find_element(bank, 'slot', 'slot', bank_list.get('id'), 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', bank_count)) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: # lshw is not able to get the complete mac addr for ib # devices Let's workaround it with an ip command. if name.text.startswith('ib'): cmds = "ip addr show %s | grep link | awk '{print $2}'" status_ip, output_ip = cmd(cmds % name.text) hw_lst.append(('network', name.text, 'serial', output_ip.split('\n')[0])) else: find_element(elt, 'serial', 'serial', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, 'size', 'size', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl(sock, SIOCGIFNETMASK, struct.pack('256s', name.text))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) hw_lst.append( ('network', name.text, 'ipv4-network', "%s" % IPNetwork('%s/%s' % (ipv4, cidr)).network)) except Exception: sys.stderr.write('unable to get info for %s\n' % name.text) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", 'driver', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='duplex']", 'duplex', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='speed']", 'speed', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='latency']", 'latency', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='autonegotiation']", 'autonegotiation', name.text, 'network', 'value') for elt in xml.findall(".//node[@class='processor']"): name = elt.find('physid') if name is not None: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'physid', name.text)) find_element(elt, 'product', 'product', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'vendor', 'vendor', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'size', 'frequency', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'clock', 'clock', 'physical_%s' % socket_count, 'cpu') find_element(elt, "configuration/setting[@id='cores']", 'cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='enabledcores']", 'enabled_cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='threads']", 'threads', 'physical_%s' % socket_count, 'cpu', 'value') socket_count = socket_count + 1 else: sys.stderr.write("Unable to run lshw: %s\n" % output) hw_lst.append(('cpu', 'physical', 'number', str(socket_count))) status, output = cmd('nproc') if status == 0: hw_lst.append(('cpu', 'logical', 'number', str(output)))
def modprobe(module): 'Load a kernel module using modprobe.' status, _ = cmd('modprobe %s' % module) if status == 0: sys.stderr.write('Info: Probing %s failed\n' % module)
def get_volume(): val = cmd("amixer") ret = re.findall("Playback [0-9]* \[([0-9]*)%\] \[([\w]*)\]",val) return int(ret[0][0]), ret[0][1]
if args.msg: msg = re.sub("@N@", "\n", args.msg) elif args.report_file: msg = open(args.report_file).read() else: parser.error( "Missing issue message: -m|--message <message> OR -R|--report-file <file-path>" ) print "Authenticating to Github and connecting to repo" repo_dir = join(SCRIPT_DIR, 'repos', args.repo.replace("-", "_")) if exists(join(repo_dir, "repo_config.py")): sys.path.insert(0, repo_dir) import repo_config gh = Github( login_or_token=open(expanduser(repo_config.GH_TOKEN)).read().strip()) print "Authentication succeeeded" gh_repo = gh.get_repo(args.repo) e, o = cmd( "curl -s 'https://api.github.com/search/issues?q=%s+repo:%s+in:title+type:issue' | grep '\"number\"' | sed 's|.*: ||;s|,.*|'" % (urllib.quote(args.title), args.repo)) issue = None if not e: try: issue = gh_repo.get_issue(int(o)) except: pass if issue: print "Updaing comment" issue.create_comment(msg) else: print "Creating issue request" gh_repo.create_issue(args.title, msg)
def privmsg(server, word, word_eol, args): import commands try: commands.cmd(server, word, word_eol, usrManager, relayManager, loadedModules) except:
def setup_network(channel, ipv4, netmask, gateway, vlan_id=-1): 'Define the network of an IPMI interface.' sys.stderr.write('Info: ipmi_setup_network: Setting network ip="%s", ' 'netmask="%s", gateway="%s", vland_id="%d" on ' 'channel %s\n' % (ipv4, netmask, gateway, vlan_id, channel)) # NOTE (leseb): assuming you're missing an argument # and this already happened # ipmitool always returns 0 and prompt the valid values... cmd('ipmitool lan set %s ipsrc static' % channel) cmd('ipmitool lan set %s ipaddr %s' % (channel, ipv4)) cmd('ipmitool lan set %s netmask %s' % (channel, netmask)) cmd('ipmitool lan set %s defgw ipaddr %s' % (channel, gateway)) cmd('ipmitool lan set %s arp respond on' % channel) if vlan_id >= 0: cmd('ipmitool lan set %s vlan id %d' % (channel, vlan_id)) else: cmd('ipmitool lan set %s vlan id off' % channel) # We need to restart the bmc to insure the setup is properly done restart_bmc()
def start_bench_server(message, port_number): sys.stderr.write('Spawning netserver : (%s:%d)\n' % (message.my_peer_name, port_number)) status, output = cmd('netserver -p %d' % port_number)
def diskperfs(names): return { name: parse_hdparm_output(cmd('hdparm -t /dev/%s' % name)) for name in names }
def getpidport(port): output = cmd("netstat -lnp | grep tcp | grep " + port) print output return re.findall("LISTEN *([0-9]*)/", output)[0]
def stop_netservers(message): sys.stderr.write('Stopping netservers\n') status, output = cmd('pkill -9 netserver')
def stop_bench_servers(): cmd('pkill -9 netserver')
def findfp(pid, port): output = cmd("lsof -P -np "+ pid + " | grep IP").split("\n") fps = [] for line in output: fps.append(line.split(" ")[7]) return fps
def __init__(self): ret, val = cmd("which mpg123") assert ret == 0, "Mpg123 not available" self.p = None self.list = None
def ib_card_drv(): '''Return an array of IB device (ex: ['mlx4_0']).''' return [cmd('ibstat -l')]
def restart_bmc(): 'Restart a BMC card.' sys.stderr.write('Info: Restarting IPMI BMC\n') cmd('ipmitool bmc reset cold')
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: hw_lst.append((sys_cls, sys_type, sys_subtype, elt[0].attrib[attrib])) return elt[0].attrib[attrib] else: hw_lst.append((sys_cls, sys_type, sys_subtype, elt[0].text)) return elt[0].text return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') for elt in xml.findall(".//node[@id='memory']"): name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') bank_count = 0 for bank_list in elt.findall(".//node[@id]"): if ('bank:') in bank_list.get('id'): bank_count = bank_count+1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): find_element(bank, 'size', 'size', bank_list.get('id'), 'memory') find_element(bank, 'clock', 'clock', bank_list.get('id'), 'memory') find_element(bank, 'description', 'description', bank_list.get('id'), 'memory') find_element(bank, 'vendor', 'vendor', bank_list.get('id'), 'memory') find_element(bank, 'serial', 'serial', bank_list.get('id'), 'memory') find_element(bank, 'slot', 'slot', bank_list.get('id'), 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', bank_count)) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: # lshw is not able to get the complete mac addr for ib # devices Let's workaround it with an ip command. if name.text.startswith('ib'): cmds = "ip addr show %s | grep link | awk '{print $2}'" status_ip, output_ip = cmd(cmds % name.text) hw_lst.append(('network', name.text, 'serial', output_ip.split('\n')[0])) else: find_element(elt, 'serial', 'serial', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, 'size', 'size', name.text, 'network') find_element(elt, 'businfo', 'businfo', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl(sock, SIOCGIFNETMASK, struct.pack('256s', name.text))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) hw_lst.append( ('network', name.text, 'ipv4-network', "%s" % IPNetwork('%s/%s' % (ipv4, cidr)).network)) except Exception: sys.stderr.write('unable to get info for %s\n' % name.text) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", 'driver', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='duplex']", 'duplex', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='speed']", 'speed', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='latency']", 'latency', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='autonegotiation']", 'autonegotiation', name.text, 'network', 'value') for elt in xml.findall(".//node[@class='processor']"): name = elt.find('physid') if name is not None: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'physid', name.text)) find_element(elt, 'product', 'product', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'vendor', 'vendor', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'size', 'frequency', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'clock', 'clock', 'physical_%s' % socket_count, 'cpu') find_element(elt, "configuration/setting[@id='cores']", 'cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='enabledcores']", 'enabled_cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='threads']", 'threads', 'physical_%s' % socket_count, 'cpu', 'value') socket_count = socket_count+1 else: sys.stderr.write("Unable to run lshw: %s\n" % output) hw_lst.append(('cpu', 'physical', 'number', str(socket_count))) status, output = cmd('nproc') if status == 0: hw_lst.append(('cpu', 'logical', 'number', str(output)))
parser.add_argument("-m", "--message", dest="msg", help="Message to be posted s body of the GH issue",type=str, default='') parser.add_argument("-R", "--report_file", dest="report_file", help="File name contaning the issue message",type=str, default='') args = parser.parse_args() mgs="" if not args.repo: parser.error("Missing Repo") if not args.title: parser.error("Missing PR title") if args.msg: msg = re.sub("@N@","\n",args.msg) elif args.report_file: msg = open(args.report_file).read() else: parser.error("Missing issue message: -m|--message <message> OR -R|--report-file <file-path>") print "Authenticating to Github and connecting to repo" repo_dir = join(SCRIPT_DIR,'repos',args.repo.replace("-","_")) if exists(join(repo_dir,"repo_config.py")): sys.path.insert(0,repo_dir) import repo_config gh = Github(login_or_token=open(expanduser(repo_config.GH_TOKEN)).read().strip()) print "Authentication succeeeded" gh_repo = gh.get_repo(args.repo) e, o = cmd("curl -s 'https://api.github.com/search/issues?q=%s+repo:%s+in:title+type:issue' | grep '\"number\"' | sed -e 's|.*: ||;s|,.*||'" % (urllib.quote(args.title),args.repo)) issue = None if not e: try:issue = gh_repo.get_issue(int(o)) except: pass if issue: print "Updaing comment" issue.create_comment(msg) else: print "Creating issue request" gh_repo.create_issue(args.title, msg)
def diskperfs(names): return dict((name, parse_hdparm_output(cmd('hdparm -t /dev/%s' % name))) for name in names)
def sudo(psw, command): return cmd("echo " + psw + " | sudo -S " + command)
from subprocess import check_output def cmd(command): return check_output(command, shell=True).strip() except ImportError: # commands is deprecated and doesn't work on Windows from commands import getoutput as cmd __author__ = 'Kenneth Reitz' __license__ = 'ISC' __copyright__ = '2011 Kenneth REitz' __version__ = '0.3.1' # GitHub configurations GITHUB_USER = cmd('git config github.user') GITHUB_TOKEN = cmd('git config github.token') GHSYNC_DIR = os.environ.get('GHSYNC_DIR', '.') def run(): # cli flags upstream_on = args.flags.contains('--upstream') only_type = args.grouped.get('--only', False) organization = args[0] os.chdir(GHSYNC_DIR) # API Object github = GitHub(login=GITHUB_USER, token=GITHUB_TOKEN)
def detect_system(hw_lst, output=None): 'Detect system characteristics from the output of lshw.' socket_count = 0 def find_element(xml, xml_spec, sys_subtype, sys_type='product', sys_cls='system', attrib=None, transform=None): 'Lookup an xml element and populate hw_lst when found.' elt = xml.findall(xml_spec) if len(elt) >= 1: if attrib: txt = elt[0].attrib[attrib] else: txt = elt[0].text if transform: txt = transform(txt) hw_lst.append((sys_cls, sys_type, sys_subtype, txt)) return txt return None # handle output injection for testing purpose if output: status = 0 else: status, output = cmd('lshw -xml') if status == 0: xml = ET.fromstring(output) find_element(xml, "./node/serial", 'serial') find_element(xml, "./node/product", 'name') find_element(xml, "./node/vendor", 'vendor') find_element(xml, "./node/version", 'version') uuid = get_uuid() if uuid: hw_lst.append(('system', 'product', 'uuid', uuid)) for elt in xml.findall(".//node[@id='core']"): name = elt.find('physid') if name is not None: find_element(elt, 'product', 'name', 'motherboard', 'system') find_element(elt, 'vendor', 'vendor', 'motherboard', 'system') find_element(elt, 'version', 'version', 'motherboard', 'system') find_element(elt, 'serial', 'serial', 'motherboard', 'system') for elt in xml.findall(".//node[@id='firmware']"): name = elt.find('physid') if name is not None: find_element(elt, 'version', 'version', 'bios', 'firmware') find_element(elt, 'date', 'date', 'bios', 'firmware') find_element(elt, 'vendor', 'vendor', 'bios', 'firmware') bank_count = 0 for elt in xml.findall(".//node[@class='memory']"): if not elt.attrib['id'].startswith('memory'): continue try: location = re.search('memory(:.*)', elt.attrib['id']).group(1) except: location = '' name = elt.find('physid') if name is not None: find_element(elt, 'size', 'size', 'total', 'memory') for bank_list in elt.findall(".//node[@id]"): if ('bank:') in bank_list.get('id'): bank_count = bank_count+1 for bank in elt.findall(".//node[@id='%s']" % (bank_list.get('id'))): bank_id = bank_list.get('id').replace("bank:", "bank" + location + ":") find_element(bank, 'size', 'size', bank_id, 'memory') find_element(bank, 'clock', 'clock', bank_id, 'memory') find_element(bank, 'description', 'description', bank_id, 'memory') find_element(bank, 'vendor', 'vendor', bank_id, 'memory') find_element(bank, 'product', 'product', bank_id, 'memory') find_element(bank, 'serial', 'serial', bank_id, 'memory') find_element(bank, 'slot', 'slot', bank_id, 'memory') if bank_count > 0: hw_lst.append(('memory', 'banks', 'count', str(bank_count))) for elt in xml.findall(".//node[@class='network']"): name = elt.find('logicalname') if name is not None: find_element(elt, 'businfo', 'businfo', name.text, 'network') find_element(elt, 'vendor', 'vendor', name.text, 'network') find_element(elt, 'product', 'product', name.text, 'network') find_element(elt, "configuration/setting[@id='firmware']", 'firmware', name.text, 'network', 'value') find_element(elt, 'size', 'size', name.text, 'network') ipv4 = find_element(elt, "configuration/setting[@id='ip']", 'ipv4', name.text, 'network', 'value') if ipv4 is not None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: netmask = socket.inet_ntoa( fcntl.ioctl(sock, SIOCGIFNETMASK, struct.pack('256s', name.text))[20:24]) hw_lst.append( ('network', name.text, 'ipv4-netmask', netmask)) cidr = get_cidr(netmask) hw_lst.append( ('network', name.text, 'ipv4-cidr', cidr)) hw_lst.append( ('network', name.text, 'ipv4-network', "%s" % IPNetwork('%s/%s' % (ipv4, cidr)).network)) except Exception: sys.stderr.write('unable to get info for %s\n' % name.text) find_element(elt, "configuration/setting[@id='link']", 'link', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='driver']", 'driver', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='duplex']", 'duplex', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='speed']", 'speed', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='latency']", 'latency', name.text, 'network', 'value') find_element(elt, "configuration/setting[@id='autonegotiation']", 'autonegotiation', name.text, 'network', 'value') # lshw is not able to get the complete mac addr for ib # devices Let's workaround it with an ip command. if name.text.startswith('ib'): cmds = "ip addr show %s | grep link | awk '{print $2}'" status_ip, output_ip = cmd(cmds % name.text) hw_lst.append(('network', name.text, 'serial', output_ip.split('\n')[0].lower())) else: find_element(elt, 'serial', 'serial', name.text, 'network', transform=string.lower) for elt in xml.findall(".//node[@class='processor']"): name = elt.find('physid') if name is not None: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'physid', name.text)) find_element(elt, 'product', 'product', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'vendor', 'vendor', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'version', 'version', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'size', 'frequency', 'physical_%s' % socket_count, 'cpu') find_element(elt, 'clock', 'clock', 'physical_%s' % socket_count, 'cpu') find_element(elt, "configuration/setting[@id='cores']", 'cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='enabledcores']", 'enabled_cores', 'physical_%s' % socket_count, 'cpu', 'value') find_element(elt, "configuration/setting[@id='threads']", 'threads', 'physical_%s' % socket_count, 'cpu', 'value') cpuinfo_cmd = output_lines("grep flags /proc/cpuinfo |" "uniq | cut -d ':' -f 2") for line in cpuinfo_cmd: hw_lst.append(('cpu', 'physical_%s' % (socket_count), 'flags', line.rstrip('\n').strip())) socket_count = socket_count+1 else: sys.stderr.write("Unable to run lshw: %s\n" % output) hw_lst.append(('cpu', 'physical', 'number', str(socket_count))) status, output = cmd('nproc') if status == 0: hw_lst.append(('cpu', 'logical', 'number', str(output))) osvendor_cmd = output_lines("lsb_release -is") for line in osvendor_cmd: hw_lst.append(('system', 'os', 'vendor', line.rstrip('\n').strip())) osinfo_cmd = output_lines("lsb_release -ds | tr -d '\"'") for line in osinfo_cmd: hw_lst.append(('system', 'os', 'version', line.rstrip('\n').strip())) uname_cmd = output_lines("uname -r") for line in uname_cmd: hw_lst.append(('system', 'kernel', 'version', line.rstrip('\n').strip())) arch_cmd = output_lines("uname -i") for line in arch_cmd: hw_lst.append(('system', 'kernel', 'arch', line.rstrip('\n').strip())) cmdline_cmd = output_lines("cat /proc/cmdline") for line in cmdline_cmd: hw_lst.append(('system', 'kernel', 'cmdline', line.rstrip('\n').strip()))
def start_bench_server(port): sys.stderr.write('Spawning netserver on port %d\n' % port) status, output = cmd('netserver -p %d' % port)
#!/usr/bin/env python from commands import getstatusoutput as cmd from os.path import getmtime,join cache={} e,o = cmd("ls -d wf*of*") for d in o.split("\n"): s,s1=d.split(".list-",1) xt = int(getmtime(d)-getmtime(join(d,"jobs.json"))) if not s in cache:cache[s]={} if not xt in cache[s]: cache[s][xt]=[] e, o = cmd("find %s -name 'workflow.log' -type f" % d) tp=0 tf=0 for l in o.split("\n"): e, o = cmd("grep 'tests passed' %s" % l) x = o.replace(" failed","").split(" tests passed, ") tp=tp+sum([int(i) for i in x[0].split(" ")]) tf=tf+sum([int(i) for i in x[1].split(" ")]) cache[s][xt].append({"order": s1, "passed": tp, "failed":tf}) for s in sorted(cache.keys()): print s for xt in sorted(cache[s].keys()): for item in cache[s][xt]: print " ",xt," \t",item
def verify_csr(): print cmd("openssl req -in " + name + ".csr -noout -text")