def run_repair(n, k, d, w, helper_ids, failed_id):
    htime = ftime = 0.0

    print "running repair [HELP]..."
    cmd1 = "./repair_pmc help %d %s %s" % (failed_id, mfname, " ".join(
        map(str, helper_ids)))
    print cmd1
    stdout = Popen(cmd1, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line)  # echo output
        if 'Coding Time' in line:
            htime += float(line.split(':')[1].strip())
    stdout.close()

    print "running repair [FIX]..."
    cmd2 = "./repair_pmc fix %d %s %s" % (failed_id, mfname, " ".join(
        map(str, helper_ids)))
    print cmd2
    stdout = Popen(cmd2, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line)  # echo output
        if 'Coding Time' in line:
            ftime += float(line.split(':')[1].strip())

    return htime, ftime
Example #2
0
class CppBackend:
    executable_path = '../cpp_backend/cmake-build-debug/cpp_backend'

    def __init__(self):
        self.p = Popen([CppBackend.executable_path], shell=True, stdout=PIPE, stdin=PIPE)

    def __del__(self):
        self.p.kill()

    def send(self, s):
        self.p.stdin.write(s)
        self.p.stdin.flush()

    def get(self, decode_json=True):
        line = self.p.stdout.readline()
        result = line.decode("utf-8")
        if decode_json: result = json.loads(result)
        # print("recieved:", result)
        return result

    def reset(self):
        # raise NotImplementedError()
        self.send(dict_to_query({"query_type" : "reset"}))

    def close(self):
        self.p.close()
Example #3
0
def copy_text(text):
    cb_name = get_clipboard_name()

    if cb_name is not None:
        clipboard = Popen(cb_name, shell=True, stdin=PIPE).stdin
        clipboard.write(text)
        clipboard.close()
def run_repair(n, k, w, helper_ids, failed_id, j_tech='reed_sol_van'):
    time = 0.0
    m = n - k
    print "running repair..."
    cmd = './decoder_norecode %s' % fname
    print cmd
    stdout = Popen(cmd, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line)  # echo output
        if 'Coding Time' in line:
            time += float(line.split(':')[1].strip())
    stdout.close()
    '''
    print "encoding the falied node..."
    cmd_encode = "./encoder %s %d %d %s %d 0 0" % (fname, k, m, j_tech, w)
    stdout = Popen(cmd_encode, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line) # echo output
        if 'Coding Time' in line:
            time += float(line.split(':')[1].strip())
    stdout.close()
    '''
    return time
Example #5
0
 def _get_surface(self, lemma_morph, pos, ctxinfo):
     """
         Given a lemma+affix in RASP format, returns a tuple containing 
         (surface, lemma, affix). Uses morphg to generate the surface, or returns 2 
         copies of the input if morphg was not provided.
     """
     affix = ""
     parts = lemma_morph.rsplit("+", 1)
     if len(
             parts
     ) == 1 or lemma_morph == "+":  # No inflection, e.g. lemma_morph="+"
         lemma = surface = lemma_morph
     elif len(parts) == 2 and "+" not in parts[
             0]:  # Standard inflected unit, e.g. lemma_morph="be+s"
         lemma, affix = parts
         if self.morphg_file is not None:
             lemma_morph = lemma_morph.replace("\"", "\\\"")
             cmd = "echo \"%s_%s\" | ${morphg_res:-./%s -t}" % \
                   ( lemma_morph, pos, self.morphg_file )
             p = Popen(cmd, shell=True, stdout=PIPE).stdout
             #generates the surface form using morphg
             surface = str(p.readline(), self.encoding).split("_")[0]
             p.close()
         else:
             ctxinfo.warn_once(
                 "Not using morphg, using lemma+affix instead of surface")
             surface = lemma_morph
     else:  # the token contains one or several '+', e.g. lemma_morph="C+++"
         lemma = surface = parts[0]
         affix = parts[1]
     return (surface, lemma, affix)
Example #6
0
class mavchildexec(mavfile):
    '''a MAVLink child processes reader/writer'''
    def __init__(self, filename, source_system=255):
        from subprocess import Popen, PIPE
        import fcntl

        self.filename = filename
        self.child = Popen(filename, shell=True, stdout=PIPE, stdin=PIPE)
        self.fd = self.child.stdout.fileno()

        fl = fcntl.fcntl(self.fd, fcntl.F_GETFL)
        fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        fl = fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_GETFL)
        fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_SETFL,
                    fl | os.O_NONBLOCK)

        mavfile.__init__(self, self.fd, filename, source_system=source_system)

    def close(self):
        self.child.close()

    def recv(self, n=None):
        try:
            x = self.child.stdout.read(1)
        except Exception:
            return ''
        return x

    def write(self, buf):
        self.child.stdin.write(buf)
def create_user(username):
  print "Checking for user "+username

  p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
  output = p.stdout.read()

  if (output[0:3] != "uid"):
    # Make the pypo user
    print "Creating user "+username
    os.system("adduser --system --quiet --group --shell /bin/bash "+username)

    #set pypo password
    p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w')
    p.write('pypo\n')
    p.write('pypo\n')
    p.close()
  else:
    print "User already exists."
  #add pypo to audio group
  os.system("adduser " + username + " audio 1>/dev/null 2>&1")
  #add pypo to www-data group
  os.system("adduser " + username + " www-data 1>/dev/null 2>&1")
  #add pypo to pulse group
  os.system("adduser " + username + " pulse 1>/dev/null 2>&1")
  #add pypo to pulse-access group
  os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1")
Example #8
0
File: vft.py Project: mfkiwl/sdfirm
class PIPEFrame(VFT):  #PIPE for backup
    def __init__(self, name="pipe"):
        super(PIPEFrame, self).__init__(name)
        self.buff = ''  #template buff
        self.p = None

    def open(self):
        self.stopping = False
        try:
            os.environ[
                "PATH"] = os.environ["PATH"] + ';' + r'C:\python35\vft\fwutils'
            self.p = Popen('imcdiag.exe -p COM3',
                           stdout=PIPE,
                           stdin=PIPE,
                           stderr=STDOUT,
                           shell=True)
            #self.start()
        except Exception as e:
            logging.info(e)
            os._exit(0)

    def is_open(self):
        return True

    def close(self):
        self.stopping = True
        self.p.close()

    def read(self):
        data = self.p.stdout.readline().decode()
        return data

    def write(self, cmd):
        self.p.stdin.write(cmd.encode())
Example #9
0
    def _get_fields(self, msg_path, length=50):
        cmd = [
            'mu',
            'view',
            msg_path,
            '--summary-len=5',
            '--muhome=%s' % config.HIPFLASK_FOLDERS['mu']
        ]

        p = Popen(cmd, stdout=PIPE).stdout
        fields = p.read().splitlines()
        p.close()

        message = {}
        for field in fields:
            separator = field.find(':')
            
            if separator == -1:
                continue

            key = field[0:separator].lower()
            value = field[separator+2:]
            if len(value) > length:
                value = value[:length] + '...'
            message[key] = value

        return message
Example #10
0
def _hostIsUp(host, count=1, timeout=1):
    """
    Executes a ping command and sets the appropriate attribute.
    Parameters: A host, optional: Amount of pings, Timeout
    
    """
    
    thecommand = 'ping -n {0} -w {1} -a {2}'.format(count, timeout, host.ipaddress)
    
    results = Popen(thecommand, stdout=PIPE).stdout
    output = results.readlines()
    results.close()
    
    # Convert the returned bytearrays to strings.
    output = [item.decode('utf8') for item in output]
    output = ' '.join(output)

    if ('Request timed out' in output) or ('Destination net unreachable' in output):
        if host.isup == True:
            host.isup = False
            host.changed = True
    else:
        if host.isup == False:
            host.isup = True
            host.changed = True
def main(argv):
	run_in_reverse = False
	if len(argv) > 1:
		if argv[1] == '--help' or argv[1] == '-h':
			print ('Usage: %s [<commit>]' % argv[0])
			print ('\tdiff to framework, ' +
					'optionally restricting to files in <commit>')
			sys.exit(0)
		elif argv[1] == '--reverse':
			print "Running in reverse"
			run_in_reverse = True
		else:
			print ("**** Pulling file list from: %s" % argv[1])
			pipe = Popen(['git', 'diff', '--name-only',  argv[1]], stdout=PIPE).stdout
			for line in iter(pipe.readline,''):
				path = line.rstrip()
				file = path[path.rfind('/') + 1:]
				print '**** watching: %s' % file
				WATCH.append(file);
			pipe.close()

	if run_in_reverse:
		#dirCompare(FW_RES, PROTO_RES, ".xml", run_in_reverse)
		print ("**** Source files:")
		dirCompare(FW_SRC, PROTO_SRC, ".java", run_in_reverse)
	else:
		#dirCompare(PROTO_RES, FW_RES, ".xml", run_in_reverse)
		print ("**** Source files:")
		dirCompare(PROTO_SRC, FW_SRC, ".java", run_in_reverse)

	if (os.path.exists(TEMP_FILE1)):
		os.remove(TEMP_FILE1)

	if (os.path.exists(TEMP_FILE2)):
		os.remove(TEMP_FILE2)
Example #12
0
class SAMReader:
    def __init__(self, fileName, isBam=False):
        if (isBam == False and fileName[-4:] == ".sam"):
            self.f = open(fileName)
        elif (isBam == True and fileName[-4:] == ".bam"):
            args = "samtools view " + fileName
            print args.split()
            self.f = Popen(args.split(), stdout=PIPE).stdout
        else:
            print("your suffix and does not match value self.isBam")
            sys.exit(1)
        self.header = list()  # store SAM header
        self.lineNo = 0  # store current read line number
        self.line = ""  # store current read line
        signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    def __iter__(self):
        return self

    def next(self):
        self.line = self.f.readline()
        self.lineNo += 1
        while (self.line != '' and self.line[0] == '@'):
            self.header.append(self.line)
            self.line = self.f.readline()
            self.lineNo += 1

        if (self.line == ''):
            self.f.close()
            raise StopIteration

        fields = self.line.split('\t')
        record = dict()
        record["QNAME"] = fields[0]
        record["FLAG"] = int(fields[1])
        record["RNAME"] = fields[2]
        record["POS"] = int(fields[3])
        record["MAPQ"] = int(fields[4])
        record["CIGAR"] = fields[5]
        record["MRNM"] = fields[6]
        record["MPOS"] = int(fields[7])
        record["ISIZE"] = int(fields[8])
        record["SEQ"] = fields[9]
        record["QUAL"] = fields[10]
        record["TAGS"] = fields[11:]

        # we don't care the optional tags unless necessary
        #         if (len(fields) > 11):
        #             for i in fields[11:]:
        #                 (tag, vtype, value) = i.split(":")
        #                 if (vtype=="i"):
        #                     record[tag] = int(value)
        #                 elif(vtype=="f"):
        #                     record[tag] = float(value)
        #                 else:
        #                     record[tag] = value
        return record

    def dump(self):
        print self.line
Example #13
0
    def __init__(self, setupsDir=DEFAULT_SETUPS_DIR):

        # initial setup of ups itself:
        os.environ['UPS_SHELL'] = 'sh'

        # initial setup of ups itself:
        os.environ['UPS_SHELL'] = 'sh'
        if POPEN_AVAILABLE:
            f = Popen('. %s/setups.sh; ' % setupsDir + \
                      'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
                      'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
                      'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
                      'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";',
                      shell=True,
                      stdout=PIPE).stdout
        else:
            f = os.popen('. %s/setups.sh; ' % setupsDir + \
                         'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
                         'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
                         'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
                         'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";')
        exec f.read()
        f.close()

        # we need to initialize the following so that we can
        #  make the correct changes to sys.path later when products
        #  we setup modify PYTHONPATH
        self._pythonPath = os.environ.get('PYTHONPATH', '')
        self._sysPath = sys.path
        (self._internalSysPathPrepend, self._internalSysPathAppend) = self._getInitialSyspathElements()
