Merge pull request #42 from RetiredWizard/pydosreadonly
Some checks failed
Validate Build / validate-build (push) Has been cancelled

Add ability for PyDOS to switch between read-write/read-only modes
This commit is contained in:
foamyguy 2025-08-04 13:14:55 -05:00 committed by GitHub
commit 8b5b975ed6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

View file

@ -32,10 +32,17 @@ import gc
imp = "B"
if implementation.name.upper() == "MICROPYTHON":
from micropython import mem_info
readonly = False
imp = "M"
elif implementation.name.upper() == "CIRCUITPYTHON":
if not Pydos_ui:
from supervisor import runtime, reload
import storage
import microcontroller
from adafruit_argv_file import argv_filename
readonly = storage.getmount("/").readonly
imp = "C"
gc.collect()
@ -78,10 +85,22 @@ def PyDOS():
global envVars
if "envVars" not in globals().keys():
envVars = {}
_VER = "1.52-fruitjam"
_VER = "1.53-fruitjam"
prmpVals = ['>','(',')','&','|','\x1b','\b','<','=',' ',_VER,'\n','$','']
print("Starting Py-DOS... Type 'help' for help.")
if readonly:
print("Warning: Py-DOS is running in read-only mode, some commands may not work.")
if input("Press Enter to continue or 'R' to restart in read-write mode: ").upper() == 'R':
print("\nNote: You can not modify files using the CIRCUITPY drive from a")
print("connected host computer in read-write mode. After restarting,")
print("you can use the 'readonly' command in PyDOS to return to read-only mode.\n")
if input('Are you sure? (Y/N): ').upper() == 'Y':
boot_args_file = argv_filename("/boot.py")
with open(boot_args_file, "w") as f:
f.write('[false, "/code.py"]')
microcontroller.reset()
envVars["PATH"] = f'{sep};{sep}apps{sep}PyDOS;{sep}apps{sep}PyBasic'
envVars["PROMPT"] = "$P$G"
envVars["LIB"] = ";".join(path[1:])
@ -679,7 +698,7 @@ def PyDOS():
continue
elif cmd == "HELP":
print("File Commands: DIR[/p][/w][/s], RENAME, DEL[/s], TYPE[/p], CD, MKDIR, RMDIR[/s], COPY[/y]")
print("Environment Commands: HELP, SET[/p][/a], PROMPT, PATH")
print("Environment Commands: HELP, SET[/p][/a], PROMPT, PATH, READONLY")
print("Operating System Commands: EXIT, VER, MEM, DATE [mm-dd-yy], TIME [hh:mm:ss]")
print("Batch Commands: GOTO, IF, ECHO, PAUSE")
print("Command to execute a single Python command: PEXEC [command]")
@ -1241,6 +1260,18 @@ def PyDOS():
else:
print("Illegal switch, Command Format: PEXEC[/q] python command")
elif cmd == "READONLY":
if imp != "C":
print("READONLY command is only available when running on CirucitPython.")
elif readonly:
print("The system is already set to read-only.")
else:
if input("Setting the system to read-only will cause the Fruit Jam to restart? (y/n): ").upper() == "Y":
boot_args_file = argv_filename("/boot.py")
with open(boot_args_file, "w") as f:
f.write('[true, "/code.py"]')
microcontroller.reset()
elif cmd == "EXIT":
if activeBAT:
if len(args) > 1: