|
32 | 32 | imp = "B"
|
33 | 33 | if implementation.name.upper() == "MICROPYTHON":
|
34 | 34 | from micropython import mem_info
|
| 35 | + readonly = False |
35 | 36 | imp = "M"
|
36 | 37 | elif implementation.name.upper() == "CIRCUITPYTHON":
|
37 | 38 | if not Pydos_ui:
|
38 | 39 | from supervisor import runtime, reload
|
| 40 | + |
| 41 | + import storage |
| 42 | + import microcontroller |
| 43 | + from adafruit_argv_file import argv_filename |
| 44 | + readonly = storage.getmount("/").readonly |
| 45 | + |
39 | 46 | imp = "C"
|
40 | 47 |
|
41 | 48 | gc.collect()
|
@@ -78,10 +85,22 @@ def PyDOS():
|
78 | 85 | global envVars
|
79 | 86 | if "envVars" not in globals().keys():
|
80 | 87 | envVars = {}
|
81 |
| - _VER = "1.52-fruitjam" |
| 88 | + _VER = "1.53-fruitjam" |
82 | 89 | prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
|
83 | 90 |
|
84 | 91 | print("Starting Py-DOS... Type 'help' for help.")
|
| 92 | + if readonly: |
| 93 | + print("Warning: Py-DOS is running in read-only mode, some commands may not work.") |
| 94 | + if input("Press Enter to continue or 'R' to restart in read-write mode: ").upper() == 'R': |
| 95 | + print("\nNote: You can not modify files using the CIRCUITPY drive from a") |
| 96 | + print("connected host computer in read-write mode. After restarting,") |
| 97 | + print("you can use the 'readonly' command in PyDOS to return to read-only mode.\n") |
| 98 | + if input('Are you sure? (Y/N): ').upper() == 'Y': |
| 99 | + boot_args_file = argv_filename("/boot.py") |
| 100 | + with open(boot_args_file, "w") as f: |
| 101 | + f.write('[false, "/code.py"]') |
| 102 | + microcontroller.reset() |
| 103 | + |
85 | 104 | envVars["PATH"] = f'{sep};{sep}apps{sep}PyDOS;{sep}apps{sep}PyBasic'
|
86 | 105 | envVars["PROMPT"] = "$P$G"
|
87 | 106 | envVars["LIB"] = ";".join(path[1:])
|
@@ -679,7 +698,7 @@ def readBATFile(BATfile):
|
679 | 698 | continue
|
680 | 699 | elif cmd == "HELP":
|
681 | 700 | print("File Commands: DIR[/p][/w][/s], RENAME, DEL[/s], TYPE[/p], CD, MKDIR, RMDIR[/s], COPY[/y]")
|
682 |
| - print("Environment Commands: HELP, SET[/p][/a], PROMPT, PATH") |
| 701 | + print("Environment Commands: HELP, SET[/p][/a], PROMPT, PATH, READONLY") |
683 | 702 | print("Operating System Commands: EXIT, VER, MEM, DATE [mm-dd-yy], TIME [hh:mm:ss]")
|
684 | 703 | print("Batch Commands: GOTO, IF, ECHO, PAUSE")
|
685 | 704 | print("Command to execute a single Python command: PEXEC [command]")
|
@@ -1241,6 +1260,18 @@ def readBATFile(BATfile):
|
1241 | 1260 | else:
|
1242 | 1261 | print("Illegal switch, Command Format: PEXEC[/q] python command")
|
1243 | 1262 |
|
| 1263 | + elif cmd == "READONLY": |
| 1264 | + if imp != "C": |
| 1265 | + print("READONLY command is only available when running on CirucitPython.") |
| 1266 | + elif readonly: |
| 1267 | + print("The system is already set to read-only.") |
| 1268 | + else: |
| 1269 | + if input("Setting the system to read-only will cause the Fruit Jam to restart? (y/n): ").upper() == "Y": |
| 1270 | + boot_args_file = argv_filename("/boot.py") |
| 1271 | + with open(boot_args_file, "w") as f: |
| 1272 | + f.write('[true, "/code.py"]') |
| 1273 | + microcontroller.reset() |
| 1274 | + |
1244 | 1275 | elif cmd == "EXIT":
|
1245 | 1276 | if activeBAT:
|
1246 | 1277 | if len(args) > 1:
|
|
0 commit comments