Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark regex pattern variables raw strings #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ppadb/command/host/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Host(Command):
CONNECT_RESULT_PATTERN = "(connected to|already connected)"
CONNECT_RESULT_PATTERN = r"(connected to|already connected)"

OFFLINE = "offline"
DEVICE = "device"
Expand Down
2 changes: 1 addition & 1 deletion ppadb/command/host_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class HostAsync:
CONNECT_RESULT_PATTERN = "(connected to|already connected)"
CONNECT_RESULT_PATTERN = r"(connected to|already connected)"

OFFLINE = "offline"
DEVICE = "device"
Expand Down
8 changes: 4 additions & 4 deletions ppadb/command/transport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def screencap(self):
return result

def clear(self, package):
clear_result_pattern = "(Success|Failed)"
clear_result_pattern = r"(Success|Failed)"

result = self.shell("pm clear {}".format(package))
m = re.search(clear_result_pattern, result)
Expand All @@ -68,7 +68,7 @@ def framebuffer(self):
def list_features(self):
result = self.shell("pm list features 2>/dev/null")

result_pattern = "^feature:(.*?)(?:=(.*?))?\r?$"
result_pattern = r"^feature:(.*?)(?:=(.*?))?\r?$"
features = {}
for line in result.split('\n'):
m = re.match(result_pattern, line)
Expand All @@ -80,7 +80,7 @@ def list_features(self):

def list_packages(self):
result = self.shell("pm list packages 2>/dev/null")
result_pattern = "^package:(.*?)\r?$"
result_pattern = r"^package:(.*?)\r?$"

packages = []
for line in result.split('\n'):
Expand All @@ -92,7 +92,7 @@ def list_packages(self):

def get_properties(self):
result = self.shell("getprop")
result_pattern = "^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$"
result_pattern = r"^\[([\s\S]*?)\]: \[([\s\S]*?)\]\r?$"

properties = {}
for line in result.split('\n'):
Expand Down
4 changes: 2 additions & 2 deletions ppadb/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@


class Device(Transport, Serial, Input, Utils, WM, Traffic, CPUStat, BatteryStats):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)"

def __init__(self, client, serial):
self.client = client
Expand Down
4 changes: 2 additions & 2 deletions ppadb/device_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def _get_src_info(src):


class DeviceAsync(TransportAsync):
INSTALL_RESULT_PATTERN = "(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = "(Success|Failure.*|.*Unknown package:.*)"
INSTALL_RESULT_PATTERN = r"(Success|Failure|Error)\s?(.*)"
UNINSTALL_RESULT_PATTERN = r"(Success|Failure.*|.*Unknown package:.*)"

def __init__(self, client, serial):
self.client = client
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/cpustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def total(self):

class CPUStat(Plugin):
total_cpu_pattern = re.compile(
"cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s")
r"cpu\s+([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s([\d]+)\s")

def cpu_times(self):
return self.get_total_cpu()
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_traffic(self, package_name):
cmd = 'dumpsys package {} | grep userId'.format(package_name)
result = self.shell(cmd).strip()

pattern = "userId=([\d]+)"
pattern = r"userId=([\d]+)"

if result:
match = re.search(pattern, result)
Expand Down
20 changes: 10 additions & 10 deletions ppadb/plugins/device/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_top_activity(self):
return None

def get_top_activities(self):
pattern = "ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)"
pattern = r"ACTIVITY\s([\w\.]+)/([\w\.]+)\s[\w\d]+\spid=([\d]+)"
cmd = "dumpsys activity top | grep ACTIVITY"
result = self.shell(cmd)

Expand All @@ -45,13 +45,13 @@ def get_top_activities(self):
return activities

def get_meminfo(self, package_name):
total_meminfo_re = re.compile('\s*TOTAL\s*(?P<pss>\d+)'
'\s*(?P<private_dirty>\d+)'
'\s*(?P<private_clean>\d+)'
'\s*(?P<swapped_dirty>\d+)'
'\s*(?P<heap_size>\d+)'
'\s*(?P<heap_alloc>\d+)'
'\s*(?P<heap_free>\d+)')
total_meminfo_re = re.compile(r'\s*TOTAL\s*(?P<pss>\d+)'
r'\s*(?P<private_dirty>\d+)'
r'\s*(?P<private_clean>\d+)'
r'\s*(?P<swapped_dirty>\d+)'
r'\s*(?P<heap_size>\d+)'
r'\s*(?P<heap_alloc>\d+)'
r'\s*(?P<heap_free>\d+)')

cmd = 'dumpsys meminfo {}'.format(package_name)
result = self.shell(cmd)
Expand Down Expand Up @@ -82,7 +82,7 @@ def get_uid(self, package_name):
cmd = 'dumpsys package {} | grep userId'.format(package_name)
result = self.shell(cmd).strip()

pattern = "userId=([\d]+)"
pattern = r"userId=([\d]+)"

if result:
match = re.search(pattern, result)
Expand All @@ -99,7 +99,7 @@ def get_package_version_name(self, package_name):
cmd = 'dumpsys package {} | grep versionName'.format(package_name)
result = self.shell(cmd).strip()

pattern = "versionName=([\d\.]+)"
pattern = r"versionName=([\d\.]+)"

if result:
match = re.search(pattern, result)
Expand Down
2 changes: 1 addition & 1 deletion ppadb/plugins/device/wm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
])

class WM(Plugin):
SIZE_RE = 'Physical size:\s([\d]+)x([\d]+)'
SIZE_RE = r'Physical size:\s([\d]+)x([\d]+)'
def wm_size(self):
result = self.shell("wm size")
match = re.search(self.SIZE_RE, result)
Expand Down