Example #14
0
    def _inhaleresults(self, cmd):
        if POPEN_AVAILABLE:
            p = Popen(cmd, shell=True, 
                      stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
            (stdin, stdout, stderr) = (p.stdin, p.stdout, p.stderr)
        else:
            (stdin,stdout,stderr) = os.popen3(cmd)
        try:
            filename = stdout.read()
            filename = filename[0:-1]
            if (filename == "/dev/null"):
                msg = stderr.read()
                raise upsException(msg)
        finally:
            stdin.close()
            stdout.close()
            stderr.close()

        cutHere = '--------------cut here-------------'
	setup = open(filename, 'a')
	setup.write(self._getNewPythonEnv(cutHere))
	setup.close()

        if POPEN_AVAILABLE:
            f = Popen("/bin/sh %s" % filename,
                      shell=True, stdout=PIPE).stdout
        else:
            f = os.popen("/bin/sh %s" % filename)
	c1 = f.read()
	f.close()

        (realUpsStuff, ourOsEnvironmentStuff) = re.split('.*%s' % cutHere, c1)
        #print("ourOsEnvironmentStuff = %s" % ourOsEnvironmentStuff)
        exec ourOsEnvironmentStuff
Example #15
0
class LineReader:
    def __init__(self, fname):
        if fname.endswith(".gz"):
            if not os.path.isfile(fname):
                raise IOError(fname)
            self.f = Popen(["gunzip", "-c", fname], stdout=PIPE, stderr=PIPE)
            self.zipped = True
        else:
            self.f = open(fname, "r")
            self.zipped = False

    def readlines(self):
        if self.zipped:
            for line in self.f.stdout:
                yield line
        else:
            for line in self.f.readlines():
                yield line

    def close(self):
        if self.zipped:
            if self.f.poll() == None:
                os.kill(self.f.pid, signal.SIGHUP)
        else:
            self.f.close()

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

    def __iter__(self):
        return self.readlines()
class LineReader(object):
    def __init__(self, fname):
        if fname.endswith('.gz'):
            if not os.path.isfile(fname):
                raise IOError(fname)
            self.f = Popen(['gunzip', '-c', fname], stdout=PIPE, stderr=PIPE)
            self.zipped = True
        else:
            self.f = open(fname, 'r')
            self.zipped = False

    def readlines(self):
        if self.zipped:
            for line in self.f.stdout:
                yield line
        else:
            for line in self.f.readlines():
                yield line

    def close(self):
        if self.zipped:
            if self.f.poll() == None:
                os.kill(self.f.pid, signal.SIGHUP)
        else:
            self.f.close()

    def __enter__(self):
        return self

    def __exit__(self, type, value, traceback):
        self.close()

    def __iter__(self):
        return self.readlines()
Example #17
0
def git_version(path):
    from subprocess import Popen, PIPE, STDOUT
    cmd = 'git --git-dir=' + path + '.git log --pretty=format:%h -n1'
    p = Popen(cmd, shell=True, stdout=PIPE).stdout
    version = p.read()
    p.close()
    return version
Example #18
0
    def save(self,filename=None):
        start = time.time()
        if filename is None:
            filename = self._genfilename()

        cmd = ' '.join([gspath,
                            '-dNOPAUSE',
                            '-q',
                            '-r300',
                            '-sDEVICE=tiffg4',
                            '-dBATCH',
                            '-sOutputFile=%s'%filename,
                            '-sPAPERSIZE=a4',
                            '-dFirstPage=%d'%self._pagenumber,
                            '-dLastPage=%d'%self._pagenumber,
                            self._origfile
                        ])
        po = Popen(cmd,shell=True,stdout=PIPE,stderr=STDOUT).stdout
        for l in po.readlines():
            self._l.debug("GS Output:%s",l)
        po.close()
        self._file = filename
        self._l.debug("Saving file %s (duration %f)",
                      filename,(time.time()-start))
        return filename
 def determineDependancies(self, app):
     otoolPipe = Popen('otool -L "%s"' % app, shell=True, stdout=PIPE).stdout
     otoolOutput = [line for line in otoolPipe]
     otoolPipe.close()
     libs = [line.split()[0] for line in otoolOutput[1:] if "Qt" in line and not "@executable_path" in line]
     frameworks = [lib[:lib.find(".framework")+len(".framework")] for lib in libs]
     return zip(frameworks, libs)
def git_version(path):
	from subprocess import Popen, PIPE, STDOUT
	cmd = 'git --git-dir=' + path + '.git log --pretty=format:%h -n1'
	p = Popen(cmd, shell=True, stdout=PIPE).stdout
	version = p.read()
	p.close()
	return version
Example #21
0
def executeCommandAndArguments(caa, dumpfilepath):
    result = Popen(caa, stdout=PIPE).stdout

    dumpfile = open(dumpfilepath, 'w')
    dumpfile.write( result.read() )
    dumpfile.close()
    result.close()
def run_repair(n, k, w, helper_ids, failed_id, j_tech='reed_sol_van'):
    time = 0.0
    m = n - k
    print "running repair..."
    cmd = './decoder_norecode %s' % fname
    print cmd
    stdout = Popen(cmd, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line) # echo output
        if 'Coding Time' in line:
            time += float(line.split(':')[1].strip())
    stdout.close()

    '''
    print "encoding the falied node..."
    cmd_encode = "./encoder %s %d %d %s %d 0 0" % (fname, k, m, j_tech, w)
    stdout = Popen(cmd_encode, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line) # echo output
        if 'Coding Time' in line:
            time += float(line.split(':')[1].strip())
    stdout.close()
    '''
    return time
Example #23
0
def set_clipboard(text):
    from subprocess import Popen, PIPE

    pipe = Popen(['xsel', '--primary --input'], shell=True, stdin=PIPE).stdin
    pipe.write(bytes(text, 'ascii'))
    pipe.flush()
    pipe.close()
Example #24
0
def get_surface( lemma_morph, pos ) :
    """
        Given a lemma+morph in RASP format, returns a tuple containing (surface,
        lemma). Uses morphg to generate the surface, or returns 2 copies of
        the input if morphg was not provided.
    """
    global morphg_file
    parts = lemma_morph.rsplit("+",1)
    if len(parts) == 1 or lemma_morph == "+": # No inflection
        lemma = surface = lemma_morph
    elif len(parts) == 2 and "+" not in parts[0]: # Standard inflected unit
        lemma = parts[0] 
        if morphg_file is not None : 
            lemma_morph = lemma_morph.replace("\"","\\\"")
            cmd = "echo \"%s_%s\" | ${morphg_res:-./%s -t}" % \
                  ( lemma_morph, pos, morphg_file )
            p = Popen(cmd, shell=True, stdout=PIPE).stdout
            #generates the surface form using morphg
            surface = unicode(p.readline(), 'utf-8').split("_")[ 0 ]
            p.close()
        else:
            surface = lemma
    else: # the token contains one or several '+'
        lemma = surface = parts[0]
    return ( surface, lemma )
def reorient(filename, orig_dir, seg_dir, seg_orient="RAI"):
    '''
    Reorients a single image to its original orientation prior to being run
    through Roy's segmentation script (which uses RAI) using 3dresample.  
    First checks against original scan to see if reorientation is necessary, 
    then reorients.

    Reoriented image is saved to dst_dir/
    Requires AFNI 3dresample

    Params:
        - filename: string, name of NIFTI file to skullstrip 
        - src_dir: string, source directory
    '''
    orig_filepath = os.path.join(orig_dir, filename)
    call = "3dinfo -orient " + orig_filepath
    pipe = Popen(call, shell=True, stdout=PIPE).stdout
    three_digit_code = pipe.read()[:3].decode()
    pipe.close()

    dst_dir = os.path.join(seg_dir, "reoriented")
    if not os.path.exists(dst_dir):
        os.makedirs(dst_dir)

    # if three_digit_code != seg_orient:
    # reorient lesion membership
    infile = os.path.join(seg_dir, filename)
    outfile = os.path.join(dst_dir, filename)
    call = "3dresample -orient " + three_digit_code\
        + " -inset " + infile + " -prefix " + outfile
    os.system(call)
Example #26
0
    def run(self, edit):
        selections = self.view.sel()

        # For now we don't try to balance multiple or non-empty selections, just insert as usual
        if len(selections) > 1:
            for selection in reversed(selections):
                self.insert(edit, selection)
            return

        selection = selections[0]

        if not selection.empty():
            self.insert(edit, selection)
            return

        point = selection.end()
        line = self.view.line(point)
        os.environ["TM_CURRENT_LINE"] = self.view.substr(line).encode("utf-8")
        os.environ["TM_LINE_INDEX"] = unicode(self.view.rowcol(point)[1])
        os.environ["TM_SUPPORT_PATH"] = os.getcwd().encode("utf-8")
        pipe = Popen(
            ["ruby",
             os.path.join(self.package_path(), self.PARSER_PATH)],
            shell=False,
            stdout=PIPE,
            stderr=STDOUT).stdout
        snippet = pipe.read()
        pipe.close()

        self.view.erase(edit, line)
        self.view.run_command("insert_snippet",
                              {"contents": unicode(snippet, "utf-8")})
Example #27
0
def create_user(username):
    print "Checking for user " + username

    p = Popen('id ' + username,
              shell=True,
              stdin=PIPE,
              stdout=PIPE,
              stderr=STDOUT,
              close_fds=True)
    output = p.stdout.read()

    if (output[0:3] != "uid"):
        # Make the pypo user
        print "Creating user " + username
        os.system("adduser --system --quiet --group --shell /bin/bash " +
                  username)

        #set pypo password
        p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w')
        p.write('pypo\n')
        p.write('pypo\n')
        p.close()
    else:
        print "User already exists."
    #add pypo to audio group
    os.system("adduser " + username + " audio 1>/dev/null 2>&1")
    #add pypo to www-data group
    os.system("adduser " + username + " www-data 1>/dev/null 2>&1")
    #add pypo to pulse group
    os.system("adduser " + username + " pulse 1>/dev/null 2>&1")
    #add pypo to pulse-access group
    os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1")
def run_repair(n, k, d, w, helper_ids, failed_id):
    htime = ftime = 0.0

    print "running repair [HELP]..."
    cmd1 = "./repair_pmc help %d %s %s" % (failed_id, mfname, " ".join(map(str, helper_ids)))
    print cmd1
    stdout = Popen(cmd1, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line) # echo output
        if 'Coding Time' in line:
            htime += float(line.split(':')[1].strip())
    stdout.close()

    print "running repair [FIX]..."
    cmd2 = "./repair_pmc fix %d %s %s" % (failed_id, mfname, " ".join(map(str, helper_ids)))
    print cmd2
    stdout = Popen(cmd2, shell=True, stdout=PIPE, stderr=sys.stderr).stdout

    for line in stdout:
        if VERBOSE:
            sys.stdout.write(line) # echo output
        if 'Coding Time' in line:
            ftime += float(line.split(':')[1].strip())

    return htime, ftime
Example #29
0
def main():
    # Get the repository root
    stdout = None
    if os.path.exists("/Applications/Deadline/Resources/bin/deadlinecommand"):
        stdout = os.popen(
            "/Applications/Deadline/Resources/bin/deadlinecommand GetRepositoryRoot"
        )
    elif os.path.exists("/usr/local/Prime_Focus/Deadline/bin/deadlinecommand"):
        stdout = Popen(("/usr/local/Prime_Focus/Deadline/bin/deadlinecommand",
                        "GetRepositoryRoot"),
                       stdout=PIPE).stdout
    else:
        stdout = os.popen("deadlinecommand GetRepositoryRoot")
    path = stdout.read()
    path += "/submission/Nuke"
    path = path.replace("\n", "").replace("\\", "/")
    stdout.close()

    # Add the path to the system path
    print "Appending \"" + path + "\" to system path to import SubmitNukeToDeadline module"
    sys.path.append(path)

    # Import the script and call the main() function
    import SubmitNukeToDeadline
    SubmitNukeToDeadline.SubmitToDeadline(path)
Example #30
0
class mavchildexec(mavfile):
    '''a MAVLink child processes reader/writer'''
    def __init__(self, filename, source_system=255):
        from subprocess import Popen, PIPE
        import fcntl
        
        self.filename = filename
        self.child = Popen(filename, shell=True, stdout=PIPE, stdin=PIPE)
        self.fd = self.child.stdout.fileno()

        fl = fcntl.fcntl(self.fd, fcntl.F_GETFL)
        fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)

        fl = fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_GETFL)
        fcntl.fcntl(self.child.stdout.fileno(), fcntl.F_SETFL, fl | os.O_NONBLOCK)

        mavfile.__init__(self, self.fd, filename, source_system=source_system)

    def close(self):
        self.child.close()

    def recv(self,n=None):
        try:
            x = self.child.stdout.read(1)
        except Exception:
            return ''
        return x

    def write(self, buf):
        self.child.stdin.write(buf)
