@@ -50,7 +50,7 @@ def size_parser(size_str):
5050
5151
5252def create (parser : argparse .ArgumentParser , args : argparse .Namespace ) -> int :
53- """Create LittleFS image from directory content """
53+ """Create LittleFS image from file/ directory contents. """
5454 # fs_size OR block_count may be populated; make them consistent.
5555 if args .block_count is None :
5656 block_count = args .fs_size // args .block_size
@@ -69,9 +69,16 @@ def create(parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
6969 print (f" Image: { args .destination } " )
7070
7171 source = Path (args .source ).absolute ()
72+ if source .is_dir ():
73+ sources = source .rglob ("*" )
74+ root = source
75+ else :
76+ sources = [source ]
77+ root = source .parent
78+
7279 fs = _fs_from_args (args )
73- for path in source . rglob ( "*" ) :
74- rel_path = path .relative_to (source )
80+ for path in sources :
81+ rel_path = path .relative_to (root )
7582 if path .is_dir ():
7683 if args .verbose :
7784 print ("Adding Directory:" , rel_path )
@@ -88,7 +95,7 @@ def create(parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
8895
8996
9097def _list (parser : argparse .ArgumentParser , args : argparse .Namespace ) -> int :
91- """List LittleFS image content """
98+ """List LittleFS image contents. """
9299 fs = _fs_from_args (args , mount = False )
93100 fs .context .buffer = bytearray (args .source .read_bytes ())
94101 fs .mount ()
@@ -112,8 +119,8 @@ def _list(parser: argparse.ArgumentParser, args: argparse.Namespace) -> int:
112119 return 0
113120
114121
115- def unpack (parser : argparse .ArgumentParser , args : argparse .Namespace ) -> int :
116- """Unpack LittleFS image to directory"""
122+ def extract (parser : argparse .ArgumentParser , args : argparse .Namespace ) -> int :
123+ """Extract LittleFS image contents to a directory. """
117124 fs = _fs_from_args (args , mount = False )
118125 fs .context .buffer = bytearray (args .source .read_bytes ())
119126 fs .mount ()
@@ -197,7 +204,7 @@ def add_command(handler, name="", help=""):
197204 parser_create .add_argument (
198205 "source" ,
199206 type = Path ,
200- help = "Source directory of files to encode into a littlefs filesystem." ,
207+ help = "Source file/ directory-of- files to encode into a littlefs filesystem." ,
201208 )
202209 parser_create .add_argument (
203210 "destination" ,
@@ -224,20 +231,20 @@ def add_command(handler, name="", help=""):
224231 help = "LittleFS filesystem size. Accepts byte units; e.g. 1MB and 1048576 are equivalent." ,
225232 )
226233
227- parser_unpack = add_command (unpack )
228- parser_unpack .add_argument (
234+ parser_extract = add_command (extract )
235+ parser_extract .add_argument (
229236 "source" ,
230237 type = Path ,
231238 help = "Source LittleFS filesystem binary." ,
232239 )
233- parser_unpack .add_argument (
240+ parser_extract .add_argument (
234241 "destination" ,
235242 default = Path ("." ),
236243 nargs = "?" ,
237244 type = Path ,
238245 help = "Destination directory. Defaults to current directory." ,
239246 )
240- parser_unpack .add_argument (
247+ parser_extract .add_argument (
241248 "--block-size" ,
242249 type = size_parser ,
243250 required = True ,
0 commit comments