Drive
elva.apps.drive
ELVA drive app.
Classes:
-
AsyncQueueEventHandler
–Asynchronous file system event handler.
-
AsyncQueueIterator
–Asynchronous file system event iterator.
-
Drive
–Drive object.
Functions:
-
pprint_json
–Pretty-print JSON strings.
-
print_tree
–Pretty-print a file tree.
-
main
–Main routine starting the drive app.
AsyncQueueEventHandler(queue, loop, *args, **kwargs)
Bases: FileSystemEventHandler
Asynchronous file system event handler.
Parameters:
-
queue
(Queue
) –the asynchronous queue to put file system event objects in.
-
loop
(BaseEventLoop
) –the asynchronous event loop.
-
args
(tuple
, default:()
) –positional arguments passed to
watchdog.events.FileSystemEventHandler
. -
kwargs
(dict
, default:{}
) –keyword arguments passed to
watchdog.events.FileSystemEventHandler
.
Methods:
-
on_any_event
–Hook called on any file system event detected.
Source code in src/elva/apps/drive.py
on_any_event(event)
Hook called on any file system event detected.
This method puts the file system event object in the asynchronous queue.
Parameters:
-
event
(FileSystemEvent
) –an object holding information about the observed file system event.
Source code in src/elva/apps/drive.py
AsyncQueueIterator(queue, loop=None)
Asynchronous file system event iterator.
Parameters:
-
queue
(Queue
) –the asynchronous queue to read file sytem event objects from.
-
loop
(Optional[BaseEventLoop]
, default:None
) –the asynchronous event loop.
Methods:
-
__aiter__
–Implement the asynchronous iterator protocol.
-
__anext__
–Define the next asynchronous iterator step:
Source code in src/elva/apps/drive.py
__aiter__()
__anext__()
async
Define the next asynchronous iterator step:
Returns:
-
FileSystemEvent
–the next file system event object in the asynchronous event queue.
Raises:
-
StopAsyncIteration
–if there is no file system event object.
Source code in src/elva/apps/drive.py
Drive(path=None, doc=None)
Bases: BaseApp
Drive object.
Parameters:
-
path
(None | str
, default:None
) –the path to watch on recursively.
-
doc
(None | Doc
, default:None
) –the Y document to store the contents in.
Methods:
-
callback
–Hook called on a change in the Y map directory tree.
-
read_tree
–Read the directory tree.
-
start
–Start the drive app.
-
tree_entry
–Generate a tree entry:
-
dispatch
–Dispatch to event methods based on the given file system event.
-
on_created
–Hook called on a created source.
-
on_deleted
–Hook called on a deleted source.
-
on_opened
–Hook called on an opened source.
-
on_closed
–Hook called on a closed source.
-
on_modified
–Hook called on a modified source.
-
on_moved
–Hook called on a moved source.
Source code in src/elva/apps/drive.py
callback(event)
Hook called on a change in the Y map directory tree.
Prints the event object for debugging purposes.
Parameters:
-
event
(MapEvent
) –an object holding information about the change in the Y map directory tree.
Source code in src/elva/apps/drive.py
read_tree()
async
Read the directory tree.
Source code in src/elva/apps/drive.py
start()
async
Start the drive app.
This reads the directory tree under the given path and starts the watcher as well as the dispatcher routine for incoming file system events.
Source code in src/elva/apps/drive.py
tree_entry(path, doc=None)
Generate a tree entry:
Parameters:
-
path
(str
) –a path within the directory tree
-
doc
(None | Doc
, default:None
) –the associated Y document with the given path.
Returns:
Source code in src/elva/apps/drive.py
dispatch(event)
Dispatch to event methods based on the given file system event.
Parameters:
-
event
(FileSystemEvent
) –file system event to dispatch.
Source code in src/elva/apps/drive.py
on_created(event)
Hook called on a created source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
on_deleted(event)
Hook called on a deleted source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
on_opened(event)
Hook called on an opened source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
on_closed(event)
Hook called on a closed source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
on_modified(event)
Hook called on a modified source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
on_moved(event)
Hook called on a moved source.
Parameters:
-
event
(FileSystemEvent
) –file system event to read the source path from.
Source code in src/elva/apps/drive.py
_watch(path, queue, loop, recursive=False)
async
Watch a directory for changes.
Parameters:
-
path
(Path
) –the path where watch for file system events.
-
queue
(Queue
) –the asynchronous queue to put file system events in.
-
loop
(BaseEventLoop
) –the asynchronous event loop.
-
recursive
(bool
, default:False
) –flag whether to also watch for file system events in subdirectories.
Source code in src/elva/apps/drive.py
_dispatch(queue)
async
Dispatch file system events read from the asynchronous event queue.
Parameters:
-
queue
(Queue
) –the asynchronous queue to get file system event objects from.