Beispiel #1
0
    def test_findEventXWindowTimeout(self):
        old_logger_name = self.logger.name
        self.logger.name = "TestXHash.test_findEventXWindow"
        p = popen2.Popen4("sleep 2;/usr/X11R6/bin/xlogo")
        w = self.xhash.findEventXWindow("xlogo", 1)
        self.assertEqual(w, None)
        time.sleep(3)
        old_list = self.xhash.clearEvents(1)
        found_window = False
        for w in old_list:
            if w.window_title == "xlogo":
                found_window = True
                break
        self.assert_(found_window)

        (pout, pin) = popen2.popen4("ps --ppid %s -o pid=" % p.pid)
        pids = pout.readlines()
        cmd = "sleep 2;kill -9 %s " % p.pid
        for pid in pids:
            cmd += "%s " % pid.strip()

        (pout, pin) = popen2.popen4(cmd)

        w = self.xhash.findEventXWindow("xlogo", 1)
        self.assertEqual(w, None)
        self.logger.name = old_logger_name
Beispiel #2
0
    def test_getEventList(self):
        old_logger_name = self.logger.name
        self.logger.name = "TestXHash.test_checkXEvent"
        p = popen2.Popen4("sleep 1;/usr/X11R6/bin/xlogo")
        wlist = self.xhash.getEventList()
        self.logger.info("getNextEvent returned: %s", wlist)
        found_window = False
        for w in wlist:
            if w.window_title == "xlogo":
                found_window = True
        self.assert_(found_window)
        (pout, pin) = popen2.popen4("ps --ppid %s -o pid=" % p.pid)
        pids = pout.readlines()
        cmd = "sleep 1;kill -9 %s " % p.pid
        for pid in pids:
            cmd += "%s " % pid.strip()

        (pout, pin) = popen2.popen4(cmd)
        wlist = self.xhash.getEventList()
        self.logger.info("getNextEvent returned: %s", wlist)
        found_window = False
        for w in wlist:
            if w.window_title == "xlogo":
                found_window = True
        self.assert_(found_window)
        self.logger.name = old_logger_name
Beispiel #3
0
    def test_getEventListTimeout(self):
        old_logger_name = self.logger.name
        self.logger.name = "TestXHash.test_checkXEventTimeout"
        p = popen2.Popen4("sleep 3;/usr/X11R6/bin/xlogo")
        wlist = self.xhash.getEventList(timeout=1)
        #self.logger.info( "getNextEvent returned: %#x - %s", w.this_window, w.window_title )
        self.assertEqual(len(wlist), 0)
        time.sleep(3)
        old_list = self.xhash.clearQueue()
        found_window = False
        for w in old_list:
            if w.window_title == "xlogo":
                found_window = True
        self.assert_(found_window)

        (pout, pin) = popen2.popen4("ps --ppid %s -o pid=" % p.pid)
        pids = pout.readlines()
        cmd = "sleep 2;kill -9 %s " % p.pid
        for pid in pids:
            cmd += "%s " % pid.strip()

        (pout, pin) = popen2.popen4(cmd)
        wlist = self.xhash.getEventList(timeout=1)
        self.assertEqual(len(wlist), 0)

        self.logger.name = old_logger_name
Beispiel #4
0
	def display(self):
		if self.strip:

			# generate random filename (better to use datetime)
			rand_str 	= lambda n: ''.join([random.choice(string.lowercase) for i in xrange(n)])
			file 		= rand_str(10)  

			#self.strip.show()
			self.strip.save('/Users/mattthompson/Desktop/development/code/portfolio/python/photo-booth/pics/' + file + '.png')
			# print
			popen2.popen4("lpr -P HP_ENVY_4510_series " + "/Users/mattthompson/Desktop/development/code/portfolio/python/photo-booth/pics/" + file + ".png")
Beispiel #5
0
def createPartition(dev,
                    attempts = 10,
                    timeOut = 1000):
    """
    Create a single partition on <dev> spanning the whole device.
    """
    count = 1
    stat = 1
    while (count < attempts):
        logFile = "/tmp/ngasDiskFormat.log"
        os.system("rm -f %s" % logFile)
        command = "/sbin/sfdisk %s > %s" % (dev, logFile)
        print "Command to create partition: " + command
        startTime = time.time()
        sfdisk = popen4(command)
        # This creates a partition spanning the whole disk
        sfdisk[1].write("\n;\n;\n;\n;\n")
        startTime = time.time()
        sfdisk[0].close()
        sfdisk[1].close()
        stat = pollLogFile(logFile, "Re-reading the partition table ...",
                           timeOut)
        os.system("rm -f %s" % logFile)
        deltaTime = int(time.time() - startTime + 0.5)
        if (stat):
            msg = "Formatting disk failed (timed out) after %ds/attempt: %d"
            print msg % (deltaTime, count)
            timeOut += (timeOut * .1)
        else:
            print "Formatting disk succeeded after %ds/attempt: %d" %\
                  (deltaTime, count)
            break
        count += 1
    return stat
