Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Refactor lib.check
Browse files Browse the repository at this point in the history
  • Loading branch information
srevinsaju committed Apr 20, 2020
1 parent 4f1b5b8 commit aef6178
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 84 deletions.
1 change: 1 addition & 0 deletions appimage/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export GUISCRCPY_ADB="${APPDIR}/usr/bin/adb"
export ADB="${APPDIR}/usr/bin/adb"
export SCRCPY_SERVER_PATH="${APPDIR}/usr/share/scrcpy/scrcpy-server"
export PATH="${APPDIR}/usr/bin:${PATH}"
export GUISCRCPY_APPIMAGE="TRUE"

{{ python-executable }} -s ${APPDIR}/opt/python{{ python-version }}/bin/guiscrcpy "$@"
72 changes: 39 additions & 33 deletions guiscrcpy/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtWidgets import QMessageBox

from guiscrcpy.lib.check import adb
from guiscrcpy.lib.check import scrcpy
from guiscrcpy.lib.check import Adb
from guiscrcpy.lib.check import Scrcpy
from guiscrcpy.lib.config import InterfaceConfig
from guiscrcpy.lib.process import is_running
from guiscrcpy.lib.toolkit import UXMapper
Expand All @@ -75,16 +75,16 @@
# Add precedence for guiscrcpy to check environment variables
# for the paths of `adb` and `scrcpy` over the configuration files.
if os.getenv('GUISCRCPY_ADB', None) is None:
adb.path = config['adb']
Adb.path = config['adb']
else:
adb.path = os.getenv('GUISCRCPY_ADB')
Adb.path = os.getenv('GUISCRCPY_ADB')

if os.getenv('GUISCRCPY_SCRCPY', None) is None:
scrcpy.path = config['scrcpy']
Scrcpy.path = config['scrcpy']
else:
scrcpy.path = os.getenv('GUISCRCPY_SCRCPY')
Scrcpy.path = os.getenv('GUISCRCPY_SCRCPY')

scrcpy.server_path = config['scrcpy-server']
Scrcpy.server_path = config['scrcpy-server']

# Initialize argument parser
parser = argparse.ArgumentParser('guiscrcpy v{}'.format(VERSION))
Expand Down Expand Up @@ -147,7 +147,7 @@
args += " -t "
if config['dispRO']:
args += " --turn-screen-off "
scrcpy.start(scrcpy.path, args)
Scrcpy.start(Scrcpy.path, args)

logging.debug("Importing modules...")

Expand Down Expand Up @@ -221,7 +221,8 @@ def __init__(self):
self.flaglineedit.setText(config['extra'])
else:
pass
except Exception as e:
except Exception as err:
logging.debug(f"Exception: flaglineedit.text(config[extra]) {err}")
pass

# set bottom instance and side instance as enabled by default
Expand Down Expand Up @@ -251,7 +252,7 @@ def settings_mgr(self):

def network_mgr(self):
from guiscrcpy.ux.network import InterfaceNetwork
self.nm = InterfaceNetwork(adb.path)
self.nm = InterfaceNetwork(Adb.path)
self.nm.init()
self.nm.show()

Expand All @@ -262,8 +263,11 @@ def mapp(self):
mapper.file_check()
else:
logging.warning(
"guiscrcpy ~ mapper is not initialized. Initialize by running" +
"$ guiscrcpy-mapper" + "reset points by" + "$ guiscrcpy-mapper -r")
"guiscrcpy ~ mapper is not initialized. "
"Initialize by running" +
"$ guiscrcpy-mapper" + "reset points by" +
"$ guiscrcpy-mapper -r"
)

@staticmethod
def launch_usb_audio():
Expand All @@ -283,7 +287,8 @@ def about(self):
about_message_box.about(
self.pushButton,
"Info",
"Please restart guiscrcpy to reset the settings. guiscrcpy will now exit",
"Please restart guiscrcpy to reset the settings. "
"guiscrcpy will now exit",
)
about_message_box.addButton("OK", about_message_box.hide())
about_message_box.show()
Expand All @@ -297,7 +302,8 @@ def reset(self):
message_box.about(
self.pushButton,
"Info",
"Please restart guiscrcpy to reset the settings. guiscrcpy will now exit",
"Please restart guiscrcpy to reset the settings. "
"guiscrcpy will now exit",
)
message_box.addButton("OK", self.quit_window())
message_box.show()
Expand Down Expand Up @@ -334,7 +340,7 @@ def __dial_change_cb(self):
pass

def __refresh_devices_combo_box_cb(self):
devices_list = adb.devices(adb.path)
devices_list = Adb.devices(Adb.path)

if len(devices_list) == 0:
self.private_message_box_adb.setText("DEVICE IS NOT CONNECTED")
Expand Down Expand Up @@ -502,7 +508,7 @@ def start_act(self):
f"connected; (color id "
f"matches toolkit color)")

