Skip to content

Commit

Permalink
refactor: move crash_reports into reports
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Feb 19, 2022
1 parent 7baa222 commit bc3f3bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
22 changes: 22 additions & 0 deletions src/rpcclient/rpcclient/darwin/crash_reports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import List

from pycrashreport.crash_report import CrashReport


class CrashReports:
def __init__(self, client, crash_reports_dir):
self._client = client
self._crash_reports_dir = crash_reports_dir

def list(self, prefixed='') -> List[CrashReport]:
result = []
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
with self._client.fs.open(entry.path, 'r') as f:
result.append(CrashReport(f.readall().decode(), filename=entry.path))
return result

def clear(self, prefixed=''):
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
self._client.fs.remove(entry.path)
20 changes: 2 additions & 18 deletions src/rpcclient/rpcclient/darwin/reports.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
from typing import List

from pycrashreport.crash_report import CrashReport
from rpcclient.darwin.crash_reports import CrashReports


class Reports:
def __init__(self, client, crash_reports_dir):
self._client = client
self._crash_reports_dir = crash_reports_dir

def list_crash_reports(self, prefixed='') -> List[CrashReport]:
result = []
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
with self._client.fs.open(entry.path, 'r') as f:
result.append(CrashReport(f.readall().decode(), filename=entry.path))
return result

def clear_crash_reports(self, prefixed=''):
for entry in self._client.fs.scandir(self._crash_reports_dir):
if entry.is_file() and entry.name.endswith('.ips') and entry.name.startswith(prefixed):
self._client.fs.remove(entry.path)
self.crash_reports = CrashReports(client, crash_reports_dir)
2 changes: 1 addition & 1 deletion src/rpcclient/rpcclient/macos/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class MacosClient(DarwinClient):
def __init__(self, sock, sysname: str, hostname: str, port: int = None):
super().__init__(sock, sysname, hostname, port)
self.bluetooth = Bluetooth(self)
self.crash_reports = Reports(self, CRASH_REPORTS_DIR)
self.reports = Reports(self, CRASH_REPORTS_DIR)

0 comments on commit bc3f3bb

Please sign in to comment.