Example #31
0
def get_surface(lemma_morph, pos):
    """
        Given a lemma+morph in RASP format, returns a tuple containing (surface,
        lemma). Uses morphg to generate the surface, or returns 2 copies of
        the input if morphg was not provided.
    """
    global morphg_file
    parts = lemma_morph.rsplit("+", 1)
    if len(parts) == 1 or lemma_morph == "+":  # No inflection
        lemma = surface = lemma_morph
    elif len(parts) == 2 and "+" not in parts[0]:  # Standard inflected unit
        lemma = parts[0]
        if morphg_file is not None:
            lemma_morph = lemma_morph.replace("\"", "\\\"")
            cmd = "echo \"%s_%s\" | ${morphg_res:-./%s -t}" % \
                  ( lemma_morph, pos, morphg_file )
            p = Popen(cmd, shell=True, stdout=PIPE).stdout
            #generates the surface form using morphg
            surface = unicode(p.readline(), 'utf-8').split("_")[0]
            p.close()
        else:
            surface = lemma
    else:  # the token contains one or several '+'
        lemma = surface = parts[0]
    return (surface, lemma)
Example #32
0
def main():
    parser = argparse.ArgumentParser(
        description=
        "Takes a BAM file preferably one already filtered to be uniquely mapped reads."
    )
    parser.add_argument('input_fasta', help="FASTAFILE indexed")
    parser.add_argument('input_sorted_bam', help="BAMFILE sorted indexed")
    parser.add_argument('--threads',
                        type=int,
                        default=multiprocessing.cpu_count(),
                        help="Number of threads defautl cpu_count")
    parser.add_argument(
        '--include_multiply_mapped_reads',
        action='store_true',
        help=
        "Include multiply mapped reads that are excluded by default.  Note that this feature is not complete as it is with the 256 sam filter.  it will only remove secondary alignments while still leaving the multiply mapped primary alignments.  To only use uniquely mapped reads you need to pre-filter on unique and start from that indexed bam."
    )
    parser.add_argument(
        '--include_indels',
        action='store_true',
        help=
        "By default only SNPs and only loci with multiple genotypes are output.  This will output indels."
    )
    parser.add_argument('--consensus',
                        action='store_true',
                        help="Use the original caller")
    args = parser.parse_args()
    #read the sam header
    p = Popen(('samtools view -H ' + args.input_sorted_bam).split(),
              stdout=PIPE)
    chromlens = {}
    for line in p.stdout:
        m = re.match('@SQ\s+SN:(\S+)\s+LN:(\d+)', line.rstrip())
        if not m: continue
        chromlens[m.group(1)] = int(m.group(2))
    #Lets break these up now
    z = 0
    itersize = 10000000
    for chrom in chromlens:
        for i in range(1, chromlens[chrom], itersize):
            z += 1
    global gtotal
    gtotal = z
    if args.threads > 1:
        p = multiprocessing.Pool(processes=args.threads)
    for chrom in chromlens:
        for i in range(1, chromlens[chrom], itersize):
            rstart = i
            rend = itersize + i - 1
            if rend > chromlens[chrom]: rend = chromlens[chrom]
            if args.threads <= 1:
                v = get_region_vcf(args, chrom, rstart, rend)
                do_output(v)
            else:
                p.apply_async(get_region_vcf,
                              args=(args, chrom, rstart, rend),
                              callback=do_output)
    if args.threads > 1:
        p.close()
        p.join()