scrcpy.start(scrcpy.path, arguments_scrcpy)
Scrcpy.start(Scrcpy.path, arguments_scrcpy)
final_time = time.time()
eta = final_time - initial_time
print("scrcpy launched in {:.2f}s".format(eta))
Expand Down Expand Up @@ -542,43 +548,43 @@ def bootstrap0():
app.processEvents()
cfedited = False

if (adb.path is None) or (not os.path.exists(adb.path)):
adb.path = openFileNameDialog(None, 'adb')
if (Adb.path is None) or (not os.path.exists(Adb.path)):
Adb.path = openFileNameDialog(None, 'adb')
cfedited = True
config['adb'] = adb.path
config['adb'] = Adb.path

if (scrcpy.path is None) or (not os.path.exists(scrcpy.path)):
scrcpy.path = openFileNameDialog(None, 'scrcpy')
if (Scrcpy.path is None) or (not os.path.exists(Scrcpy.path)):
Scrcpy.path = openFileNameDialog(None, 'scrcpy')
cfedited = True
config['scrcpy'] = scrcpy.path
config['scrcpy'] = Scrcpy.path

# on windows, users are likely not to add the scrcpy-server to the
# SCRCPY_SERVER_PATH
scrcpy_server_path_env = os.getenv('SCRCPY_SERVER_PATH', None)
if scrcpy_server_path_env:
if os.path.exists(scrcpy_server_path_env):
config['scrcpy-server'] = scrcpy.server_path
config['scrcpy-server'] = Scrcpy.server_path
else:
scrcpy.server_path = openFileNameDialog(None, 'scrcpy-server')
Scrcpy.server_path = openFileNameDialog(None, 'scrcpy-server')
cfedited = True
config['scrcpy-server'] = scrcpy.server_path
os.environ['SCRCPY_SERVER_PATH'] = scrcpy.server_path
elif ((scrcpy.server_path is None) or
(not os.path.exists(scrcpy.server_path))) and (
config['scrcpy-server'] = Scrcpy.server_path
os.environ['SCRCPY_SERVER_PATH'] = Scrcpy.server_path
elif ((Scrcpy.server_path is None) or
(not os.path.exists(Scrcpy.server_path))) and (
platform.System().system() == 'Windows'
):
scrcpy.server_path = openFileNameDialog(None, 'scrcpy-server')
Scrcpy.server_path = openFileNameDialog(None, 'scrcpy-server')
cfedited = True
config['scrcpy-server'] = scrcpy.server_path
os.environ['SCRCPY_SERVER_PATH'] = scrcpy.server_path
config['scrcpy-server'] = Scrcpy.server_path
os.environ['SCRCPY_SERVER_PATH'] = Scrcpy.server_path
elif platform.System().system() == "Windows":
os.environ['SCRCPY_SERVER_PATH'] = scrcpy.server_path
os.environ['SCRCPY_SERVER_PATH'] = Scrcpy.server_path

if cfedited:
cfgmgr.update_config(config)
cfgmgr.write_file()

adb.devices(adb.path)
Adb.devices(Adb.path)
guiscrcpy = InterfaceGuiscrcpy()
guiscrcpy.show()
app.processEvents()
Expand Down
41 changes: 20 additions & 21 deletions guiscrcpy/lib/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
environment = System()


def check(binary):
pass


class scrcpy:
class Scrcpy:
def __init__(self):
pass

Expand Down Expand Up @@ -59,7 +55,7 @@ def check():
environment.paths()))


class adb:
class Adb:
def __init__(self):
pass

