Exemple #1
0
def test_text_truncate(fs: LittleFS):
    with fs.open('trunc.txt', 'w') as f:
        f.write('Some Content')

    with fs.open('trunc.txt', 'r+') as f:
        f.truncate()

    assert fs.open('trunc.txt', 'r').read() == ''
Exemple #2
0
def fs():
    fs = LittleFS(block_size=128, block_count=64)
    fs.mkdir('/dir')
    fs.mkdir('/dir/emptyA')
    fs.mkdir('/dir/emptyB')
    fs.mkdir('/dir/sub')
    with fs.open('/dir/sub/file.txt', 'w') as fh:
        fh.write('Sample Text')
    with fs.open('/dir/file.txt', 'w') as fh:
        fh.write('Sample Text')
    yield fs
Exemple #3
0
def fs():
    fs = LittleFS(block_size=128, block_count=64)
    fs.mkdir('mydir')

    with fs.open('test.txt', 'w') as f:
        f.write('1234567890')

    with fs.open('test.bin', 'wb') as f:
        contents = bytes.fromhex('11 22 33 44 aa bb cc dd ee ff')
        f.write(contents)

    yield fs
Exemple #4
0
def test_rename(fs: LittleFS):
    # File rename
    fs.rename('/dir/file.txt', '/dir/file_renamed.txt')
    files_in_dir = fs.listdir('/dir')

    assert 'file.txt' not in files_in_dir
    assert 'file_renamed.txt' in files_in_dir

    # Directory Rename
    fs.rename('/dir/sub', '/dir/sub_renamed')
    files_in_dir = fs.listdir('/dir')

    assert 'sub' not in files_in_dir
    assert 'sub_renamed' in files_in_dir
def make_lfs(args):
    context = FileContext(getattr(args, 'image-file'))
    lfs = LittleFS(context=context,
                   block_size=args.block_size,
                   block_count=args.block_count)
    return lfs
Exemple #6
0
def fs():
    fs = LittleFS(block_size=128, block_count=64)
    yield fs
cwd = os.getcwd()

os.chdir(dataPath)

fileList = []
dirList = []

for (dirpath, dirnames, filenames) in os.walk('.'):
    for f in filenames:
        if (f[:1] != '.'):
            fileList.append(os.path.join(dirpath, f))
    for d in dirnames:
        if (d[:1] != '.'):
            dirList.append(os.path.join(dirpath, d))

fs = LittleFS(block_size=blockSize,
              block_count=blockCount)  # create a 448kB partition

for curDir in dirList:
    print("Creating dir " + curDir)
    fs.mkdir(curDir)

for curFile in fileList:
    print("Adding file " + curFile)
    with open(curFile, 'rb') as f:
        data = f.read()

    with fs.open(curFile, 'wb') as fh:
        fh.write(data)

outName = argList[-1]
Exemple #8
0
img_filename = args.img_filename
img_size = args.img_size
block_size = args.block_size
read_size = args.read_size
prog_size = args.prog_size
source_dir = args.source

block_count = img_size / block_size
if block_count * block_size != img_size:
    print("image size should be a multiple of block size")
    exit(1)

fs = LittleFS(
    block_size=block_size,
    block_count=block_count,
    read_size=read_size,
    prog_size=prog_size,
)

# Note: path component separator etc are assumed to be compatible
# between littlefs and host.
for root, dirs, files in os.walk(source_dir):
    print(f"root {root} dirs {dirs} files {files}")
    for dir in dirs:
        path = os.path.join(root, dir)
        relpath = os.path.relpath(path, start=source_dir)
        print(f"Mkdir {relpath}")
        fs.mkdir(relpath)
    for f in files:
        path = os.path.join(root, f)
        relpath = os.path.relpath(path, start=source_dir)
Exemple #9
0
parser.add_argument("--img-size", type=int, default=1 * 1024 * 1024)
parser.add_argument("--block-size", type=int, default=4096)
parser.add_argument("--read-size", type=int, default=256)
parser.add_argument("--prog-size", type=int, default=256)
args = parser.parse_args()

img_filename = args.img_filename
img_size = args.img_size
block_size = args.block_size
read_size = args.read_size
prog_size = args.prog_size

block_count = img_size / block_size
if block_count * block_size != img_size:
    print("image size should be a multiple of block size")
    exit(1)

fs = LittleFS(
    block_size=block_size,
    block_count=block_count,
    read_size=read_size,
    prog_size=prog_size,
)

with open(img_filename, "rb") as f:
    data = f.read()
fs.context.buffer = bytearray(data)

for root, dirs, files in fs.walk("."):
    print(f"root {root} dirs {dirs} files {files}")
Exemple #10
0
#
import getopt, sys
from littlefs import LittleFS
from pathlib import Path

print("Building LittleFS image…")

argList = sys.argv[1:]
arxx = {argList[i]: argList[i + 1] for i in range(0, len(argList) - 1, 2)}
print(arxx)

dataPath = arxx["-c"]  # Grab the source path parameter

fileList = [pth for pth in Path(dataPath).iterdir() if pth.stem[0] != '.'
            ]  # Create a list of all the files in the directory

fs = LittleFS(block_size=4096,
              block_count=3072)  # Open LittleFS, create a 12MB partition

for curFile in fileList:
    print("Adding " + curFile.name)
    with open(curFile, 'rb') as f:  # Read the file into a buffer
        data = f.read()

    with fs.open(curFile.name,
                 'w') as fh:  # Write the file to the LittleFS partition
        fh.write(data)

outName = argList[-1]  # The last argument is the destination file name
with open(outName, 'wb') as fh:  # Dump the filesystem content to a file
    fh.write(fs.context.buffer)