Example #33
0
def play_announce():
    # write text file for announcer
    announce_text = open('announce.txt', 'w')
    announcer_contents(announce_text)
    announce_text.close()
    # make announce.wav using announcer program
    announcer = Popen(radio_settings.announcer, shell=True, stdin=PIPE)
    announcer_contents(announcer.stdin)
    announcer.stdin.close()
    # update title and pick bgm while we're waiting for announcer to finish
    icecast.update_metadata(radio_settings.announce_title)
    announce_bgm = os.path.join(
        radio_settings.announce_bgm_directory,
        choice(os.listdir(radio_settings.announce_bgm_directory)))
    announcer.wait()
    # play announce.wav mixed with bgm
    player = Popen([radio_settings.player, announce_bgm, "announce.wav"],
                   bufsize=4096,
                   stdout=PIPE).stdout
    print "announcement... %s %s %s" % (radio_settings.player, announce_bgm,
                                        "announce.wav")
    try:
        play_loop(player)
    finally:
        player.close()
Example #34
0
    def __init__(self, setupsDir=DEFAULT_SETUPS_DIR):

        # initial setup of ups itself:
        os.environ['UPS_SHELL'] = 'sh'

        # initial setup of ups itself:
        os.environ['UPS_SHELL'] = 'sh'
        if POPEN_AVAILABLE:
            f = Popen('. %s/setups.sh; ' % setupsDir + \
                      'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
                      'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
                      'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
                      'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";',
                      shell=True,
                      stdout=PIPE).stdout
        else:
            f = os.popen('. %s/setups.sh; ' % setupsDir + \
                         'echo os.environ\\[\\"UPS_DIR\\"\\]=\\"${UPS_DIR}\\"; ' + \
                         'echo os.environ\\[\\"PRODUCTS\\"\\]=\\"${PRODUCTS}\\";' + \
                         'echo os.environ\\[\\"SETUP_UPS\\"\\]=\\"${SETUP_UPS}\\";' + \
                         'echo os.environ\\[\\"PYTHONPATH\\"\\]=\\"${PYTHONPATH}\\";')
        exec f.read()
        f.close()

        # we need to initialize the following so that we can
        #  make the correct changes to sys.path later when products
        #  we setup modify PYTHONPATH
        self._pythonPath = os.environ.get('PYTHONPATH', '')
        self._sysPath = sys.path
        (self._internalSysPathPrepend,
         self._internalSysPathAppend) = self._getInitialSyspathElements()
    def run(self, edit):
        selections = self.view.sel()

        # For now we don't try to balance multiple or non-empty selections, just insert as usual
        if len(selections) > 1:
            for selection in reversed(selections):
                self.insert(edit, selection)
            return

        selection = selections[0]

        if not selection.empty():
            self.insert(edit, selection)
            return

        point = selection.end()
        line = self.view.line(point)
        os.environ["TM_CURRENT_LINE"] = self.view.substr(line).encode("utf-8")
        os.environ["TM_LINE_INDEX"] = unicode(self.view.rowcol(point)[1])
        os.environ["TM_SUPPORT_PATH"] = os.getcwd().encode("utf-8")
        pipe = Popen(["ruby", os.path.join(self.package_path(), self.PARSER_PATH)], shell=False, stdout=PIPE, stderr=STDOUT).stdout
        snippet = pipe.read()
        pipe.close()

        self.view.erase(edit, line)
        self.view.run_command("insert_snippet", {"contents": unicode(snippet, "utf-8")})
