-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmauto.py
executable file
·51 lines (42 loc) · 1.66 KB
/
mauto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
import sys
import random
import re
from datetime import datetime, timedelta
import time
import subprocess
rom_files = []
working_directory = subprocess.check_output(["pwd"]).strip()
# #move cfg to .mednafen
subprocess.check_output(["touch", "psx.cfg"])
subprocess.check_output("echo \"autosave 1\" >> psx.cfg", shell=True)
subprocess.check_output("echo \"filesys.path_state " + working_directory + "/save_states\" >> psx.cfg", shell=True)
subprocess.check_output("mv psx.cfg ~/.mednafen/", shell=True)
if len(sys.argv) == 2:
rom_folder = sys.argv[1]
rom_files = filter(lambda file: re.match(r'.*\.(cue|ccd)$', file), os.listdir(rom_folder))
m3u_files = filter(lambda file: re.match(r'.*\.(m3u)$', file), os.listdir(rom_folder))
m3u_names = map(lambda file: file.split('.')[0], m3u_files)
#True if the cue or ccd file has a matching m3u file
def has_m3u(file):
for name in m3u_names:
if name in file:
return True
return False
#Filter out roms that are multi disc (have m3u file)
rom_files = filter(lambda file: not has_m3u(file), rom_files)
#Add the m3u's to the possible roms
rom_files = rom_files + m3u_files
rom_files = map(lambda file: '/' + rom_folder + file, rom_files)
elif len(sys.argv) == 3 and sys.argv[1] == "-d":
rom_files = open(sys.argv[2], "w")
while 1:
mednafen_process = subprocess.Popen(["mednafen", working_directory + random.choice(rom_files).strip()])
start = datetime.now()
#delta of 20 minutes between changes
delta = timedelta(minutes=20)
while datetime.now() - start <= delta:
if mednafen_process.poll() is not None:
break
if mednafen_process.returncode is None:
mednafen_process.kill()