Skip to content

Commit

Permalink
feat(#151): Made GUI dependencies optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbl committed Mar 13, 2020
1 parent 309df75 commit 2d57b95
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ Finally, you can install the project with Pip:

```
pip3 install -U pip setuptools wheel
# Without GUI dependencies
pip3 install -U -e .
# With GUI dependencies
pip3 install -U -e '.[GUI]'
```

This should install all the dependencies required to run PyRDP.
This should install the dependencies required to run PyRDP. If you choose to install without GUI dependencies,
it will not be possible to use `pyrdp-player` without headless mode (`--headless`)

If you ever want to leave your virtual environment, you can simply deactivate it:

Expand Down
40 changes: 27 additions & 13 deletions bin/pyrdp-player.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
import sys
import os

from PySide2.QtWidgets import QApplication
try:
from PySide2.QtWidgets import QApplication
from pyrdp.player import MainWindow
HAS_GUI = True
except ModuleNotFoundError:
HAS_GUI = False

from pyrdp.logging import LOGGER_NAMES, NotifyHandler
from pyrdp.player import MainWindow

def prepareLoggers(logLevel: int, outDir: Path):
def prepareLoggers(logLevel: int, outDir: Path, headless: bool):
logDir = outDir / "logs"
logDir.mkdir(exist_ok = True)

Expand All @@ -42,15 +46,20 @@ def prepareLoggers(logLevel: int, outDir: Path):
pyrdpLogger.addHandler(fileHandler)
pyrdpLogger.setLevel(logLevel)

# https://docs.python.org/3/library/os.html
if os.name != "nt":
notifyHandler = NotifyHandler()
notifyHandler.setFormatter(notificationFormatter)

uiLogger = logging.getLogger(LOGGER_NAMES.PLAYER_UI)
uiLogger.addHandler(notifyHandler)
else:
pyrdpLogger.warning("Notifications are not supported for your platform, they will be disabled.")
if not headless and HAS_GUI:
# https://docs.python.org/3/library/os.html
if os.name != "nt":
try:
notifyHandler = NotifyHandler()
notifyHandler.setFormatter(notificationFormatter)

uiLogger = logging.getLogger(LOGGER_NAMES.PLAYER_UI)
uiLogger.addHandler(notifyHandler)
except Exception:
# No notification daemon or DBus, can't use notifications.
pass
else:
pyrdpLogger.warning("Notifications are not supported for your platform, they will be disabled.")

def main():
"""
Expand All @@ -63,13 +72,18 @@ def main():
parser.add_argument("-p", "--port", help="Bind port (default: 3000)", default=3000)
parser.add_argument("-o", "--output", help="Output folder", default="pyrdp_output")
parser.add_argument("-L", "--log-level", help="Log level", default="INFO", choices=["INFO", "DEBUG", "WARNING", "ERROR", "CRITICAL"], nargs="?")
parser.add_argument("--headless", help="Parse a replay without rendering the user interface.", action="store_true")

args = parser.parse_args()
outDir = Path(args.output)
outDir.mkdir(exist_ok = True)

logLevel = getattr(logging, args.log_level)
prepareLoggers(logLevel, outDir)
prepareLoggers(logLevel, outDir, args.headless)

if not HAS_GUI and not args.headless:
logging.error('Headless mode is not specified and PySide2 is not installed. Install PySide2 to use the graphical user interface.')
exit(127)

app = QApplication(sys.argv)
mainWindow = MainWindow(args.bind, int(args.port), args.replay)
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
'pyasn1',
'pycryptodome',
'pyopenssl',
'PySide2',
'pytz',
'rsa',
'service_identity',
'twisted',
'dbus-python;platform_system!="Windows"',
'notify2;platform_system!="Windows"'
],
extras_require={
"GUI": ['PySide2', 'dbus-python;platform_system!="Windows"', 'notify2;platform_system!="Windows"']
}
)

0 comments on commit 2d57b95

Please sign in to comment.