mirror of
https://github.com/mvt-project/mvt.git
synced 2026-02-15 18:02:44 +00:00
Compare commits
3 Commits
fix/add-py
...
feature/an
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82f5e5c627 | ||
|
|
2bb613fe09 | ||
|
|
355850bd5c |
@@ -12,6 +12,8 @@ from typing import List, Optional
|
|||||||
from mvt.common.command import Command
|
from mvt.common.command import Command
|
||||||
|
|
||||||
from .modules.androidqf import ANDROIDQF_MODULES
|
from .modules.androidqf import ANDROIDQF_MODULES
|
||||||
|
from .modules.bugreport import BUGREPORT_MODULES
|
||||||
|
from .modules.bugreport.base import BugReportModule
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -39,7 +41,11 @@ class CmdAndroidCheckAndroidQF(Command):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.name = "check-androidqf"
|
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.format: Optional[str] = None
|
||||||
self.archive: Optional[zipfile.ZipFile] = None
|
self.archive: Optional[zipfile.ZipFile] = None
|
||||||
@@ -54,12 +60,44 @@ class CmdAndroidCheckAndroidQF(Command):
|
|||||||
for fname in subfiles:
|
for fname in subfiles:
|
||||||
file_path = os.path.relpath(os.path.join(root, fname), parent_path)
|
file_path = os.path.relpath(os.path.join(root, fname), parent_path)
|
||||||
self.files.append(file_path)
|
self.files.append(file_path)
|
||||||
|
|
||||||
elif os.path.isfile(self.target_path):
|
elif os.path.isfile(self.target_path):
|
||||||
self.format = "zip"
|
self.format = "zip"
|
||||||
self.archive = zipfile.ZipFile(self.target_path)
|
self.archive = zipfile.ZipFile(self.target_path)
|
||||||
self.files = self.archive.namelist()
|
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):
|
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":
|
if self.format == "zip":
|
||||||
module.from_zip_file(self.archive, self.files)
|
module.from_zip_file(self.archive, self.files)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user