def main(workingDir):
    #this is to downlaod all the Couty shape file in the server here

    downloadZipPath = workingDir + "CountyZip//"

    CoutyPath = workingDir + "County//"
    if not os.path.exists(CoutyPath):
        os.mkdir(CoutyPath)

    #this is to define the outputresultPath
    outputResPath = workingDir + "outputRes//"
    coutyOutputResPath = outputResPath + "County//"

    if not os.path.exists(outputResPath):
        os.mkdir(outputResPath)

    coutyOutputResPath = outputResPath + "County//"
    if not os.path.exists(coutyOutputResPath):
        os.mkdir(coutyOutputResPath)

    temPath = downloadZipPath + "t1_2015_us_county.zip"
    unzipCountyPath = CoutyPath

    #can not unzip the couty files
    outAndErrorStream, inStream = popen2.popen4(workingDir + '7z.exe e -o' + unzipCountyPath + ' ' + temPath +" -aoa")      #when you run program first, plsease do this to unzip the shape file
    outAndErrorStream.close()
    inStream.close()
Beispiel #7
0
def run_in_tmp(fs, nexus):
    """
    @param fs: fieldstorage-like user options
    @param nexus: the nexus object that defines the tree and alignment
    @return: from_paml
    """
    # create the control object
    config = Paml.PamlConfig()
    config.set_hky()
    # create the baseml.ctl control file
    ctl_string = config.to_ctl_string()
    with open(Paml.baseml_ctl, 'wt') as fout:
        print >> fout, ctl_string
    # create the nexus object that defines the tree and alignment
    nexus = Nexus.get_sample_nexus_object()
    # create the baseml.newick tree file
    with open(Paml.baseml_newick, 'wt') as fout:
        print >> fout, nexus.tree.get_newick_string()
    # create the baseml.phylip alignment file
    s_phylip = Phylip.get_alignment_string_non_interleaved(nexus.alignment)
    with open(Paml.baseml_phylip, 'wt') as fout:
        print >> fout, s_phylip
    # run PAML
    args = [Config.baseml_exe_path, Paml.baseml_ctl]
    from_paml, to_paml = popen2.popen4(args)
    return from_paml
Beispiel #8
0
    def execute(self,
                cmd,
                debug=False,
                workdir=None,
                echo=None,
                getReturnCode=False):
        """Execute the command cmd. If specified change the working directory

        Currently no error-handling is done
        :return: A list with all the output-lines of the execution"""
        if debug:
            print_(cmd)

        oldDir = None
        if workdir:
            oldDir = os.getcwd()
            os.chdir(workdir)

        if type(cmd) == list:
            fpath = cmd[0]
        else:
            fpath = cmd.split(" ")[0]

        # Check if the file is there. Then we assume that this is a script
        if os.path.exists(fpath):
            # Script seems to be unexecutable
            if not os.access(fpath, os.X_OK):
                error("The script file", fpath, "is not executable")

        if sys.version_info < (2, 6):
            raus, rein = popen4(cmd)
        else:
            p = Popen(cmd,
                      shell=True,
                      stdin=PIPE,
                      stdout=PIPE,
                      stderr=STDOUT,
                      close_fds=True,
                      universal_newlines=True)
            (rein, raus) = (p.stdin, p.stdout)
        if echo != None:
            tmp = []
            while p.poll() == None:
                l = raus.readline()
                print_(echo, l, end="")
                tmp.append(l)
        else:
            tmp = raus.readlines()
        # line=raus.readline()
        # while line!="":
        #     print line
        #     line=raus.readline()

        if oldDir:
            os.chdir(oldDir)

        if getReturnCode:
            return p.returncode, tmp
        else:
            return tmp
def main(workingDir):
    #this is to downlaod all the Couty shape file in the server here

    downloadZipPath = workingDir + "CountyZip//"

    CoutyPath = workingDir + "County//"
    if not os.path.exists(CoutyPath):
        os.mkdir(CoutyPath)

    #this is to define the outputresultPath
    outputResPath = workingDir + "outputRes//"
    coutyOutputResPath = outputResPath + "County//"

    if not os.path.exists(outputResPath):
        os.mkdir(outputResPath)

    coutyOutputResPath = outputResPath + "County//"
    if not os.path.exists(coutyOutputResPath):
        os.mkdir(coutyOutputResPath)

    temPath = downloadZipPath + "t1_2015_us_county.zip"
    unzipCountyPath = CoutyPath

    #can not unzip the couty files
    outAndErrorStream, inStream = popen2.popen4(
        workingDir + '7z.exe e -o' + unzipCountyPath + ' ' + temPath + " -aoa"
    )  #when you run program first, plsease do this to unzip the shape file
    outAndErrorStream.close()
    inStream.close()
Beispiel #10
0
def c_make_results(block):
    cmd = 'make %s' % " ".join(block)
    print 'Running: ', cmd

    out, input = popen2.popen4(cmd)
    results = out.readlines()
    return results
Beispiel #11
0
    def runCmdQ(self):

        # build a single string out of all the queued cmds
        self.cmdBuf = "\n".join(self.cmdq) + "\n"
        self.cmdBufHash = sha.new(self.cmdBuf).hexdigest()
        self.cmdq = []

        # bail if the command set hasn't changed
        self.log(4, "oldCmdBuf=%s" % self.cmdBufHashOld)
        self.log(4, "newCmdBuf=%s" % self.cmdBufHash)

        if self.cmdBuf == self.cmdBufOld:
            self.log(3, "runCmdQ: no change to tc command set - bailing")
            return
        if self.cmdBufOld != '':
            self.log(2, "connections have changed, rebuilding qdiscs")

        # fire off the commands to a shell child proc
        shOut, shIn = popen2.popen4("/bin/sh")
        shIn.write(self.cmdBuf)
        shIn.close()
        out = shOut.read()
        shOut.close()

        # save the command buf for future comparison
        self.cmdBufOld = self.cmdBuf

        # for debugging
        self.log(3, "SCRIPT:\n%sOUT:\n%s" % (self.cmdBuf, out))
