Compare commits
68 Commits
2022.10.0.
...
2022.12.0
Author | SHA1 | Date | |
---|---|---|---|
68e01afb5b | |||
2e0a8bb1ff | |||
b02aebef35 | |||
099a51ed93 | |||
e4aedb354b | |||
301768b842 | |||
856960d799 | |||
d0877a4ea6 | |||
3c20ab296a | |||
4dc7ee3314 | |||
05bd5e8593 | |||
2fe3912a07 | |||
2840628443 | |||
f0f79e7e3b | |||
e8ae635c88 | |||
d8f7e03815 | |||
ba1b5e49ae | |||
703a2c91b5 | |||
4a54bb62de | |||
9e84c8359b | |||
5139876d90 | |||
6aef49de40 | |||
186b336bf3 | |||
1bbec27d1a | |||
f0a8d69e22 | |||
8bd237206c | |||
6bf7c3a2bc | |||
2e8be741cc | |||
abd0352750 | |||
25d91b85f3 | |||
f08eb42105 | |||
f450102c93 | |||
db28645e98 | |||
23efb776e7 | |||
7f621b282f | |||
5dc7fce1e7 | |||
879f59b0d5 | |||
511622820a | |||
0914f969e5 | |||
c611045290 | |||
89ac9e90d6 | |||
ae2a98b3bc | |||
bd242baa0a | |||
8e4caeb2a8 | |||
3b55b3d5a5 | |||
cc3b1afaa1 | |||
a22b6fdbdb | |||
e3041c4b5b | |||
8ad6d50a04 | |||
4db000f6d7 | |||
3821624c3b | |||
60a722b4ec | |||
65132aa107 | |||
48eac124a5 | |||
be23b18d33 | |||
748cc66946 | |||
304b2e4255 | |||
9fa183f143 | |||
82df528395 | |||
49e3bddc91 | |||
c52bf961e1 | |||
df3f9f0306 | |||
ef2d73aadc | |||
1ed721cccb | |||
a724216563 | |||
2bcf4d7a97 | |||
2dfa2dd68f | |||
e94ed0b7f0 |
@@ -131,7 +131,15 @@
|
||||
"di-cli": "pip install cpl-cli --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"di-discord": "pip install cpl-discord --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"di-query": "pip install cpl-query --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"di-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de"
|
||||
"di-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
|
||||
"prod-install": "cpl pi-core; cpl pi-cli; cpl pi-query; cpl pi-translation;",
|
||||
"pi": "cpl prod-install",
|
||||
"pi-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip.sh-edraft.de",
|
||||
"pi-cli": "pip install cpl-cli --pre --upgrade --extra-index-url https://pip.sh-edraft.de",
|
||||
"pi-discord": "pip install cpl-discord --pre --upgrade --extra-index-url https://pip.sh-edraft.de",
|
||||
"pi-query": "pip install cpl-query --pre --upgrade --extra-index-url https://pip.sh-edraft.de",
|
||||
"pi-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip.sh-edraft.de"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
upload:
|
||||
prod:
|
||||
cpl:
|
||||
twine upload --repository-url https://pip.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
twine upload -r pip.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
cli:
|
||||
twine upload --repository-url https://pip.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
twine upload -r pip.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
|
||||
query:
|
||||
twine upload --repository-url https://pip-dev.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
|
||||
exp:
|
||||
cpl:
|
||||
twine upload --repository-url https://pip-exp.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
twine upload -r pip-exp.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
|
||||
cli:
|
||||
twine upload --repository-url https://pip-exp.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
twine upload -r pip-exp.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
|
||||
query:
|
||||
twine upload --repository-url https://pip-exp.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
twine upload -r pip-exp.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
|
||||
dev:
|
||||
cpl:
|
||||
twine upload --repository-url https://pip-dev.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-core/publish/setup/*
|
||||
|
||||
cli:
|
||||
twine upload --repository-url https://pip-dev.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
|
||||
|
||||
query:
|
||||
twine upload --repository-url https://pip-dev.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-query/publish/setup/*
|
||||
|
||||
install:
|
||||
prod:
|
||||
pip install --extra-index-url https://pip.sh-edraft.de/ sh_cpl
|
||||
pip install --extra-index-url https://pip.sh-edraft.de/ sh_cpl-cli
|
||||
pip install --extra-index-url https://pip.sh-edraft.de/ sh_cpl-query
|
||||
|
||||
exp:
|
||||
pip install --extra-index-url https://pip-exp.sh-edraft.de/ sh_cpl
|
||||
pip install --extra-index-url https://pip-exp.sh-edraft.de/ sh_cpl-cli
|
||||
pip install --extra-index-url https://pip-exp.sh-edraft.de/ sh_cpl-query
|
||||
|
||||
dev:
|
||||
pip install --extra-index-url https://pip-dev.sh-edraft.de/ sh_cpl
|
||||
pip install --extra-index-url https://pip-dev.sh-edraft.de/ sh_cpl-cli
|
||||
pip install --extra-index-url https://pip-dev.sh-edraft.de/ sh_cpl-query
|
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# activate venv
|
||||
source /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/venv/bin/activate
|
||||
|
||||
# CPL
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_core
|
||||
cpl build
|
||||
|
||||
# CLI
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_cli
|
||||
cpl build
|
||||
|
||||
# CPL Query
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_query
|
||||
cpl build
|
@@ -1,3 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
google-chrome $PWD/../docs/build/html/index.html
|
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd ../docs/
|
||||
sphinx-apidoc -o source/ ../src/cpl_core
|
||||
sphinx-apidoc -o source/ ../src/cpl_query
|
||||
make clean
|
||||
make html;
|
||||
rm source/cpl_query.tests.rst
|
@@ -1 +0,0 @@
|
||||
print('Hello World')
|
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
# activate venv
|
||||
source /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/venv/bin/activate
|
||||
|
||||
# CPL
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_core
|
||||
cpl publish
|
||||
|
||||
# CLI
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_cli
|
||||
cpl publish
|
||||
|
||||
# CPL Query
|
||||
cd /home/sven/Nextcloud_Sven/Schreibtisch/git_sh-edraft_de/sh_cpl/src/cpl_query
|
||||
cpl publish
|
@@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $1 == "-prod" ]; then
|
||||
twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*
|
||||
twine upload -r pip.sh-edraft.de dist/cpl-core/publish/setup/*
|
||||
twine upload -r pip.sh-edraft.de dist/cpl-query/publish/setup/*
|
||||
elif [ $1 == "-exp" ]; then
|
||||
twine upload -r pip-exp.sh-edraft.de dist/cpl-cli/publish/setup/*
|
||||
twine upload -r pip-exp.sh-edraft.de dist/cpl-core/publish/setup/*
|
||||
twine upload -r pip-exp.sh-edraft.de dist/cpl-query/publish/setup/*
|
||||
|
||||
else
|
||||
twine upload -r pip-dev.sh-edraft.de dist/cpl-cli/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*
|
||||
fi
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .main import main
|
||||
from .startup import Startup
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.build'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.generate'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.console.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.console.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.console.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.library'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.library.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.library.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.library.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.unittest'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.unittest.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.new.unittest.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli._templates.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -29,4 +29,4 @@ from .publish_service import PublishService
|
||||
from .version_service import VersionService
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -14,6 +14,7 @@ from cpl_cli._templates.generate.thread_template import ThreadTemplate
|
||||
from cpl_cli._templates.generate.validator_template import ValidatorTemplate
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -22,13 +23,20 @@ from cpl_core.utils.string import String
|
||||
|
||||
class GenerateService(CommandABC):
|
||||
|
||||
def __init__(self, configuration: ConfigurationABC):
|
||||
def __init__(
|
||||
self,
|
||||
configuration: ConfigurationABC,
|
||||
workspace: WorkspaceSettings,
|
||||
):
|
||||
"""
|
||||
Service for the CLI command generate
|
||||
:param configuration:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._config = configuration
|
||||
self._workspace = workspace
|
||||
|
||||
self._schematics = {
|
||||
"abc": {
|
||||
"Upper": "ABC",
|
||||
@@ -129,6 +137,28 @@ class GenerateService(CommandABC):
|
||||
template.write(value)
|
||||
template.close()
|
||||
|
||||
def _create_init_files(self, file_path: str, template: TemplateFileABC, class_name: str, schematic: str, rel_path: str):
|
||||
if not os.path.isdir(os.path.dirname(file_path)):
|
||||
os.makedirs(os.path.dirname(file_path))
|
||||
directory = ''
|
||||
for subdir in template.path.split('/'):
|
||||
directory = os.path.join(directory, subdir)
|
||||
if subdir == 'src':
|
||||
continue
|
||||
|
||||
file = InitTemplate(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)
|
||||
if os.path.exists(os.path.join(os.path.abspath(directory), file.name)):
|
||||
continue
|
||||
|
||||
Console.spinner(
|
||||
f'Creating {os.path.abspath(directory)}/{file.name}',
|
||||
self._create_file,
|
||||
os.path.join(os.path.abspath(directory), file.name),
|
||||
file.value,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
def _generate(self, schematic: str, name: str, template: TemplateFileABC):
|
||||
"""
|
||||
Generates files by given schematic, name and template
|
||||
@@ -144,27 +174,13 @@ class GenerateService(CommandABC):
|
||||
rel_path = '/'.join(parts[:-1])
|
||||
class_name = parts[len(parts) - 1]
|
||||
|
||||
if 'src' not in rel_path and not os.path.exists(os.path.join(self._env.working_directory, rel_path)):
|
||||
rel_path = f'src/{rel_path}'
|
||||
if self._workspace is not None and parts[0] in self._workspace.projects:
|
||||
rel_path = os.path.dirname(self._workspace.projects[parts[0]])
|
||||
|
||||
template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)
|
||||
|
||||
file_path = os.path.join(self._env.working_directory, template.path, template.name)
|
||||
if not os.path.isdir(os.path.dirname(file_path)):
|
||||
os.makedirs(os.path.dirname(file_path))
|
||||
directory = ''
|
||||
for subdir in template.path.split('/'):
|
||||
directory = os.path.join(directory, subdir)
|
||||
if subdir != 'src':
|
||||
file = InitTemplate(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)
|
||||
Console.spinner(
|
||||
f'Creating {os.path.abspath(directory)}/{file.name}',
|
||||
self._create_file,
|
||||
os.path.join(os.path.abspath(directory), file.name),
|
||||
file.value,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
self._create_init_files(file_path, template, class_name, schematic, rel_path)
|
||||
|
||||
if os.path.isfile(file_path):
|
||||
Console.error(f'{String.first_to_upper(schematic)} already exists!\n')
|
||||
|
@@ -76,23 +76,33 @@ class InstallService(CommandABC):
|
||||
Console.spinner(
|
||||
f'Installing: {dependency}',
|
||||
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
|
||||
'--upgrade',
|
||||
source=self._cli_settings.pip_path,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
local_package = Pip.get_package(dependency)
|
||||
if local_package is None:
|
||||
Error.warn(f'Installation of package {dependency} failed!')
|
||||
return
|
||||
|
||||
for dependency in self._project_settings.dev_dependencies:
|
||||
Console.spinner(
|
||||
f'Installing dev: {dependency}',
|
||||
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
|
||||
'--upgrade',
|
||||
source=self._cli_settings.pip_path,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
local_package = Pip.get_package(dependency)
|
||||
if local_package is None:
|
||||
Error.warn(f'Installation of package {dependency} failed!')
|
||||
return
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.reset_executable()
|
||||
@@ -154,7 +164,7 @@ class InstallService(CommandABC):
|
||||
Console.spinner(
|
||||
f'Installing: {package}' if not self._is_dev else f'Installing dev: {package}',
|
||||
Pip.install if not self._is_virtual else self._wait, package if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in package or 'cpl_' in package else None,
|
||||
source=self._cli_settings.pip_path,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -221,6 +231,18 @@ class InstallService(CommandABC):
|
||||
args.remove('simulate')
|
||||
Console.write_line('Running in simulation mode:')
|
||||
|
||||
if 'cpl-prod' in args:
|
||||
args.remove('cpl-prod')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip.sh-edraft.de'})
|
||||
|
||||
if 'cpl-exp' in args:
|
||||
args.remove('cpl-exp')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip-exp.sh-edraft.de'})
|
||||
|
||||
if 'cpl-dev' in args:
|
||||
args.remove('cpl-dev')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip-dev.sh-edraft.de'})
|
||||
|
||||
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
|
||||
|
||||
if len(args) == 0:
|
||||
|
@@ -54,6 +54,7 @@ class NewService(CommandABC):
|
||||
self._use_service_providing: bool = False
|
||||
self._use_async: bool = False
|
||||
self._use_venv: bool = False
|
||||
self._use_base: bool = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -159,7 +160,8 @@ class NewService(CommandABC):
|
||||
if self._workspace is None:
|
||||
project_path = os.path.join(self._env.working_directory, self._rel_path, self._project.name)
|
||||
else:
|
||||
project_path = os.path.join(self._env.working_directory, 'src', self._rel_path, String.convert_to_snake_case(self._project.name))
|
||||
base = '' if self._use_base else 'src'
|
||||
project_path = os.path.join(self._env.working_directory, base, self._rel_path, String.convert_to_snake_case(self._project.name))
|
||||
|
||||
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
||||
Console.write_line(project_path)
|
||||
@@ -292,6 +294,9 @@ class NewService(CommandABC):
|
||||
if self._env.working_directory.endswith(project):
|
||||
project = ''
|
||||
|
||||
if self._workspace is None and self._use_base:
|
||||
project = f'{self._rel_path}/{project}'
|
||||
|
||||
VenvHelper.init_venv(
|
||||
False,
|
||||
self._env,
|
||||
@@ -335,6 +340,9 @@ class NewService(CommandABC):
|
||||
if 'venv' in args:
|
||||
self._use_venv = True
|
||||
args.remove('venv')
|
||||
if 'base' in args:
|
||||
self._use_base = True
|
||||
args.remove('base')
|
||||
|
||||
console = self._config.get_configuration(ProjectTypeEnum.console.value)
|
||||
library = self._config.get_configuration(ProjectTypeEnum.library.value)
|
||||
|
@@ -8,10 +8,12 @@ from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.live_server.start_executable import StartExecutable
|
||||
from cpl_cli.publish import PublisherService
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class RunService(CommandABC):
|
||||
@@ -22,7 +24,8 @@ class RunService(CommandABC):
|
||||
services: ServiceProviderABC,
|
||||
project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings,
|
||||
workspace: WorkspaceSettings
|
||||
workspace: WorkspaceSettings,
|
||||
publisher: PublisherService,
|
||||
):
|
||||
"""
|
||||
Service for the CLI command start
|
||||
@@ -41,8 +44,10 @@ class RunService(CommandABC):
|
||||
self._project_settings = project_settings
|
||||
self._build_settings = build_settings
|
||||
self._workspace = workspace
|
||||
self._publisher = publisher
|
||||
|
||||
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
|
||||
self._is_dev = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -80,16 +85,36 @@ class RunService(CommandABC):
|
||||
|
||||
self._src_dir = os.path.dirname(json_file)
|
||||
|
||||
def _build(self):
|
||||
if self._is_dev:
|
||||
return
|
||||
|
||||
self._env.set_working_directory(self._src_dir)
|
||||
self._publisher.build()
|
||||
self._src_dir = os.path.abspath(os.path.join(
|
||||
self._src_dir,
|
||||
self._build_settings.output_path,
|
||||
self._project_settings.name,
|
||||
'build',
|
||||
String.convert_to_snake_case(self._project_settings.name)
|
||||
))
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if 'dev' in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
|
||||
if len(args) >= 1:
|
||||
self._set_project_by_args(args[0])
|
||||
args.remove(args[0])
|
||||
|
||||
self._build()
|
||||
|
||||
start_service = StartExecutable(self._env, self._build_settings)
|
||||
start_service.run(args, self._project_settings.python_executable, self._src_dir, output=False)
|
||||
Console.write_line()
|
||||
|
@@ -4,6 +4,7 @@ import subprocess
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_cli.migrations.base.migration_service_abc import MigrationServiceABC
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -23,7 +24,8 @@ class UpdateService(CommandABC):
|
||||
env: ApplicationEnvironmentABC,
|
||||
build_settings: BuildSettings,
|
||||
project_settings: ProjectSettings,
|
||||
cli_settings: CLISettings):
|
||||
cli_settings: CLISettings,
|
||||
migrations: MigrationServiceABC):
|
||||
"""
|
||||
Service for the CLI command update
|
||||
:param config:
|
||||
@@ -39,6 +41,7 @@ class UpdateService(CommandABC):
|
||||
self._build_settings = build_settings
|
||||
self._project_settings = project_settings
|
||||
self._cli_settings = cli_settings
|
||||
self._migrations = migrations
|
||||
self._is_simulation = False
|
||||
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
@@ -56,7 +59,7 @@ class UpdateService(CommandABC):
|
||||
:return:
|
||||
"""
|
||||
dependencies = []
|
||||
for package in self._project_settings.dependencies:
|
||||
for package in [*self._project_settings.dependencies, *self._project_settings.dev_dependencies]:
|
||||
name = package
|
||||
if '==' in package:
|
||||
name = package.split('==')[0]
|
||||
@@ -76,7 +79,7 @@ class UpdateService(CommandABC):
|
||||
'--upgrade',
|
||||
'--upgrade-strategy',
|
||||
'eager',
|
||||
source=self._cli_settings.pip_path if 'cpl-' in name else None,
|
||||
source=self._cli_settings.pip_path,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
@@ -105,6 +108,15 @@ class UpdateService(CommandABC):
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
if 'cpl-cli' in [y for x, y in dependencies]:
|
||||
import cpl_cli
|
||||
|
||||
Console.spinner(
|
||||
'Running migrations', self._migrations.migrate_from, cpl_cli.__version__,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
Console.write_line(f'Found {len(self._project_settings.dependencies)} dependencies.')
|
||||
|
||||
@staticmethod
|
||||
@@ -169,6 +181,18 @@ class UpdateService(CommandABC):
|
||||
Console.write_line('Running in simulation mode:')
|
||||
self._is_simulation = True
|
||||
|
||||
if 'cpl-prod' in args:
|
||||
args.remove('cpl-prod')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip.sh-edraft.de'})
|
||||
|
||||
if 'cpl-exp' in args:
|
||||
args.remove('cpl-exp')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip-exp.sh-edraft.de'})
|
||||
|
||||
if 'cpl-dev' in args:
|
||||
args.remove('cpl-dev')
|
||||
self._cli_settings.from_dict({'PipPath': 'https://pip-dev.sh-edraft.de'})
|
||||
|
||||
VenvHelper.init_venv(False, self._env, self._project_settings)
|
||||
|
||||
self._check_project_dependencies()
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -31,4 +31,4 @@ from .workspace_settings import WorkspaceSettings
|
||||
from .workspace_settings_name_enum import WorkspaceSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -3,8 +3,8 @@
|
||||
"Name": "cpl-cli",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "7",
|
||||
"Micro": "0.post2"
|
||||
"Minor": "12",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,7 +16,7 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.7.0.post2"
|
||||
"cpl-core>=2022.12.0"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.live_server'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -6,17 +6,24 @@ import psutil as psutil
|
||||
from watchdog.events import FileSystemEventHandler
|
||||
from watchdog.observers import Observer
|
||||
|
||||
from cpl_cli.publish import PublisherService
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.live_server.live_server_thread import LiveServerThread
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class LiveServerService(FileSystemEventHandler):
|
||||
|
||||
def __init__(self, env: ApplicationEnvironmentABC, project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings):
|
||||
def __init__(
|
||||
self,
|
||||
env: ApplicationEnvironmentABC,
|
||||
project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings,
|
||||
publisher: PublisherService,
|
||||
):
|
||||
"""
|
||||
Service for the live development server
|
||||
:param env:
|
||||
@@ -28,12 +35,15 @@ class LiveServerService(FileSystemEventHandler):
|
||||
self._env = env
|
||||
self._project_settings = project_settings
|
||||
self._build_settings = build_settings
|
||||
self._publisher = publisher
|
||||
|
||||
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
|
||||
self._wd = self._src_dir
|
||||
self._ls_thread = None
|
||||
self._observer = None
|
||||
|
||||
self._args: list[str] = []
|
||||
self._is_dev = False
|
||||
|
||||
def _start_observer(self):
|
||||
"""
|
||||
@@ -75,10 +85,11 @@ class LiveServerService(FileSystemEventHandler):
|
||||
self._restart()
|
||||
|
||||
def _start(self):
|
||||
self._build()
|
||||
self._start_observer()
|
||||
self._ls_thread = LiveServerThread(
|
||||
self._project_settings.python_executable,
|
||||
self._src_dir,
|
||||
self._wd,
|
||||
self._args,
|
||||
self._env,
|
||||
self._build_settings
|
||||
@@ -87,6 +98,22 @@ class LiveServerService(FileSystemEventHandler):
|
||||
self._ls_thread.join()
|
||||
Console.close()
|
||||
|
||||
def _build(self):
|
||||
if self._is_dev:
|
||||
return
|
||||
|
||||
self._env.set_working_directory(self._src_dir)
|
||||
Console.disable()
|
||||
self._publisher.build()
|
||||
Console.enable()
|
||||
self._wd = os.path.abspath(os.path.join(
|
||||
self._src_dir,
|
||||
self._build_settings.output_path,
|
||||
self._project_settings.name,
|
||||
'build',
|
||||
String.convert_to_snake_case(self._project_settings.name)
|
||||
))
|
||||
|
||||
def start(self, args: list[str]):
|
||||
"""
|
||||
Starts the CPL live development server
|
||||
@@ -97,6 +124,10 @@ class LiveServerService(FileSystemEventHandler):
|
||||
Console.error('Project has no entry point.')
|
||||
return
|
||||
|
||||
if 'dev' in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
|
||||
self._args = args
|
||||
Console.write_line('** CPL live development server is running **')
|
||||
self._start()
|
||||
|
@@ -5,6 +5,7 @@ import pkg_resources
|
||||
from cpl_cli.cli import CLI
|
||||
from cpl_cli.startup import Startup
|
||||
from cpl_cli.startup_argument_extension import StartupArgumentExtension
|
||||
from cpl_cli.startup_migration_extension import StartupMigrationExtension
|
||||
from cpl_cli.startup_workspace_extension import StartupWorkspaceExtension
|
||||
from cpl_core.application.application_builder import ApplicationBuilder
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
@@ -34,6 +35,7 @@ def main():
|
||||
app_builder.use_startup(Startup)
|
||||
app_builder.use_extension(StartupWorkspaceExtension)
|
||||
app_builder.use_extension(StartupArgumentExtension)
|
||||
app_builder.use_extension(StartupMigrationExtension)
|
||||
for extension in get_startup_extensions():
|
||||
app_builder.use_extension(extension)
|
||||
|
||||
|
26
src/cpl_cli/migrations/__init__.py
Normal file
26
src/cpl_cli/migrations/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
26
src/cpl_cli/migrations/base/__init__.py
Normal file
26
src/cpl_cli/migrations/base/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
15
src/cpl_cli/migrations/base/migration_abc.py
Normal file
15
src/cpl_cli/migrations/base/migration_abc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class MigrationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, version: str):
|
||||
self._version = version
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
return self._version
|
||||
|
||||
@abstractmethod
|
||||
def migrate(self): pass
|
10
src/cpl_cli/migrations/base/migration_service_abc.py
Normal file
10
src/cpl_cli/migrations/base/migration_service_abc.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class MigrationServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def migrate_from(self, version: str): pass
|
11
src/cpl_cli/migrations/migration_2022_10.py
Normal file
11
src/cpl_cli/migrations/migration_2022_10.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from cpl_cli.migrations.base.migration_abc import MigrationABC
|
||||
|
||||
|
||||
class Migration202210(MigrationABC):
|
||||
|
||||
def __init__(self):
|
||||
MigrationABC.__init__(self, '2022.10')
|
||||
|
||||
def migrate(self):
|
||||
# This migration could be deleted, but stays as an example.
|
||||
pass
|
26
src/cpl_cli/migrations/service/__init__.py
Normal file
26
src/cpl_cli/migrations/service/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.migrations.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
21
src/cpl_cli/migrations/service/migration_service.py
Normal file
21
src/cpl_cli/migrations/service/migration_service.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from packaging import version
|
||||
|
||||
from cpl_cli.migrations.base.migration_abc import MigrationABC
|
||||
from cpl_cli.migrations.base.migration_service_abc import MigrationServiceABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class MigrationService(MigrationServiceABC):
|
||||
|
||||
def __init__(self, services: ServiceProviderABC):
|
||||
MigrationServiceABC.__init__(self)
|
||||
|
||||
self._services = services
|
||||
|
||||
def migrate_from(self, _v: str):
|
||||
for migration_type in MigrationABC.__subclasses__():
|
||||
migration: MigrationABC = self._services.get_service(migration_type)
|
||||
if version.parse(migration.version) <= version.parse(_v):
|
||||
continue
|
||||
|
||||
migration.migrate()
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .publisher_abc import PublisherABC
|
||||
from .publisher_service import PublisherService
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -433,7 +433,7 @@ class PublisherService(PublisherABC):
|
||||
3. Copies all included source files to dist_path/build
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125)
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'build'))
|
||||
|
||||
@@ -456,7 +456,7 @@ class PublisherService(PublisherABC):
|
||||
4. Remove all included source from dist_path/publish
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125)
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'publish'))
|
||||
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.source_creator'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -42,7 +42,10 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-prod', ['cp', 'CP']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-exp', ['ce', 'CE']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-dev', ['cd', 'CD'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'new', ['n', 'N'], NewService, True) \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'console', ['c', 'C'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'library', ['l', 'L'], ' ') \
|
||||
@@ -52,18 +55,24 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'startup', ['s', 'S']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'service-providing', ['sp', 'SP']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'nothing', ['n', 'N']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'venv', ['v', 'V'])
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'venv', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'base', ['b', 'B'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-prod', ['cp', 'CP']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-exp', ['ce', 'CE']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'cpl-dev', ['cd', 'CD'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'version', ['v', 'V'], VersionService, True)
|
||||
|
||||
config.for_each_argument(lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, '--', 'help', ['h', 'H']))
|
||||
|
28
src/cpl_cli/startup_migration_extension.py
Normal file
28
src/cpl_cli/startup_migration_extension.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_cli.migrations.base.migration_abc import MigrationABC
|
||||
from cpl_cli.migrations.base.migration_service_abc import MigrationServiceABC
|
||||
from cpl_cli.migrations.migration_2022_10 import Migration202210
|
||||
from cpl_cli.migrations.service.migration_service import MigrationService
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class StartupMigrationExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_singleton(MigrationServiceABC, MigrationService)
|
||||
services.add_singleton(MigrationABC, Migration202210)
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.validators'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.7.0.post2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='7', micro='0.post2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -29,4 +29,4 @@ from .startup_abc import StartupABC
|
||||
from .startup_extension_abc import StartupExtensionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -30,15 +30,18 @@ class ApplicationBuilder(ApplicationBuilderABC):
|
||||
self._app_extensions: list[Callable] = []
|
||||
self._startup_extensions: list[Callable] = []
|
||||
|
||||
def use_startup(self, startup: Type[StartupABC]):
|
||||
def use_startup(self, startup: Type[StartupABC]) -> 'ApplicationBuilder':
|
||||
self._startup = startup()
|
||||
return self
|
||||
|
||||
def use_extension(self, extension: Type[Union[ApplicationExtensionABC, StartupExtensionABC]]):
|
||||
def use_extension(self, extension: Type[Union[ApplicationExtensionABC, StartupExtensionABC]]) -> 'ApplicationBuilder':
|
||||
if issubclass(extension, ApplicationExtensionABC) and extension not in self._app_extensions:
|
||||
self._app_extensions.append(extension)
|
||||
elif issubclass(extension, StartupExtensionABC) and extension not in self._startup_extensions:
|
||||
self._startup_extensions.append(extension)
|
||||
|
||||
return self
|
||||
|
||||
def _build_startup(self):
|
||||
for ex in self._startup_extensions:
|
||||
extension = ex()
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -35,4 +35,4 @@ from .validator_abc import ValidatorABC
|
||||
from .variable_argument import VariableArgument
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -177,7 +177,7 @@ class Configuration(ConfigurationABC):
|
||||
|
||||
Console.write_line()
|
||||
self._set_variable('ACTIVE_EXECUTABLE', script)
|
||||
css.run([])
|
||||
css.run(self._additional_arguments)
|
||||
|
||||
def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]):
|
||||
for i in range(0, len(arg_list)):
|
||||
@@ -334,6 +334,13 @@ class Configuration(ConfigurationABC):
|
||||
cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
|
||||
self._handle_pre_or_post_executables(True, exe, services)
|
||||
self._set_variable('ACTIVE_EXECUTABLE', exe.name)
|
||||
args = self.get_configuration('ARGS')
|
||||
if args is not None:
|
||||
for arg in args.split(' '):
|
||||
if arg == '':
|
||||
continue
|
||||
self._additional_arguments.append(arg)
|
||||
|
||||
cmd.execute(self._additional_arguments)
|
||||
self._handle_pre_or_post_executables(False, exe, services)
|
||||
prevent = exe.prevent_next_executable
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .foreground_color_enum import ForegroundColorEnum
|
||||
from .spinner_thread import SpinnerThread
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -500,7 +500,7 @@ class Console:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write, args))
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write, *args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
@@ -523,7 +523,7 @@ class Console:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_at, x, y, args))
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_at, x, y, *args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
@@ -542,7 +542,7 @@ class Console:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line, args))
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line, *args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
@@ -567,7 +567,7 @@ class Console:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line_at, x, y, args))
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line_at, x, y, *args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
|
@@ -3,8 +3,8 @@
|
||||
"Name": "cpl-core",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "10",
|
||||
"Micro": "1"
|
||||
"Minor": "12",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -26,4 +26,4 @@ from .database_settings import DatabaseSettings
|
||||
from .table_abc import TableABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .database_connection import DatabaseConnection
|
||||
from .database_connection_abc import DatabaseConnectionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .database_context import DatabaseContext
|
||||
from .database_context_abc import DatabaseContextABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -31,4 +31,4 @@ from .service_provider import ServiceProvider
|
||||
from .service_provider_abc import ServiceProviderABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -26,4 +26,4 @@ from .environment_name_enum import EnvironmentNameEnum
|
||||
from .application_environment import ApplicationEnvironment
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .logging_settings import LoggingSettings
|
||||
from .logging_settings_name_enum import LoggingSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -37,16 +37,29 @@ class Logger(LoggerABC):
|
||||
self._check_for_settings(self._time_format_settings, TimeFormatSettings)
|
||||
self._check_for_settings(self._log_settings, LoggingSettings)
|
||||
|
||||
self._log = Template(self._log_settings.filename).substitute(
|
||||
date_time_now=self._env.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||
start_time=self._env.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||
)
|
||||
self._path = self._log_settings.path
|
||||
self._level = self._log_settings.level
|
||||
self._console = self._log_settings.console
|
||||
|
||||
self.create()
|
||||
|
||||
@property
|
||||
def _log(self) -> str:
|
||||
return Template(self._log_settings.filename).substitute(
|
||||
date_time_now=self._env.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||
date_now=self._env.date_time_now.strftime(self._time_format_settings.date_format),
|
||||
time_now=self._env.date_time_now.strftime(self._time_format_settings.time_format),
|
||||
start_time=self._env.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||
)
|
||||
|
||||
@property
|
||||
def _path(self) -> str:
|
||||
return Template(self._log_settings.path).substitute(
|
||||
date_time_now=self._env.date_time_now.strftime(self._time_format_settings.date_time_format),
|
||||
date_now=self._env.date_time_now.strftime(self._time_format_settings.date_format),
|
||||
time_now=self._env.date_time_now.strftime(self._time_format_settings.time_format),
|
||||
start_time=self._env.start_time.strftime(self._time_format_settings.date_time_log_format)
|
||||
)
|
||||
|
||||
def _check_for_settings(self, settings: ConfigurationModelABC, settings_type: type):
|
||||
self._level = LoggingLevelEnum.OFF
|
||||
self._console = LoggingLevelEnum.FATAL
|
||||
@@ -112,7 +125,8 @@ class Logger(LoggerABC):
|
||||
try:
|
||||
# open log file and append always
|
||||
if not os.path.isdir(self._path):
|
||||
self._fatal_console(__name__, 'Log directory not found')
|
||||
self._warn_console(__name__, 'Log directory not found, try to recreate logger')
|
||||
self.create()
|
||||
|
||||
with open(self._path + self._log, "a+", encoding="utf-8") as f:
|
||||
f.write(string + '\n')
|
||||
@@ -153,9 +167,9 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.TRACE.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.TRACE.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.set_foreground_color(ForegroundColorEnum.grey)
|
||||
Console.write_line(output)
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
@@ -166,9 +180,9 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.DEBUG.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.DEBUG.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.set_foreground_color(ForegroundColorEnum.blue)
|
||||
Console.write_line(output)
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
@@ -179,7 +193,7 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.INFO.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.INFO.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line(output)
|
||||
@@ -192,7 +206,7 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.WARN.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.WARN.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.yellow)
|
||||
Console.write_line(output)
|
||||
@@ -211,7 +225,7 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.ERROR.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.ERROR.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(output)
|
||||
@@ -230,7 +244,7 @@ class Logger(LoggerABC):
|
||||
if self._level.value >= LoggingLevelEnum.FATAL.value:
|
||||
self._append_log(output)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.FATAL.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(output)
|
||||
@@ -238,6 +252,22 @@ class Logger(LoggerABC):
|
||||
|
||||
sys.exit()
|
||||
|
||||
def _warn_console(self, name: str, message: str):
|
||||
r"""Writes a warning to console only
|
||||
|
||||
Parameter
|
||||
---------
|
||||
name: :class:`str`
|
||||
Error name
|
||||
message: :class:`str`
|
||||
Error message
|
||||
"""
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.WARN.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.yellow)
|
||||
Console.write_line(self._get_string(name, LoggingLevelEnum.WARN, message))
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
def _fatal_console(self, name: str, message: str, ex: Exception = None):
|
||||
r"""Writes an error to console only
|
||||
|
||||
@@ -258,7 +288,7 @@ class Logger(LoggerABC):
|
||||
else:
|
||||
output = self._get_string(name, LoggingLevelEnum.ERROR, message)
|
||||
|
||||
# check if message can be shown in console_old
|
||||
# check if message can be shown in console
|
||||
if self._console.value >= LoggingLevelEnum.FATAL.value:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(output)
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .email_client_settings import EMailClientSettings
|
||||
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -71,10 +71,6 @@ class EMailClient(EMailClientABC):
|
||||
self._logger.trace(__name__, f'Started {__name__}.send_mail')
|
||||
try:
|
||||
self.login()
|
||||
email.body += f'\n\nDies ist eine automatische E-Mail.' \
|
||||
f'\nGesendet von {self._environment.application_name}-{self._environment.environment_name}@{self._environment.host_name} für ' \
|
||||
f'{self._environment.customer}.'
|
||||
|
||||
self._logger.debug(__name__, f'Try to send email to {email.receiver_list}')
|
||||
self._server.sendmail(self._mail_settings.user_name, email.receiver_list, email.get_content(self._mail_settings.user_name))
|
||||
self._logger.info(__name__, f'Sent email to {email.receiver_list}')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.pipes'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -30,4 +30,4 @@ from .to_camel_case_pipe import ToCamelCasePipe
|
||||
from .to_snake_case_pipe import ToSnakeCasePipe
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -11,4 +11,7 @@ class VersionPipe(PipeABC):
|
||||
if atr.value not in value:
|
||||
raise KeyError(atr.value)
|
||||
|
||||
return f'{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}.{value[VersionSettingsNameEnum.micro.value]}'
|
||||
v_str = f'{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}'
|
||||
if value[VersionSettingsNameEnum.micro.value] is not None:
|
||||
v_str += f'.{value[VersionSettingsNameEnum.micro.value]}'
|
||||
return v_str
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .time_format_settings import TimeFormatSettings
|
||||
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.1'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -26,4 +26,4 @@ from .string import String
|
||||
from .pip import Pip
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -65,7 +65,7 @@ class Pip:
|
||||
"""
|
||||
result = None
|
||||
with suppress(Exception):
|
||||
args = [cls._executable, "-m", "pip", "show", package]
|
||||
args = [cls._executable, "-m", "pip", "freeze"]
|
||||
|
||||
result = subprocess.check_output(
|
||||
args,
|
||||
@@ -74,18 +74,11 @@ class Pip:
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
for p in str(result.decode()).split('\n'):
|
||||
if p.startswith(package):
|
||||
return p
|
||||
|
||||
new_package: list[str] = str(result, 'utf-8').lower().split('\n')
|
||||
new_version = ''
|
||||
|
||||
for atr in new_package:
|
||||
if 'version' in atr:
|
||||
new_version = atr.split(': ')[1]
|
||||
|
||||
if new_version != '':
|
||||
return f'{package}=={new_version}'
|
||||
|
||||
return package
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_outdated(cls) -> bytes:
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -55,4 +55,4 @@ def get_discord_collection(services: 'ServiceCollectionABC') -> 'DiscordCollecti
|
||||
# build-ignore-end
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from collections import namedtuple
|
||||
from .discord_bot_application_abc import DiscordBotApplicationABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .discord_command_abc import DiscordCommandABC
|
||||
from .discord_commands_meta import DiscordCogMeta
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from collections import namedtuple
|
||||
from .discord_bot_settings import DiscordBotSettings
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.container'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -31,4 +31,4 @@ from .thread import Thread
|
||||
from .voice_channel import VoiceChannel
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -3,8 +3,8 @@
|
||||
"Name": "cpl-discord",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "10",
|
||||
"Micro": "2"
|
||||
"Minor": "12",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,17 +16,15 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.10.1",
|
||||
"discord.py==2.0.1",
|
||||
"cpl-query==2022.10.2"
|
||||
"cpl-core>=2022.12.0",
|
||||
"discord.py==2.1.0",
|
||||
"cpl-query>=2022.12.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.7.0.post2"
|
||||
"cpl-cli>=2022.12.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {
|
||||
"linux": ""
|
||||
},
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
|
@@ -37,6 +37,10 @@ from cpl_discord.events.on_private_channel_create_abc import OnPrivateChannelCre
|
||||
from cpl_discord.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC
|
||||
from cpl_discord.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC
|
||||
from cpl_discord.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC
|
||||
from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC
|
||||
from cpl_discord.events.on_raw_reaction_clear_abc import OnRawReactionClearABC
|
||||
from cpl_discord.events.on_raw_reaction_clear_emoji_abc import OnRawReactionClearEmojiABC
|
||||
from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC
|
||||
from cpl_discord.events.on_reaction_add_abc import OnReactionAddABC
|
||||
from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC
|
||||
from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
|
||||
@@ -87,6 +91,10 @@ class DiscordEventTypesEnum(Enum):
|
||||
on_private_channel_delete = OnPrivateChannelDeleteABC
|
||||
on_private_channel_pins_update = OnPrivateChannelPinsUpdateABC
|
||||
on_private_channel_update = OnPrivateChannelUpdateABC
|
||||
on_raw_reaction_add = OnRawReactionAddABC
|
||||
on_raw_reaction_clear = OnRawReactionClearABC
|
||||
on_raw_reaction_clear_emoji = OnRawReactionClearEmojiABC
|
||||
on_raw_reaction_remove = OnRawReactionRemoveABC
|
||||
on_reaction_add = OnReactionAddABC
|
||||
on_reaction_clear = OnReactionClearABC
|
||||
on_reaction_clear_emoji = OnReactionClearEmojiABC
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.events'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -69,4 +69,4 @@ from .on_voice_state_update_abc import OnVoiceStateUpdateABC
|
||||
from .on_webhooks_update_abc import OnWebhooksUpdateABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
13
src/cpl_discord/events/on_raw_reaction_add_abc.py
Normal file
13
src/cpl_discord/events/on_raw_reaction_add_abc.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
|
||||
class OnRawReactionAddABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_raw_reaction_add(self, payload: RawReactionActionEvent): pass
|
||||
|
13
src/cpl_discord/events/on_raw_reaction_clear_abc.py
Normal file
13
src/cpl_discord/events/on_raw_reaction_clear_abc.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
|
||||
class OnRawReactionClearABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_raw_reaction_clear(self, payload: RawReactionActionEvent): pass
|
||||
|
13
src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py
Normal file
13
src/cpl_discord/events/on_raw_reaction_clear_emoji_abc.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
|
||||
class OnRawReactionClearEmojiABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_raw_reaction_clear_emoji(self, payload: RawReactionActionEvent): pass
|
||||
|
13
src/cpl_discord/events/on_raw_reaction_remove_abc.py
Normal file
13
src/cpl_discord/events/on_raw_reaction_remove_abc.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
|
||||
class OnRawReactionRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_raw_reaction_remove(self, payload: RawReactionActionEvent): pass
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.helper'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from collections import namedtuple
|
||||
from .to_containers_converter import ToContainersConverter
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_discord.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.2'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -29,4 +29,4 @@ from .discord_service import DiscordService
|
||||
from .discord_service_abc import DiscordServiceABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='2')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -43,8 +43,8 @@ class DiscordBotService(DiscordBotServiceABC):
|
||||
|
||||
def _get_settings(self, settings_from_config: DiscordBotSettings) -> DiscordBotSettings:
|
||||
new_settings = DiscordBotSettings()
|
||||
token = settings_from_config.token
|
||||
prefix = settings_from_config.prefix
|
||||
token = None if settings_from_config is None else settings_from_config.token
|
||||
prefix = None if settings_from_config is None else settings_from_config.prefix
|
||||
env_token = self._config.get_configuration('TOKEN')
|
||||
env_prefix = self._config.get_configuration('PREFIX')
|
||||
|
||||
|
@@ -2,6 +2,7 @@ from datetime import datetime
|
||||
from typing import Optional, Sequence, Union, Type
|
||||
|
||||
import discord
|
||||
from discord import RawReactionActionEvent
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context, CommandError, Cog, Command
|
||||
|
||||
@@ -46,6 +47,10 @@ from cpl_discord.events.on_private_channel_create_abc import OnPrivateChannelCre
|
||||
from cpl_discord.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC
|
||||
from cpl_discord.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC
|
||||
from cpl_discord.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC
|
||||
from cpl_discord.events.on_raw_reaction_add_abc import OnRawReactionAddABC
|
||||
from cpl_discord.events.on_raw_reaction_clear_abc import OnRawReactionClearABC
|
||||
from cpl_discord.events.on_raw_reaction_clear_emoji_abc import OnRawReactionClearEmojiABC
|
||||
from cpl_discord.events.on_raw_reaction_remove_abc import OnRawReactionRemoveABC
|
||||
from cpl_discord.events.on_reaction_add_abc import OnReactionAddABC
|
||||
from cpl_discord.events.on_reaction_clear_abc import OnReactionClearABC
|
||||
from cpl_discord.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
|
||||
@@ -161,12 +166,12 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
self._logger.trace(__name__, f'Received on_message:\n\t{message}\n\t{message.content}')
|
||||
self._logger.trace(__name__, f'Received on_message:\n\t{message}')
|
||||
await self._handle_event(OnMessageABC, message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_delete(self, message: discord.Message):
|
||||
self._logger.trace(__name__, f'Received on_message_delete:\n\t{message}\n\t{message.content}')
|
||||
self._logger.trace(__name__, f'Received on_message_delete:\n\t{message}')
|
||||
await self._handle_event(OnMessageDeleteABC, message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
@@ -179,6 +184,26 @@ class DiscordService(DiscordServiceABC, commands.Cog, metaclass=DiscordCogMeta):
|
||||
self._logger.trace(__name__, f'Received on_message_edit:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnMessageEditABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
|
||||
self._logger.trace(__name__, f'Received on_raw_reaction_add')
|
||||
await self._handle_event(OnRawReactionAddABC, payload)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_remove(self, payload: RawReactionActionEvent):
|
||||
self._logger.trace(__name__, f'Received on_raw_reaction_remove')
|
||||
await self._handle_event(OnRawReactionRemoveABC, payload)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_clear(self, payload: RawReactionActionEvent):
|
||||
self._logger.trace(__name__, f'Received on_raw_reaction_clear')
|
||||
await self._handle_event(OnRawReactionClearABC, payload)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_raw_reaction_clear_emoji(self, payload: RawReactionActionEvent):
|
||||
self._logger.trace(__name__, f'Received on_raw_reaction_clear_emoji')
|
||||
await self._handle_event(OnRawReactionClearEmojiABC, payload)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_reaction_add:\n\t{reaction}\n\t{user}')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.9'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='9')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_query.base'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.9'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='9')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
2
src/cpl_query/base/default_lambda.py
Normal file
2
src/cpl_query/base/default_lambda.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def default_lambda(x: object):
|
||||
return x
|
34
src/cpl_query/base/ordered_queryable.py
Normal file
34
src/cpl_query/base/ordered_queryable.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from collections.abc import Callable
|
||||
|
||||
from cpl_query.base.ordered_queryable_abc import OrderedQueryableABC
|
||||
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument
|
||||
from cpl_query.iterable.iterable import Iterable
|
||||
|
||||
|
||||
class OrderedQueryable(OrderedQueryableABC):
|
||||
r"""Implementation of :class: `cpl_query.extension.Iterable` `cpl_query.extension.OrderedIterableABC`
|
||||
"""
|
||||
|
||||
def __init__(self, _t: type, _values: Iterable = None, _func: Callable = None):
|
||||
OrderedQueryableABC.__init__(self, _t, _values, _func)
|
||||
|
||||
def then_by(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.func)
|
||||
|
||||
self._funcs.append(_func)
|
||||
|
||||
return OrderedQueryable(self.type, sorted(self, key=lambda *args: [f(*args) for f in self._funcs]), _func)
|
||||
|
||||
def then_by_descending(self: OrderedQueryableABC, _func: Callable) -> OrderedQueryableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.func)
|
||||
|
||||
self._funcs.append(_func)
|
||||
return OrderedQueryable(self.type, sorted(self, key=lambda *args: [f(*args) for f in self._funcs], reverse=True), _func)
|
@@ -2,20 +2,20 @@ from abc import abstractmethod
|
||||
from collections.abc import Callable
|
||||
from typing import Iterable
|
||||
|
||||
from cpl_query.iterable.iterable_abc import IterableABC
|
||||
from cpl_query.base.queryable_abc import QueryableABC
|
||||
|
||||
|
||||
class OrderedIterableABC(IterableABC):
|
||||
class OrderedQueryableABC(QueryableABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, _t: type, _func: Callable = None, _values: Iterable = None):
|
||||
IterableABC.__init__(self, _t, _values)
|
||||
def __init__(self, _t: type, _values: Iterable = None, _func: Callable = None):
|
||||
QueryableABC.__init__(self, _t, _values)
|
||||
self._funcs: list[Callable] = []
|
||||
if _func is not None:
|
||||
self._funcs.append(_func)
|
||||
|
||||
@abstractmethod
|
||||
def then_by(self, func: Callable) -> 'OrderedIterableABC':
|
||||
def then_by(self, func: Callable) -> 'OrderedQueryableABC':
|
||||
r"""Sorts OrderedList in ascending order by function
|
||||
|
||||
Parameter
|
||||
@@ -29,7 +29,7 @@ class OrderedIterableABC(IterableABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def then_by_descending(self, func: Callable) -> 'OrderedIterableABC':
|
||||
def then_by_descending(self, func: Callable) -> 'OrderedQueryableABC':
|
||||
r"""Sorts OrderedList in descending order by function
|
||||
|
||||
Parameter
|
@@ -1,10 +1,19 @@
|
||||
from abc import abstractmethod, ABC
|
||||
from typing import Optional, Callable, Union
|
||||
|
||||
from cpl_query._helper import is_number
|
||||
from cpl_query.base.sequence_abc import SequenceABC
|
||||
from cpl_query.exceptions import InvalidTypeException, ArgumentNoneException, ExceptionArgument, IndexOutOfRangeException
|
||||
|
||||
class QueryableABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def _default_lambda(x: object):
|
||||
return x
|
||||
|
||||
|
||||
class QueryableABC(SequenceABC):
|
||||
|
||||
def __init__(self, t: type = None, values: list = None):
|
||||
SequenceABC.__init__(self, t, values)
|
||||
|
||||
def all(self, _func: Callable = None) -> bool:
|
||||
r"""Checks if every element of list equals result found by function
|
||||
|
||||
@@ -17,9 +26,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return self.count(_func) == self.count()
|
||||
|
||||
@abstractmethod
|
||||
def any(self, _func: Callable = None) -> bool:
|
||||
r"""Checks if list contains result found by function
|
||||
|
||||
@@ -32,9 +43,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return self.where(_func).count() > 0
|
||||
|
||||
@abstractmethod
|
||||
def average(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
r"""Returns average value of list
|
||||
|
||||
@@ -47,10 +60,12 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Union[int, float, complex]
|
||||
"""
|
||||
pass
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
@abstractmethod
|
||||
def contains(self, value: object) -> bool:
|
||||
return self.sum(_func) / self.count()
|
||||
|
||||
def contains(self, _value: object) -> bool:
|
||||
r"""Checks if list contains value given by function
|
||||
|
||||
Parameter
|
||||
@@ -62,9 +77,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
bool
|
||||
"""
|
||||
pass
|
||||
if _value is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.value)
|
||||
|
||||
return self.where(lambda x: x == _value).count() > 0
|
||||
|
||||
@abstractmethod
|
||||
def count(self, _func: Callable = None) -> int:
|
||||
r"""Returns length of list or count of found elements
|
||||
|
||||
@@ -77,9 +94,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
int
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
return self.__len__()
|
||||
|
||||
return self.where(_func).__len__()
|
||||
|
||||
@abstractmethod
|
||||
def distinct(self, _func: Callable = None) -> 'QueryableABC':
|
||||
r"""Returns list without redundancies
|
||||
|
||||
@@ -92,39 +111,62 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
@abstractmethod
|
||||
def element_at(self, index: int) -> any:
|
||||
result = []
|
||||
known_values = []
|
||||
for element in self:
|
||||
value = _func(element)
|
||||
if value in known_values:
|
||||
continue
|
||||
|
||||
known_values.append(value)
|
||||
result.append(element)
|
||||
|
||||
return type(self)(self._type, result)
|
||||
|
||||
def element_at(self, _index: int) -> any:
|
||||
r"""Returns element at given index
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
Value at index: any
|
||||
Value at _index: any
|
||||
"""
|
||||
pass
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
@abstractmethod
|
||||
def element_at_or_default(self, index: int) -> Optional[any]:
|
||||
result = self[_index]
|
||||
if result is None:
|
||||
raise IndexOutOfRangeException
|
||||
|
||||
return result
|
||||
|
||||
def element_at_or_default(self, _index: int) -> Optional[any]:
|
||||
r"""Returns element at given index or None
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
Value at index: Optional[any]
|
||||
Value at _index: Optional[any]
|
||||
"""
|
||||
pass
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
try:
|
||||
return self[_index]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
@abstractmethod
|
||||
def first(self) -> any:
|
||||
r"""Returns first element
|
||||
|
||||
@@ -132,9 +174,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
First element of list: any
|
||||
"""
|
||||
pass
|
||||
if len(self) == 0:
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return self[0]
|
||||
|
||||
@abstractmethod
|
||||
def first_or_default(self) -> any:
|
||||
r"""Returns first element or None
|
||||
|
||||
@@ -142,9 +186,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
First element of list: Optional[any]
|
||||
"""
|
||||
pass
|
||||
if len(self) == 0:
|
||||
return None
|
||||
|
||||
return self[0]
|
||||
|
||||
@abstractmethod
|
||||
def for_each(self, _func: Callable = None):
|
||||
r"""Runs given function for each element of list
|
||||
|
||||
@@ -153,9 +199,36 @@ class QueryableABC(ABC):
|
||||
func: :class: `Callable`
|
||||
function to call
|
||||
"""
|
||||
pass
|
||||
if _func is not None:
|
||||
for element in self:
|
||||
_func(element)
|
||||
|
||||
return self
|
||||
|
||||
def group_by(self, _func: Callable = None) -> 'QueryableABC':
|
||||
r"""Groups by func
|
||||
|
||||
Returns
|
||||
-------
|
||||
Grouped list[list[any]]: any
|
||||
"""
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
groups = {}
|
||||
|
||||
for v in self:
|
||||
value = _func(v)
|
||||
if v not in groups:
|
||||
groups[value] = []
|
||||
|
||||
groups[value].append(v)
|
||||
|
||||
v = []
|
||||
for g in groups.values():
|
||||
v.append(type(self)(None, g))
|
||||
x = type(self)(type(self), v)
|
||||
return x
|
||||
|
||||
@abstractmethod
|
||||
def last(self) -> any:
|
||||
r"""Returns last element
|
||||
|
||||
@@ -163,9 +236,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Last element of list: any
|
||||
"""
|
||||
pass
|
||||
if len(self) == 0:
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return self[len(self) - 1]
|
||||
|
||||
@abstractmethod
|
||||
def last_or_default(self) -> any:
|
||||
r"""Returns last element or None
|
||||
|
||||
@@ -173,9 +248,11 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Last element of list: Optional[any]
|
||||
"""
|
||||
pass
|
||||
if len(self) == 0:
|
||||
return None
|
||||
|
||||
return self[len(self) - 1]
|
||||
|
||||
@abstractmethod
|
||||
def max(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
r"""Returns the highest value
|
||||
|
||||
@@ -188,19 +265,33 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Union[int, float, complex]
|
||||
"""
|
||||
pass
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
@abstractmethod
|
||||
def median(self) -> Union[int, float]:
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return _func(max(self, key=_func))
|
||||
|
||||
def median(self, _func=None) -> Union[int, float]:
|
||||
r"""Return the median value of data elements
|
||||
|
||||
Returns
|
||||
-------
|
||||
Union[int, float]
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = self.order_by(_func).select(_func).to_list()
|
||||
length = len(result)
|
||||
i = int(length / 2)
|
||||
return (
|
||||
result[i]
|
||||
if length % 2 == 1
|
||||
else (float(result[i - 1]) + float(result[i])) / float(2)
|
||||
)
|
||||
|
||||
@abstractmethod
|
||||
def min(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
r"""Returns the lowest value
|
||||
|
||||
@@ -213,9 +304,14 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Union[int, float, complex]
|
||||
"""
|
||||
pass
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return _func(min(self, key=_func))
|
||||
|
||||
@abstractmethod
|
||||
def order_by(self, _func: Callable = None) -> 'QueryableABC':
|
||||
r"""Sorts elements by function in ascending order
|
||||
|
||||
@@ -228,9 +324,12 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
from cpl_query.base.ordered_queryable import OrderedQueryable
|
||||
return OrderedQueryable(self.type, sorted(self, key=_func), _func)
|
||||
|
||||
@abstractmethod
|
||||
def order_by_descending(self, _func: Callable = None) -> 'QueryableABC':
|
||||
r"""Sorts elements by function in descending order
|
||||
|
||||
@@ -243,9 +342,12 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
from cpl_query.base.ordered_queryable import OrderedQueryable
|
||||
return OrderedQueryable(self.type, sorted(self, key=_func, reverse=True), _func)
|
||||
|
||||
@abstractmethod
|
||||
def reverse(self) -> 'QueryableABC':
|
||||
r"""Reverses list
|
||||
|
||||
@@ -253,29 +355,31 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
return type(self)(self._type, list(reversed(self)))
|
||||
|
||||
@abstractmethod
|
||||
def select(self, _f: Callable) -> 'QueryableABC':
|
||||
def select(self, _func: Callable) -> 'QueryableABC':
|
||||
r"""Formats each element of list to a given format
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
@abstractmethod
|
||||
def select_many(self, _f: Callable) -> 'QueryableABC':
|
||||
return type(self)(any, [_func(_o) for _o in self])
|
||||
|
||||
def select_many(self, _func: Callable) -> 'QueryableABC':
|
||||
r"""Flattens resulting lists to one
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
# The line below is pain. I don't understand anything of it...
|
||||
# written on 09.11.2022 by Sven Heidemann
|
||||
return type(self)(any, [_a for _o in self for _a in _func(_o)])
|
||||
|
||||
@abstractmethod
|
||||
def single(self) -> any:
|
||||
r"""Returns one single element of list
|
||||
|
||||
@@ -288,9 +392,13 @@ class QueryableABC(ABC):
|
||||
ArgumentNoneException: when argument is None
|
||||
Exception: when argument is None or found more than one element
|
||||
"""
|
||||
pass
|
||||
if len(self) > 1:
|
||||
raise Exception('Found more than one element')
|
||||
elif len(self) == 0:
|
||||
raise Exception('Found no element')
|
||||
|
||||
return self[0]
|
||||
|
||||
@abstractmethod
|
||||
def single_or_default(self) -> Optional[any]:
|
||||
r"""Returns one single element of list
|
||||
|
||||
@@ -298,39 +406,48 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Found value: Optional[any]
|
||||
"""
|
||||
pass
|
||||
if len(self) > 1:
|
||||
raise Exception('Index out of range')
|
||||
elif len(self) == 0:
|
||||
return None
|
||||
|
||||
@abstractmethod
|
||||
def skip(self, index: int) -> 'QueryableABC':
|
||||
return self[0]
|
||||
|
||||
def skip(self, _index: int) -> 'QueryableABC':
|
||||
r"""Skips all elements from index
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
@abstractmethod
|
||||
def skip_last(self, index: int) -> 'QueryableABC':
|
||||
return type(self)(self.type, values=self[_index:])
|
||||
|
||||
def skip_last(self, _index: int) -> 'QueryableABC':
|
||||
r"""Skips all elements after index
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
index = len(self) - _index
|
||||
return type(self)(self._type, self[:index])
|
||||
|
||||
@abstractmethod
|
||||
def sum(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
r"""Sum of all values
|
||||
|
||||
@@ -343,39 +460,54 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
Union[int, float, complex]
|
||||
"""
|
||||
pass
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
@abstractmethod
|
||||
def take(self, index: int) -> 'QueryableABC':
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = 0
|
||||
for x in self:
|
||||
result += _func(x)
|
||||
|
||||
return result
|
||||
|
||||
def take(self, _index: int) -> 'QueryableABC':
|
||||
r"""Takes all elements from index
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
@abstractmethod
|
||||
def take_last(self, index: int) -> 'QueryableABC':
|
||||
return type(self)(self._type, self[:_index])
|
||||
|
||||
def take_last(self, _index: int) -> 'QueryableABC':
|
||||
r"""Takes all elements after index
|
||||
|
||||
Parameter
|
||||
---------
|
||||
index: :class:`int`
|
||||
_index: :class:`int`
|
||||
index
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
index = len(self) - _index
|
||||
|
||||
if index >= len(self) or index < 0:
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return type(self)(self._type, self[index:])
|
||||
|
||||
@abstractmethod
|
||||
def where(self, _func: Callable = None) -> 'QueryableABC':
|
||||
r"""Select element by function
|
||||
|
||||
@@ -388,4 +520,15 @@ class QueryableABC(ABC):
|
||||
-------
|
||||
:class: `cpl_query.base.queryable_abc.QueryableABC`
|
||||
"""
|
||||
pass
|
||||
if _func is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.func)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = []
|
||||
for element in self:
|
||||
if _func(element):
|
||||
result.append(element)
|
||||
|
||||
return type(self)(self.type, result)
|
||||
|
116
src/cpl_query/base/sequence_abc.py
Normal file
116
src/cpl_query/base/sequence_abc.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from itertools import islice
|
||||
|
||||
from cpl_query.base.sequence_values import SequenceValues
|
||||
|
||||
|
||||
class SequenceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, t: type = None, values: list = None):
|
||||
ABC.__init__(self)
|
||||
if values is None:
|
||||
values = []
|
||||
|
||||
if t is None and len(values) > 0:
|
||||
t = type(values[0])
|
||||
|
||||
if t is None:
|
||||
t = any
|
||||
|
||||
self._type = t
|
||||
self._set_values(values)
|
||||
|
||||
@classmethod
|
||||
def __class_getitem__(cls, _t: type):
|
||||
return _t
|
||||
|
||||
def __len__(self):
|
||||
return len(self._values)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._values)
|
||||
|
||||
def next(self):
|
||||
return next(self._values)
|
||||
|
||||
def __next__(self):
|
||||
return self.next()
|
||||
|
||||
def __getitem__(self, n):
|
||||
values = [x for x in self]
|
||||
if isinstance(n, slice):
|
||||
try:
|
||||
return values[n]
|
||||
except Exception as e:
|
||||
raise e
|
||||
|
||||
for i in range(len(values)):
|
||||
if i == n:
|
||||
return values[i]
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {list(self).__repr__()}>'
|
||||
|
||||
@property
|
||||
def type(self) -> type:
|
||||
return self._type
|
||||
|
||||
def _check_type(self, __object: any):
|
||||
if self._type == any:
|
||||
return
|
||||
|
||||
if self._type is not None and type(__object) != self._type and not isinstance(type(__object), self._type) and not issubclass(type(__object), self._type):
|
||||
raise Exception(f'Unexpected type: {type(__object)}\nExpected type: {self._type}')
|
||||
|
||||
def _set_values(self, values: list):
|
||||
self._values = SequenceValues(values, self._type)
|
||||
|
||||
def to_list(self) -> list:
|
||||
r"""Converts :class: `cpl_query.base.sequence_abc.SequenceABC` to :class: `list`
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `list`
|
||||
"""
|
||||
return [x for x in self]
|
||||
|
||||
def copy(self) -> 'SequenceABC':
|
||||
r"""Creates a copy of sequence
|
||||
|
||||
Returns
|
||||
-------
|
||||
SequenceABC
|
||||
"""
|
||||
return type(self)(self._type, self.to_list())
|
||||
|
||||
@classmethod
|
||||
def empty(cls) -> 'SequenceABC':
|
||||
r"""Returns an empty sequence
|
||||
|
||||
Returns
|
||||
-------
|
||||
Sequence object that contains no elements
|
||||
"""
|
||||
return cls()
|
||||
|
||||
def index(self, _object: object) -> int:
|
||||
r"""Returns the index of given element
|
||||
|
||||
Returns
|
||||
-------
|
||||
Index of object
|
||||
|
||||
Raises
|
||||
-------
|
||||
IndexError if object not in sequence
|
||||
"""
|
||||
for i, o in enumerate(self):
|
||||
if o == _object:
|
||||
return i
|
||||
|
||||
raise IndexError
|
||||
|
||||
@classmethod
|
||||
def range(cls, start: int, length: int) -> 'SequenceABC':
|
||||
return cls(int, list(range(start, length)))
|
@@ -5,15 +5,13 @@ from cpl_query.exceptions import IndexOutOfRangeException
|
||||
|
||||
|
||||
class SequenceValues:
|
||||
def __init__(self, data, _t: type):
|
||||
if data is None:
|
||||
data = []
|
||||
|
||||
def __init__(self, data: list, _t: type):
|
||||
if len(data) > 0:
|
||||
def type_check(_t: type, _l: list):
|
||||
return all(isinstance(x, _t) for x in _l)
|
||||
return all([_t == any or isinstance(x, _t) for x in _l])
|
||||
|
||||
if not type_check(_t, data):
|
||||
print([type(x) for x in data])
|
||||
raise Exception(f'Unexpected type\nExpected type: {_t}')
|
||||
|
||||
if not hasattr(data, '__iter__'):
|
||||
@@ -30,7 +28,7 @@ class SequenceValues:
|
||||
|
||||
def __iter__(self):
|
||||
i = 0
|
||||
while i < len(self):
|
||||
while i < self._len():
|
||||
yield next(self._cycle)
|
||||
i += 1
|
||||
|
||||
|
@@ -3,8 +3,8 @@
|
||||
"Name": "cpl-query",
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "10",
|
||||
"Micro": "9"
|
||||
"Minor": "12",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_query.enumerable'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.10.9'
|
||||
__version__ = '2022.12.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,8 +23,6 @@ from collections import namedtuple
|
||||
# imports:
|
||||
from .enumerable import Enumerable
|
||||
from .enumerable_abc import EnumerableABC
|
||||
from .ordered_enumerable import OrderedEnumerable
|
||||
from .ordered_enumerable_abc import OrderedEnumerableABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='10', micro='9')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='0')
|
||||
|
@@ -1,9 +1,4 @@
|
||||
from typing import Union, Callable, Optional
|
||||
|
||||
from cpl_query._helper import is_number
|
||||
from cpl_query.enumerable.enumerable_abc import EnumerableABC
|
||||
from cpl_query.enumerable.ordered_enumerable_abc import OrderedEnumerableABC
|
||||
from cpl_query.exceptions import ArgumentNoneException, ExceptionArgument, InvalidTypeException, IndexOutOfRangeException
|
||||
|
||||
|
||||
def _default_lambda(x: object):
|
||||
@@ -14,306 +9,5 @@ class Enumerable(EnumerableABC):
|
||||
r"""Implementation of :class: `cpl_query.enumerable.enumerable_abc.EnumerableABC`
|
||||
"""
|
||||
|
||||
def __init__(self, t: type = None, values: Union[list, iter] = None):
|
||||
def __init__(self, t: type = None, values: list = None):
|
||||
EnumerableABC.__init__(self, t, values)
|
||||
|
||||
def all(self, _func: Callable = None) -> bool:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = self.where(_func)
|
||||
return len(result) == len(self)
|
||||
|
||||
def any(self, _func: Callable = None) -> bool:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = self.where(_func)
|
||||
return len(result) > 0
|
||||
|
||||
def average(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return float(self.sum(_func)) / float(self.count())
|
||||
|
||||
def contains(self, _value: object) -> bool:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _value is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.value)
|
||||
|
||||
return self.where(lambda x: x == _value).count() > 0
|
||||
|
||||
def count(self, _func: Callable = None) -> int:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
return len(self)
|
||||
|
||||
return len(self.where(_func))
|
||||
|
||||
def distinct(self, _func: Callable = None) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
result = Enumerable()
|
||||
known_values = []
|
||||
for element in self:
|
||||
value = _func(element)
|
||||
if value in known_values:
|
||||
continue
|
||||
|
||||
known_values.append(value)
|
||||
result.add(element)
|
||||
|
||||
return result
|
||||
|
||||
def element_at(self, _index: int) -> any:
|
||||
self._values.reset()
|
||||
while _index >= 0:
|
||||
current = self.next()
|
||||
if _index == 0:
|
||||
return current
|
||||
_index -= 1
|
||||
|
||||
def element_at_or_default(self, _index: int) -> any:
|
||||
try:
|
||||
return self.element_at(_index)
|
||||
except IndexOutOfRangeException:
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def empty() -> 'EnumerableABC':
|
||||
r"""Returns an empty enumerable
|
||||
|
||||
Returns
|
||||
-------
|
||||
Enumerable object that contains no elements
|
||||
"""
|
||||
return Enumerable()
|
||||
|
||||
def first(self: EnumerableABC, _func=None) -> any:
|
||||
if _func is not None:
|
||||
return self.where(_func).element_at(0)
|
||||
return self.element_at(0)
|
||||
|
||||
def first_or_default(self: EnumerableABC, _func=None) -> Optional[any]:
|
||||
if _func is not None:
|
||||
return self.where(_func).element_at_or_default(0)
|
||||
return self.element_at_or_default(0)
|
||||
|
||||
def for_each(self, _func: Callable = None):
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
for element in self:
|
||||
_func(element)
|
||||
|
||||
def last(self: EnumerableABC) -> any:
|
||||
return self.element_at(self.count() - 1)
|
||||
|
||||
def last_or_default(self: EnumerableABC) -> Optional[any]:
|
||||
return self.element_at_or_default(self.count() - 1)
|
||||
|
||||
def max(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return _func(max(self, key=_func))
|
||||
|
||||
def median(self, _func=None) -> Union[int, float]:
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
result = self.order_by(_func).select(_func).to_list()
|
||||
length = len(result)
|
||||
i = int(length / 2)
|
||||
return (
|
||||
result[i]
|
||||
if length % 2 == 1
|
||||
else (float(result[i - 1]) + float(result[i])) / float(2)
|
||||
)
|
||||
|
||||
def min(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return _func(min(self, key=_func))
|
||||
|
||||
def order_by(self, _func: Callable = None) -> OrderedEnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
from cpl_query.enumerable.ordered_enumerable import OrderedEnumerable
|
||||
return OrderedEnumerable(self.type, _func, sorted(self, key=_func))
|
||||
|
||||
def order_by_descending(self, _func: Callable = None) -> OrderedEnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
from cpl_query.enumerable.ordered_enumerable import OrderedEnumerable
|
||||
return OrderedEnumerable(self.type, _func, sorted(self, key=_func, reverse=True))
|
||||
|
||||
@staticmethod
|
||||
def range(start: int, length: int) -> 'EnumerableABC':
|
||||
return Enumerable(int, range(start, length))
|
||||
|
||||
def reverse(self: EnumerableABC) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
return Enumerable(self.type, list(reversed(self.to_list())))
|
||||
|
||||
def select(self, _func: Callable = None) -> EnumerableABC:
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
_l = [_func(_o) for _o in self]
|
||||
return Enumerable(self._type if len(_l) < 1 else type(_l[0]), _l)
|
||||
|
||||
def select_many(self, _func: Callable = None) -> EnumerableABC:
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
# The line below is pain. I don't understand anything of the list comprehension...
|
||||
# written on 09.11.2022 by Sven Heidemann
|
||||
_l = [_a for _o in self for _a in _func(_o)]
|
||||
return Enumerable(self._type if len(_l) < 1 else type(_l[0]), _l)
|
||||
|
||||
def single(self: EnumerableABC) -> any:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if len(self) > 1:
|
||||
raise IndexError('Found more than one element')
|
||||
elif len(self) == 0:
|
||||
raise IndexOutOfRangeException(f'{type(self).__name__} is empty')
|
||||
|
||||
return self.element_at(0)
|
||||
|
||||
def single_or_default(self: EnumerableABC) -> Optional[any]:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if len(self) > 1:
|
||||
raise IndexError('Found more than one element')
|
||||
elif len(self) == 0:
|
||||
return None
|
||||
|
||||
return self.element_at(0)
|
||||
|
||||
def skip(self, _index: int) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
_list = self.to_list()
|
||||
|
||||
if _index >= len(_list):
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return Enumerable(self.type, _list[_index:])
|
||||
|
||||
def skip_last(self, _index: int) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
index = len(self) - _index
|
||||
|
||||
if index >= len(self) or index < 0:
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return self.take(len(self) - _index)
|
||||
|
||||
def take(self, _index: int) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
_list = self.to_list()
|
||||
|
||||
if _index >= len(_list):
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return Enumerable(self.type, _list[:_index])
|
||||
|
||||
def take_last(self, _index: int) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _index is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.index)
|
||||
|
||||
_list = self.to_list()
|
||||
index = len(_list) - _index
|
||||
|
||||
if index >= len(_list) or index < 0:
|
||||
raise IndexOutOfRangeException()
|
||||
|
||||
return self.skip(index)
|
||||
|
||||
def sum(self, _func: Callable = None) -> Union[int, float, complex]:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None and not is_number(self.type):
|
||||
raise InvalidTypeException()
|
||||
|
||||
if _func is None:
|
||||
_func = _default_lambda
|
||||
|
||||
return sum([_func(x) for x in self])
|
||||
|
||||
def where(self, _func: Callable = None) -> EnumerableABC:
|
||||
if self is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.list)
|
||||
|
||||
if _func is None:
|
||||
raise ArgumentNoneException(ExceptionArgument.func)
|
||||
|
||||
return Enumerable(self.type, list(filter(_func, self._values)))
|
||||
|
@@ -1,8 +1,6 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Iterable
|
||||
|
||||
from cpl_query.base.queryable_abc import QueryableABC
|
||||
from cpl_query.base.sequence_values import SequenceValues
|
||||
|
||||
|
||||
class EnumerableABC(QueryableABC):
|
||||
@@ -11,81 +9,15 @@ class EnumerableABC(QueryableABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, t: type = None, values: list = None):
|
||||
if t == any or t is None and values is not None:
|
||||
t = type(values[0])
|
||||
QueryableABC.__init__(self, t, values)
|
||||
|
||||
self._type, self._values, self._remove_error_check = t, SequenceValues(values, t), True
|
||||
|
||||
def __len__(self):
|
||||
return len(self._values)
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self._values)
|
||||
|
||||
def next(self):
|
||||
return next(self._values)
|
||||
|
||||
def __next__(self):
|
||||
return self.next()
|
||||
|
||||
def __repr__(self):
|
||||
return f'<{type(self).__name__} {list(self).__repr__()}>'
|
||||
|
||||
@property
|
||||
def type(self) -> type:
|
||||
return self._type
|
||||
self._remove_error_check = True
|
||||
|
||||
def set_remove_error_check(self, _value: bool):
|
||||
r"""Set flag to check if element exists before removing
|
||||
"""
|
||||
self._remove_error_check = _value
|
||||
|
||||
def add(self, __object: object) -> None:
|
||||
r"""Adds an element to the enumerable.
|
||||
"""
|
||||
if self._type is not None and type(__object) != self._type and not isinstance(type(__object), self._type) and not issubclass(type(__object), self._type):
|
||||
raise Exception(f'Unexpected type: {type(__object)}\nExpected type: {self._type}')
|
||||
|
||||
if len(self) == 0 and self._type is None:
|
||||
self._type = type(__object)
|
||||
|
||||
self._values = SequenceValues([*self._values, __object], self._type)
|
||||
|
||||
def clear(self):
|
||||
r"""Removes all elements
|
||||
"""
|
||||
del self._values
|
||||
self._values = []
|
||||
|
||||
def extend(self, __list: Iterable) -> 'EnumerableABC':
|
||||
r"""Adds elements of given list to enumerable
|
||||
|
||||
Parameter
|
||||
---------
|
||||
__enumerable: :class: `cpl_query.enumerable.enumerable_abc.EnumerableABC`
|
||||
index
|
||||
"""
|
||||
self._values = SequenceValues([*self._values, *__list], self._type)
|
||||
return self
|
||||
|
||||
def remove(self, __object: object) -> None:
|
||||
r"""Removes element from list
|
||||
|
||||
Parameter
|
||||
---------
|
||||
__object: :class:`object`
|
||||
value
|
||||
|
||||
Raises
|
||||
---------
|
||||
`Element not found` when element does not exist. Check can be deactivated by calling <enumerable>.set_remove_error_check(False)
|
||||
"""
|
||||
if self._remove_error_check and __object not in self._values:
|
||||
raise Exception('Element not found')
|
||||
|
||||
# self._values.remove(__object)
|
||||
self._values = SequenceValues([x for x in self.to_list() if x != __object], self._type)
|
||||
|
||||
def to_iterable(self) -> 'IterableABC':
|
||||
r"""Converts :class: `cpl_query.enumerable.enumerable_abc.EnumerableABC` to :class: `cpl_query.iterable.iterable_abc.IterableABC`
|
||||
|
||||
@@ -95,12 +27,3 @@ class EnumerableABC(QueryableABC):
|
||||
"""
|
||||
from cpl_query.iterable.iterable import Iterable
|
||||
return Iterable(self._type, self.to_list())
|
||||
|
||||
def to_list(self) -> list:
|
||||
r"""Converts :class: `cpl_query.base.sequence_abc.SequenceABC` to :class: `list`
|
||||
|
||||
Returns
|
||||
-------
|
||||
:class: `list`
|
||||
"""
|
||||
return [x for x in self]
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user