mirror of
https://github.com/mvt-project/mvt
synced 2025-10-21 22:42:15 +02:00
Compare commits
3 Commits
fix/create
...
feature/an
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82f5e5c627 | ||
|
|
2bb613fe09 | ||
|
|
355850bd5c |
@@ -12,6 +12,8 @@ from typing import List, Optional
|
||||
from mvt.common.command import Command
|
||||
|
||||
from .modules.androidqf import ANDROIDQF_MODULES
|
||||
from .modules.bugreport import BUGREPORT_MODULES
|
||||
from .modules.bugreport.base import BugReportModule
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -39,7 +41,11 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
)
|
||||
|
||||
self.name = "check-androidqf"
|
||||
self.modules = ANDROIDQF_MODULES
|
||||
|
||||
# We can load AndroidQF and bugreport modules here, as
|
||||
# AndroidQF dump will contain a bugreport.
|
||||
self.modules = ANDROIDQF_MODULES + BUGREPORT_MODULES
|
||||
# TODO: Check how to namespace and deduplicate modules.
|
||||
|
||||
self.format: Optional[str] = None
|
||||
self.archive: Optional[zipfile.ZipFile] = None
|
||||
@@ -54,12 +60,44 @@ class CmdAndroidCheckAndroidQF(Command):
|
||||
for fname in subfiles:
|
||||
file_path = os.path.relpath(os.path.join(root, fname), parent_path)
|
||||
self.files.append(file_path)
|
||||
|
||||
elif os.path.isfile(self.target_path):
|
||||
self.format = "zip"
|
||||
self.archive = zipfile.ZipFile(self.target_path)
|
||||
self.files = self.archive.namelist()
|
||||
|
||||
def load_bugreport(self):
|
||||
# Refactor this file list loading
|
||||
# First we need to find the bugreport file location
|
||||
bugreport_zip_path = None
|
||||
for file_name in self.files:
|
||||
if file_name.endswith("bugreport.zip"):
|
||||
bugreport_zip_path = file_name
|
||||
break
|
||||
else:
|
||||
self.log.warning("No bugreport.zip found in the AndroidQF dump")
|
||||
return None
|
||||
|
||||
if self.format == "zip":
|
||||
# Create handle to the bugreport.zip file inside the AndroidQF dump
|
||||
handle = self.archive.open(bugreport_zip_path)
|
||||
bugreport_zip = zipfile.ZipFile(handle)
|
||||
else:
|
||||
# Load the bugreport.zip file from the extracted AndroidQF dump on disk.
|
||||
parent_path = Path(self.target_path).absolute().parent.as_posix()
|
||||
bug_report_path = os.path.join(parent_path, bugreport_zip_path)
|
||||
bugreport_zip = zipfile.ZipFile(bug_report_path)
|
||||
|
||||
return bugreport_zip
|
||||
|
||||
def module_init(self, module):
|
||||
if isinstance(module, BugReportModule):
|
||||
bugreport_archive = self.load_bugreport()
|
||||
if not bugreport_archive:
|
||||
return
|
||||
module.from_zip(bugreport_archive, bugreport_archive.namelist())
|
||||
return
|
||||
|
||||
if self.format == "zip":
|
||||
module.from_zip_file(self.archive, self.files)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user