def getModules(env, idl_file):
    include_args = ''
    listCmd = []
    for directory in env['CPPPATH']:
        include_args += "-I%s " % (directory)
    try:
        defines = "-D%s "*len(env['CPPDEFINES']) % tuple(env['CPPDEFINES'])
    except KeyError:
        defines = ""
    command = 'omniidl -bpython -Wbstdout %s %s %s' % (defines, include_args, idl_file)
    (output, input) = popen2.popen4(command)
    text, t = '', None
    while t != '':
        t = output.read()
        text += t
    output.close()
    input.close()
    try:
        recovered_modules = modules_re.findall(text)[0]
        parsed_modules = recovered_modules.replace('"','').replace(' ', '').split(',')
        parsed_modules.remove('')
        print "modules extracted from idl file " + str(idl_file) + " = ", parsed_modules
        return parsed_modules
    except IndexError:
        print "could not extract any modules from idl file", str(idl_file)
        return []
Beispiel #13
0
def c_make_results(block):
  cmd = 'make %s' % " ".join( block )
  print 'Running: ', cmd

  out, input = popen2.popen4(cmd)
  results = out.readlines()
  return results
Beispiel #14
0
def do_cmd(item):
    iteration, m, n = item
    cmdLine = programsDir + program + " " + outFileDir + sys.argv[1] + str(
        iteration) + ".in " + str(m) + " " + str(n)
    print("Execution of program: " + cmdLine)
    execOut, execIn = popen4(cmdLine)
    output = execOut.read()
Beispiel #15
0
 def commit(self, db):
     self.file.close()
     try:
         os.unlink(self.name+".cab")
     except OSError:
         pass
     for k, v in [(r"Software\Microsoft\VisualStudio\7.1\Setup\VS", "VS7CommonBinDir"),
                  (r"Software\Microsoft\Win32SDK\Directories", "Install Dir")]:
         try:
             key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, k)
         except WindowsError:
             continue
         cabarc = os.path.join(_winreg.QueryValueEx(key, v)[0], r"Bin", "cabarc.exe")
         _winreg.CloseKey(key)
         if not os.path.exists(cabarc):continue
         break
     else:
         print "WARNING: cabarc.exe not found in registry"
         cabarc = "cabarc.exe"
     f = popen2.popen4(r'"%s" -m lzx:21 n %s.cab @%s.txt' % (cabarc, self.name, self.name))[0]
     for line in f:
         if line.startswith("  -- adding "):
             sys.stdout.write(".")
         else:
             sys.stdout.write(line)
         sys.stdout.flush()
     if not os.path.exists(self.name+".cab"):
         raise IOError, "cabarc failed"
     add_data(db, "Media",
             [(1, self.index, None, "#"+self.name, None, None)])
     add_stream(db, self.name, self.name+".cab")
     os.unlink(self.name+".txt")
     os.unlink(self.name+".cab")
     db.Commit()
 def _cvs(self, rest):
     """
     Execute a given CVS command, return lines output as a result.
     """
     cmd = "%s -z3 -d%s %s" % (self.cvs_bin, self.root, rest)
     (sout, sin) = popen4(cmd)
     return sout.readlines()
Beispiel #17
0
def find_graphviz(tool='dot'):
    (pout, pin) = popen4("which %s" %(tool))
    pin.close()
    dot = pout.read()
    pout.close()
    if not path.isabs(dot): return None
    return path.dirname(dot)
def checkPath(path,autoprops):
  log_message ("checkPath: [%s]\n" % (path));
  #sys.stderr.write ("Checking autoprops on [%s] ...\n" % (path))
  okay = 1
  is_dir = (path[-1] == '/')
  for pattern in autoprops.keys():
    #log_message("#Pattern [%s] \n" % (pattern))
    if fnmatch(path,pattern):
      #log_message("#Match [%s ~ %s] \n" % (pattern, path))
      items = autoprops[pattern]
      for item in items:
        propname = item[0]
        log_message("#Propname [%s] \n" % (propname))
        if is_dir and propname == 'svn:keywords':
          log_message ("Skip checking %s on directory [%s] ...\n" % (propname, path))
        else:
          expected = item[1] # already lower case
          cmd = "%s propget -t %s %s %s %s" % (SVNLOOK,trans,repos,propname,path)
          #propget = Popen(split (cmd), stdout=PIPE).stdout
          #log_message("Launch command=%s \n" % (cmd))
          (propget, prop_in) = popen2.popen4(cmd)
          #log_message("Read output \n")
          propval = lower(propget.read())
          status = propget.close()
          prop_in.close()
          #log_message("Finish command \n")
          if propval.find(expected) < 0:
            okay = 0
            #if not status:
            #sys.stderr.write("Property value '%s=%s' not found (or not expected) on path '%s'\n" % (propname,expected,path))
            sys.stderr.write("Props '%s=%s' missing (or not expected)\n" % (propname,expected))
  log_message ("checkPath: [%s] done\n" % (path));
  return okay
Beispiel #19
0
def find_graphviz(tool='dot'):
    (pout, pin) = popen4("which %s" % (tool))
    pin.close()
    dot = pout.read()
    pout.close()
    if not path.isabs(dot): return None
    return path.dirname(dot)
Beispiel #20
0
def run_in_tmp(fs, nexus):
    """
    @param fs: fieldstorage-like user options
    @param nexus: the nexus object that defines the tree and alignment
    @return: from_paml
    """
    # create the control object
    config = Paml.PamlConfig()
    config.set_hky()
    # create the baseml.ctl control file
    ctl_string = config.to_ctl_string()
    with open(Paml.baseml_ctl, 'wt') as fout:
        print >> fout, ctl_string
    # create the nexus object that defines the tree and alignment
    nexus = Nexus.get_sample_nexus_object()
    # create the baseml.newick tree file
    with open(Paml.baseml_newick, 'wt') as fout:
        print >> fout, nexus.tree.get_newick_string()
    # create the baseml.phylip alignment file
    s_phylip = Phylip.get_alignment_string_non_interleaved(nexus.alignment)
    with open(Paml.baseml_phylip, 'wt') as fout:
        print >> fout, s_phylip
    # run PAML
    args = [Config.baseml_exe_path, Paml.baseml_ctl]
    from_paml, to_paml = popen2.popen4(args)
    return from_paml
Beispiel #21
0
def run_hky(tree, alignment):
    """
    @param tree: a tree object
    @param alignment: an alignment object
    @return: messages from the program but not the results
    """
    # create the baseml.ctl control file
    config = PamlConfig()
    config.set_hky()
    config.to_ctl_string()
    with open(baseml_ctl, 'wt') as fout:
        print >> fout, config.to_ctl_string()
    # create the nexus object that defines the tree and alignment
    nexus = Nexus.get_sample_nexus_object()
    # create the baseml.newick tree file
    with open(baseml_newick, 'wt') as fout:
        print >> fout, nexus.tree.get_newick_string()
    # create the baseml.phylip alignment file
    phylip_string = Phylip.get_alignment_string_non_interleaved(
        nexus.alignment)
    with open(baseml_phylip, 'wt') as fout:
        print >> fout, phylip_string
    # change the current directory to the data directory
    with Util.remember_cwd():
        os.chdir(Config.data_path)
        # run PAML
        exe_path = Config.baseml_exe_path
        ctl_path = baseml_ctl
        #cmd = '%s %s > /dev/null' % (exe_path, ctl_path)
        #os.system(cmd)
        from_paml, to_paml = popen2.popen4([exe_path, ctl_path])
        #p = subprocess.Popen([cmd, arg], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
        # change back to the old directory
    return from_paml.read()
Beispiel #22
0
def run_hky(tree, alignment):
    """
    @param tree: a tree object
    @param alignment: an alignment object
    @return: messages from the program but not the results
    """
    # create the baseml.ctl control file
    config = PamlConfig()
    config.set_hky()
    config.to_ctl_string()
    with open(baseml_ctl, "wt") as fout:
        print >> fout, config.to_ctl_string()
    # create the nexus object that defines the tree and alignment
    nexus = Nexus.get_sample_nexus_object()
    # create the baseml.newick tree file
    with open(baseml_newick, "wt") as fout:
        print >> fout, nexus.tree.get_newick_string()
    # create the baseml.phylip alignment file
    phylip_string = Phylip.get_alignment_string_non_interleaved(nexus.alignment)
    with open(baseml_phylip, "wt") as fout:
        print >> fout, phylip_string
    # change the current directory to the data directory
    with Util.remember_cwd():
        os.chdir(Config.data_path)
        # run PAML
        exe_path = Config.baseml_exe_path
        ctl_path = baseml_ctl
        # cmd = '%s %s > /dev/null' % (exe_path, ctl_path)
        # os.system(cmd)
        from_paml, to_paml = popen2.popen4([exe_path, ctl_path])
        # p = subprocess.Popen([cmd, arg], stdin=subprocess.PIPE, stdout=subprocess.PIPE, close_fds=True)
        # change back to the old directory
    return from_paml.read()
 def _cvs(self, rest):
     """
     Execute a given CVS command, return lines output as a result.
     """
     cmd = "%s -z3 -d%s %s" % (self.cvs_bin, self.root, rest)
     (sout, sin) = popen4(cmd)
     return sout.readlines()
Beispiel #24
0
def make_pipe_win(cmd, ignore_retcode=False):
    outs, ins = popen2.popen4(cmd)
    ins.close()
    out=outs.read()
    retcode=outs.close()
    if retcode and not ignore_retcode:
        raise Error('FAILED(%d): %s\n%s' % (retcode,cmd,out))
    return out
Beispiel #25
0
 def ipaddress_obj(self):
     (output, input) = popen4('catior %s' % self.__str__())
     hostname = ipaddress_re.findall(output.read())[0]
     output.close()
     input.close()
     host, aliases, ips = socket.gethostbyname_ex(hostname)
     ip = ips[0]
     return ip
Beispiel #26
0
    def __RRregAvailable(self):

        try:
            regRes = popen2.popen4('reg')[0].readlines()
            return True if regRes[0] == 'ERROR: Invalid syntax.\n' and regRes[
                1] == 'Type "REG /?" for usage.\n' else False
        except:
            return False
 def stopTC(self):
     shOut, shIn = popen2.popen4("/bin/sh")
     cmd = "\n "+ TC + " qdisc del dev " + IF + " root" 
     shIn.write(cmd)
     shIn.close()
     out = shOut.read()
     shOut.close()
     print("stopping TC by %s \n, output: %s" % (cmd, out))
Beispiel #28
0
def make_pipe_win(cmd, ignore_retcode=False):
    outs, ins = popen2.popen4(cmd)
    ins.close()
    out = outs.read()
    retcode = outs.close()
    if retcode and not ignore_retcode:
        raise Error('FAILED(%d): %s\n%s' % (retcode, cmd, out))
    return out
