-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
future3 - Feature "sync shared" (#2009)
* first callback test * default sync_shared settings added * moved test callback methods * fixed logger call * changed logger name * test rpc call sync_folder * settings added * added test rsync call (subprocess) * fixed path * fixed paths * fixed errorlogging * changed subprocess shell=false * added player update * fixed subprocess args * fixed rsync parameter * update database on caller. added return value * added "wait for database update" * added server and directory checks loglevels adjusted * fixed sync for subfolder shortcuts * fixed ignored files * refactored path handling use os.path instead of string concatenation fixed handling for abs path folder name * refactored logic in control class * added check for "on_rfid_scan_enabled" * sync_full added * added check for feature activation * correction of bool value handling evaluate to false if settings not correctly set (e.g. as string) * fix flake8 errors * update log message and fix result code * added ssh support * refactored paths for run_params * speed up ssh mode perform less checks for folder existence * added sync_change_on_rfid_scan * updated default settings format like ConfigHandler would save it * added command binding for Ui * fixed binding of command options and made them lowercase * changed invalid parameter handling * added sync_card_database update card id only on rfid scan sync overwrite on full sync * refactorings added locking on cfg access updated methodnames updated logging methods reordered flake8 corrections * exclude folder.conf if existing from V2.x * changed call on rfid scan to callback * fix flake8 errors * fix indendation for JS * combine settings of credentials for modes * naming convention * refactored function names to be more clear * changed options of sync_change_on_rfid_scan options changed from "true"/"false" to "enable"/"disable" * moved identical prechecks to functions * renamed "sync_full" to "sync_all" * Fix function calls fix for: moved identical prechecks to functions * renamed "sync_full" to "sync_all" correction for logging * added "update_wait" and fixed to much locking * changed call on play_card to callback * changed precheck names to "is sync enabled" * updated function names "is_file" and "is_dir" * reduced nesting complexity * Changed rfid callback state to Enum renamed callback class add state as enum * Changed playcontent callback state to Enum added state as num moved callback and enum to seperate class callback class with generic to be able to use in more play functions * fix import * fixed generic type definition * harmonised precheck for sync_change_on_rfid_scan * refactored methods to util class * renamed syncutil to syncutils. fixed import * fixed flake8 * Moved syncutils up * renamed module sync_shared to rfidcards * renamed sync_shared to sync_rfidcards * fix flake8 * updated documentation * Updated translation for en * Updated language * Updated language * Update docs --------- Co-authored-by: pabera <[email protected]>
- Loading branch information
1 parent
8eee27b
commit 99bad28
Showing
19 changed files
with
730 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Syncronisation RFID Cards | ||
************************* | ||
|
||
This component handles the synchronisation of RFID cards (audiofolder and card database entries). | ||
|
||
It allows to manage card database entries and audiofiles of one to many Phonieboxes | ||
in a central place (e.g. NAS, primary Phoniebox etc.) in the network, | ||
but allows to play the audio offline once the data has synced. | ||
The synchronisation can be initiated with the command ``sync-all`` | ||
and optionally on every RFID scan for a particular CardID and its corresponding audiofolder. | ||
To execute the ``sync-all`` command, bind a RFID card to the command. | ||
For the "RFID scan sync" feature, activate the option in the configuration | ||
or bind a RFID card to the command for dynamic activation or deactivation. | ||
|
||
Synchronisation | ||
--------------- | ||
|
||
The synchronisation will be FROM a server TO the Phoniebox, overriding existing files. | ||
A local configuration will be lost after the synchronization. | ||
If you want to make the initial setup e.g. via WebUi copy the files and use it as a base for the server. | ||
|
||
To access the files on the server, 2 modes are supported: SSH or MOUNT. | ||
Please make sure you have the correct access rights to the source and use key-based authentication for SSH. | ||
|
||
RFID scan sync | ||
^^^^^^^^^^^^^^ | ||
If the feature "RFID scan sync" is activated, there will be a check on every RFID scan against the server | ||
if a matching card entry and audiofolder is available. If so, changes will be synced. | ||
The playback will be delayed for the time the data is transfered (see "sync-all" to use a full synchronization if a lot of new files have been added). | ||
If the server is not reachable, the check will be aborted after the timeout. | ||
Therfore, an unreachable server will cause a delay (see commands to toggle activation state). | ||
Deleted card entries / audiofolders (not the contained items) will not be purged locally if deleted on remote. | ||
This is also true for changed card entries (the old audiofolder / -files will remain). To remove not existing items us a "sync-all". | ||
|
||
Configuration | ||
------------- | ||
|
||
Set the corresponding setting in ``shared\settings\jukebox.yaml`` to activate this feature. | ||
|
||
.. code-block:: yaml | ||
modules: | ||
named: | ||
... | ||
sync_rfidcards: synchronisation.rfidcards | ||
... | ||
sync_rfidcards: | ||
enable: false | ||
config_file: ../../shared/settings/sync_rfidcards.yaml | ||
The settings file (``shared\settings\sync_rfidcards.yaml``) contains the following configuration | ||
|
||
.. code-block:: yaml | ||
sync_rfidcards: | ||
# Holds the activation state of the optional feature "RFID scan sync". Values are "TRUE" or "FALSE" | ||
on_rfid_scan_enabled: true # bool | ||
# Server Access mode. MOUNT or SSH | ||
mode: mount # 'mount' or 'ssh' | ||
credentials: | ||
# IP or hostname of the server (used to check connectivity and for SSH mode). e.g. "192.168.0.2" or "myhomeserver.local" | ||
server: '' | ||
# Port (used to check connectivity and for SSH mode). e.g. "80" or "22" | ||
port: # int | ||
# Timeout to reach the server (in seconds) (used to check connectivity). e.g. 1 | ||
timeout: 1 # int | ||
# Path to the shared files to sync (without trailing slash) (remote path for SSH mode or local path for MOUNT mode). e.g. "/mnt/Phoniebox" | ||
path: '' | ||
# Username if SSH mode is used. | ||
username: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sync_rfidcards: | ||
on_rfid_scan_enabled: true # bool | ||
mode: mount # 'mount' or 'ssh' | ||
credentials: | ||
server: '' | ||
port: # int | ||
timeout: 1 # int | ||
path: '' | ||
username: '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
from enum import Enum | ||
from typing import Callable, Generic, TypeVar | ||
|
||
from jukebox.callingback import CallbackHandler | ||
|
||
|
||
class PlayCardState(Enum): | ||
firstSwipe = 0, | ||
secondSwipe = 1 | ||
|
||
|
||
STATE = TypeVar('STATE', bound=Enum) | ||
|
||
|
||
class PlayContentCallbacks(Generic[STATE], CallbackHandler): | ||
""" | ||
Callbacks are executed in various play functions | ||
""" | ||
|
||
def register(self, func: Callable[[str, STATE], None]): | ||
""" | ||
Add a new callback function :attr:`func`. | ||
Callback signature is | ||
.. py:function:: func(folder: str, state: STATE) | ||
:noindex: | ||
:param folder: relativ path to folder to play | ||
:param state: indicator of the state inside the calling | ||
""" | ||
super().register(func) | ||
|
||
def run_callbacks(self, folder: str, state: STATE): | ||
""":meta private:""" | ||
super().run_callbacks(folder, state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.