File: model.py

package info (click to toggle)
pcbasic 2.0.7-9
  • links: PTS
  • area: main
  • in suites: sid
  • size: 35,416 kB
  • sloc: python: 28,411; sh: 103; makefile: 10
file content (67 lines) | stat: -rwxr-xr-x 1,634 bytes parent folder | download | duplicates (3)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
""" PC-BASIC model creation

(c) 2020--2023 Rob Hagemans
This file is released under the GNU GPL version 3 or later.
"""

from __future__ import print_function

import sys
import os
import shutil
import json
import subprocess


HERE = os.path.dirname(os.path.abspath(__file__))
TESTNAME = sys.argv[1]

if TESTNAME.endswith('/'):
    TESTNAME = TESTNAME[:-1]

# e.g. basic/gwbasic/TestName
try:
    DIR, TESTNAME = os.path.split(TESTNAME)
    _, PRESET = os.path.split(DIR)
except ValueError:
    PRESET = 'gwbasic'

GW_OPTIONS = sys.argv[2:]

with open(os.path.join(HERE, '_settings', 'settings.json')) as settings:
    SETTINGS = json.load(settings)[PRESET]

PATH = os.path.join(HERE, 'basic', PRESET, TESTNAME)
MODEL = os.path.join(PATH, 'model')
BAS = 'TEST.BAS'

if not os.path.isdir(PATH):
    sys.exit('Test {} not found.'.format(TEMPLATE))

shutil.rmtree(MODEL, ignore_errors=True)
shutil.copytree(
    PATH, MODEL,
    ignore=lambda _path, _names: list(set(['output', 'model']) & set(_names))
)
CALL = [
    'dosbox',
    '-conf', '{}'.format(os.path.join('_settings', SETTINGS['conf'])),
    '-c', 'MOUNT C {}'.format(MODEL),
    '-c', 'MOUNT E {}'.format(SETTINGS['dir']),
    '-c', 'C:',
    '-c', 'E:\\{} {} {}'.format(SETTINGS['exe'], BAS, ' '.join(GW_OPTIONS)),
    '-c', 'EXIT'
]
print('calling:', ' '.join(CALL))
subprocess.call(CALL, cwd=HERE)

for name in os.listdir(PATH):
    if name == 'model':
        continue
    delpath = os.path.join(MODEL, name)
    print('removing: {}'.format(delpath))
    if os.path.isdir(name):
        shutil.rmtree(delpath)
    else:
        os.remove(delpath)