in scripts/microcleanfs.py [0:0]
def main(args: List[str]) -> None:
opts = docopt(__doc__, argv=args)
port = opts['PORT']
force = opts['--force']
print('Connecting to {}'.format(port), file=sys.stderr)
board = Pyboard(port)
files = Files(board)
# Specifying subdirectories DOES NOT work as they will be deleted when the
# parent directory is deleted. Specifying top level directories DOES work.
exclude_files = ['boot.py']
print('Removing the contents of the file system')
wait_for_board()
for name in files.ls(long_format=False):
if force or name not in exclude_files:
try:
files.rm(name)
except (RuntimeError, PyboardError):
try:
files.rmdir(name)
except (RuntimeError, PyboardError):
print('Unknown Error removing file {}'.format(name),
file=sys.stderr)
print('Done')