Skip to content

Commit 3b88fd1

Browse files
committed
rename unpack->extract. Add CLI to README
1 parent aef2e9b commit 3b88fd1

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

README.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ from scratch the latest version is recommended.
7070
.. csv-table::
7171
:header: "LittleFS Version", "Package Version", "LittleFS File System Version"
7272

73+
2.9.0, v0.11.X, 2.0 / 2.1 [#f1]_
7374
2.9.0, v0.10.X, 2.0 / 2.1 [#f1]_
7475
2.8.0, 0.8.X-0.9.X, 2.0 / 2.1 [#f1]_
7576
2.7.0, 0.7.X, 2.0 / 2.1 [#f1]_
@@ -92,6 +93,44 @@ on other platforms the source package is used and a compiler is required:
9293
+ MacOS: Python 3.8 - 3.12 / x86_64, arm64
9394
+ Windows: Python 3.8 - 3.12 / 32- & 64-bit
9495

96+
CLI
97+
===
98+
littlefs-python comes bundled with a command-line tool, ``littlefs-python``, that can be used to create and extract littlefs binary images.
99+
100+
.. code:: console
101+
102+
$ littlefs-python --help
103+
usage: littlefs-python [-h] [--version] {create,extract,list} ...
104+
105+
Create, extract and inspect LittleFS filesystem images. Use one of the
106+
commands listed below, the '-h' / '--help' option can be used on each command
107+
to learn more about the usage.
108+
109+
optional arguments:
110+
-h, --help show this help message and exit
111+
--version show program's version number and exit
112+
113+
Available Commands:
114+
{create,extract,list}
115+
create Create LittleFS image from file/directory contents.
116+
extract Extract LittleFS image contents to a directory.
117+
list List LittleFS image contents.
118+
119+
To create a littlefs binary image:
120+
121+
.. code:: console
122+
123+
# Creates a 1-megabyte "lfs.bin" containing README.rst
124+
$ littlefs-python create README.rst lfs.bin --fs-size=1mb --block-size=4096
125+
126+
# Creates a 1-megabyte "lfs.bin" containing the contents of the examples/ folder
127+
$ littlefs-python create examples lfs.bin --fs-size=1mb --block-size=4096
128+
129+
To extract the contents of a littlefs binary image:
130+
131+
.. code:: console
132+
133+
$ littlefs-python extract lfs.bin output/ --block-size=4096
95134
96135
Development Setup
97136
=================

src/littlefs/__main__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def size_parser(size_str):
5050

5151

5252
def 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

9097
def _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

Comments
 (0)