Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d5cbeed49 | |||
|
|
e95b59ae3d | ||
|
|
7e6aacc82f | ||
|
|
cb4872d057 | ||
|
|
f9c03a83f3 | ||
|
|
f4ac5360b7 | ||
|
|
9581772c9e | ||
|
|
da10ea2c19 | ||
|
|
842b8b6a5c | ||
|
|
5975be2ca5 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -43,4 +43,5 @@ helpers-results
|
|||||||
/.mypy_cache/
|
/.mypy_cache/
|
||||||
.coverage
|
.coverage
|
||||||
.mypy_cache
|
.mypy_cache
|
||||||
test/tmp
|
test/tmp
|
||||||
|
test/nextcloud_pwd.mdp
|
||||||
@@ -18,7 +18,7 @@ name = "dabdatasync"
|
|||||||
description = "dabdatasync"
|
description = "dabdatasync"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.11"
|
requires-python = ">=3.11"
|
||||||
keywords = ["chacha","chacha","template","dabdatasync"]
|
keywords = ["chacha","dabdatasync","dab","debian","proxmox","pydabfactory"]
|
||||||
license = { file = "LICENSE.md" }
|
license = { file = "LICENSE.md" }
|
||||||
|
|
||||||
authors = [
|
authors = [
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ import sys
|
|||||||
from tap import Tap
|
from tap import Tap
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from . import __Summuary__, __Name__
|
from . import __Summuary__, __Name__, __version__
|
||||||
from . import datasync
|
from . import datasync
|
||||||
from . import exceptions
|
from . import exceptions
|
||||||
|
from . import compressors
|
||||||
|
|
||||||
|
|
||||||
class dabdatasync_args_GetServices(Tap):
|
class dabdatasync_args_GetServices(Tap):
|
||||||
@@ -36,7 +37,10 @@ class dabdatasync_args_service_abstract(Tap):
|
|||||||
service: Optional[str] = None
|
service: Optional[str] = None
|
||||||
|
|
||||||
def configure(self) -> None:
|
def configure(self) -> None:
|
||||||
self.add_argument("--service")
|
self.add_argument(
|
||||||
|
"--service",
|
||||||
|
help=f"specify the service to use (availables: {datasync.DataSync_Factory.get_list()}, first found in priority if not set)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class dabdatasync_args_service_compress_abstract(dabdatasync_args_service_abstract):
|
class dabdatasync_args_service_compress_abstract(dabdatasync_args_service_abstract):
|
||||||
@@ -46,7 +50,10 @@ class dabdatasync_args_service_compress_abstract(dabdatasync_args_service_abstra
|
|||||||
|
|
||||||
def configure(self) -> None:
|
def configure(self) -> None:
|
||||||
super().configure()
|
super().configure()
|
||||||
self.add_argument("--compressor")
|
self.add_argument(
|
||||||
|
"--compressor",
|
||||||
|
help=f"specify the compressor method (availables: {compressors.DataSync_Compressors.get_list()}, .tar.gz if not set)",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class dabdatasync_args_PullData(dabdatasync_args_service_compress_abstract):
|
class dabdatasync_args_PullData(dabdatasync_args_service_compress_abstract):
|
||||||
@@ -65,11 +72,15 @@ class dabdatasync_args(Tap):
|
|||||||
"""Main CLI arg parser"""
|
"""Main CLI arg parser"""
|
||||||
|
|
||||||
verbosity: int = 0
|
verbosity: int = 0
|
||||||
|
help: bool = False
|
||||||
|
version: bool = False
|
||||||
|
|
||||||
def configure(self) -> None:
|
def configure(self) -> None:
|
||||||
|
self.add_argument("--version", action="store_true", help="show version string")
|
||||||
|
self.add_argument("-h", "--help", action="store_true", help="full help")
|
||||||
self.add_argument("-v", "--verbosity", action="count", help="increase output verbosity")
|
self.add_argument("-v", "--verbosity", action="count", help="increase output verbosity")
|
||||||
|
|
||||||
self.add_subparsers(dest="command", help="command type", required=True)
|
self.add_subparsers(dest="command", help="command type")
|
||||||
self.add_subparser("GetServices", dabdatasync_args_GetServices, help="Get registered services list")
|
self.add_subparser("GetServices", dabdatasync_args_GetServices, help="Get registered services list")
|
||||||
self.add_subparser("PullData", dabdatasync_args_PullData, help="Pull data from the service")
|
self.add_subparser("PullData", dabdatasync_args_PullData, help="Pull data from the service")
|
||||||
self.add_subparser("PushData", dabdatasync_args_PushData, help="Push data to the service")
|
self.add_subparser("PushData", dabdatasync_args_PushData, help="Push data to the service")
|
||||||
@@ -81,12 +92,26 @@ class dabdatasync_args(Tap):
|
|||||||
self.command: Union[str, None] = cast(Union[str, None], self.command) # pylint: disable=attribute-defined-outside-init
|
self.command: Union[str, None] = cast(Union[str, None], self.command) # pylint: disable=attribute-defined-outside-init
|
||||||
|
|
||||||
|
|
||||||
def fct_main(i_args: list[str]) -> None: # pylint: disable=too-many-branches,too-complex
|
def fct_main(i_args: list[str]) -> None: # pylint: disable=too-many-branches,too-complex,too-many-statements
|
||||||
"""CLI main function"""
|
"""CLI main function"""
|
||||||
parser: dabdatasync_args = dabdatasync_args(prog=__Name__, description=__Summuary__)
|
parser: dabdatasync_args = dabdatasync_args(prog=__Name__, description=__Summuary__)
|
||||||
|
|
||||||
args: dabdatasync_args = parser.parse_args(i_args)
|
args: dabdatasync_args = parser.parse_args(i_args)
|
||||||
|
|
||||||
|
if args.help or args.version:
|
||||||
|
print(f"{__Name__} version {__version__}")
|
||||||
|
|
||||||
|
if args.help:
|
||||||
|
print(parser.format_help())
|
||||||
|
|
||||||
|
for name, subparser in parser._subparsers.choices.items(): # type: ignore[union-attr] # pylint: disable=protected-access
|
||||||
|
print("=========================")
|
||||||
|
print(f"Subparser {{{name}}}")
|
||||||
|
print(subparser.format_help())
|
||||||
|
|
||||||
|
if args.help or args.version:
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
logger.remove()
|
logger.remove()
|
||||||
if args.verbosity:
|
if args.verbosity:
|
||||||
if args.verbosity == 1:
|
if args.verbosity == 1:
|
||||||
@@ -143,13 +168,13 @@ def fct_main(i_args: list[str]) -> None: # pylint: disable=too-many-branches,to
|
|||||||
selected_dabdatasync.wipe_remote_data()
|
selected_dabdatasync.wipe_remote_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
raise RuntimeError("Invalid argument")
|
raise RuntimeError("a command is required")
|
||||||
|
|
||||||
|
|
||||||
def CLI():
|
def CLI():
|
||||||
"""wrapper for .toml declared script"""
|
"""wrapper for .toml declared script"""
|
||||||
fct_main(sys.argv)
|
fct_main(sys.argv[1:])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
fct_main(sys.argv[1:])
|
CLI()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import warnings
|
|||||||
|
|
||||||
try: # pragma: no cover
|
try: # pragma: no cover
|
||||||
__version__ = version("dabdatasync")
|
__version__ = version("dabdatasync")
|
||||||
except PackageNotFoundError: # pragma: no cover
|
except PackageNotFoundError: # pragma: no cover
|
||||||
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
|
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
|
||||||
__version__ = "?.?.?"
|
__version__ = "?.?.?"
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,11 @@ class DataSync_Compressors:
|
|||||||
return found[0]
|
return found[0]
|
||||||
raise DataSyncException_TooManyCompressorFound()
|
raise DataSyncException_TooManyCompressorFound()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_list(cls) -> list[str]:
|
||||||
|
"""return the available compressor name list"""
|
||||||
|
return [_.compressor_name for _ in cls._availables]
|
||||||
|
|
||||||
|
|
||||||
@DataSync_Compressors.register
|
@DataSync_Compressors.register
|
||||||
class DataSync_Compressor__tar_gz(A_DataSync_Compressor):
|
class DataSync_Compressor__tar_gz(A_DataSync_Compressor):
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class A_DataSync(ABC):
|
|||||||
"""Abstract DataSync class"""
|
"""Abstract DataSync class"""
|
||||||
|
|
||||||
service_name: str = "ABSTRACT"
|
service_name: str = "ABSTRACT"
|
||||||
|
priority: int = 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@final
|
@final
|
||||||
@@ -178,3 +179,8 @@ class DataSync_Factory:
|
|||||||
"""decorator to register a concrete class to the factory"""
|
"""decorator to register a concrete class to the factory"""
|
||||||
cls.ar_cls_DataSync.add(_cls)
|
cls.ar_cls_DataSync.add(_cls)
|
||||||
return _cls
|
return _cls
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_list(cls) -> list[str]:
|
||||||
|
"""return the available DataSync concrete class name list"""
|
||||||
|
return [_.service_name for _ in cls.ar_cls_DataSync]
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class C_DataSync_NextCloud(A_DataSync):
|
|||||||
"""Concrete DataSync class - Nextcloud"""
|
"""Concrete DataSync class - Nextcloud"""
|
||||||
|
|
||||||
service_name: str = "Nextcloud"
|
service_name: str = "Nextcloud"
|
||||||
|
priority: int = 100
|
||||||
|
|
||||||
def __init__(self, manifest: dict[Any, Any], cls_compressor: type[A_DataSync_Compressor]) -> None:
|
def __init__(self, manifest: dict[Any, Any], cls_compressor: type[A_DataSync_Compressor]) -> None:
|
||||||
super().__init__(manifest, cls_compressor)
|
super().__init__(manifest, cls_compressor)
|
||||||
|
|||||||
@@ -4,4 +4,4 @@
|
|||||||
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the license along with this
|
# You should have received a copy of the license along with this
|
||||||
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ import unittest
|
|||||||
from os import chdir, path as os_path
|
from os import chdir, path as os_path
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import pprint
|
import pprint
|
||||||
|
import os
|
||||||
|
import glob
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from contextlib import redirect_stdout, redirect_stderr
|
from contextlib import redirect_stdout, redirect_stderr
|
||||||
import shutil
|
import shutil
|
||||||
|
import json
|
||||||
from contexttimer import Timer
|
from contexttimer import Timer
|
||||||
|
|
||||||
print(__name__)
|
print(__name__)
|
||||||
@@ -33,10 +36,45 @@ class TestDabDataSync(unittest.TestCase):
|
|||||||
shutil.copytree(testdir_path / "test_data_origin", testdir_path / "test_data")
|
shutil.copytree(testdir_path / "test_data_origin", testdir_path / "test_data")
|
||||||
shutil.copytree(testdir_path / "test_data_origin", testdir_path / "test_data2")
|
shutil.copytree(testdir_path / "test_data_origin", testdir_path / "test_data2")
|
||||||
|
|
||||||
|
nextcloud_pwd = ""
|
||||||
|
if "nextcloud_pwd" in os.environ:
|
||||||
|
nextcloud_pwd = os.environ.get("nextcloud_pwd")
|
||||||
|
elif os.path.isfile(testdir_path / "nextcloud_pwd.mdp"):
|
||||||
|
with open(testdir_path / "nextcloud_pwd.mdp", "rt", encoding="utf-8") as pwd_file:
|
||||||
|
nextcloud_pwd = pwd_file.read()
|
||||||
|
else:
|
||||||
|
raise RuntimeError("NextCloud pwd file not found")
|
||||||
|
|
||||||
|
files = glob.glob(str(testdir_path / "*.json"))
|
||||||
|
files += glob.glob(str(testdir_path / "*.json"))
|
||||||
|
for file in files:
|
||||||
|
with open(file) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
try:
|
||||||
|
data["Args"]["FSSync_NextCloud_Password"]["value"] = nextcloud_pwd
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
os.remove(file)
|
||||||
|
with open(file, "w") as f:
|
||||||
|
json.dump(data, f, sort_keys=True, indent=4)
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
shutil.rmtree(testdir_path / "test_data", ignore_errors=True)
|
shutil.rmtree(testdir_path / "test_data", ignore_errors=True)
|
||||||
shutil.rmtree(testdir_path / "test_data2", ignore_errors=True)
|
shutil.rmtree(testdir_path / "test_data2", ignore_errors=True)
|
||||||
|
|
||||||
|
files = glob.glob(str(testdir_path / "*.json"))
|
||||||
|
files += glob.glob(str(testdir_path / "*.json"))
|
||||||
|
for file in files:
|
||||||
|
with open(file) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
try:
|
||||||
|
data["Args"]["FSSync_NextCloud_Password"]["value"] = ""
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
os.remove(file)
|
||||||
|
with open(file, "w") as f:
|
||||||
|
json.dump(data, f, sort_keys=True, indent=4)
|
||||||
|
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
self.assertNotEqual(dabdatasync.__version__, "?.?.?")
|
self.assertNotEqual(dabdatasync.__version__, "?.?.?")
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
||||||
"Args": {}}
|
"Args": {}
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
{
|
{
|
||||||
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002"}
|
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002"
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,25 @@
|
|||||||
{
|
{
|
||||||
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
||||||
"Args": {
|
"Args": {
|
||||||
"FSSync_NextCloud_Enabled": {"type": "BOOL", "value": false},
|
"FSSync_NextCloud_Address": {
|
||||||
"FSSync_NextCloud_Address": {"type": "URL", "value": "https://chacha.ddns.net/nextcloud"},
|
"type": "URL",
|
||||||
"FSSync_NextCloud_User": {"type": "STRING", "value": "chacha-bot"},
|
"value": "https://chacha.ddns.net/nextcloud"
|
||||||
"FSSync_NextCloud_Password": {"type": "STRING", "value": "F3P8m-nQHik-NSmb2-mnFEF-s85RE"},
|
},
|
||||||
"FSSync_NextCloud_Path": {"type": "STRING", "value": "pydabfactory"}
|
"FSSync_NextCloud_Enabled": {
|
||||||
}}
|
"type": "BOOL",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
"FSSync_NextCloud_Password": {
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"FSSync_NextCloud_Path": {
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "pydabfactory"
|
||||||
|
},
|
||||||
|
"FSSync_NextCloud_User": {
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "chacha-bot"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
"APP_ID": "2a13dff2-1298-11ee-be56-0242ac120002",
|
||||||
"Args": {
|
"Args": {
|
||||||
"FSSync_NextCloud_Enabled": {"type": "BOOL", "value": true}
|
"FSSync_NextCloud_Enabled": {
|
||||||
}}
|
"type": "BOOL",
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user