Beispiel #29
0
def publish_gums(cp, template):
    hostname = cp_get(cp, "ce", 'name', gethostname())
    siteID = cp_get(cp, "site", "unique_name", gethostname())
    gumsConfig = vdtDir(os.path.expandvars('$VDT_LOCATION/gums/config/gums-client.properties'),
                        '/etc/gums/gums-client.properties')
    
    gumsConfigFile = open(gumsConfig, 'r')
    gums_re = re.compile('gums.authz\s*=\s*(https://(.*):.*?/(.*))')

    lines = gumsConfigFile.readlines()
    for line in lines:
        m = gums_re.match(line)
        if m: (gums_uri, gums_host) = m.groups()[0:2]

    os.putenv('X509_USER_CERT', '/etc/grid-security/http/httpcert.pem')
    os.putenv('X509_USER_KEY' , '/etc/grid-security/http/httpkey.pem')

    mapping_subject_dn = '/GIP-GUMS-Probe-Identity'
    mapping_subject_name = '`grid-cert-info -subject` '
    gums_command = vdtDir(os.path.expandvars('$VDT_LOCATION/gums/scripts/gums-service'),
                          '/usr/bin/gums-service')
    gums_command += ' mapUser -s ' + mapping_subject_name + mapping_subject_dn

    (gums_output, pin) = popen2.popen4(gums_command)

    gums_id_re = re.compile('.*\[userName: (.*)\].*')

    status = "Warning"
    statusInfo = "Test mapping failed: if GUMS was not down, check logs" +\
                 " at " + gums_host + ':' + '$VDT_LOCATION/tomcat/v55/logs'

    lines = gums_output.readlines()
    for line in lines:
        m = gums_id_re.match(line)
        if m:
            uidMapping = m.groups([0])
            status = "OK"
            statusInfo = "Test mapping successful: user id = %s" % uidMapping
            break
            
    info = {'serviceID': gums_uri,
            'serviceType': 'GUMS',
            'serviceName': 'Authorization',
            'version': 'UNDEFINED',
            'endpoint': gums_uri,
            'semantics': 'UNDEFINED',
            'owner': '',
            'url': gums_uri,
            'uri': gums_uri,
            'status': status,
            'statusInfo': statusInfo,
            'wsdl': 'Not Applicable',
            'startTime': 'Not Applicable', 
            'siteID': siteID,
            'acbr': '__GIP_DELETEME'
            }

    printTemplate(template, info)
Beispiel #30
0
 def start_python(self, cmd_line):
     outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line))
     infp.close()
     data = outfp.read()
     outfp.close()
     # try to cleanup the child so we don't appear to leak when running
     # with regrtest -R.  This should be a no-op on Windows.
     popen2._cleanup()
     return data
Beispiel #31
0
def sh(cmd):
    _cmd = cmd
    print cmd
    # launch command 2 times to see what append and be able 
    # to test in doc tests
    os.system(_cmd)
    child_stdout_and_stderr, child_stdin = popen2.popen4(_cmd)
    child_stdin.close()
    print child_stdout_and_stderr.read()
 def start_python(self, cmd_line):
     outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line))
     infp.close()
     data = outfp.read()
     outfp.close()
     # try to cleanup the child so we don't appear to leak when running
     # with regrtest -R.  This should be a no-op on Windows.
     popen2._cleanup()
     return data
Beispiel #33
0
def legacy_shell_injections(input):
    """ 
    Numerous legacy APIs for shells in Python stdlib
    """
    os.system(input)
    os.popen(input)
    os.popen2(input)
    os.popen3(input)
    os.popen4(input)
    posix.system(input)
    posix.popen(input)
    popen2.popen2(input)
    popen2.popen3(input)
    popen2.popen4(input)
    popen2.Popen3(input)
    popen2.Popen4(input)
    commands.getoutput(input)
    commands.getstatusoutput(input)
Beispiel #34
0
def sh(cmd):
    _cmd = cmd
    print cmd
    # launch command 2 times to see what append and be able
    # to test in doc tests
    os.system(_cmd)
    child_stdout_and_stderr, child_stdin = popen2.popen4(_cmd)
    child_stdin.close()
    print child_stdout_and_stderr.read()
Beispiel #35
0
 def __init__(self):
     Launch.__init__(self)
     # Start a Pymacs helper subprocess for executing Python code.
     python = os.environ.get('PYMACS_PYTHON') or 'python'
     command = python + ' -c "from Pymacs.pymacs import main; main(\'..\')"'
     import popen2
     self.output, self.input = popen2.popen4(command)
     text = self.receive()
     from Pymacs import __version__
     assert text == '(version "%s")\n' % __version__, repr(text)
Beispiel #36
0
def python2_specific():
    """
    These tests are mostly included to check for extra paths that can be generated if
    we can track flow into the implementation of a stdlib function, and then to another sink.
    See comment in query for more details.
    """

    files = request.args.get("files", "")
    os.popen2("ls " + files)
    os.popen3("ls " + files)
    os.popen4("ls " + files)

    platform.popen("ls " + files)

    popen2.popen2("ls " + files)
    popen2.popen3("ls " + files)
    popen2.popen4("ls " + files)
    popen2.Popen3("ls " + files)
    popen2.Popen4("ls " + files)