Expand All @@ -76,13 +72,13 @@ def check():
@staticmethod
def shell_input(path, command, device_id=None):
if device_id:
shellx = Popen(
Popen(
_("{} -s {} shell input {}".format(path, device_id, command)),
stdout=PIPE,
stderr=PIPE,
)
else:
shellx = Popen(
Popen(
_("{} shell input {}".format(path, command)),
stdout=PIPE,
stderr=PIPE,
Expand All @@ -91,52 +87,55 @@ def shell_input(path, command, device_id=None):
@staticmethod
def get_dimensions(path, device_id=None):
if device_id:
shellx = Popen(
shell_adb = Popen(
_("{} -s {} shell wm size".format(path, device_id)),
stdout=PIPE, stderr=PIPE)
else:
shellx = Popen(_("{} shell wm size".format(path)),
shell_adb = Popen(_("{} shell wm size".format(path)),
stdout=PIPE, stderr=PIPE)
raw_dimensions = shellx.stdout.read().decode().strip('\n')
raw_dimensions = shell_adb.stdout.read().decode().strip('\n')
for i in ['Override size', 'Physical size']:
if i in raw_dimensions:
out = raw_dimensions[raw_dimensions.find(i):]
out_decoded = out.split(':')[1].strip()
dimValues = out_decoded.split('x')
return dimValues
dimension_values = out_decoded.split('x')
return dimension_values
else:
logging.error(
"AndroidDeviceError: adb shell wm size did not return 'Physical Size' or 'Override Size'"
"AndroidDeviceError: adb shell wm size did not return "
"'Physical Size' or 'Override Size'"
)
return False

@staticmethod
def shell(path, command, device_id=None):
if device_id:
shellx = Popen(_("{} -s {} shell {}".format(path,
Popen(_("{} -s {} shell {}".format(path,
device_id, command)),
stdout=PIPE, stderr=PIPE)
else:
shellx = Popen(_("{} shell {}".format(path, command)),
Popen(_("{} shell {}".format(path, command)),
stdout=PIPE, stderr=PIPE)
return True

@staticmethod
def command(path, command, device_id=None):
if device_id:
shellx = Popen(
adb_shell_output = Popen(
_("{} -s {} {}".format(path, device_id, command)), stdout=PIPE,
stderr=PIPE)
else:
shellx = Popen(_("{} {}".format(path, command)),
stdout=PIPE, stderr=PIPE)
return shellx
adb_shell_output = Popen(_("{} {}".format(path, command)),
stdout=PIPE, stderr=PIPE)
return adb_shell_output

@staticmethod
def devices(increment=''):
if increment is None:
raise FileNotFoundError(
"guiscrcpy couldn't find adb. Please specify path to adb in configuration file")
"guiscrcpy couldn't find adb. "
"Please specify path to adb in configuration file"
)
proc = Popen(_(increment + " devices"), stdout=PIPE)
output = [[y.strip() for y in x.split('\t')]
for x in decode_process(proc)[1:]][:-1]
Expand Down
8 changes: 4 additions & 4 deletions guiscrcpy/lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import json
import os

from guiscrcpy.lib.check import adb
from guiscrcpy.lib.check import scrcpy
from guiscrcpy.lib.check import Adb
from guiscrcpy.lib.check import Scrcpy
from guiscrcpy.platform import platform


Expand Down Expand Up @@ -51,11 +51,11 @@ def validate(self):
# check scrcpy and adb are not None, else replace it with original
# values
if self.config['adb'] is None:
adb_path = adb.check()
adb_path = Adb.check()
if adb_path:
self.config['adb'] = adb_path
if self.config['scrcpy'] is None:
scrcpy_path = scrcpy.check()
scrcpy_path = Scrcpy.check()
if scrcpy_path:
self.config['scrcpy'] = scrcpy_path
if (self.config['scrcpy-server'] is not None) and (
Expand Down
8 changes: 4 additions & 4 deletions guiscrcpy/lib/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from PyQt5.QtGui import QPixmap
from pynput import keyboard

from guiscrcpy.lib.check import adb
from guiscrcpy.lib.check import Adb
from guiscrcpy.lib.config import InterfaceConfig

get1 = False
Expand All @@ -42,7 +42,7 @@

cfgmgr = InterfaceConfig()
config = cfgmgr.get_config()
adb.path = config['adb']
Adb.path = config['adb']

jsong = 'guiscrcpy.mapper.json'

Expand All @@ -53,7 +53,7 @@
print('With USB debugging turned on.')
print("+++++++++++++++++++++++++++++++++++++++")
print("Waiting for device")
adb.command(adb.path, 'wait-for-any-device')
Adb.command(Adb.path, 'wait-for-any-device')
print("Device : OK!")

cfgpath = cfgmgr.cfgpath
Expand All @@ -65,7 +65,7 @@
help="Remove prefernces")
args = parser.parse_args()

dimensions = adb.get_dimensions(adb.path)
dimensions = Adb.get_dimensions(Adb.path)


class MapperUI(QtWidgets.QWidget):
Expand Down
8 changes: 4 additions & 4 deletions guiscrcpy/lib/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pystray
from PIL import Image, ImageDraw

from guiscrcpy.lib.check import adb
from guiscrcpy.lib.check import Adb

logging.warning("Launching notification auditor")

Expand All @@ -39,7 +39,7 @@ def __init__(self):

def callback(self, icon):
notif = Popen(
adb.path +
Adb.path +
"adb shell dumpsys notification | grep ticker | cut -d= -f2",
stdout=PIPE,
shell=True,
Expand All @@ -54,15 +54,15 @@ def callback(self, icon):
"Notif Auditor is experimental on Windows. If you wish to help out on this issue. Open a PR on github"
)
notif = Popen(
adb.path +
Adb.path +
"adb shell dumpsys notification | findstr ticker ",
stdout=PIPE,
shell=True,
)
else:
"Notif Auditor is experimental on Linux. If you wish to help out on this issue. Open a PR on github"
notif = Popen(
adb.path +
Adb.path +
"adb shell dumpsys notification | grep ticker | cut -d= -f2",
stdout=PIPE,
shell=True,
Expand Down
Loading

0 comments on commit aef6178

Please sign in to comment.