Skip to content

Commit 8b5b975

Browse files
authored
Merge pull request #42 from RetiredWizard/pydosreadonly
Add ability for PyDOS to switch between read-write/read-only modes
2 parents f3e9e23 + fe54703 commit 8b5b975

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

builtin_apps/PyDOS/PyDOS.bmp

-11 KB
Binary file not shown.

builtin_apps/PyDOS/code.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@
3232
imp = "B"
3333
if implementation.name.upper() == "MICROPYTHON":
3434
from micropython import mem_info
35+
readonly = False
3536
imp = "M"
3637
elif implementation.name.upper() == "CIRCUITPYTHON":
3738
if not Pydos_ui:
3839
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+
3946
imp = "C"
4047

4148
gc.collect()
@@ -78,10 +85,22 @@ def PyDOS():
7885
global envVars
7986
if "envVars" not in globals().keys():
8087
envVars = {}
81-
_VER = "1.52-fruitjam"
88+
_VER = "1.53-fruitjam"
8289
prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
8390

8491
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+
85104
envVars["PATH"] = f'{sep};{sep}apps{sep}PyDOS;{sep}apps{sep}PyBasic'
86105
envVars["PROMPT"] = "$P$G"
87106
envVars["LIB"] = ";".join(path[1:])
@@ -679,7 +698,7 @@ def readBATFile(BATfile):
679698
continue
680699
elif cmd == "HELP":
681700
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")
683702
print("Operating System Commands: EXIT, VER, MEM, DATE [mm-dd-yy], TIME [hh:mm:ss]")
684703
print("Batch Commands: GOTO, IF, ECHO, PAUSE")
685704
print("Command to execute a single Python command: PEXEC [command]")
@@ -1241,6 +1260,18 @@ def readBATFile(BATfile):
12411260
else:
12421261
print("Illegal switch, Command Format: PEXEC[/q] python command")
12431262

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+
12441275
elif cmd == "EXIT":
12451276
if activeBAT:
12461277
if len(args) > 1:

0 commit comments

Comments
 (0)