Beispiel #37
0
def createFileSystem(partition):
    """
    Create a reiserfs file system on <partition>.
    """
    command = '/sbin/mkreiserfs %s  > /dev/null 2>&1' % partition
    mkfs = popen4(command)
    mkfs[1].write('y\n')
    mkfs[0].close()
    mkfs[1].close()
    return 0
Beispiel #38
0
 def popen4(cmd, mode="t", bufsize=-1):
     """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
     may be a sequence, in which case arguments will be passed directly to
     the program without shell intervention (as with os.spawnv()).  If 'cmd'
     is a string it will be passed to the shell (as with os.system()). If
     'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
     file objects (child_stdin, child_stdout_stderr) are returned."""
     import popen2
     stdout, stdin = popen2.popen4(cmd, bufsize)
     return stdin, stdout
Beispiel #39
0
 def RunEsxCfgVolume(self, hostname):
     cmd = "ssh root@%s esxcfg-volume -l" % (hostname)
     print("$ %s" % cmd)
     out = []
     (stdout, stdin) = popen2.popen4(cmd)
     stdin.close()
     for line in stdout:
         out.append(line)
     stdout.close()
     sys.stdout.write("".join(out))
Beispiel #40
0
 def popen4(cmd, mode="t", bufsize=-1):
     """Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
     may be a sequence, in which case arguments will be passed directly to
     the program without shell intervention (as with os.spawnv()).  If 'cmd'
     is a string it will be passed to the shell (as with os.system()). If
     'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
     file objects (child_stdin, child_stdout_stderr) are returned."""
     import popen2
     stdout, stdin = popen2.popen4(cmd, bufsize)
     return stdin, stdout
Beispiel #41
0
 def __init__(self):
     Launch.__init__(self)
     # Start a Pymacs helper subprocess for executing Python code.
     python = os.environ.get('PYMACS_PYTHON') or 'python'
     command = python + ' -c "from Pymacs.pymacs import main; main(\'..\')"'
     import popen2
     self.output, self.input = popen2.popen4(command)
     text = self.receive()
     from Pymacs import __version__
     assert text == '(version "%s")\n' % __version__, repr(text)
 def executeCommand(self, cmd):
     '''Executes command p_cmd.'''
     w = self.log
     w('Executing "%s"...' % cmd)
     outstream, instream = popen2.popen4(cmd)
     outTxt = outstream.readlines()
     instream.close()
     outstream.close()
     for line in outTxt:
         w(line[:-1])
     w('Done.')
Beispiel #43
0
	def get_output(self, cmd, conform_regexes = None):
		""" Run 'cmd', return the output. """
		if conform_regexes is None:
			conform_regexes = STANDARD_CONFORM_REGEXES

		child_stdout_stderr, child_stdin = popen2.popen4(cmd)
		child_stdin.close()

		result = child_stdout_stderr.read()
		result = self.regex_process(conform_regexes, result)
		return result
Beispiel #44
0
 def print_preview(self, song):
   import songwrite2.plugins.ps_native.ps_latex as ps_latex
   global PREVIEW_TMP_FILE
   
   if PREVIEW_TMP_FILE: remove_preview_tmp_file()
     
   pdf = ps_latex.psify(song, pdf = 1)
   if "%s" in globdef.config.PREVIEW_COMMAND_PDF:
     import tempfile, popen2
     fid, PREVIEW_TMP_FILE = tempfile.mkstemp(suffix = ".pdf", text = 0)
     open(PREVIEW_TMP_FILE, "w").write(pdf)
     command = globdef.config.PREVIEW_COMMAND_PDF % PREVIEW_TMP_FILE
     print "Running '%s'" % command
     popen2.popen4(command)
   else:
     import popen2
     print "Running '%s'" % globdef.config.PREVIEW_COMMAND_PDF
     output, input = popen2.popen4(globdef.config.PREVIEW_COMMAND_PDF)
     input.write(pdf)
     input.close()
def main():
    """
    Detect login activity changes and report in feed.
    """
    # Construct the feed generator
    f = LogBufferFeed(FEED_DIR)
    f.MAX_AGE = 24 * 60 * 60 # 1 day
    f.FEED_META['feed.title']   = '%s Login Activity' % SITE_NAME
    f.FEED_META['feed.tagline'] = \
        'Summary of login activity on the %s server' % SITE_NAME
   
    # Call the command and capture output
    (sout, sin) = popen4(COMMAND) 
    new_lines   = [ x for x in sout.readlines() 
                    if x.find('reboot') == -1 ]
    
    # Attempt load up output from the previous run.
    old_lines = None
    old_output_fn = os.path.join(FEED_DIR, 'old_output.gz')
    if os.path.exists(old_output_fn):
        old_lines = gzip.open(old_output_fn, "r").readlines()
    
    # If there is previous output, check for changes...
    if old_lines:
        
        # Run a diff on the previous and current program output.
        diff_lines = [ x for x in difflib.ndiff(old_lines, new_lines) ]

        # Extract only the lines that have changed.
        changes_lines = [ x for x in diff_lines 
                          if x.startswith('-') or x.startswith('+') ]
        
        # Construct and append a new entry if there were changes
        if len(changes_lines) > 0:
            esc_changes_lines = [escape(x) for x in changes_lines]
            esc_diff_lines = [escape(x) for x in diff_lines]
            entry = FeedEntryDict({
                'link'    : '',
                'title'   : TITLE_TMPL % { 
                    'changes' : len(changes_lines) 
                },
                'summary' : SUMMARY_TMPL % {
                    'changes_lines' : "<br />".join(esc_changes_lines),
                    'diff_lines'    : "<br />".join(esc_diff_lines)
                }
            })
            f.append_entry(entry)

    # Save output from the current run for use next time.
    gzip.open(old_output_fn, "w").write("".join(new_lines))

    # Output the current feed entries as both RSS and Atom
    open(FEED_NAME_FN % 'rss', 'w').write(f.scrape_rss())
    open(FEED_NAME_FN % 'atom', 'w').write(f.scrape_atom())
