Exemplo n.º 1
0
def get_file(in_tar_path, start_response, tfo):
    """Print file if text else download

    :param in_tar_path: internal tar path to file
    :param start_response: callback, provided by 'mod_wsgi'
    :param tfo: open tarfile object
    """
    status = "200 OK"

    filobj = tfo.extractfile(in_tar_path)
    testline = filobj.read(size=40)
    try:
        testline.decode("utf-8")
        filobj.seek(0)
        response_headers = [
            ('Content-type', 'text/plain'),
            ('Content-Disposition',
             'filename={}'.format(os.path.split(in_tar_path)[1]))
        ]
    except UnicodeDecodeError:
        response_headers = [
            ('Content-type', 'application/octet-stream'),
            ('Content-Disposition',
             'attachment; filename={}'.format(os.path.split(in_tar_path)[1]))
        ]

    start_response(status, response_headers)
    while True:
        buf = filobj.read(256)
        if buf:
            yield buf
        else:
            tfo.close()
            raise exceptions.StopIteration()
Exemplo n.º 2
0
 def __iter__(self):
     cur = ctypes.POINTER(Token)()
     while 1:
         cur = DLL.token_table_get_next(self._tableobj, cur)
         if bool(cur):
             yield cur.contents
         else:
             raise exceptions.StopIteration(_("hit end of table."))
Exemplo n.º 3
0
 def __iter__(self):
     cur = ctypes.POINTER(SmbiosStructure)()
     while 1:
         cur = DLL.smbios_table_get_next_struct(self._tableobj, cur)
         if bool(cur):
             yield cur.contents
         else:
             raise exceptions.StopIteration(_("hit end of table."))
Exemplo n.º 4
0
 def next(self):
     """Next component."""
     if self._i >= self.ncomponents:
         self._i = 0
         raise exceptions.StopIteration()
     else:
         self._i += 1
     return self.components[self._i - 1]
Exemplo n.º 5
0
def DASQuery(query, ntries=6, sleep=1):
    """
    Query das expecting to execute python client
    """
    das = '%s/src/TopQuarkAnalysis/TopPairBSM/test/das.py' % os.environ[
        'CMSSW_BASE']
    dasquery = '%s --query "%s" --format json --limit 10000' % (das, query)
    for n in range(ntries):
        stdout = tempfile.TemporaryFile()
        subprocess.check_call(dasquery, shell=True, stdout=stdout)
        stdout.seek(0)
        payload = json.load(stdout)
        if not payload['nresults'] > 0:
            time.sleep(sleep)
            sleep = 2 * sleep
            continue
        return payload
    raise exceptions.StopIteration('Failed das quary after %d iterations' %
                                   ntries)
Exemplo n.º 6
0
 def proc_cmd_quit(self, cmd, cmd_args):
     raise exceptions.StopIteration("quit")