Example #36
0
    def cmd_output(self, p, cmdl, **kwargs):
        """ Run HLExtract and return the output.
        p - package (needs full path, use getPackagePath())
        cmdl - list, containing commands e.g.: [ '-ld', '-f' ]
        kwargs:
            options - string, containing options
        """
        cmd_output = []
        cmd_output.append('-p "%s"' % p)
        if 'options' in kwargs:
            cmd_output.append(self._cmd_options(kwargs['options']))
        if self.volatile is True:
            cmd_output.append('-v')
        if type(cmdl) is list:
            cmd_output.extend(cmdl) # Simply extend with the list of commands gien.
        else:
            cmd_output.append(cmdl)
        cmd = r'bin\HLExtract.exe' + ' ' + ' '.join(cmd_output)

        """ Begin code that I don't fully understand yet. """
        process = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
        output = []
        for z in process.stdout.readlines():
            output.append(z.strip('\r\n'))
        process.close()
        return output
Example #37
0
def loadKernelLog():
	data = Data(0)
	data.dmesg['boot']['start'] = data.start = ktime = 0.0
	data.stamp = {
		'time': datetime.now().strftime('%B %d %Y, %I:%M:%S %p'),
		'host': sysvals.hostname,
		'mode': 'boot', 'kernel': ''}

	if(sysvals.dmesgfile):
		lf = open(sysvals.dmesgfile, 'r')
	else:
		lf = Popen('dmesg', stdout=PIPE).stdout
	for line in lf:
		line = line.replace('\r\n', '')
		idx = line.find('[')
		if idx > 1:
			line = line[idx:]
		m = re.match('[ \t]*(\[ *)(?P<ktime>[0-9\.]*)(\]) (?P<msg>.*)', line)
		if(not m):
			continue
		ktime = float(m.group('ktime'))
		if(ktime > 120):
			break
		msg = m.group('msg')
		data.end = data.initstart = ktime
		data.dmesgtext.append(line)
		if(ktime == 0.0 and re.match('^Linux version .*', msg)):
			if(not data.stamp['kernel']):
				data.stamp['kernel'] = sysvals.kernelVersion(msg)
			continue
		m = re.match('.* setting system clock to (?P<t>.*) UTC.*', msg)
		if(m):
			utc = int((datetime.now() - datetime.utcnow()).total_seconds())
			bt = datetime.strptime(m.group('t'), '%Y-%m-%d %H:%M:%S')
			bt = bt - timedelta(seconds=int(ktime)-utc)
			data.boottime = bt.strftime('%Y-%m-%d_%H:%M:%S')
			data.stamp['time'] = bt.strftime('%B %d %Y, %I:%M:%S %p')
			continue
		m = re.match('^calling *(?P<f>.*)\+.*', msg)
		if(m):
			data.valid = True
			f = m.group('f')
			data.newAction('boot', f, 0, '', ktime, -1, '')
			continue
		m = re.match('^initcall *(?P<f>.*)\+.*', msg)
		if(m):
			f = m.group('f')
			list = data.dmesg['boot']['list']
			if(f in list):
				dev = list[f]
				dev['end'] = ktime
				data.end = ktime
			continue
		if(re.match('^Freeing unused kernel memory.*', msg)):
			break

	data.dmesg['boot']['end'] = data.end
	lf.close()
	return data
Example #38
0
 def determineDependancies(self, app):
     otoolPipe = Popen('otool -L "%s"' % app, shell=True, stdout=PIPE).stdout
     otoolOutput = [line for line in otoolPipe]
     otoolPipe.close()
     libs = [line.split()[0] for line in otoolOutput[1:] if ("Qt" in line or "phonon" in line) and "@executable_path" not in line]
     frameworks = [lib[:lib.find(".framework") + len(".framework")] for lib in libs]
     frameworks = [framework[framework.rfind('/') + 1:] for framework in frameworks]
     return zip(frameworks, libs)
Example #39
0
 def enableUnicode(self):
     cmd = [
         self.p4d, "-r", self.server_root, "-L", "log", "-vserver=3", "-xi"
     ]
     f = Popen(cmd, stdout=PIPE).stdout
     for s in f.readlines():
         pass
     f.close()
Example #40
0
 def determineDependancies(self, app):
     otoolPipe = Popen('otool -L "%s"' % app, shell=True, stdout=PIPE).stdout
     otoolOutput = [line for line in otoolPipe]
     otoolPipe.close()
     libs = [line.split()[0] for line in otoolOutput[1:] if ("Qt" in line or "phonon" in line) and "@executable_path" not in line]
     frameworks = [lib[:lib.find(".framework") + len(".framework")] for lib in libs]
     frameworks = [framework[framework.rfind('/') + 1:] for framework in frameworks]
     return zip(frameworks, libs)
Example #41
0
      def _backup(self):
          f = Popen(self.config.get('Settings', 'lv_search_cmd'), shell=True,stdout=PIPE).stdout
          lv_list = [ eachLine.strip() for eachLine in f ]
          f.close()

          server_proxy = xmlrpclib.ServerProxy('http://%s:%s' % 
                                               (self.config.get('Settings', 'manager_ip'),
                                                self.config.get('Settings', 'manager_port'), 
                                                ) )
          for lv in lv_list:
              bEof  = False
              index = 0
              while bEof == False:
                    if self.task_queue.empty():
                       try:
                           s = lv.split('/')
                           if len(s) != 0:
                              fName     = s[len(s)-1]+'.'+str(index)+'.img'
                              ddCmd     = 'dd if='+lv+' skip='+str(index)+' bs=20M count=5 of='+fName
                              ddProcess = Popen(ddCmd, shell=True)
                              ddProcess.wait()
                              if ddProcess.returncode != 0:
                                 print 'dd command failed: LV:%s;Block:%s' % (lv, str(index), )
                                 self._Alarm(self.config.get('Settings', 'sender'),
                                             self.config.get('Settings', 'receiver'), 
                                             'dd command failed: LV:%s;Block:%s' % (lv, str(index), ) )
                                 continue

                              fSize = os.stat(os.getcwd()+'/'+fName).st_size 
                              if fSize > 0:
                                 md5 = self._generateMd5(fName)
                                 server_proxy.request_backup(s[len(s)-1]+'.'+str(index), md5)
                                 print 'send md5: %s; file name:%s' % (md5, fName, )
                              
                              if fSize < 100*1024*1024:
                                 bEof = True
                       
                       except socket.error, e:
                           self._Alarm(self.config.get('Settings', 'sender'),
                                       self.config.get('Settings', 'receiver'), 
                                       'Request backup failed')
                       index = index + 1
                    else:
                       bItem = self.task_queue.get(False)
                       try:
                           if self.transferData(bItem):
                              server_proxy.notify(bItem.taskid, 1)
                           else:
                              server_proxy.notify(bItem.taskid, 0) 
                           print 'Finished, Notify Manager-----------------' 
                       except socket.error, e:
                           self._Alarm(self.config.get('Settings', 'sender'),
                                       self.config.get('Settings', 'receiver'), 
                                       'Notify Manager failed, taskid: %s' % bItem.taskid)
                           print 'Notify Manager failed-----------------' 
                        
                       if os.path.exists(os.getcwd()+'/'+fName):
                          os.remove(os.getcwd()+'/'+fName) 
Example #42
0
def play_one_song(song, update_metadata=True):
    if update_metadata:
        icecast.update_metadata(get_metadata(song))
    player = Popen([radio_settings.player, song], bufsize=4096, stdout=PIPE).stdout
    print "playing %s..." % song
    try:
        play_loop(player)
    finally: # close the player when any exception is thrown
        player.close()
Example #43
0
def execute_redis_cli(cmd):
	redis_cli_exe = redis_cli_info["cmd"]
	params = [redis_cli_exe] + cmd.split(' ')
	output = Popen(params, stdout=PIPE, stderr=PIPE)
	if output is not None:
		stdout = output.stdout.read()
		err = output.stderr.read()
		output.close()
		return stdout, err
	return None, None
Example #44
0
def play_one_song(song, update_metadata=True):
    if update_metadata:
        icecast.update_metadata(get_metadata(song))
    player = Popen([radio_settings.player, song], bufsize=4096,
                   stdout=PIPE).stdout
    print "playing %s..." % song
    try:
        play_loop(player)
    finally:  # close the player when any exception is thrown
        player.close()
Example #45
0
def execute_redis_cli(cmd):
    redis_cli_exe = redis_cli_info["cmd"]
    params = [redis_cli_exe] + cmd.split(' ')
    output = Popen(params, stdout=PIPE, stderr=PIPE)
    if output is not None:
        stdout = output.stdout.read()
        err = output.stderr.read()
        output.close()
        return stdout, err
    return None, None
Example #46
0
def factor_sig(n):
    pipe = Popen(["factor", str(n)], shell=False, stdout=PIPE).stdout
    l = pipe.readline()
    pipe.close()
    sig = {}
    factors_s = re.sub("^[^:]*:", "", l)
    for x in re.findall("[0-9]+", factors_s):
        if x not in sig:
            sig[x] = 0
        sig[x] += 1
    return sorted(sig.values())
Example #47
0
def factor_sig(n):
    pipe = Popen(['factor', str(n)], shell=False, stdout=PIPE).stdout
    l = pipe.readline()
    pipe.close()
    sig = {}
    factors_s = re.sub('^[^:]*:', '', l)
    for x in re.findall('[0-9]+', factors_s):
        if x not in sig:
            sig[x] = 0
        sig[x] += 1
    return sorted(sig.values())
Example #48
0
def copy_text(text):
    """
    Copy text to the system clipboard
    """

    cb_name = get_clipboard_name()

    if cb_name is not None:
        clipboard = Popen(cb_name, shell=True, stdin=PIPE).stdin
        clipboard.write(text)
        clipboard.close()
Example #49
0
def factor_sig(n):
    pipe = Popen(['factor', str(n)], shell=False, stdout=PIPE).stdout
    l = pipe.readline()
    pipe.close()
    sig = {}
    factors_s = re.sub('^[^:]*:', '', l)
    for x in re.findall('[0-9]+', factors_s):
        if not x in sig:
            sig[x] = 0
        sig[x] += 1
    return sorted(sig.values())
Example #50
0
def unpack7z(srcFile, dstDir, progress=None):
    # extract srcFile to dstDir
    progress = progress or Progress()

    # count the files in the archive
    length = 0
    reList = re.compile(u'Path = (.*?)(?:\r\n|\n)', re.U)
    command = ur'"%s" l -slt "%s"' % (dirs['compiled'].join(u'7z.exe').s,
                                      srcFile.s)
    ins, err = Popen(command, stdout=PIPE, stdin=PIPE,
                     startupinfo=startupinfo).communicate()
    ins = StringIO.StringIO(ins)
    for line in ins:
        length += 1
    ins.close()

    if progress:
        progress(0, srcFile.s + u'\n' + _(u'Extracting files...'))
        progress.setFull(1 + length)
    #end if

    app7z = dirs['compiled'].join(u'7z.exe').s
    command = u'"%s" x "%s" -y -o"%s"' % (app7z, srcFile.s, dstDir.s)

    #--Extract files
    ins = Popen(command, stdout=PIPE, stdin=PIPE,
                startupinfo=startupinfo).stdout
    #--Error Checking, and progress feedback
    #--Note subArchives for recursive unpacking
    reExtracting = re.compile(u'Extracting\s+(.+)', re.U)
    regMatch = reExtracting.match
    reError = re.compile(u'Error: (.*)', re.U)
    regErrMatch = reError.match
    errorLine = []
    index = 0
    for line in ins:
        line = unicode(line, 'utf8')
        maExtracting = regMatch(line)
        if len(errorLine) or regErrMatch(line):
            errorLine.append(line)
        if maExtracting:
            extracted = GPath(maExtracting.group(1).strip())
            if progress:
                progress(
                    index, srcFile.s + u'\n' + _(u'Extracting files...') +
                    u'\n' + extracted.s)
            #end if
            index += 1
        #end if
    #end for
    result = ins.close()
    if result:
        raise StateError(srcFile.s + u': Extraction failed:\n' +
                         u'\n'.join(errorLine))