Beispiel #46
0
 def executeCommand(self, cmd):
     """Executes command p_cmd."""
     w = self.log
     w('Executing "%s"...' % cmd)
     outstream, instream = popen2.popen4(cmd)
     outTxt = outstream.readlines()
     instream.close()
     outstream.close()
     for line in outTxt:
         w(line[:-1])
     w("Done.")
Beispiel #47
0
    def get_output(self, cmd, conform_regexes=None):
        """ Run 'cmd', return the output. """
        if conform_regexes is None:
            conform_regexes = STANDARD_CONFORM_REGEXES

        child_stdout_stderr, child_stdin = popen2.popen4(cmd)
        child_stdin.close()

        result = child_stdout_stderr.read()
        result = self.regex_process(conform_regexes, result)
        return result
Beispiel #48
0
 def validate(self, odf_file_content):
   fd, file_name = tempfile.mkstemp()
   os.write(fd, odf_file_content)
   os.close(fd)
   stdout, stdin = popen2.popen4('odflint %s' % file_name)
   stdin.close()
   error_list = ''
   for line in stdout:
     if line.startswith('Error: '):
       error_list += line
   os.unlink(file_name)
   return error_list
def main():
    if (len(sys.argv) != 2):
        usage()
        exit(2)

    if not os.path.exists(sys.argv[1]):
        print "Error: Folder does not exist or you don't have the needed permissions"
        usage()
        exit(2)

    if not os.path.isdir(sys.argv[1]):
        usage()
        exit(2)

    arcsdir = os.path.abspath(sys.argv[1])

    os.chdir(arcsdir)

    fl = os.listdir('.')
    filelist = []

    for x in fl:
        if re.compile(".arc.gz$").search(x, 1):
            filelist.append(x)  
    
    
    st = open('status.log', 'w')

    st.write('Processing ARC files in Folder: %s \n' % os.getcwd())
    
    for x in filelist:
        arcfile = os.path.abspath(x)
        st.write('ms-extract-arc:\t\t' + popen2.popen4("ms-extract-arc.py " + arcfile)[0].read())
        st.write('ms-scanner-clamav:\t' + popen2.popen4("ms-scanner-clamav.py " + arcfile[:-7])[0].read())
        st.write(popen2.popen3("rm -rf %s" % arcfile[:-7])[2].read())

    st.write('Done!\n')
    st.close()
Beispiel #50
0
    def setup(self, path=None):
        """
        Look for SExtractor program ('sextractor', or 'sex').
        If a full path is provided, only this path is checked.
        Raise a SExtractorException if it failed.
        Return program and version if it succeed.
        """

        # -- Finding sextractor program and its version
        # first look for 'sextractor', then 'sex'

        candidates = ['sextractor', 'sex']

        if (path):
            candidates = [path]
        
        selected=None
        for candidate in candidates:
            try:
                (_out_err, _in) = popen2.popen4(candidate)
                versionline = _out_err.read()
                if (versionline.find("SExtractor") != -1):
                    selected=candidate
                    break
            except IOError:
                continue
                
        if not(selected):
            raise SExtractorException, \
                  """
                  Cannot find SExtractor program. Check your PATH,
                  or provide the SExtractor program path in the constructor.
                  """

        _program = selected

        # print versionline
        _version_match = re.search("[Vv]ersion ([0-9\.])+", versionline)
        if not _version_match:
            raise SExtractorException, \
                  "Cannot determine SExtractor version."

        _version = _version_match.group()[8:]
        if not _version:
            raise SExtractorException, \
                  "Cannot determine SExtractor version."

        # print "Use " + self.program + " [" + self.version + "]"

        return _program, _version
Beispiel #51
0
def findExecutable_unix( executable ):
    import popen2, os
    if os.path.exists( executable ): 
        return executable
    else:
        try:
            ret = popen2.popen4("which %s" % executable)[0].readlines()[0].strip()
            # crappy implementation
            if len(ret.split())>1 and ret.startswith( 'no' ):
                raise "not found"
            return ret
            pass
        except:
            raise RuntimeError , "Cannot find executable %s" % executable
    def isLayouterPresent(self, layouter=""):
        """Check if current or specified layouter is present on the system.
        """

        if not layouter:
            layouter = self.getLayouter()

        layouter = os.path.join(GV_BIN_PATH, layouter)

        (pout,pin) = popen2.popen4(cmd = "%s -V" % layouter)
        pin.close()
        output = pout.read()
        pout.close()

        return "version" in output
