Skip to content

Commit

Permalink
Updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrast committed Oct 5, 2019
1 parent 8440d42 commit 7160e73
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
8 changes: 6 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ littlefs-python offers two interfaces to the underlying littlefs library:
- A C-Style API which exposes all functions from the library using a minimal
wrapper, written in Cython, to access the functions.
- A pythonic high-level API which offers convenient functions similiar to
the ones known for normal files. The API is built on the C-Style layer
and methods can mostly be mixed and matched if required.
the ones known from the :mod:`os` standard library module.

Both API's can be mixed and matched if required.

C-Style API
===========
Expand Down Expand Up @@ -37,3 +37,7 @@ The :class:`~littlefs.lfs.LFSConfig` class exposes most of the internal fields f

Pythonic API
============

The pythonic API is a very early phase and not well documented.
Please have a look at the example in the readme or the main page
of the documentation for an example.
42 changes: 42 additions & 0 deletions src/littlefs/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,66 @@ def __init__(self, buffsize):
self.buffer = bytearray([0xFF] * buffsize)

def read(self, cfg, block, off, size):
"""read data
Parameters
----------
cfg : ~littlefs.lfs.LFSConfig
Filesystem configuration object
block : int
Block number to read
off : int
Offset from start of block
size : int
Number of bytes to read.
"""
logging.getLogger(__name__).debug('LFS Read : Block: %d, Offset: %d, Size=%d' % (block, off, size))
start = block * cfg.block_size + off
end = start + size
return self.buffer[start:end]

def prog(self, cfg, block, off, data):
"""program data
Parameters
----------
cfg : ~littlefs.lfs.LFSConfig
Filesystem configuration object
block : int
Block number to program
off : int
Offset from start of block
data : bytes
Data to write
"""
logging.getLogger(__name__).debug('LFS Prog : Block: %d, Offset: %d, Data=%s' % (block, off, data))
start = block * cfg.block_size + off
end = start + len(data)
self.buffer[start:end] = data
return 0

def erase(self, cfg, block):
"""Erase a block
Parameters
----------
cfg : ~littlefs.lfs.LFSConfig
Filesystem configuration object
block : int
Block number to read
"""
logging.getLogger(__name__).debug('LFS Erase: Block: %d' % block)
start = block * cfg.block_size
end = start + cfg.block_size
self.buffer[start:end] = [0xFF] * cfg.block_size
return 0

def sync(self, cfg):
"""Sync cached data
Parameters
----------
cfg : ~littlefs.lfs.LFSConfig
Filesystem configuration object
"""
return 0
14 changes: 7 additions & 7 deletions src/littlefs/lfs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cdef int _lfs_read(const lfs_config *c, lfs_block_t block, lfs_off_t off, void *
data = ctx.user_context.read(ctx, block, off, size)
memcpy(buffer, <char *>data, size)
return 0


cdef int _lfs_prog(const lfs_config *c, lfs_block_t block, lfs_off_t off, const void * buffer, lfs_size_t size):
ctx = <object>c.context
Expand Down Expand Up @@ -59,7 +59,7 @@ cdef class LFSConfig:


def __init__(self, context=None, **kwargs):
# If the block size and count is not given, create a
# If the block size and count is not given, create a
# small memory with minimal block size and 8KB size
block_size = kwargs.get('block_size', 128)
block_count = kwargs.get('block_count', 64)
Expand Down Expand Up @@ -90,15 +90,15 @@ cdef class LFSConfig:
@property
def prog_size(self):
return self._impl.prog_size

@property
def block_size(self):
return self._impl.block_size

@property
def block_count(self):
return self._impl.block_count

@property
def cache_size(self):
return self._impl.cache_size
Expand All @@ -112,7 +112,7 @@ cdef class LFSFilesystem:
cdef lfs_t _impl


cdef class LFSFile:
cdef class LFSFile:
cdef lfs_file_t _impl


Expand Down Expand Up @@ -144,14 +144,14 @@ def unmount(LFSFilesystem fs):

def remove(LFSFilesystem fs, path):
"""Remove a file or directory
If removing a direcotry, the directory must be empty.
"""
return _raise_on_error(lfs_remove(&fs._impl, path.encode(FILENAME_ENCODING)))

def rename(LFSFilesystem fs, oldpath, newpath):
"""Rename or move a file or directory
If the destination exists, it must match the source in type.
If the destination is a directory, the directory must be empty.
"""
Expand Down

0 comments on commit 7160e73

Please sign in to comment.