Skip to content

Commit f25e0a6

Browse files
committed
use py2snes 1.0.2
1 parent 6a816df commit f25e0a6

File tree

6 files changed

+64
-374
lines changed

6 files changed

+64
-374
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dist/
44
src/test.py
55
src/romloader.yaml
66
env/
7-
.vscode/
7+
.vscode/
8+
testing/

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
websocket-client>=0.54.0
2-
PyYAML>=3.13
1+
PyYAML>=3.13
2+
py2snes>=1.0.2

romloader.example.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ default_destination: "/romloader"
1010
### a set of rules to use to put certain ROMs in certain locations, such as your randomizer ROMs, useful for MSU1 users
1111
rules:
1212
alttpr:
13-
name_pattern: "ALttP - VT_*" # look for an input ROM that matches this name
13+
name_pattern:
14+
- "ALttP - VT_*" # look for an input ROM that matches this name
15+
- "ER_*"
16+
- "Daily Challenge_*"
1417
destinations:
1518
- name: default
1619
path: "/LinkToThePast/Transferred"
@@ -36,22 +39,26 @@ rules:
3639
path: "/LinkToThePast/MSU1/ZeldaReOrchestrated"
3740
romname: alttp_msu.sfc
3841
smz3:
39-
name_pattern: "SMALttP - sm-*"
42+
name_pattern:
43+
- "SMALttP - sm-*"
4044
destinations:
4145
- name: default
4246
path: "/smz3"
4347
smw:
44-
name_pattern: "smw-*"
48+
name_pattern:
49+
- "smw-*"
4550
destinations:
4651
- name: default
4752
path: "/SuperMarioWorld/Rando"
4853
supermetroiditem:
49-
name_pattern: "Item Randomizer *"
54+
name_pattern:
55+
- "Item Randomizer *"
5056
destinations:
5157
- name: default
5258
path: "/SuperMetroid/Rando"
5359
supermetroidvaria:
54-
name_pattern: "VARIA_Randomizer_*"
60+
name_pattern:
61+
- "VARIA_Randomizer_*"
5562
destinations:
5663
- name: default
5764
path: "/SuperMetroid/Rando"

romloader.py

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from time import sleep
55

66
import yaml
7+
import py2snes
78

8-
from py2snes import usb2snes
9-
from py2snes import usb2snesException
9+
import asyncio
1010

1111
def show_exception_and_exit(exc_type, exc_value, tb):
1212
import traceback
@@ -24,6 +24,7 @@ def show_exception_and_exit(exc_type, exc_value, tb):
2424
with open(scriptpath + "\\romloader.yaml") as configfile:
2525
try:
2626
config = yaml.load(configfile)
27+
print("loading config file at " + os.path.abspath(scriptpath + "\\romloader.yaml"))
2728
except yaml.YAMLError as e:
2829
print(e)
2930
sys.exit(1)
@@ -32,22 +33,20 @@ def show_exception_and_exit(exc_type, exc_value, tb):
3233
with open("romloader.yaml") as configfile:
3334
try:
3435
config = yaml.load(configfile)
36+
print("loading config file at " + os.path.abspath("romloader.yaml"))
3537
except yaml.YAMLError as e:
3638
print(e)
3739
sys.exit(1)
3840
except FileNotFoundError:
3941
config = {"default_destination": '/romloader'}
4042

4143

42-
def main():
44+
async def main():
4345
try:
4446
rompath = sys.argv[1]
4547
except IndexError:
46-
try:
47-
rompath = config['debug_copypath']
48-
except:
49-
raise IndexError('We need a path to the ROM file to load.')
50-
sys.exit(1)
48+
raise Exception('We need a path to the ROM file to load.')
49+
sys.exit(1)
5150
filename = os.path.basename(rompath)
5251

5352
rule = matchrule(filename)
@@ -73,59 +72,48 @@ def main():
7372
path = '/romloader'
7473
romname = filename
7574

76-
for a in range(10):
77-
try:
78-
# initiate connection to the websocket server
79-
conn = usb2snes()
80-
81-
devicelist = conn.DeviceList()
82-
83-
# Attach to usb2snes, use the device configured if it is set, otherwise
84-
# have it find the first device.
85-
if "device" in config:
86-
print('Attaching to specified device {device}'.format(
87-
device=config['device']
88-
))
89-
com = conn.Attach(config['device'])
90-
elif len(devicelist) > 1:
91-
com = conn.Attach(get_comm_device(devicelist))
92-
else:
93-
print('Attaching to first device found.')
94-
com = conn.Attach()
95-
print('Attached to device \"{com}\"'.format(
96-
com=com
97-
))
98-
99-
conn.Name('RomLoader')
100-
if not rule:
101-
conn.MakeDir('/romloader')
102-
conn.List(path)
103-
print("copying rom to {fullpath}".format(
104-
fullpath=path + '/' + romname
105-
))
106-
conn.PutFile(rompath, path + '/' + romname)
107-
print("verifying rom copy is complete")
108-
conn.List(path)
109-
print("booting rom")
110-
conn.Boot(path + '/' + romname)
111-
conn.close()
112-
113-
sleep(5)
114-
break
115-
except KeyboardInterrupt:
116-
break
117-
except:
118-
print("Unexpected error:", sys.exc_info()[0])
119-
conn.close()
120-
sleep(6)
121-
continue
75+
# initiate connection to the websocket server
76+
snes = py2snes.snes()
77+
await snes.connect()
78+
79+
devicelist = await snes.DeviceList()
80+
81+
# Attach to usb2snes, use the device configured if it is set, otherwise
82+
# have it find the first device.
83+
if "device" in config:
84+
print('Attaching to specified device {device}'.format(
85+
device=config['device']
86+
))
87+
await snes.Attach(config['device'])
88+
elif len(devicelist) > 1:
89+
await snes.Attach(get_comm_device(devicelist))
90+
else:
91+
print('Attaching to first device found.')
92+
await snes.Attach(devicelist[0])
93+
print('Attached to device \"{com}\"'.format(
94+
com=snes.device
95+
))
96+
97+
await snes.Name('RomLoader')
98+
if not rule:
99+
await snes.MakeDir('/romloader')
100+
await snes.List(path)
101+
print("copying rom to {fullpath}".format(
102+
fullpath=path + '/' + romname
103+
))
104+
await snes.PutFile(rompath, path + '/' + romname)
105+
print("booting rom")
106+
await snes.Boot(path + '/' + romname)
107+
108+
await asyncio.sleep(5)
122109

123110

124111
def matchrule(name):
125112
if "rules" in config:
126113
for rule in config['rules']:
127-
if fnmatch.fnmatch(name, config['rules'][rule]['name_pattern']):
128-
return rule
114+
for pattern in config['rules'][rule]['name_pattern']:
115+
if fnmatch.fnmatch(name, pattern):
116+
return rule
129117
else:
130118
return None
131119

@@ -152,4 +140,6 @@ def get_comm_device(devicelist):
152140
dst_idx = int(input('What device? '))
153141
return devicelist[dst_idx]
154142

155-
main()
143+
if __name__ == '__main__':
144+
loop = asyncio.get_event_loop()
145+
loop.run_until_complete(main())

romloader.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
block_cipher = None
44

5-
a = Analysis(['src/romloader.py'],
5+
a = Analysis(['romloader.py'],
66
pathex=['D:\\Code\\RomLoader'],
77
binaries=[],
88
datas=[],

0 commit comments

Comments
 (0)