Beispiel #53
0
   def collSplit(self):
      """ splits an event collection into a number of sub-collections, 
          based on GUID boundaries but with a specified number of events per 
          sub-collection """
 
      self.tntPrint("TNTJobSplitter being called now")

      # split the collection into sub-collections
      masterCollection = re.split('\.root', self.collection)[0]
      #print "########################"
      #print "Master collection is"
      #print masterCollection
      #print "########################"
      global _strippedCollection
      _strippedCollection = masterCollection
      global _tagfileCollection
      _tagfileCollection = self.src_collection_name

      # make sure there is nothing already stored in collection list
      global _subCollections
      _subCollections = {}
  
      # TODO: when CollSplitByGUID in POOL release, use that instead of having local executable
      #exe = os.path.join(os.path.dirname(__file__),'CollSplitByGUID')
      #splitCommand=exe + " -src " + self.inDir + masterCollection + " RootCollection -minevents " + self.minevents 
      #print "########################"
      #print "CALLING CollSplitByGUID - Note using input tag file and not myEvent.root created from CollAppend"
      #print "########################" 
      splitCommand="CollSplitByGUID.exe -xmlInput CollSplitByGUID.exe.xml" 
      self.tntPrint(splitCommand)
      outputhandle, inputhandle = popen2.popen4(splitCommand)
      inputhandle.close()
      output = outputhandle.readlines()
      #print output
      outputhandle.close()
      for line in output:   
         collName = ""
         guidList = []
         if line.startswith("Created"):
            words = line.split()
            collName = words[3]
            self.tntPrint("Moving " + collName + ".root to " + self.inDir)
            #move sub-collections to Ganga workspace
            shutil.move(collName + ".root",self.inDir)
            for word in words[6:]:
               guidList.append(word)
            # collect mapping of sub-collections to the guids they contain
            _subCollections[self.inDir + collName] = guidList   
def main(workingDir,URL):
    #TODO:here is the specific download method,you should change here, so that it can download spefific URL file to workingdir
    #this is to set the passwork and username
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    password_mgr.add_password(None, URL, "*****@*****.**", "USGSwoodard14")
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    opener = urllib2.build_opener(handler)
    opener.open(URL)
    urllib2.install_opener(opener)

    #here is to build a new staging directory that will store the downloaded file
    print "begin downloading FROM" + URL
    logging.info("begin downloading FROM" + URL)

    req =urllib2.urlopen(URL)

    # downLoadFileName = downLoadFileName[:-4]

    #here is to get the downloadfilepath,the default downloading path is workingdir/staging
    downLoadPath = workingDir + "staging//"
    if not os.path.exists(downLoadPath):
        os.makedirs(downLoadPath)

    #here is to get the name of downloaded layer
    logging.info("begin get the name of downloaded File" + URL)
    URLCompList = URL.split('/')
    downLoadFileName = URLCompList[-1]
    title = downLoadFileName[:-4]
    logging.info("finish get the name of downloaded File" + URL)

    #here is to get the download fileName
    logging.info("begin downloading" + title)
    with open(downLoadPath + downLoadFileName, 'wb') as fp:
        shutil.copyfileobj(req, fp)
    fp.close()
    print "finish downloading"
    logging.info("finish downloading" + title)


    #here is to unzip the downloaded layer
    #make sure there is 7z.exe in the workingDir
    logging.info("begin unzip" + URL)                                     #there is .zip for the
    outAndErrorStream, inStream = popen2.popen4(workingDir + '7z.exe e -o' + workingDir + 'staging\ ' + workingDir + "staging\\" + downLoadFileName + " -aoa")
    outAndErrorStream.close()
    inStream.close()
    logging.info("finish unzip" + URL)

    return title
    def execute(self,cmd,debug=False,workdir=None,echo=None):
        """Execute the command cmd. If specified change the working directory

        Currently no error-handling is done
        @return: A list with all the output-lines of the execution"""
        if debug:
            print_(cmd)

        oldDir=None
        if workdir:
            oldDir=os.getcwd()
            os.chdir(workdir)

        if type(cmd)==list:
            fpath=cmd[0]
        else:
            fpath=cmd.split(" ")[0]

        # Check if the file is there. Then we assume that this is a script
        if os.path.exists(fpath):
            # Script seems to be unexecutable
            if not os.access(fpath, os.X_OK):
                error("The script file",fpath,"is not executable")

        if sys.version_info<(2,6):
            raus,rein = popen4(cmd)
        else:
            p = Popen(cmd, shell=True,
                      stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True,
                      universal_newlines=True)
            (rein,raus)=(p.stdin,p.stdout)
        if echo!=None:
            tmp=[]
            while p.poll()==None:
                l=raus.readline()
                print_(echo,l,end="")
                tmp.append(l)
        else:
            tmp=raus.readlines()
        # line=raus.readline()
        # while line!="":
        #     print line
        #     line=raus.readline()

        if oldDir:
            os.chdir(oldDir)

        return tmp
Beispiel #56
0
    def handle(self, body):
        """ The body contains a input file """

        self.log.notice("[PipeHandler]")
        command = self.params
        self.log.debug("[PipeHandler]: command='%s'" % command)

        pout, pin = popen2.popen4(command)
        pin.write(body)
        pin.close()
        
        result = pout.read()
        pout.close()
        self.log.debug("[PipeHandler]: result='%s'" % result)
        
        return [('text/plain', result)]
Beispiel #57
0
    def start_prolog(self):
        if sys.platform[:3] == "win" or sys.platform == "os2emx":
            (self._stdout, self.stdin) = popen2.popen4("sicstus -i", 0)
            self.pid = 0
        else:
            inst = popen2.Popen4('sicstus -i', -1)
            self.pid = inst.pid
            #print "child has pid:", self.pid
            self._stdout = inst.fromchild
            self.stdin = inst.tochild

        self.stdout = MemListener(self._stdout, self)
        self.stdout.start()

        #reset vars
        self.reset_state()
        self.running = True