Skip to content

Commit

Permalink
check 64213 first, then 23074, then fallback to 8080
Browse files Browse the repository at this point in the history
  • Loading branch information
tcprescott committed Aug 30, 2020
1 parent 07a47b8 commit f839e43
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PyYAML>=3.13
py2snes>=1.0.2
py2snes>=1.0.2
psutil
31 changes: 28 additions & 3 deletions romloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@

import yaml
import py2snes
import psutil

import asyncio
import socket


def show_exception_and_exit(exc_type, exc_value, tb):
import traceback
traceback.print_exception(exc_type, exc_value, tb)
input("Press key to exit.")
sys.exit(-1)


sys.excepthook = show_exception_and_exit


Expand All @@ -24,7 +28,8 @@ def show_exception_and_exit(exc_type, exc_value, tb):
with open(scriptpath + "\\romloader.yaml") as configfile:
try:
config = yaml.load(configfile)
print("loading config file at " + os.path.abspath(scriptpath + "\\romloader.yaml"))
print("loading config file at " +
os.path.abspath(scriptpath + "\\romloader.yaml"))
except yaml.YAMLError as e:
print(e)
sys.exit(1)
Expand All @@ -33,7 +38,8 @@ def show_exception_and_exit(exc_type, exc_value, tb):
with open("romloader.yaml") as configfile:
try:
config = yaml.load(configfile)
print("loading config file at " + os.path.abspath("romloader.yaml"))
print("loading config file at " +
os.path.abspath("romloader.yaml"))
except yaml.YAMLError as e:
print(e)
sys.exit(1)
Expand Down Expand Up @@ -74,7 +80,20 @@ async def main():

# initiate connection to the websocket server
snes = py2snes.snes()
await snes.connect()

a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

if is_open(64213):
address = 'ws://localhost:64213'
elif is_open(23074):
address = 'ws://localhost:23074'
elif is_open(8080):
address = 'ws://localhost:8080'
else:
raise Exception(
'Unable to connect to a suitable port! Please ensure qusb2nes is listening on 64213, 23074, or 8080!')

await snes.connect(address=address)

devicelist = await snes.DeviceList()

Expand Down Expand Up @@ -133,13 +152,19 @@ def get_destination(rule, romname):
name = romname
return path, name


def get_comm_device(devicelist):
print('----------------------------')
for idx, device in enumerate(devicelist):
print(str(idx) + ' - ' + device)
dst_idx = int(input('What device? '))
return devicelist[dst_idx]


def is_open(port: int):
return port in [i.laddr.port for i in psutil.net_connections()]


if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

0 comments on commit f839e43

Please sign in to comment.