Ejemplo n.º 1
0
    def preprocess(dir_path: str) -> None:
        """
        If the sens_http_flows.json/xml does not have the corresponding png, del it.
        :param dir_path:
        """
        def del_file(ext: str):
            path = os.path.join(root, base_name + ext)
            if os.path.exists(path):
                os.remove(path)
                logger.info('rm %s', path)

        for root, dirs, files in os.walk(dir_path):
            for d in dirs:
                d = os.path.join(root, d)
                if not any(fname.endswith('.png') for fname in os.listdir(d)):
                    logger.info('rm %s', d)
                    shutil.rmtree(d,
                                  ignore_errors=False,
                                  onerror=handle_remove_readonly)
            for file_name in files:
                if not file_name.endswith('.xml'):
                    continue
                base_name = file_name_no_ext(os.path.join(root, file_name))
                if os.path.exists(os.path.join(root, base_name + '.png')):
                    continue
                del_file('.xml')
                del_file('.json')
                del_file('.pcap')
                del_file('_sens_http_flows.json')
Ejemplo n.º 2
0
 def __init__(self, data_dir, label, xml, ui_doc=None):
     logger.debug(data_dir)
     self.dir = data_dir
     self.id = os.path.basename(data_dir) + '_' + file_name_no_ext(xml)
     self.label = label
     # Collect the topic and the app name from the html
     self.html = find_html(data_dir)
     self.topic = ''
     self.app_name = ''
     # self.views = []
     self.xml = xml
     if self.html:
         self.topic, self.app_name = description(self.html)
         logger.debug('%s, %s', self.topic, self.app_name)
     # Parse user interfaces
     if ui_doc is None:
         views, self.ui_doc = hierarchy_xml(xml)
     elif ui_doc is not None:
         self.ui_doc = ui_doc
     else:
         self.ui_doc = ''
Ejemplo n.º 3
0
def test_file_name_no_ext():
    assert file_name_no_ext('/Users/bob/folder/audio.wav') == 'audio'
Ejemplo n.º 4
0
def test_file_name_no_ext_only_file():
    assert file_name_no_ext('file!!.mp3') == 'file!!'
Ejemplo n.º 5
0
def test_file_name_no_ext_with_slash():
    assert file_name_no_ext('/c/user/file.mp3') == 'file'
Ejemplo n.º 6
0
def test_file_name_no_ext_empty():
    assert file_name_no_ext('') == ''
Ejemplo n.º 7
0
import os
import shutil
from utils import file_name_no_ext

print(file_name_no_ext('F:/FlowIntent/Location/0/test.json'))