def test_get_dirs(self): test_dirs = ["dir_1", "dir_2", "dir_1/sub_dir"] for item in test_dirs: os.mkdir(os.path.join(self.tmp_dir.name, item)) result = get_dirs_in_dir(self.tmp_dir.name) self.assertEqual(sorted(result), [ os.path.join(self.tmp_dir.name, "dir_1"), os.path.join(self.tmp_dir.name, "dir_2") ], "found dirs not correct")
def _get_plugin_src_dirs(base_dir): plug_in_base_path = Path(get_src_dir(), base_dir) plugin_dirs = get_dirs_in_dir(str(plug_in_base_path)) plugins = [] for plugin_path in plugin_dirs: plugin_code_dir = Path(plugin_path, 'code') if plugin_code_dir.is_dir(): plugins.append(str(plugin_code_dir)) else: logging.warning('Plugin has no code directory: {}'.format(plugin_path)) return plugins
def main(): _create_signature_dir() for plugin_dir in get_dirs_in_dir(os.path.join(get_src_dir(), 'plugins/analysis')): signature_dir = os.path.join(plugin_dir, 'signatures') if os.path.isdir(signature_dir): print('Compile signatures in {}'.format(signature_dir)) with NamedTemporaryFile(mode='w') as tmp_file: _create_joint_signature_file(signature_dir, tmp_file) _create_compiled_signature_file(signature_dir, tmp_file) return 0
def _get_plugin_src_dirs(base_dir): plug_in_base_path = Path(get_src_dir(), base_dir) plugin_dirs = get_dirs_in_dir(str(plug_in_base_path)) plugins = [] for plugin_path in plugin_dirs: # Ignore cache directories if Path(plugin_path).name == '__pycache__': continue plugin_code_dir = Path(plugin_path, 'code') if plugin_code_dir.is_dir(): plugins.append(str(plugin_code_dir)) else: logging.warning( 'Plugin has no code directory: {}'.format(plugin_path)) return plugins
def _get_plugin_src_dirs(base_dir: str) -> List[str]: ''' Returns a list of all plugin code directories. E.g. if base_dir contains the qemu_exec plugin it would return `base_dir`/qemu_exec/code. :param base_dir: The root directory of all plugins ''' plug_in_base_path = Path(get_src_dir(), base_dir) plugin_dirs = get_dirs_in_dir(str(plug_in_base_path)) plugins = [] for plugin_path in plugin_dirs: if plugin_path.endswith('__pycache__'): continue plugin_code_dir = Path(plugin_path, 'code') if plugin_code_dir.is_dir(): plugins.append(str(plugin_code_dir)) else: logging.warning( 'Plugin has no code directory: {}'.format(plugin_path)) return plugins
def test_get_dirs_in_dir_error(self): result = get_dirs_in_dir("/none_existing/dir") self.assertEqual(result, [], "error result should be an empty list")