scripts: dbglfs3.py: Adopted % as littlefs root dir character
The idea is this is similar to ~ for the home directory, hopefully simplifying littlefs path parsing in scripts: - /hi -> hi in root dir - ./hi -> hi in current dir - ../hi -> hi in parent dir - ~/hi -> hi in home dir - %/hi -> hi in littlefs root dir Note this only works when standalone: - ~hi != ~/hi - %hi != %/hi And files named % can still be referenced with a ./ prefix: - ./% -> % in current dir - %/% -> % in littlefs root dir --- This is probably overkill for dbglfs3.py, as the arg ordering was already enough to disambiguate disk path vs mroot address vs littlefs path, but eventually I think the idea will be useful for more powerful scripts. A hypothetical: $ mklfs3 cp disk -b4096 -r image_files %/image_files
This commit is contained in:
+12
-5
@@ -4422,8 +4422,14 @@ def dbg_files(lfs, paths, *,
|
|||||||
# parse all paths first, error if anything is malformed
|
# parse all paths first, error if anything is malformed
|
||||||
dirs = []
|
dirs = []
|
||||||
# default paths to the root dir
|
# default paths to the root dir
|
||||||
for path in (paths or ['/']):
|
for path in (paths or ['%']):
|
||||||
try:
|
try:
|
||||||
|
# skip leading %
|
||||||
|
if path == '%':
|
||||||
|
path = '/'
|
||||||
|
if path.startswith('%/'):
|
||||||
|
path = path[1:]
|
||||||
|
# lookup path
|
||||||
dir = lfs.pathlookup(path,
|
dir = lfs.pathlookup(path,
|
||||||
all=args.get('all'))
|
all=args.get('all'))
|
||||||
except Lfs3.PathError as e:
|
except Lfs3.PathError as e:
|
||||||
@@ -4952,16 +4958,17 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'mroots',
|
'mroots',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
type=lambda x: rbydaddr(x) if not x.startswith('/') else x,
|
type=lambda x: rbydaddr(x) if not x.startswith('%') else x,
|
||||||
action=AppendMrootOrPath,
|
action=AppendMrootOrPath,
|
||||||
help="Block address of the mroots. Defaults to 0x{0,1}.")
|
help="Block address of the mroots. Defaults to 0x{0,1}.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'paths',
|
'paths',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
type=lambda x: rbydaddr(x) if not x.startswith('/') else x,
|
type=lambda x: rbydaddr(x) if not x.startswith('%') else x,
|
||||||
action=AppendMrootOrPath,
|
action=AppendMrootOrPath,
|
||||||
help="Paths to show, must start with a leading slash. Defaults "
|
help="Paths to show, must start with %% where %% indicates the "
|
||||||
"to the root directory.")
|
"root littlefs directory. Defaults to the root littlefs "
|
||||||
|
"directory.")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--trunk',
|
'--trunk',
|
||||||
type=lambda x: int(x, 0),
|
type=lambda x: int(x, 0),
|
||||||
|
|||||||
Reference in New Issue
Block a user