Example #51
0
def copy_text(text):
    """
    Copy text to the system clipboard
    """

    cb_name = get_clipboard_name()

    if cb_name is not None:
        clipboard = Popen(cb_name, shell=True, stdin=PIPE).stdin
        clipboard.write(text)
        clipboard.close()
Example #52
0
def test_popen():
    f = Popen(('uname', '-a'), stdout=PIPE).stdout
    data = f.readline()
    f.close()
    print data

    print '-'*30
    f = Popen('who', stdout=PIPE).stdout
    data = [eachLine.strip() for eachLine in f]
    f.close()
    for eachLine in data:
        print eachLine
Example #53
0
def _call_pass_native(args = []):
    BUFSIZE = 4096
    cmd = ["pass"]
    for arg in args:
        cmd.append(arg)
    try:
        pipe = Popen(cmd, bufsize=BUFSIZE, stdout=PIPE).stdout
        out = pipe.read()
        pipe.close()
        return out
    except FileNotFoundError:
        return None
Example #54
0
def unpack7z(srcFile, dstDir, progress=None):
    # extract srcFile to dstDir
    progress = progress or Progress()

    # count the files in the archive
    length = 0
    reList = re.compile('Path = (.*?)(?:\r\n|\n)')
    if bosh.inisettings['EnableUnicode']:
        command = r'"%s" l -slt "%s"' % (dirs['compiled'].join('7zUnicode.exe').s, srcFile.s)
    else:
        command = r'"%s" l -slt "%s"' % (dirs['compiled'].join('7z.exe').s, srcFile.s)
    ins, err = Popen(command, stdout=PIPE, startupinfo=startupinfo).communicate()
    ins = stringBuffer(ins)
    for line in ins: length += 1
    ins.close()

    if progress:
        progress(0,_("%s\nExtracting files...") % srcFile.s)
        progress.setFull(1+length)
    #end if

    if bosh.inisettings['EnableUnicode']:
        app7z = dirs['compiled'].join('7zUnicode.exe').s
    else:
        app7z = dirs['compiled'].join('7z.exe').s
    command = '"%s" x "%s" -y -o"%s"' % (app7z, srcFile.s, dstDir.s)

    #--Extract files
    ins = Popen(command, stdout=PIPE, startupinfo=startupinfo).stdout
    #--Error Checking, and progress feedback
    #--Note subArchives for recursive unpacking
    reExtracting = re.compile('Extracting\s+(.+)')
    regMatch = reExtracting.match
    reError = re.compile('Error: (.*)')
    regErrMatch = reError.match
    errorLine = []
    index = 0
    for line in ins:
        maExtracting = regMatch(line)
        if len(errorLine) or regErrMatch(line):
            errorLine.append(line)
        if maExtracting:
            extracted = GPath(maExtracting.group(1).strip())
            if progress:
                progress(index,_("%s\nExtracting files...\n%s") % (srcFile.s,extracted.s))
            #end if
            index += 1
        #end if
    #end for
    result = ins.close()
    if result:
        raise StateError(_("%s: Extraction failed:\n%s") % (srcFile.s, "\n".join(errorLine)))
def main():
    parser = argparse.ArgumentParser(
        description="", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument(
        'input',
        help=
        "Sorted bam (preferrably indexed) Use - for STDIN sam. If streaming in be sure to remove unmapped reads"
    )
    parser.add_argument(
        '--threads',
        type=int,
        default=1,
        help=
        "use multiple threads the bam has been indexed.  Order is not preserved."
    )
    args = parser.parse_args()

    single_thread = True
    if args.threads == 1: single_thread = True
    elif args.input != '-':
        if os.path.isfile(args.input + '.bai'): single_thread = False
        else:
            single_thread = True
            sys.stderr.write(
                "Warning doing single thread because lacking index\n")

    chrs = None
    if args.input != '-':
        chrs = set()
        cmd = 'samtools view -H ' + args.input
        p = Popen(cmd.split(), stdout=PIPE)
        for line in p.stdout:
            m = re.match('@SQ\s+SN:(\S+)\s+LN:\d+', line)
            if m: chrs.add(m.group(1))
        p.communicate()
    #easy case of single thread
    if single_thread:
        if args.input == '-':
            dostream(sys.stdin)
        else:
            cmd = 'samtools view -F 4 -h ' + args.input
            p = Popen(cmd.split(), stdout=PIPE)
            dostream(p.stdout)
            p.communicate()
    else:
        p = Pool(processes=args.threads)
        for chr in sorted(chrs):
            p.apply_async(dofilestream,
                          args=(args.input, chr),
                          callback=printres)
        p.close()
        p.join()
Example #56
0
def executeCmd(cmd):
    from subprocess import Popen, PIPE, STDOUT

    fromCmd = Popen(cmd, shell=True, stdout=PIPE,
		    stderr=STDOUT, close_fds=True).stdout

    while True:
	line = fromCmd.readline()
	if len(line) == 0:
	    break
	debug(line)

    fromCmd.close()
Example #57
0
def getNetworkParams():
    """Return a dictionary of network parameters. Values include:

ssid     Current SSID
bssid    Current Base Station ID
"""
    from subprocess import Popen, PIPE

    networkParams = {}

    airportCmd = "%s -I " % binaries["airport"]

    debug("Running %s" % airportCmd)
    pipe = Popen(airportCmd, shell=True, stdout=PIPE).stdout

    while True:
	line = pipe.readline()
	if len(line) == 0:
	    break
	components = line.split()
	if components[0] == "SSID:":
	    networkParams["ssid"] = components[1]
	    continue
	if components[0] == "BSSID:":
	    networkParams["bssid"] = components[1]
	    continue

    pipe.close()

    # Query interface, which one depends on wether we're using the airport
    # or not
    if networkParams.has_key("SSID"):
	interface = airportIF
    else:
	interface = ethernetIF
    
    ifconfigCmd = "%s %s" % (binaries["ifconfig"], interface)
    debug("Running %s" % ifconfigCmd)
    pipe = Popen(ifconfigCmd, shell=True, stdout=PIPE).stdout

    while True:
	line = pipe.readline()
	if len(line) == 0:
	    break
	components = line.split()
	if components[0] == "inet":
	    networkParams["IPaddress"] = components[1]

    pipe.close()

    return networkParams