This client pulls PCAP files for building report.

    Returns:
        A list with `view_pcap` , `meta` and `filename` objects.
328955
def run():
    

    global WORKBENCH
    
    # Grab grab_server_argsrver args
    args = client_helper.grab_server_args()

    # Start up workbench connection
    WORKBENCH = zerorpc.Client(timeout=300, heartbeat=60)
    WORKBENCH.connect('tcp://'+args['server']+':'+args['port'])

    data_path = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), '../data/pcap')
    file_list = [os.path.join(data_path, child) for child in \
                os.listdir(data_path)]
    results = []
    for filename in file_list:

        # Skip OS generated files
        if '.DS_Store' in filename: continue

        # Process the pcap file
        with open(filename,'rb') as f:
            md5 = WORKBENCH.store_sample(f.read(), filename, 'pcap')
            result = WORKBENCH.work_request('view_pcap', md5)
            result.update(WORKBENCH.work_request('meta', result['view_pcap']['md5']))
            result['filename'] = result['meta']['filename'].split('/')[-1]
            results.append(result)

    return results
518080
def submit_and_render():
    
    data = request.files.file
    template = env.get_template("results.html")
    if not data:
        pass
    results = analyse_pcap(data.file, data.filename)
    results.update(base)
    return template.render(results)
508439
def get_meta(filepath):
    
    meta = {}
    try:
        from PIL import Image
        with Image.open(filepath) as img:
            width, height = img.size
        meta['width'] = width
        meta['height'] = height
        meta['channels'] = len(img.mode)  # RGB, RGBA - does this always work?
    except ImportError:
        pass

    # Get times - creation, last edit, last open
    meta['file'] = mpu.io.get_file_meta(filepath)
    return meta
596155
def _get_fastq_files(ldetail, read, fastq_dir):
    
    return glob.glob(os.path.join(fastq_dir, "Project_%s" % ldetail["project_name"],
                                  "Sample_%s" % ldetail["name"],
                                  "%s_*_%s_*.fastq.gz" % (ldetail["name"], read)))
618395
def get_and_update_package_metadata():
    
    global setup_arguments
    global METADATA_FILENAME

    if not os.path.exists('.git') and os.path.exists(METADATA_FILENAME):
        with open(METADATA_FILENAME) as fh:
            metadata = json.load(fh)
    else:
        git = Git(version=setup_arguments['version'])
        metadata = {
            'version': git.version,
            'long_description': 'Tool to pip install missing imports and more',
            'git_hash': git.hash,
            'git_origin': git.origin,
            'git_branch': git.branch
        }
        for readme_file in ['README.rst', 'README.md', 'README.txt']:
            if os.path.exists(readme_file):
                with open(readme_file) as file_handle:
                    metadata['long_description'] = file_handle.read()
                break
        with open(METADATA_FILENAME, 'w') as fh:
            json.dump(metadata, fh)
    return metadata
74954
def files(self):
        
        info = self.metainfo['info']
        if 'length' in info:    # Singlefile
            yield info['name']
        elif 'files' in info:   # Multifile torrent
            rootdir = self.name
            for fileinfo in info['files']:
                yield os.path.join(rootdir, os.path.join(*fileinfo['path']))
914615
def gather_files(self):
        
        self.all_files = utils.files_in_path(self.paths["role"])

        return len(self.all_files)
1059081
def build_views(self):
        
        # Then loop through and run them all
        for view_str in self.view_list:
            logger.debug("Building %s" % view_str)
            if self.verbosity > 1:
                self.stdout.write("Building %s" % view_str)
            view = get_callable(view_str)
            self.get_view_instance(view).build_method()
1354151
def get_attachment_content(self, request, queryset):
        

        return self.dump_report_content(request, self.get_report_data_rows(request, queryset))
1332104
def get_all_file_report_pages(self, query):
        
        responses = []
        r = self.get_hashes_from_search(query)
        responses.append(r)

        if ('results' in r.keys()) and ('next_page' in r['results'].keys()):
            next_page = r['results']['next_page']
        else:
            next_page = None

        while next_page:
            r = self.get_hashes_from_search(query, next_page)

            if ('results' in r.keys()) and ('next_page' in r['results'].keys()):
                next_page = r['results']['next_page']
            else:
                next_page = None

            responses.append(r)
        return dict(results=responses)
1189175
def read_pcap_from_source(self):
        
        if self._capture_node:
            compute = self._capture_node["node"].compute
            return compute.stream_file(self._project, "tmp/captures/" + self._capture_file_name)
1338395
def views(self):
        
        if self._views:
            return self._views
        elif not self.abstract:
            return self.read_meta()._views

        raise EmptyDocumentException()
1367821
def list_files(self, project_name):
        
        project = self._get_project_for_name(project_name)
        file_path_dict = self._get_file_path_dict_for_project(project)
        return list(file_path_dict)
284003
def _file_list(self, folder):
        ''''''
        rtn = []
        walk = self._walk_report(folder)
        for key,val in walk.items():
            for v in val:
                x=os.path.join(key,v)
                rtn.append(x)

        self.file_count = len(rtn)  #a count of the files we'll have in the final cleaned sosreport, for reporting
        return rtn
462121
def get_result_files(self, result):
        
        if isinstance(result, dict):
            result_id = result['meta']['id']
        else:  # Should already be a string containing the id
            result_id = result

        result_data_dir = os.path.join(self.get_data_dir(), result_id)

        filenames = next(os.walk(result_data_dir))[2]

        filename_path_pairs = [
            (f, os.path.join(self.get_data_dir(), result_id, f))
            for f in filenames]

        return {k: v for k, v in filename_path_pairs}
356318
def find_candidate_metadata_files(names):
        """"""
        tuples = [
            x.split('/') for x in map(try_decode, names)
            if 'METADATA' in x
        ]
        return [x[1] for x in sorted([(len(x), x) for x in tuples])]
986845
def get_image_list(self, name, dir_structure='original'):
        
        assert name in ['train', 'val', 'test']
        assert dir_structure in ['original', 'train']
        add_label_to_fname = (name != 'train' and dir_structure != 'original')
        if add_label_to_fname:
            synset = self.get_synset_1000()

        fname = os.path.join(self.dir, name + '.txt')
        assert os.path.isfile(fname), fname
        with open(fname) as f:
            ret = []
            for line in f.readlines():
                name, cls = line.strip().split()
                cls = int(cls)

                if add_label_to_fname:
                    name = os.path.join(synset[cls], name)

                ret.append((name.strip(), cls))
        assert len(ret), fname
        return ret