Python 3.13: Fix and polish #1
@ -37,12 +37,12 @@
|
|||||||
from random import shuffle ## allowing us to randomize selection of cars.
|
from random import shuffle ## allowing us to randomize selection of cars.
|
||||||
import glob ## allowing us to search the file system for .choochoo files.
|
import glob ## allowing us to search the file system for .choochoo files.
|
||||||
import sys ## so we can read command line arguments.
|
import sys ## so we can read command line arguments.
|
||||||
import getpass ## so we can get the user's username
|
|
||||||
import curses
|
import curses
|
||||||
from signal import signal, SIGINT
|
from signal import signal, SIGINT
|
||||||
import time ## allowing the loop steps of train animation to be slowed
|
import time ## allowing the loop steps of train animation to be slowed
|
||||||
import string ## for input validation
|
import string ## for input validation
|
||||||
from inspect import cleandoc
|
from inspect import cleandoc
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
traincarFN = ".choochoo"
|
traincarFN = ".choochoo"
|
||||||
max_x = 35 ## max length of train car.
|
max_x = 35 ## max length of train car.
|
||||||
@ -122,16 +122,15 @@ def print_help():
|
|||||||
|
|
||||||
|
|
||||||
def test_user_car():
|
def test_user_car():
|
||||||
username = getpass.getuser()
|
fname = Path.home() / traincarFN
|
||||||
fname = "/home/" + username + "/" + traincarFN
|
|
||||||
try:
|
try:
|
||||||
myfile = open(fname, 'r')
|
choochoo_string = fname.read_text("utf-8")
|
||||||
except:
|
except OSError as err:
|
||||||
print("ERROR: Couldn't open " + fname)
|
raise OSError(
|
||||||
print("Either it doesn't exist, or is not readble by the tilde.train script.")
|
f"Couldn't open {fname}\n"
|
||||||
sys.exit(1)
|
"Either it doesn't exist, or is not readble by the tilde.train script."
|
||||||
|
) from err
|
||||||
|
|
||||||
choochoo_string = myfile.read()
|
|
||||||
choochoo_list = choochoo_string.split("\n")
|
choochoo_list = choochoo_string.split("\n")
|
||||||
|
|
||||||
car = "\n".join(choochoo_list)
|
car = "\n".join(choochoo_list)
|
||||||
@ -177,17 +176,14 @@ def test_user_car():
|
|||||||
if train_height > max_y+1:
|
if train_height > max_y+1:
|
||||||
print("FAIL. Your train car is too tall.")
|
print("FAIL. Your train car is too tall.")
|
||||||
print("It should be no taller than " + str(max_y) + " lines in height.")
|
print("It should be no taller than " + str(max_y) + " lines in height.")
|
||||||
myfile.close()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if train_length > max_x:
|
if train_length > max_x:
|
||||||
print("FAIL. Your train car is too long.")
|
print("FAIL. Your train car is too long.")
|
||||||
print("It should be no longer than " + str(max_x) + " characters in length.")
|
print("It should be no longer than " + str(max_x) + " characters in length.")
|
||||||
myfile.close()
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("PASS. Your train car will work on the tilde.town tracks! :)")
|
print("PASS. Your train car will work on the tilde.town tracks! :)")
|
||||||
myfile.close()
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def link_car(car):
|
def link_car(car):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user