Compare commits
749 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b6cf5962aa | |||
| d3084041a9 | |||
| c1e65bf0dc | |||
| 688381b106 | |||
| c3e3367264 | |||
| c3d51e29fc | |||
| cae2e6d92e | |||
| 347418bdc5 | |||
| 153fc8922e | |||
| cdbfaeb013 | |||
| 4062a6ebe4 | |||
| 46ef6b3938 | |||
| c1b9c0fb4a | |||
| 8ede2998fe | |||
| 41f974fe6e | |||
| e7af5ce322 | |||
| 7881294554 | |||
| b3fd122fcd | |||
| 1dd48899d7 | |||
| f357e97ce5 | |||
| 2d8ecd424a | |||
| affbbc822d | |||
| 43ea732c5f | |||
| 708918464f | |||
| ed2377c288 | |||
| b819eb439c | |||
| b3ed7101fc | |||
| a3504af376 | |||
| 81c2f1cba9 | |||
| bea5b22251 | |||
| e04d0beb68 | |||
| 08ba097aaa | |||
| ea968d94e4 | |||
| 8e12c72b07 | |||
| 8dee4d8f70 | |||
| 315b8e631a | |||
| cbb1860f25 | |||
| 9839bcaa14 | |||
| da54337221 | |||
| a6a1e764d1 | |||
| eb6aa08c10 | |||
| 14a190a67f | |||
| cf5ae89884 | |||
| 558dfb8ced | |||
| 2ec8fc22b3 | |||
| c94700495b | |||
| 69a3bc5e31 | |||
| d189f49418 | |||
| 60fb416b67 | |||
| 792429d19d | |||
| 106975015e | |||
| 1117735f2e | |||
| 0378f8944a | |||
| 75fde0f444 | |||
| 04f610c799 | |||
| 3178b59147 | |||
| 9c7008e179 | |||
| 7ff7dbc56b | |||
| 823d524a81 | |||
| 1b60debba7 | |||
| 3fc713cc8d | |||
| bb26c7e94d | |||
| 52404cf5d3 | |||
| 32223bcfc2 | |||
| 4e2bdb2b59 | |||
| d72514205c | |||
| 9b4afdbe18 | |||
| 6751541269 | |||
| fe9918af16 | |||
| d2c56f1a3f | |||
| 8624549aa6 | |||
| 9a6ce704b7 | |||
| 9af2a1962d | |||
| a8d4a7a362 | |||
| 943f5ad50b | |||
| 4cd8fea07a | |||
| 82b3a22ac8 | |||
| 2c6367a408 | |||
| af94a0c52d | |||
| 9c374f6bb2 | |||
| d0a19458c5 | |||
| 5d6e7677de | |||
| 01309e3124 | |||
| 083e1ce4a1 | |||
| 8c012e5902 | |||
| 5e6d17cc86 | |||
| c4a71de83f | |||
| 01bc746092 | |||
| 87d023ef7f | |||
| 119052f9a2 | |||
| 43710717c9 | |||
| 7bf5e25c5e | |||
| faa030df96 | |||
| b2efe285a9 | |||
| 9e28dce5ce | |||
| 8179508248 | |||
| 2c3664c1b9 | |||
| 269f083662 | |||
| 8b40c65661 | |||
| 7be3cf38dc | |||
| b18a7297a7 | |||
| 7f46fbe87a | |||
| e0ca7c2ae6 | |||
| 6389a940bc | |||
| 48d0daabf5 | |||
| 8fc3c04720 | |||
| 351f953fdb | |||
| e1560dfab5 | |||
| c9bc6a026a | |||
| 83f0e8bd42 | |||
| 7af83b49a5 | |||
| 59263ece6e | |||
| a507ed9f46 | |||
| 6b451142e2 | |||
| 12beea05a7 | |||
| 713fa5243c | |||
| d600852bec | |||
| c09f2f8e83 | |||
| 2fb515195c | |||
| 889f51f5c5 | |||
| 742ba8314a | |||
| b95d90a191 | |||
| 46fa49a102 | |||
| d5e89d6e2a | |||
| 086fc75fec | |||
| 05c33990bb | |||
| cbae40ef4d | |||
| 002ba6b4e0 | |||
| 85f75b4677 | |||
| 95d8df5bea | |||
| ac1cd9bdde | |||
| 2d9bb79af7 | |||
| 120c9e6800 | |||
| 6f3099a8db | |||
| e46711dc54 | |||
| 59920c59e0 | |||
| 604bb8f55c | |||
| 2f8dc63cdc | |||
| 4fbb3ec838 | |||
| 6818fe9a5c | |||
| 3854fa5aa6 | |||
| 1ca459e67a | |||
| fe8ffb2839 | |||
| 42fb88c35d | |||
| db7a0786a9 | |||
| f9f2612356 | |||
| df81bb599f | |||
| 6d2492c1cf | |||
| e244535557 | |||
| 5f10603fe5 | |||
| 6b8491eea2 | |||
| b63bf41294 | |||
| f6cc3a7ddf | |||
| d1c93abe2c | |||
| d6e3b37f7f | |||
| 9840779af4 | |||
| b893ec1fcf | |||
| d5e5bfe69d | |||
| 4afe5c4581 | |||
| e054ac364e | |||
| 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 | |||
| c7e2f8609c | |||
| 9d2321cc9c | |||
| 61d9912950 | |||
| f23d32a92a | |||
| dc489cbf7a | |||
| 41d24aae99 | |||
| 6b50bba139 | |||
| 139422fd32 | |||
| 409e11df42 | |||
| f3a11f9791 | |||
| 8dcc5b4011 | |||
| d0f65834f1 | |||
| 47ed0a705d | |||
| ae3192b63c | |||
| bb461f5fba | |||
| 52069b7bb3 | |||
| f0ed0bd2e1 | |||
| e868a120f0 | |||
| 70652aeb4c | |||
| 28adcc4e49 | |||
| affbb1ee7b | |||
| d8a4210c9b | |||
| b16d555e33 | |||
| 4380142ccd | |||
| 91f2d6cb21 | |||
| 249b071ee9 | |||
| 53fe437100 | |||
| fc63f3616e | |||
| a528511732 | |||
| dbe1d37046 | |||
| 988965ed52 | |||
| 3c5ca594d5 | |||
| 452b30c899 | |||
| 85c5b26fdf | |||
| 92ed684866 | |||
| 88e83db330 | |||
| 55609fc691 | |||
| e0d89f967f | |||
| b2ce8a6924 | |||
| 71efbd1b42 | |||
| e36939a108 | |||
| 721461fc1b | |||
| 72ee59b2b4 | |||
| 95159da0fc | |||
| 330d702347 | |||
| cbf669d3bd | |||
| 7498fe3255 | |||
| 880998e8ca | |||
| ecc9657eaa | |||
| 125f65cf1b | |||
| 1cd9c7d669 | |||
| 5165f31066 | |||
| 10d33e5d1d | |||
| fb35e8b8b2 | |||
| 4402bcce73 | |||
| 8839b26f00 | |||
| a79358725c | |||
| 2ab1576230 | |||
| c0be380f69 | |||
| c0ae0c8389 | |||
| 4a766e8284 | |||
| 2772ea8df2 | |||
| a604f0e821 | |||
| 6995b25518 | |||
| e4f843829f | |||
| 39b6ca790c | |||
| 4c8d7a8031 | |||
| 6d75bc433e | |||
| 8bb7fbd1c4 | |||
| ad03e655e9 | |||
| 61d3974a47 | |||
| 3d852c87e2 | |||
| 0e46528f32 | |||
| bb8fa1f6a8 | |||
| 9fdaa810c0 | |||
| 4083ac0c14 | |||
| b9e0b7ccd0 | |||
| 4b9e428abb | |||
| 63ad13e09a | |||
| cc06a308a1 | |||
| e9fdd20181 | |||
| 8692686cb5 | |||
| db29ad36fe | |||
| 0710b25317 | |||
| cbd2964f42 | |||
| f51118f13c | |||
| 323e363b42 | |||
| e8a4fe6142 | |||
| 587d9b359c | |||
| c2632253ac | |||
| 45be77dd10 | |||
| 78ffbcc33d | |||
| d83d1a244e | |||
| fa002a50ac | |||
| 32507afae9 | |||
| 6de3bbdaf4 | |||
| 6e50d0cb22 | |||
| 9e978f3ece | |||
| 32478926c8 | |||
| 2925788d01 | |||
| c0789cf4f7 | |||
| 89d591ce0a | |||
| 77c560b40c | |||
| dad4913bcd | |||
| 9b56650d4b | |||
| 9fca2018e5 | |||
| e5dd890931 | |||
| beadbf8e91 | |||
| ff5f9b833d | |||
| 162f06001a | |||
| 348fad24c7 | |||
| f9748cdb76 | |||
| 56380763a9 | |||
| 3a1630b687 | |||
| a593f34cde | |||
| 49cce5fa1a | |||
| df7bd06629 | |||
| e0da77fd4b | |||
| 833dd83008 | |||
| ce0ad4013f | |||
| 698f80adfe | |||
| d0b0f4bfcb | |||
| d23ea86ccf | |||
| 15d938b172 | |||
| 6c1d7a3b29 | |||
| c28f551682 | |||
| def92c78c8 | |||
| ddff9dec11 | |||
| 9e0e85d646 | |||
| b05ca7e980 | |||
| 8f8a9f7dd7 | |||
| df32978a31 | |||
| 79b51cf8c5 | |||
| a72dd0dc2e | |||
| d937c4c0e6 | |||
| 46cceb0910 | |||
| e74e39c189 | |||
| c2706c7737 | |||
| d0e66d24bd | |||
| c1a1849ad2 | |||
| 0675105731 | |||
| 7ee0b951a8 | |||
| d8168f024c | |||
| 2654dc7c69 | |||
| 4224960837 | |||
| 907c3a8fff | |||
| 28505479ba | |||
| 84d3abce3f | |||
| 9050dffc53 | |||
| e0f69c9bdf | |||
| bbd0a60f98 | |||
| e23f4187fe | |||
| 15f200df3a | |||
| a1a3ad6fb5 | |||
| d6677d53a3 | |||
| 07e43b50d1 | |||
| ac83555b24 | |||
| 1ab358059c | |||
| 5bf83c0d77 | |||
| 03ac00c6e3 | |||
| 0122d8fc78 | |||
| a66ce96dbf | |||
| 6da8e30446 | |||
| 539ed13be4 | |||
| 036a553f64 | |||
| 976a14584b | |||
| ed69f52927 | |||
| 98847495e6 | |||
| 40f132da33 | |||
| 5feb44595a | |||
| 48c6941f1a | |||
| a8756d493a | |||
| 9f4077a073 | |||
| 3e7a3d75c5 | |||
| 477d2d87d3 | |||
| 7a65dbe39b | |||
| f83755ac77 | |||
| a590cfd066 | |||
| f317035342 | |||
| 8900bdd446 | |||
| 35ecf158a2 | |||
| 353c1d30ec | |||
| 1c94fb5bd1 | |||
| cf305aeebb | |||
| 90e97433e0 | |||
| 125a85a0af | |||
| cfb8838c73 | |||
| 824d491ebc | |||
| d694c408c0 | |||
| d1bb266d49 | |||
| 419fcc3d29 | |||
| 24ab6a51c1 | |||
| dec4a45d98 | |||
| d11c56db03 | |||
| fc23315cc7 | |||
| 1f503fe20d | |||
| 4564f7ac0e | |||
| 7b823e1141 | |||
| dac3d9c6bb | |||
| ccca904cb8 | |||
| c66a81c0ec | |||
| fb810e2943 | |||
| 5cc663dedc | |||
| 593372699b | |||
| 1899cb5b86 | |||
| 0a285f2d28 | |||
| 94c82e6701 | |||
| 0d37c86061 | |||
| 6c8e9ccd89 | |||
| e7cf545502 | |||
| 44182eec86 | |||
| 0f5b1b7586 | |||
| 4fe073580a | |||
| 2fed654c16 | |||
| 8ebd4864d3 | |||
| a495532a4d | |||
| d87ce72f07 | |||
| 50201346e2 | |||
| 773b154371 | |||
| 5b59d1d384 | |||
| dcd8583183 | |||
| 97e52b39c0 | |||
| 581013b61a | |||
| fd68d25a1d | |||
| 588f93f7b1 | |||
| 96f402dcdd | |||
| c1b7fca8d5 | |||
| 2e4e7ccc57 | |||
| ada3d133df | |||
| 61e7b9d684 | |||
| 24172c658c | |||
| 62ac976b99 | |||
| 1f445a99b2 | |||
| 025286052b | |||
| 32a856f8e8 | |||
| 21f50f3b24 | |||
| ce77d41246 | |||
| dec137220c | |||
| 01c7e155c3 | |||
| dcbcb67ce8 | |||
| d57fd10718 | |||
| 2b91db5d81 | |||
| dffa3de1ec | |||
| 403837901b | |||
| 0de725c907 | |||
| e811e08c52 | |||
| 6518ae7516 | |||
| 95b5f99f1f | |||
| de22e79b71 | |||
| 127c67e566 | |||
| 3523dbd5c5 | |||
| b526a07e19 | |||
| d9f10edbb7 | |||
| 7616cd4c69 | |||
| afe75f6848 | |||
| c0e2db8281 | |||
| 3727af11c4 | |||
| 450295cfcf | |||
| 457bce8aa9 | |||
| 0f81497ea3 | |||
| fa7ee800e1 | |||
| 56b7452e55 | |||
| 9d73566453 | |||
| 28ba0c174a | |||
| 5d0444bcc0 | |||
| 40876005d5 | |||
| ac6d941822 | |||
| 113b365a47 | |||
| 2f785536e1 | |||
| 9ab4013b4b | |||
| b3b04f03ce | |||
| 57040f85f0 | |||
| 589ef4fd4c | |||
| 4b829cc484 | |||
| 98e343a108 | |||
| 7749d5a789 | |||
| c3b48bfa41 | |||
| 470e7ab2f4 | |||
| 4ceea36926 | |||
| b3f8174663 | |||
| 58dccea28b | |||
| ca086e01d7 | |||
| c5b1a95661 | |||
| d7881774a8 | |||
| 6eec92243e | |||
| 124b236182 | |||
| 2dc96cdf3d | |||
| 6f7923debc | |||
| 90d148b4a5 | |||
| 73e2c5ec10 | |||
| f31522dcd9 | |||
| a83607fd81 | |||
| 707df3f27d | |||
| 0f43e57831 | |||
| c08ab33060 | |||
| ee2abd98b3 | |||
| e39661a42a | |||
| 9518d19580 | |||
| adf95faaf8 | |||
| 2f92e9909d | |||
| b18f2c4bcd | |||
| 784ba049ad | |||
| 4d6d19d2e5 | |||
| 6fa47f19af | |||
| fb2872422e | |||
| 8460c0fa33 | |||
| 18f95341f4 | |||
| a8011267d9 | |||
| f8ebb4f1d7 | |||
| 3903f85368 | |||
| 05a9bdbf4a | |||
| 2809a9cd82 | |||
| 1c6794dc40 | |||
| cac80657df | |||
| 11241d8f99 | |||
| 308e5c9b0c | |||
| c12ff4f9e3 | |||
| 091c89df2c | |||
| 63a67be0ee | |||
| c68224b31a | |||
| 9f219757c3 | |||
| e09a4402b3 | |||
| 6867eb0e65 | |||
| ffaa5c4a2b | |||
| b9499108d8 | |||
| 37175b7227 | |||
| 2b5831c5fe | |||
| 62c8b9c68d | |||
| a080119c44 | |||
| a26c6f1bd9 | |||
| daac14e099 | |||
| d4b5c32a21 | |||
| c115afd736 | |||
| e7863a92e0 | |||
| 82a9e3a23a | |||
| a3a0a150a8 | |||
| 6951a19670 | |||
| 669133d491 | |||
| c60598b3f6 | |||
| 45733b30ef | |||
| f8bd86692e | |||
| 5e5d86cf94 | |||
| e0b7728719 | |||
| 0f85d4b9bc | |||
| a3fff9c7d7 | |||
| 8dcf3a6768 | |||
| 94949394de | |||
| b7be439381 | |||
| 0cae3428b9 | |||
| cc7755bafc | |||
| 4e78b9c12b | |||
| 5c80cf2222 | |||
| d02548e1a8 | |||
| 51efe973e8 | |||
| 0bb272d89b | |||
| 59f6843ea9 | |||
| be6838f97b | |||
| d5b2d3605b | |||
| 7a48917fb4 | |||
| 59832742b6 | |||
| f9f04901c0 | |||
| 593ffbb068 | |||
| 3d35f2ac63 | |||
| 5bfba581cb | |||
| 8fb570468c | |||
| 128fda60b0 | |||
| ab539c15dd | |||
| b931ba6e17 | |||
| f611aa73db | |||
| 69f697e36f | |||
| 654fb69295 | |||
| 850d44a105 | |||
| 8d4597705d | |||
| fa5655414a | |||
| 6fc4cebbfe | |||
| 89f3c5833f | |||
| adf9a33e83 | |||
| 4adf6bc834 | |||
| 9026f021ed | |||
| e562c31033 | |||
| 7b90b5af57 | |||
| cda1fabd4f | |||
| 4209055d62 | |||
| ed1a4eb88c | |||
| 478f1ad0ff | |||
| 80eb1da0e1 | |||
| ae39d43ea9 | |||
| 602c48bc06 | |||
| d34d501520 | |||
| 8f3ee53915 | |||
| 7eca382cb3 | |||
| f8f5d46491 | |||
| 696c62292b | |||
| d94b25d9d8 | |||
| 93829027af | |||
| cce4b6b191 | |||
| 0876f06282 | |||
| c970412a66 | |||
| 6af9328e14 | |||
| 5987b71c80 | |||
| 79fdc0c60b | |||
| cfb6a84799 | |||
| faa7e701fd | |||
| d5b8286f68 | |||
| a3d5737eaf | |||
| 314bb1b722 | |||
| 1c353bbcdf | |||
| 036b9dcc2d | |||
| 0fec5719bc | |||
| 3572081e43 | |||
| 8cf7f494b3 | |||
| b1165e169a | |||
| 284ebe1b11 | |||
| d51659db3e | |||
| 3aa3a874c9 | |||
| 113d3199b1 | |||
| 5712a9ad67 | |||
| 1f8d420749 | |||
| 9065ef901c | |||
| b2c5d304f8 | |||
| 70ae7dd9e6 | |||
| 94b122d677 | |||
| f6fc5d09e7 | |||
| 2b5c75cc67 | |||
| 167f813bcf | |||
| 7b9765e5b1 | |||
| 7ad01d4bdd | |||
| d19c47e571 | |||
| 4bfc647b91 | |||
| 98117ed7ad | |||
| cc9b25356c | |||
| a95d6e7f8a | |||
| fe5c41ac09 | |||
| b672174960 | |||
| a8691ced5b | |||
| fc53f90ecd | |||
| 0f836b5c7d | |||
| 34ed7123d1 | |||
| 5f668e17c9 | |||
| 806888bf49 | |||
| e8756a09ca | |||
| e38988be1b | |||
| 4009c93353 | |||
| 3ba5c10fad | |||
| 2552f1d43c | |||
| 5be2e83798 | |||
| d4919e027c | |||
| 7ef238b64d | |||
| 703d20f43f | |||
| d9bd7911ef | |||
| 6a5c832288 | |||
| dc849c4f71 | |||
| 76a6ba11fb | |||
| 305a19730f | |||
| de15e81703 | |||
| b91544a0da | |||
| caca34168e | |||
| 18b8ac589d | |||
| d85e628784 | |||
| 1e150cf10c | |||
| 9b0f0b7559 | |||
| cc118b5030 | |||
| 3e7ff78861 | |||
| 448d538d21 | |||
| d368161eb3 | |||
| eef8488ca2 | |||
| b22d04b145 | |||
| 6579e54c2b | |||
| 88c0153ca2 | |||
| f28c6ab309 | |||
| 976041f812 | |||
| 7693dd462f | |||
| df5e61cf98 | |||
| df87d08be3 | |||
| 33cb35e26f | |||
| 18b2cd8f2f | |||
| 7ab2a881e8 | |||
| 960de880ee | |||
| c0d8904782 | |||
| b6d508526a | |||
| 31307485f0 | |||
| 612c3583f1 | |||
| 6cdd3376f1 | |||
| b947789779 | |||
| 0da83935fc | |||
| 3428c70b69 | |||
| 3d511ff727 | |||
| cf2f293290 | |||
| c39601a35d | |||
| 5f36e0a43e | |||
| 31fe1c5cd7 | |||
| 0cdecd893a | |||
| 260fe06be8 | |||
| 8ddfd35a82 | |||
| 099bae3d7c | |||
| 9758e1fae2 | |||
| 211143d6ab | |||
| 70b49a098a | |||
| e2544f90fe | |||
| c223524d1b | |||
| 1789e2671a | |||
| d0812bcf5c | |||
| 4d5368e5fc | |||
| f3be927440 | |||
| d0e3e1792f | |||
| 31793fb290 | |||
| 41ddc86961 | |||
| 30ef74dd18 | |||
| bc69476bb2 | |||
| 05b9fd801b | |||
| 7af7f866c1 | |||
| 069e44bee6 | |||
| 3c0dd00a99 | |||
| afb91c8f1f | |||
| ca51f88d2b | |||
| a683b70c5f | |||
| c650e87443 | |||
| 36dfedf918 | |||
| 252f2b55fe | |||
| 99091a2540 | |||
| c3fdb7a049 |
9
.gitignore
vendored
9
.gitignore
vendored
@@ -106,10 +106,14 @@ celerybeat.pid
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
venv_*/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Custom Environments
|
||||
cpl-env/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
@@ -129,5 +133,8 @@ dmypy.json
|
||||
.pyre/
|
||||
|
||||
# IDE
|
||||
.vscode/
|
||||
.idea/
|
||||
PythonImportHelper-v2-Completion.json
|
||||
|
||||
# cpl unittest stuff
|
||||
unittests/test_*_playground
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
MIT License Copyright (c) <year> <copyright holders>
|
||||
MIT License Copyright (c) 2020 - 2023 sh-edraft.de
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
153
README.md
153
README.md
@@ -1,2 +1,153 @@
|
||||
# sh_common_py_lib
|
||||
<h1 align="center">CPL - Common python library</h1>
|
||||
|
||||
<!-- Summary -->
|
||||
<p align="center">
|
||||
<!-- <img src="" alt="cpl-logo" width="120px" height="120px"/> -->
|
||||
<br>
|
||||
<i>
|
||||
CPL is a development platform for python server applications
|
||||
<br>using Python.</i>
|
||||
<br>
|
||||
</p>
|
||||
|
||||
## Table of Contents
|
||||
<!-- TABLE OF CONTENTS -->
|
||||
<ol>
|
||||
<li><a href="#Features">Features</a></li>
|
||||
<li>
|
||||
<a href="#getting-started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#prerequisites">Prerequisites</a></li>
|
||||
<li><a href="#installation">Installation</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#roadmap">Roadmap</a></li>
|
||||
<li><a href="#contributing">Contributing</a></li>
|
||||
<li><a href="#license">License</a></li>
|
||||
<li><a href="#contact">Contact</a></li>
|
||||
</ol>
|
||||
|
||||
## Features
|
||||
<!-- FEATURE OVERVIEW -->
|
||||
- Expandle
|
||||
- Application base
|
||||
- Standardized application classes
|
||||
- Application object builder
|
||||
- Application extension classes
|
||||
- Startup classes
|
||||
- Startup extension classes
|
||||
- Configuration
|
||||
- Configure via object mapped JSON
|
||||
- Console argument handling
|
||||
- Console class for in and output
|
||||
- Banner
|
||||
- Spinner
|
||||
- Options (menu)
|
||||
- Table
|
||||
- Write
|
||||
- Write_at
|
||||
- Write_line
|
||||
- Write_line_at
|
||||
- Dependency injection
|
||||
- Service lifetimes: singleton, scoped and transient
|
||||
- Providing of application environment
|
||||
- Environment (development, staging, testing, production)
|
||||
- Appname
|
||||
- Customer
|
||||
- Hostname
|
||||
- Runtime directory
|
||||
- Working directory
|
||||
- Logging
|
||||
- Standardized logger
|
||||
- Log-level (FATAL, ERROR, WARN, INFO, DEBUG & TRACE)
|
||||
- Mail handling
|
||||
- Send mails
|
||||
- Pipe classes
|
||||
- Convert input
|
||||
- Utils
|
||||
- Credential manager
|
||||
- Encryption via BASE64
|
||||
- PIP wrapper class based on subprocess
|
||||
- Run pip commands
|
||||
- String converter to different variants
|
||||
- to_lower_case
|
||||
- to_camel_case
|
||||
- ...
|
||||
|
||||
<!-- GETTING STARTED -->
|
||||
## Getting Started
|
||||
|
||||
[Get started with CPL][quickstart].
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Install [python] which includes [Pip installs packages][pip]
|
||||
|
||||
### Installation
|
||||
|
||||
Install the CPL package
|
||||
```sh
|
||||
pip install cpl-core --extra-index-url https://pip.sh-edraft.de
|
||||
```
|
||||
|
||||
Install the CPL CLI
|
||||
```sh
|
||||
pip install cpl-cli --extra-index-url https://pip.sh-edraft.de
|
||||
```
|
||||
|
||||
Create workspace:
|
||||
```sh
|
||||
cpl new <console|library|unittest> <PROJECT NAME>
|
||||
```
|
||||
|
||||
Run the application:
|
||||
```sh
|
||||
cd <PROJECT NAME>
|
||||
cpl start
|
||||
```
|
||||
|
||||
|
||||
<!-- ROADMAP -->
|
||||
## Roadmap
|
||||
|
||||
See the [open issues](https://git.sh-edraft.de/sh-edraft.de/sh_cpl/issues) for a list of proposed features (and known issues).
|
||||
|
||||
|
||||
|
||||
<!-- CONTRIBUTING -->
|
||||
## Contributing
|
||||
|
||||
### Contributing Guidelines
|
||||
|
||||
Read through our [contributing guidelines][contributing] to learn about our submission process, coding rules and more.
|
||||
|
||||
### Want to Help?
|
||||
|
||||
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for [contributing][contributing].
|
||||
|
||||
|
||||
|
||||
<!-- LICENSE -->
|
||||
## License
|
||||
|
||||
Distributed under the MIT License. See [LICENSE] for more information.
|
||||
|
||||
|
||||
|
||||
<!-- CONTACT -->
|
||||
## Contact
|
||||
|
||||
Sven Heidemann - sven.heidemann@sh-edraft.de
|
||||
|
||||
Project link: [https://git.sh-edraft.de/sh-edraft.de/sh_common_py_lib](https://git.sh-edraft.de/sh-edraft.de/sh_cpl)
|
||||
|
||||
<!-- External LINKS -->
|
||||
[pip_url]: https://pip.sh-edraft.de
|
||||
[python]: https://www.python.org/
|
||||
[pip]: https://pypi.org/project/pip/
|
||||
|
||||
<!-- Internal LINKS -->
|
||||
[project]: https://git.sh-edraft.de/sh-edraft.de/sh_cpl
|
||||
[quickstart]: https://git.sh-edraft.de/sh-edraft.de/sh_cpl/wiki/quickstart
|
||||
[contributing]: https://git.sh-edraft.de/sh-edraft.de/sh_cpl/wiki/contributing
|
||||
[license]: LICENSE
|
||||
|
||||
151
cpl-workspace.json
Normal file
151
cpl-workspace.json
Normal file
@@ -0,0 +1,151 @@
|
||||
{
|
||||
"WorkspaceSettings": {
|
||||
"DefaultProject": "cpl-core",
|
||||
"Projects": {
|
||||
"cpl-cli": "src/cpl_cli/cpl-cli.json",
|
||||
"cpl-core": "src/cpl_core/cpl-core.json",
|
||||
"cpl-discord": "src/cpl_discord/cpl-discord.json",
|
||||
"cpl-query": "src/cpl_query/cpl-query.json",
|
||||
"cpl-translation": "src/cpl_translation/cpl-translation.json",
|
||||
"set-version": "tools/set_version/set-version.json",
|
||||
"set-pip-urls": "tools/set_pip_urls/set-pip-urls.json",
|
||||
"unittests": "unittests/unittests/unittests.json",
|
||||
"unittests_cli": "unittests/unittests_cli/unittests_cli.json",
|
||||
"unittests_core": "unittests/unittests_core/unittests_core.json",
|
||||
"unittests_query": "unittests/unittests_query/unittests_query.json",
|
||||
"unittests_shared": "unittests/unittests_shared/unittests_shared.json",
|
||||
"unittests_translation": "unittests/unittests_translation/unittests_translation.json"
|
||||
},
|
||||
"Scripts": {
|
||||
"hello-world": "echo 'Hello World'",
|
||||
|
||||
"format": "echo 'Formatting:'; black ./",
|
||||
|
||||
"sv": "cpl set-version",
|
||||
"set-version": "cpl run set-version --dev $ARGS; echo '';",
|
||||
|
||||
"spu": "cpl set-pip-urls",
|
||||
"set-pip-urls": "cpl run set-pip-urls --dev $ARGS; echo '';",
|
||||
|
||||
"docs-build": "cpl format; echo 'Build Documentation'; cpl db-core; cpl db-discord; cpl db-query; cpl db-translation; cd docs/; make clean; make html;",
|
||||
"db-core": "cd docs/; sphinx-apidoc -o source/ ../src/cpl_core; cd ../",
|
||||
"db-discord": "cd docs/; sphinx-apidoc -o source/ ../src/cpl_discord; cd ../",
|
||||
"db-query": "cd docs/; sphinx-apidoc -o source/ ../src/cpl_query; cd ../",
|
||||
"db-translation": "cd docs/; sphinx-apidoc -o source/ ../src/cpl_translation; cd ../",
|
||||
"db": "cpl docs-build",
|
||||
|
||||
"docs-open": "xdg-open $PWD/docs/build/html/index.html &",
|
||||
"do": "cpl docs-open",
|
||||
|
||||
"test": "cpl run unittests",
|
||||
|
||||
"pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||
"build-all": "cpl build-cli; cpl build-core; cpl build-discord; cpl build-query; cpl build-translation; cpl build-set-pip-urls; cpl build-set-version",
|
||||
"ba": "cpl build-all $ARGS",
|
||||
"build-cli": "echo 'Build cpl-cli'; cd ./src/cpl_cli; cpl build; cd ../../;",
|
||||
"build-core": "echo 'Build cpl-core'; cd ./src/cpl_core; cpl build; cd ../../;",
|
||||
"build-discord": "echo 'Build cpl-discord'; cd ./src/cpl_discord; cpl build; cd ../../;",
|
||||
"build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;",
|
||||
"build-translation": "echo 'Build cpl-translation'; cd ./src/cpl_translation; cpl build; cd ../../;",
|
||||
"build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;",
|
||||
"build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;",
|
||||
|
||||
"pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||
"publish-all": "cpl publish-cli; cpl publish-core; cpl publish-discord; cpl publish-query; cpl publish-translation;",
|
||||
"pa": "cpl publish-all $ARGS",
|
||||
"publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;",
|
||||
"publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;",
|
||||
"publish-discord": "echo 'Publish cpl-discord'; cd ./src/cpl_discord; cpl publish; cd ../../;",
|
||||
"publish-query": "echo 'Publish cpl-query'; cd ./src/cpl_query; cpl publish; cd ../../;",
|
||||
"publish-translation": "echo 'Publish cpl-translation'; cd ./src/cpl_translation; cpl publish; cd ../../;",
|
||||
|
||||
"upload-prod-cli": "echo 'PROD Upload cpl-cli'; cpl upl-prod-cli;",
|
||||
"upl-prod-cli": "twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
|
||||
"upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;",
|
||||
"upl-prod-core": "twine upload -r pip.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
|
||||
"upload-prod-discord": "echo 'PROD Upload cpl-discord'; cpl upl-prod-discord;",
|
||||
"upl-prod-discord": "twine upload -r pip.sh-edraft.de dist/cpl-discord/publish/setup/*",
|
||||
|
||||
"upload-prod-query": "echo 'PROD Upload cpl-query'; cpl upl-prod-query;",
|
||||
"upl-prod-query": "twine upload -r pip.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"upload-prod-translation": "echo 'PROD Upload cpl-translation'; cpl upl-prod-translation;",
|
||||
"upl-prod-translation": "twine upload -r pip.sh-edraft.de dist/cpl-translation/publish/setup/*",
|
||||
|
||||
"upload-exp-cli": "echo 'EXP Upload cpl-cli'; cpl upl-exp-cli;",
|
||||
"upl-exp-cli": "twine upload -r pip-exp.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
|
||||
"upload-exp-core": "echo 'EXP Upload cpl-core'; cpl upl-exp-core;",
|
||||
"upl-exp-core": "twine upload -r pip-exp.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
|
||||
"upload-exp-discord": "echo 'EXP Upload cpl-discord'; cpl upl-exp-discord;",
|
||||
"upl-exp-discord": "twine upload -r pip-exp.sh-edraft.de dist/cpl-discord/publish/setup/*",
|
||||
|
||||
"upload-exp-query": "echo 'EXP Upload cpl-query'; cpl upl-exp-query;",
|
||||
"upl-exp-query": "twine upload -r pip-exp.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"upload-exp-translation": "echo 'EXP Upload cpl-translation'; cpl upl-exp-translation;",
|
||||
"upl-exp-translation": "twine upload -r pip-exp.sh-edraft.de dist/cpl-translation/publish/setup/*",
|
||||
|
||||
"upload-dev-cli": "echo 'DEV Upload cpl-cli'; cpl upl-dev-cli;",
|
||||
"upl-dev-cli": "twine upload -r pip-dev.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
|
||||
"upload-dev-core": "echo 'DEV Upload cpl-core'; cpl upl-dev-core;",
|
||||
"upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
|
||||
"upload-dev-discord": "echo 'DEV Upload cpl-discord'; cpl upl-dev-discord;",
|
||||
"upl-dev-discord": "twine upload -r pip-dev.sh-edraft.de dist/cpl-discord/publish/setup/*",
|
||||
|
||||
"upload-dev-query": "echo 'DEV Upload cpl-query'; cpl upl-dev-query;",
|
||||
"upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"upload-dev-translation": "echo 'DEV Upload cpl-translation'; cpl upl-dev-translation;",
|
||||
"upl-dev-translation": "twine upload -r pip-dev.sh-edraft.de dist/cpl-translation/publish/setup/*",
|
||||
|
||||
"pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;",
|
||||
"deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-discord; cpl deploy-prod-query; cpl deploy-prod-translation;",
|
||||
"dp": "cpl deploy-prod $ARGS",
|
||||
"deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli",
|
||||
"deploy-prod-core": "cpl publish-core; cpl upload-prod-core",
|
||||
"deploy-prod-query": "cpl publish-query; cpl upload-prod-query",
|
||||
"deploy-prod-discord": "cpl publish-discord; cpl upload-prod-discord",
|
||||
"deploy-prod-translation": "cpl publish-translation; cpl upload-prod-translation",
|
||||
|
||||
"pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;",
|
||||
"deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-discord; cpl deploy-exp-query; cpl deploy-exp-translation;",
|
||||
"de": "cpl deploy-exp $ARGS",
|
||||
"deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli",
|
||||
"deploy-exp-core": "cpl publish-core; cpl upload-exp-core",
|
||||
"deploy-exp-discord": "cpl publish-discord; cpl upload-exp-discord",
|
||||
"deploy-exp-query": "cpl publish-query; cpl upload-exp-query",
|
||||
"deploy-exp-translation": "cpl publish-translation; cpl upload-exp-translation",
|
||||
|
||||
"pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;",
|
||||
"deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-discord; cpl deploy-dev-query; cpl deploy-dev-translation;",
|
||||
"dd": "cpl deploy-dev $ARGS",
|
||||
"deploy-dev-cli": "cpl publish-cli; cpl upload-dev-cli",
|
||||
"deploy-dev-core": "cpl publish-core; cpl upload-dev-core",
|
||||
"deploy-dev-discord": "cpl publish-discord; cpl upload-dev-discord",
|
||||
"deploy-dev-query": "cpl publish-query; cpl upload-dev-query",
|
||||
"deploy-dev-translation": "cpl publish-query; cpl upload-dev-translation",
|
||||
|
||||
"dev-install": "cpl di-core; cpl di-cli; cpl di-query; cpl di-translation;",
|
||||
"di": "cpl dev-install",
|
||||
"di-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"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",
|
||||
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
56
cpl.json
56
cpl.json
@@ -1,56 +0,0 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "sh_cpl",
|
||||
"Version": {
|
||||
"Major": "2021",
|
||||
"Minor": "04",
|
||||
"Micro": "01-15"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Common Python library",
|
||||
"LongDescription": "sh-edraft Common Python library",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2020 - 2021",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"colorama==0.4.4",
|
||||
"mysql-connector==2.2.9",
|
||||
"psutil==5.8.0",
|
||||
"packaging==20.9",
|
||||
"pyfiglet==0.8.post1",
|
||||
"pynput==1.7.3",
|
||||
"SQLAlchemy==1.4.0",
|
||||
"setuptools==54.1.2",
|
||||
"tabulate==0.8.9",
|
||||
"termcolor==1.1.0",
|
||||
"watchdog==2.0.2",
|
||||
"wheel==0.36.2"
|
||||
],
|
||||
"PythonVersion": ">=3.8",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"SourcePath": "src",
|
||||
"OutputPath": "dist",
|
||||
"Main": "cpl_cli.main",
|
||||
"EntryPoint": "cpl",
|
||||
"IncludePackageData": true,
|
||||
"Included": [
|
||||
"*/templates"
|
||||
],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {
|
||||
"cpl_cli": [
|
||||
"*.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
19
docs/cli.txt
19
docs/cli.txt
@@ -1,19 +0,0 @@
|
||||
prefix: cpl
|
||||
commands:
|
||||
build
|
||||
|
||||
generate:
|
||||
abc | a
|
||||
class | c
|
||||
configmodel | cm
|
||||
enum | e
|
||||
service | s
|
||||
|
||||
help
|
||||
new
|
||||
console
|
||||
|
||||
start
|
||||
publish
|
||||
update
|
||||
version
|
||||
@@ -1,2 +0,0 @@
|
||||
python setup.py install # for install
|
||||
python setup.py sdist bdist_wheel # for build
|
||||
11
docs/pip.txt
11
docs/pip.txt
@@ -1,11 +0,0 @@
|
||||
upload:
|
||||
prod:
|
||||
twine upload --repository-url https://pip.sh-edraft.de dist/publish/setup/*
|
||||
twine upload -r pip.sh-edraft.de dist/publish/setup/*
|
||||
|
||||
dev:
|
||||
twine upload --repository-url https://pip-dev.sh-edraft.de dist/publish/setup/*
|
||||
twine upload -r pip-dev.sh-edraft.de dist/publish/setup/*
|
||||
|
||||
install:
|
||||
pip install --extra-index-url https://pip.sh-edraft.de/ sh_cpl
|
||||
2
pyproject.toml
Normal file
2
pyproject.toml
Normal file
@@ -0,0 +1,2 @@
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
@@ -1,25 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_cpl.cpl'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,31 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .application_abc import ApplicationABC
|
||||
from .application_builder import ApplicationBuilder
|
||||
from .application_builder_abc import ApplicationBuilderABC
|
||||
from .application_runtime import ApplicationRuntime
|
||||
from .application_runtime_abc import ApplicationRuntimeABC
|
||||
from .startup_abc import StartupABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,46 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
|
||||
|
||||
class ApplicationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC):
|
||||
"""
|
||||
ABC of application
|
||||
"""
|
||||
self._configuration: Optional[ConfigurationABC] = config
|
||||
self._runtime: Optional[ApplicationRuntimeABC] = runtime
|
||||
self._services: Optional[ServiceProviderABC] = services
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Entry point
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
self.configure()
|
||||
self.main()
|
||||
except KeyboardInterrupt:
|
||||
Console.close()
|
||||
|
||||
@abstractmethod
|
||||
def configure(self):
|
||||
"""
|
||||
Prepare the application
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def main(self):
|
||||
"""
|
||||
Custom entry point
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,42 +0,0 @@
|
||||
from typing import Type, Optional
|
||||
|
||||
from cpl.application.application_abc import ApplicationABC
|
||||
from cpl.application.application_builder_abc import ApplicationBuilderABC
|
||||
from cpl.application.application_runtime import ApplicationRuntime
|
||||
from cpl.application.startup_abc import StartupABC
|
||||
from cpl.configuration import Configuration
|
||||
from cpl.dependency_injection import ServiceProvider
|
||||
|
||||
|
||||
class ApplicationBuilder(ApplicationBuilderABC):
|
||||
|
||||
def __init__(self, app: Type[ApplicationABC]):
|
||||
"""
|
||||
Builder class for application
|
||||
"""
|
||||
ApplicationBuilderABC.__init__(self)
|
||||
self._app = app
|
||||
self._startup: Optional[StartupABC] = None
|
||||
|
||||
self._configuration = Configuration()
|
||||
self._runtime = ApplicationRuntime()
|
||||
self._services = ServiceProvider(self._configuration, self._runtime)
|
||||
|
||||
def use_startup(self, startup: Type[StartupABC]):
|
||||
"""
|
||||
Sets the used startup class
|
||||
:param startup:
|
||||
:return:
|
||||
"""
|
||||
self._startup = startup(self._configuration, self._runtime, self._services)
|
||||
|
||||
def build(self) -> ApplicationABC:
|
||||
"""
|
||||
Creates application host and runtime
|
||||
:return:
|
||||
"""
|
||||
if self._startup is not None:
|
||||
self._startup.configure_configuration()
|
||||
self._startup.configure_services()
|
||||
|
||||
return self._app(self._configuration, self._runtime, self._services)
|
||||
@@ -1,30 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Type
|
||||
|
||||
from cpl.application.application_abc import ApplicationABC
|
||||
from cpl.application.startup_abc import StartupABC
|
||||
|
||||
|
||||
class ApplicationBuilderABC(ABC):
|
||||
|
||||
def __init__(self, *args):
|
||||
"""
|
||||
ABC of application builder
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def use_startup(self, startup: Type[StartupABC]):
|
||||
"""
|
||||
Sets the used startup class
|
||||
:param startup:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def build(self) -> ApplicationABC:
|
||||
"""
|
||||
Creates application host and runtime
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,52 +0,0 @@
|
||||
import pathlib
|
||||
from datetime import datetime
|
||||
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
|
||||
|
||||
class ApplicationRuntime(ApplicationRuntimeABC):
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Representation of the application runtime
|
||||
"""
|
||||
ApplicationRuntimeABC.__init__(self)
|
||||
|
||||
self._start_time: datetime = datetime.now()
|
||||
self._end_time: datetime = datetime.now()
|
||||
self._working_directory = pathlib.Path().absolute()
|
||||
self._runtime_directory = pathlib.Path(__file__).parent.absolute()
|
||||
|
||||
@property
|
||||
def start_time(self) -> datetime:
|
||||
return self._start_time
|
||||
|
||||
@property
|
||||
def end_time(self) -> datetime:
|
||||
return self._end_time
|
||||
|
||||
@end_time.setter
|
||||
def end_time(self, end_time: datetime):
|
||||
self._end_time = end_time
|
||||
|
||||
@property
|
||||
def date_time_now(self) -> datetime:
|
||||
return datetime.now()
|
||||
|
||||
@property
|
||||
def working_directory(self) -> str:
|
||||
return self._working_directory
|
||||
|
||||
def set_working_directory(self, path: str = ''):
|
||||
if path != '':
|
||||
self._working_directory = path
|
||||
return
|
||||
|
||||
self._working_directory = pathlib.Path().absolute()
|
||||
|
||||
@property
|
||||
def runtime_directory(self) -> str:
|
||||
return self._runtime_directory
|
||||
|
||||
def set_runtime_directory(self, file: str):
|
||||
self._runtime_directory = pathlib.Path(file).parent.absolute()
|
||||
@@ -1,49 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class ApplicationRuntimeABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC for application runtime
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def start_time(self) -> datetime: pass
|
||||
|
||||
@start_time.setter
|
||||
@abstractmethod
|
||||
def start_time(self, start_time: datetime): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def end_time(self): pass
|
||||
|
||||
@end_time.setter
|
||||
@abstractmethod
|
||||
def end_time(self, end_time: datetime): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def date_time_now(self) -> datetime: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def working_directory(self) -> str: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def runtime_directory(self) -> str: pass
|
||||
|
||||
@abstractmethod
|
||||
def set_runtime_directory(self, runtime_directory: str):
|
||||
"""
|
||||
Sets the current runtime directory
|
||||
:param runtime_directory:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,29 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
|
||||
|
||||
class StartupABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, *args):
|
||||
"""
|
||||
ABC for a startup class
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def configure_configuration(self) -> ConfigurationABC:
|
||||
"""
|
||||
Creates configuration of application
|
||||
:return: configuration
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def configure_services(self) -> ServiceProviderABC:
|
||||
"""
|
||||
Creates service provider
|
||||
:return: service provider
|
||||
"""
|
||||
pass
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .configuration import Configuration
|
||||
from .configuration_abc import ConfigurationABC
|
||||
from .configuration_model_abc import ConfigurationModelABC
|
||||
from .configuration_variable_name_enum import ConfigurationVariableNameEnum
|
||||
from .console_argument import ConsoleArgument
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,357 +0,0 @@
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from collections import Callable
|
||||
from typing import Union, Type, Optional
|
||||
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.configuration.configuration_variable_name_enum import ConfigurationVariableNameEnum
|
||||
from cpl.configuration.console_argument import ConsoleArgument
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.environment.application_environment import ApplicationEnvironment
|
||||
from cpl.environment.environment_abc import ApplicationEnvironmentABC
|
||||
from cpl.environment.environment_name_enum import EnvironmentNameEnum
|
||||
|
||||
|
||||
class Configuration(ConfigurationABC):
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Representation of configuration
|
||||
"""
|
||||
ConfigurationABC.__init__(self)
|
||||
|
||||
self._application_environment = ApplicationEnvironment()
|
||||
self._config: dict[Union[type, str], Union[ConfigurationModelABC, str]] = {}
|
||||
|
||||
self._argument_types: list[ConsoleArgument] = []
|
||||
self._additional_arguments: list[str] = []
|
||||
|
||||
self._argument_error_function: Optional[Callable] = None
|
||||
|
||||
self._handled_args = []
|
||||
|
||||
@property
|
||||
def environment(self) -> ApplicationEnvironmentABC:
|
||||
return self._application_environment
|
||||
|
||||
@property
|
||||
def additional_arguments(self) -> list[str]:
|
||||
return self._additional_arguments
|
||||
|
||||
@property
|
||||
def argument_error_function(self) -> Optional[Callable]:
|
||||
return self._argument_error_function
|
||||
|
||||
@argument_error_function.setter
|
||||
def argument_error_function(self, argument_error_function: Callable):
|
||||
self._argument_error_function = argument_error_function
|
||||
|
||||
@staticmethod
|
||||
def _print_info(name: str, message: str):
|
||||
"""
|
||||
Prints an info message
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line(f'[{name}] {message}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
@staticmethod
|
||||
def _print_warn(name: str, message: str):
|
||||
"""
|
||||
Prints a warning
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
Console.set_foreground_color(ForegroundColorEnum.yellow)
|
||||
Console.write_line(f'[{name}] {message}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
@staticmethod
|
||||
def _print_error(name: str, message: str):
|
||||
"""
|
||||
Prints an error
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[{name}] {message}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
def _set_variable(self, name: str, value: str):
|
||||
"""
|
||||
Sets variable to given value
|
||||
:param name:
|
||||
:param value:
|
||||
:return:
|
||||
"""
|
||||
if name == ConfigurationVariableNameEnum.environment.value:
|
||||
self._application_environment.environment_name = EnvironmentNameEnum(value)
|
||||
|
||||
elif name == ConfigurationVariableNameEnum.name.value:
|
||||
self._application_environment.application_name = value
|
||||
|
||||
elif name == ConfigurationVariableNameEnum.customer.value:
|
||||
self._application_environment.customer = value
|
||||
|
||||
else:
|
||||
self._config[name] = value
|
||||
|
||||
def _validate_argument_child(self, argument: str, argument_type: ConsoleArgument,
|
||||
next_arguments: Optional[list[str]]) -> bool:
|
||||
"""
|
||||
Validates the child arguments of argument
|
||||
:param argument:
|
||||
:param argument_type:
|
||||
:param next_arguments:
|
||||
:return:
|
||||
"""
|
||||
if argument_type.console_arguments is not None and len(argument_type.console_arguments) > 0:
|
||||
found = False
|
||||
for child_argument_type in argument_type.console_arguments:
|
||||
found = self._validate_argument_by_argument_type(argument, child_argument_type, next_arguments)
|
||||
if found and child_argument_type.name not in self._additional_arguments:
|
||||
self._additional_arguments.append(child_argument_type.name)
|
||||
|
||||
if not found:
|
||||
raise Exception(f'Invalid argument: {argument}')
|
||||
|
||||
return found
|
||||
|
||||
return True
|
||||
|
||||
def _validate_argument_by_argument_type(self, argument: str, argument_type: ConsoleArgument,
|
||||
next_arguments: list[str] = None) -> bool:
|
||||
"""
|
||||
Validate argument by argument type
|
||||
:param argument:
|
||||
:param argument_type:
|
||||
:param next_arguments:
|
||||
:return:
|
||||
"""
|
||||
argument_name = ''
|
||||
value = ''
|
||||
result = False
|
||||
|
||||
if argument_type.value_token != '' and argument_type.value_token in argument:
|
||||
# ?new=value
|
||||
found = False
|
||||
for alias in argument_type.aliases:
|
||||
if alias in argument:
|
||||
found = True
|
||||
|
||||
if argument_type.name not in argument_name and not found:
|
||||
return False
|
||||
|
||||
if argument_type.is_value_token_optional is not None and argument_type.is_value_token_optional:
|
||||
if argument_type.name not in self._additional_arguments:
|
||||
self._additional_arguments.append(argument_type.name)
|
||||
result = True
|
||||
|
||||
if argument_type.token != '' and argument.startswith(argument_type.token):
|
||||
# --new=value
|
||||
argument_name = argument.split(argument_type.token)[1].split(argument_type.value_token)[0]
|
||||
else:
|
||||
# new=value
|
||||
argument_name = argument.split(argument_type.token)[1]
|
||||
|
||||
result = True
|
||||
|
||||
if argument_type.is_value_token_optional is True:
|
||||
is_valid = False
|
||||
|
||||
name_list = argument.split(argument_type.token)
|
||||
if len(name_list) > 1:
|
||||
value_list = name_list[1].split(argument_type.value_token)
|
||||
if len(value_list) > 1:
|
||||
is_valid = True
|
||||
value = argument.split(argument_type.token)[1].split(argument_type.value_token)[1]
|
||||
|
||||
if not is_valid:
|
||||
if argument_type.name not in self._additional_arguments:
|
||||
self._additional_arguments.append(argument_type.name)
|
||||
result = True
|
||||
else:
|
||||
value = argument.split(argument_type.token)[1].split(argument_type.value_token)[1]
|
||||
|
||||
if argument_name != argument_type.name and argument_name not in argument_type.aliases:
|
||||
return False
|
||||
|
||||
self._set_variable(argument_type.name, value)
|
||||
result = True
|
||||
|
||||
elif argument_type.value_token == ' ':
|
||||
# ?new value
|
||||
found = False
|
||||
for alias in argument_type.aliases:
|
||||
if alias in argument:
|
||||
found = True
|
||||
|
||||
if argument_type.name not in argument and not found:
|
||||
return False
|
||||
|
||||
if (next_arguments is None or len(next_arguments) == 0) and \
|
||||
argument_type.is_value_token_optional is not True:
|
||||
raise Exception(f'Invalid argument: {argument}')
|
||||
|
||||
if (next_arguments is None or len(next_arguments) == 0) and argument_type.is_value_token_optional is True:
|
||||
value = ''
|
||||
else:
|
||||
value = next_arguments[0]
|
||||
self._handled_args.append(value)
|
||||
|
||||
if argument_type.token != '' and argument.startswith(argument_type.token):
|
||||
# --new value
|
||||
argument_name = argument.split(argument_type.token)[1]
|
||||
else:
|
||||
# new value
|
||||
argument_name = argument
|
||||
|
||||
if argument_name != argument_type.name and argument_name not in argument_type.aliases:
|
||||
return False
|
||||
|
||||
if value == '':
|
||||
if argument_type.name not in self._additional_arguments:
|
||||
self._additional_arguments.append(argument_type.name)
|
||||
else:
|
||||
self._set_variable(argument_type.name, value)
|
||||
|
||||
result = True
|
||||
|
||||
elif argument_type.name == argument or argument in argument_type.aliases:
|
||||
# new
|
||||
self._additional_arguments.append(argument_type.name)
|
||||
result = True
|
||||
|
||||
if result:
|
||||
self._handled_args.append(argument)
|
||||
if next_arguments is not None and len(next_arguments) > 0:
|
||||
next_args = []
|
||||
if len(next_arguments) > 1:
|
||||
next_args = next_arguments[1:]
|
||||
result = self._validate_argument_child(next_arguments[0], argument_type, next_args)
|
||||
|
||||
return result
|
||||
|
||||
def add_environment_variables(self, prefix: str):
|
||||
for variable in ConfigurationVariableNameEnum.to_list():
|
||||
var_name = f'{prefix}{variable}'
|
||||
if var_name in [key.upper() for key in os.environ.keys()]:
|
||||
self._set_variable(variable, os.environ[var_name])
|
||||
|
||||
def add_console_argument(self, argument: ConsoleArgument):
|
||||
self._argument_types.append(argument)
|
||||
|
||||
def add_console_arguments(self, error: bool = None):
|
||||
for arg_name in ConfigurationVariableNameEnum.to_list():
|
||||
self.add_console_argument(ConsoleArgument('--', str(arg_name).upper(), [str(arg_name).lower()], '='))
|
||||
|
||||
arg_list = sys.argv[1:]
|
||||
for i in range(0, len(arg_list)):
|
||||
argument = arg_list[i]
|
||||
next_arguments = []
|
||||
error_message = ''
|
||||
|
||||
if argument in self._handled_args:
|
||||
break
|
||||
|
||||
if i + 1 < len(arg_list):
|
||||
next_arguments = arg_list[i + 1:]
|
||||
|
||||
found = False
|
||||
for argument_type in self._argument_types:
|
||||
try:
|
||||
found = self._validate_argument_by_argument_type(argument, argument_type, next_arguments)
|
||||
if found:
|
||||
break
|
||||
except Exception as e:
|
||||
error_message = e
|
||||
|
||||
if not found and error_message == '' and error is not False:
|
||||
error_message = f'Invalid argument: {argument}'
|
||||
|
||||
if self._argument_error_function is not None:
|
||||
self._argument_error_function(error_message)
|
||||
else:
|
||||
self._print_error(__name__, error_message)
|
||||
|
||||
exit()
|
||||
|
||||
def add_json_file(self, name: str, optional: bool = None, output: bool = True, path: str = None):
|
||||
path_root = self._application_environment.content_root_path
|
||||
if path is not None:
|
||||
path_root = path
|
||||
|
||||
if str(path_root).endswith('/') and not name.startswith('/'):
|
||||
file_path = f'{path_root}{name}'
|
||||
else:
|
||||
file_path = f'{path_root}/{name}'
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
if optional is not True:
|
||||
if output:
|
||||
self._print_error(__name__, f'File not found: {file_path}')
|
||||
|
||||
exit()
|
||||
|
||||
if output:
|
||||
self._print_warn(__name__, f'Not Loaded config file: {file_path}')
|
||||
|
||||
return None
|
||||
|
||||
config_from_file = self._load_json_file(file_path, output)
|
||||
for sub in ConfigurationModelABC.__subclasses__():
|
||||
for key, value in config_from_file.items():
|
||||
if sub.__name__ == key or sub.__name__.replace('Settings', '') == key:
|
||||
configuration = sub()
|
||||
configuration.from_dict(value)
|
||||
self.add_configuration(sub, configuration)
|
||||
|
||||
def _load_json_file(self, file: str, output: bool) -> dict:
|
||||
"""
|
||||
Reads the json file
|
||||
:param file:
|
||||
:param output:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
# open config file, create if not exists
|
||||
with open(file, encoding='utf-8') as cfg:
|
||||
# load json
|
||||
json_cfg = json.load(cfg)
|
||||
if output:
|
||||
self._print_info(__name__, f'Loaded config file: {file}')
|
||||
|
||||
return json_cfg
|
||||
except Exception as e:
|
||||
self._print_error(__name__, f'Cannot load config file: {file}! -> {e}')
|
||||
return {}
|
||||
|
||||
def add_configuration(self, key_type: type, value: ConfigurationModelABC):
|
||||
self._config[key_type] = value
|
||||
|
||||
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[
|
||||
str, Callable[ConfigurationModelABC]]:
|
||||
if type(search_type) is str:
|
||||
if search_type == ConfigurationVariableNameEnum.environment.value:
|
||||
return self._application_environment.environment_name
|
||||
|
||||
elif search_type == ConfigurationVariableNameEnum.name.value:
|
||||
return self._application_environment.application_name
|
||||
|
||||
elif search_type == ConfigurationVariableNameEnum.customer.value:
|
||||
return self._application_environment.customer
|
||||
|
||||
if search_type not in self._config:
|
||||
return None
|
||||
|
||||
for config_model in self._config:
|
||||
if config_model == search_type:
|
||||
return self._config[config_model]
|
||||
@@ -1,92 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
from collections import Callable
|
||||
from typing import Type, Union, Optional
|
||||
|
||||
from cpl.configuration.console_argument import ConsoleArgument
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.environment.environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class ConfigurationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC of configuration
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def environment(self) -> ApplicationEnvironmentABC: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def additional_arguments(self) -> list[str]: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def argument_error_function(self) -> Optional[Callable]: pass
|
||||
|
||||
@argument_error_function.setter
|
||||
@abstractmethod
|
||||
def argument_error_function(self, argument_error_function: Callable): pass
|
||||
|
||||
@abstractmethod
|
||||
def add_environment_variables(self, prefix: str):
|
||||
"""
|
||||
Reads the environment variables
|
||||
:param prefix:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_console_argument(self, argument: ConsoleArgument):
|
||||
"""
|
||||
Adds console argument to known console arguments
|
||||
:param argument:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_console_arguments(self, error: bool = None):
|
||||
"""
|
||||
Reads the console arguments
|
||||
:param error: defines is invalid argument error will be shown or not
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_json_file(self, name: str, optional: bool = None, output: bool = True, path: str = None):
|
||||
"""
|
||||
Reads and saves settings from given json file
|
||||
:param name:
|
||||
:param optional:
|
||||
:param output:
|
||||
:param path:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_configuration(self, key_type: type, value: object):
|
||||
"""
|
||||
Add configuration object
|
||||
:param key_type:
|
||||
:param value:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_configuration(self, search_type: Union[str, Type[ConfigurationModelABC]]) -> Union[
|
||||
str, Callable[ConfigurationModelABC]]:
|
||||
"""
|
||||
Returns value in configuration by given type
|
||||
:param search_type:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,20 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ConfigurationModelABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC for settings representation
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def from_dict(self, settings: dict):
|
||||
"""
|
||||
Converts attributes to dict
|
||||
:param settings:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,49 +0,0 @@
|
||||
class ConsoleArgument:
|
||||
|
||||
def __init__(self,
|
||||
token: str,
|
||||
name: str,
|
||||
aliases: list[str],
|
||||
value_token: str,
|
||||
is_value_token_optional: bool = None,
|
||||
console_arguments: list['ConsoleArgument'] = None
|
||||
):
|
||||
"""
|
||||
Representation of an console argument
|
||||
:param token:
|
||||
:param name:
|
||||
:param aliases:
|
||||
:param value_token:
|
||||
:param is_value_token_optional:
|
||||
:param console_arguments:
|
||||
"""
|
||||
self._token = token
|
||||
self._name = name
|
||||
self._aliases = aliases
|
||||
self._value_token = value_token
|
||||
self._is_value_token_optional = is_value_token_optional
|
||||
self._console_arguments = console_arguments
|
||||
|
||||
@property
|
||||
def token(self) -> str:
|
||||
return self._token
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def aliases(self) -> list[str]:
|
||||
return self._aliases
|
||||
|
||||
@property
|
||||
def value_token(self) -> str:
|
||||
return self._value_token
|
||||
|
||||
@property
|
||||
def is_value_token_optional(self) -> bool:
|
||||
return self._is_value_token_optional
|
||||
|
||||
@property
|
||||
def console_arguments(self) -> list['ConsoleArgument']:
|
||||
return self._console_arguments
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .background_color_enum import BackgroundColorEnum
|
||||
from .console import Console
|
||||
from .console_call import ConsoleCall
|
||||
from .foreground_color_enum import ForegroundColorEnum
|
||||
from .spinner_thread import SpinnerThread
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,14 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class BackgroundColorEnum(Enum):
|
||||
|
||||
default = 'on_default'
|
||||
grey = 'on_grey'
|
||||
red = 'on_red'
|
||||
green = 'on_green'
|
||||
yellow = 'on_yellow'
|
||||
blue = 'on_blue'
|
||||
magenta = 'on_magenta'
|
||||
cyan = 'on_cyan'
|
||||
white = 'on_white'
|
||||
@@ -1,528 +0,0 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from collections import Callable
|
||||
from typing import Union, Optional
|
||||
|
||||
import colorama
|
||||
import pyfiglet
|
||||
from pynput import keyboard
|
||||
from pynput.keyboard import Key
|
||||
from tabulate import tabulate
|
||||
from termcolor import colored
|
||||
|
||||
from cpl.console.background_color_enum import BackgroundColorEnum
|
||||
from cpl.console.console_call import ConsoleCall
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.console.spinner_thread import SpinnerThread
|
||||
|
||||
|
||||
class Console:
|
||||
"""
|
||||
Useful functions for handling with input and output
|
||||
"""
|
||||
colorama.init()
|
||||
_is_first_write = True
|
||||
|
||||
_background_color: BackgroundColorEnum = BackgroundColorEnum.default
|
||||
_foreground_color: ForegroundColorEnum = ForegroundColorEnum.default
|
||||
_x: Optional[int] = None
|
||||
_y: Optional[int] = None
|
||||
_disabled: bool = False
|
||||
|
||||
_hold_back = False
|
||||
_hold_back_calls: list[ConsoleCall] = []
|
||||
|
||||
_select_menu_items: list[str] = []
|
||||
_is_first_select_menu_output = True
|
||||
_selected_menu_item_index: int = 0
|
||||
_selected_menu_item_char: str = ''
|
||||
_selected_menu_option_foreground_color: ForegroundColorEnum = ForegroundColorEnum.default
|
||||
_selected_menu_option_background_color: BackgroundColorEnum = BackgroundColorEnum.default
|
||||
_selected_menu_cursor_foreground_color: ForegroundColorEnum = ForegroundColorEnum.default
|
||||
_selected_menu_cursor_background_color: BackgroundColorEnum = BackgroundColorEnum.default
|
||||
|
||||
"""
|
||||
Properties
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
def background_color(cls) -> str:
|
||||
return str(cls._background_color.value)
|
||||
|
||||
@classmethod
|
||||
@property
|
||||
def foreground_color(cls) -> str:
|
||||
return str(cls._foreground_color.value)
|
||||
|
||||
"""
|
||||
Settings
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def set_hold_back(cls, value: bool):
|
||||
cls._hold_back = value
|
||||
|
||||
@classmethod
|
||||
def set_background_color(cls, color: Union[BackgroundColorEnum, str]):
|
||||
"""
|
||||
Sets the background color
|
||||
:param color:
|
||||
:return:
|
||||
"""
|
||||
if type(color) is str:
|
||||
cls._background_color = BackgroundColorEnum[color]
|
||||
else:
|
||||
cls._background_color = color
|
||||
|
||||
@classmethod
|
||||
def set_foreground_color(cls, color: Union[ForegroundColorEnum, str]):
|
||||
"""
|
||||
Sets the foreground color
|
||||
:param color:
|
||||
:return:
|
||||
"""
|
||||
if type(color) is str:
|
||||
cls._foreground_color = ForegroundColorEnum[color]
|
||||
else:
|
||||
cls._foreground_color = color
|
||||
|
||||
@classmethod
|
||||
def reset_cursor_position(cls):
|
||||
"""
|
||||
Resets cursor position
|
||||
:return:
|
||||
"""
|
||||
cls._x = None
|
||||
cls._y = None
|
||||
|
||||
@classmethod
|
||||
def set_cursor_position(cls, x: int, y: int):
|
||||
"""
|
||||
Sets cursor position
|
||||
:param x:
|
||||
:param y:
|
||||
:return:
|
||||
"""
|
||||
cls._x = x
|
||||
cls._y = y
|
||||
|
||||
"""
|
||||
Useful protected methods
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def _output(cls, string: str, x: int = None, y: int = None, end: str = None):
|
||||
"""
|
||||
Prints given output with given format
|
||||
:param string:
|
||||
:param x:
|
||||
:param y:
|
||||
:param end:
|
||||
:return:
|
||||
"""
|
||||
if cls._is_first_write:
|
||||
cls._is_first_write = False
|
||||
|
||||
if end is None:
|
||||
end = '\n'
|
||||
|
||||
args = []
|
||||
colored_args = []
|
||||
if x is not None and y is not None:
|
||||
args.append(f'\033[{y};{x}H')
|
||||
elif cls._x is not None and cls._y is not None:
|
||||
args.append(f'\033[{cls._y};{cls._x}H')
|
||||
|
||||
colored_args.append(string)
|
||||
if cls._foreground_color != ForegroundColorEnum.default and cls._background_color == BackgroundColorEnum.default:
|
||||
colored_args.append(cls._foreground_color.value)
|
||||
elif cls._foreground_color == ForegroundColorEnum.default and cls._background_color != BackgroundColorEnum.default:
|
||||
colored_args.append(cls._background_color.value)
|
||||
elif cls._foreground_color != ForegroundColorEnum.default and cls._background_color != BackgroundColorEnum.default:
|
||||
colored_args.append(cls._foreground_color.value)
|
||||
colored_args.append(cls._background_color.value)
|
||||
|
||||
args.append(colored(*colored_args))
|
||||
print(*args, end=end)
|
||||
|
||||
@classmethod
|
||||
def _show_select_menu(cls):
|
||||
"""
|
||||
Shows the select menu
|
||||
:return:
|
||||
"""
|
||||
if not cls._is_first_select_menu_output:
|
||||
for _ in range(0, len(cls._select_menu_items) + 1):
|
||||
sys.stdout.write('\x1b[1A\x1b[2K')
|
||||
else:
|
||||
cls._is_first_select_menu_output = False
|
||||
|
||||
for i in range(0, len(cls._select_menu_items)):
|
||||
Console.set_foreground_color(cls._selected_menu_cursor_foreground_color)
|
||||
Console.set_background_color(cls._selected_menu_cursor_background_color)
|
||||
placeholder = ''
|
||||
for _ in cls._selected_menu_item_char:
|
||||
placeholder += ' '
|
||||
|
||||
Console.write_line(
|
||||
f'{cls._selected_menu_item_char if cls._selected_menu_item_index == i else placeholder} ')
|
||||
Console.set_foreground_color(cls._selected_menu_option_foreground_color)
|
||||
Console.set_background_color(cls._selected_menu_option_background_color)
|
||||
Console.write(f'{cls._select_menu_items[i]}')
|
||||
|
||||
Console.write_line()
|
||||
|
||||
@classmethod
|
||||
def _select_menu_key_press(cls, key: Key):
|
||||
"""
|
||||
Event function when key press is detected
|
||||
:param key:
|
||||
:return:
|
||||
"""
|
||||
if key == Key.down:
|
||||
if cls._selected_menu_item_index == len(cls._select_menu_items) - 1:
|
||||
return
|
||||
cls._selected_menu_item_index += 1
|
||||
cls._show_select_menu()
|
||||
|
||||
elif key == Key.up:
|
||||
if cls._selected_menu_item_index == 0:
|
||||
return
|
||||
cls._selected_menu_item_index -= 1
|
||||
cls._show_select_menu()
|
||||
|
||||
elif key == Key.enter:
|
||||
return False
|
||||
|
||||
"""
|
||||
Useful public methods
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def banner(cls, string: str):
|
||||
"""
|
||||
Prints the string as a banner
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.banner, string))
|
||||
return
|
||||
|
||||
ascii_banner = pyfiglet.figlet_format(string)
|
||||
cls.write_line(ascii_banner)
|
||||
|
||||
@classmethod
|
||||
def color_reset(cls):
|
||||
"""
|
||||
Resets color
|
||||
:return:
|
||||
"""
|
||||
cls._background_color = BackgroundColorEnum.default
|
||||
cls._foreground_color = ForegroundColorEnum.default
|
||||
|
||||
@classmethod
|
||||
def clear(cls):
|
||||
"""
|
||||
Clears the console
|
||||
:return:
|
||||
"""
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.clear))
|
||||
return
|
||||
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
@classmethod
|
||||
def close(cls):
|
||||
"""
|
||||
Close the application
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.close))
|
||||
return
|
||||
|
||||
Console.color_reset()
|
||||
Console.write('\n\n\nPress any key to continue...')
|
||||
Console.read()
|
||||
exit()
|
||||
|
||||
@classmethod
|
||||
def disable(cls):
|
||||
"""
|
||||
Disable console interaction
|
||||
:return:
|
||||
"""
|
||||
cls._disabled = True
|
||||
|
||||
@classmethod
|
||||
def error(cls, string: str, tb: str = None):
|
||||
"""
|
||||
Prints an error with traceback
|
||||
:param string:
|
||||
:param tb:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.error, string, tb))
|
||||
return
|
||||
|
||||
cls.set_foreground_color('red')
|
||||
if tb is not None:
|
||||
cls.write_line(f'{string} -> {tb}')
|
||||
else:
|
||||
cls.write_line(string)
|
||||
cls.set_foreground_color('default')
|
||||
|
||||
@classmethod
|
||||
def enable(cls):
|
||||
"""
|
||||
Enable console interaction
|
||||
:return:
|
||||
"""
|
||||
cls._disabled = False
|
||||
|
||||
@classmethod
|
||||
def read(cls, output: str = None) -> str:
|
||||
"""
|
||||
Read in line
|
||||
:param output:
|
||||
:return:
|
||||
"""
|
||||
if output is not None and not cls._hold_back:
|
||||
cls.write_line(output)
|
||||
|
||||
return input()
|
||||
|
||||
@classmethod
|
||||
def read_line(cls, output: str = None) -> str:
|
||||
"""
|
||||
Reads in next line
|
||||
:param output:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled and not cls._hold_back:
|
||||
return ''
|
||||
|
||||
if output is not None:
|
||||
cls.write_line(output)
|
||||
|
||||
cls._output('\n', end='')
|
||||
|
||||
return input()
|
||||
|
||||
@classmethod
|
||||
def table(cls, header: list[str], values: list[list[str]]):
|
||||
"""
|
||||
Prints a table with header and values
|
||||
:param header:
|
||||
:param values:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.table, header, values))
|
||||
return
|
||||
|
||||
table = tabulate(values, headers=header)
|
||||
|
||||
Console.write_line(table)
|
||||
Console.write('\n')
|
||||
|
||||
@classmethod
|
||||
def select(cls, char: str, message: str, options: list[str],
|
||||
header_foreground_color: Union[str, ForegroundColorEnum] = ForegroundColorEnum.default,
|
||||
header_background_color: Union[str, BackgroundColorEnum] = BackgroundColorEnum.default,
|
||||
option_foreground_color: Union[str, ForegroundColorEnum] = ForegroundColorEnum.default,
|
||||
option_background_color: Union[str, BackgroundColorEnum] = BackgroundColorEnum.default,
|
||||
cursor_foreground_color: Union[str, ForegroundColorEnum] = ForegroundColorEnum.default,
|
||||
cursor_background_color: Union[str, BackgroundColorEnum] = BackgroundColorEnum.default
|
||||
) -> str:
|
||||
"""
|
||||
Prints select menu
|
||||
:param char:
|
||||
:param message:
|
||||
:param options:
|
||||
:param header_foreground_color:
|
||||
:param header_background_color:
|
||||
:param option_foreground_color:
|
||||
:param option_background_color:
|
||||
:param cursor_foreground_color:
|
||||
:param cursor_background_color:
|
||||
:return: Selected option as str
|
||||
"""
|
||||
cls._selected_menu_item_char = char
|
||||
cls.options = options
|
||||
cls._select_menu_items = cls.options
|
||||
|
||||
if option_foreground_color is not None:
|
||||
cls._selected_menu_option_foreground_color = option_foreground_color
|
||||
if option_background_color is not None:
|
||||
cls._selected_menu_option_background_color = option_background_color
|
||||
|
||||
if cursor_foreground_color is not None:
|
||||
cls._selected_menu_cursor_foreground_color = cursor_foreground_color
|
||||
if cursor_background_color is not None:
|
||||
cls._selected_menu_cursor_background_color = cursor_background_color
|
||||
|
||||
Console.set_foreground_color(header_foreground_color)
|
||||
Console.set_background_color(header_background_color)
|
||||
Console.write_line(message, '\n')
|
||||
cls._show_select_menu()
|
||||
|
||||
with keyboard.Listener(
|
||||
on_press=cls._select_menu_key_press, suppress=True) as listener:
|
||||
listener.join()
|
||||
|
||||
Console.color_reset()
|
||||
return cls._select_menu_items[cls._selected_menu_item_index]
|
||||
|
||||
@classmethod
|
||||
def spinner(cls, message: str, call: Callable, *args, text_foreground_color: Union[str, ForegroundColorEnum] = None,
|
||||
spinner_foreground_color: Union[str, ForegroundColorEnum] = None,
|
||||
text_background_color: Union[str, BackgroundColorEnum] = None,
|
||||
spinner_background_color: Union[str, BackgroundColorEnum] = None, **kwargs) -> any:
|
||||
"""
|
||||
Shows spinner and calls given function
|
||||
When function has ended the spinner stops
|
||||
:param message:
|
||||
:param call:
|
||||
:param args:
|
||||
:param text_foreground_color:
|
||||
:param spinner_foreground_color:
|
||||
:param text_background_color:
|
||||
:param spinner_background_color:
|
||||
:param kwargs:
|
||||
:return: Return value of call
|
||||
"""
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.spinner, message, call, *args))
|
||||
return
|
||||
|
||||
if text_foreground_color is not None:
|
||||
cls.set_foreground_color(text_foreground_color)
|
||||
|
||||
if text_background_color is not None:
|
||||
cls.set_background_color(text_background_color)
|
||||
|
||||
if type(spinner_foreground_color) is str:
|
||||
spinner_foreground_color = ForegroundColorEnum[spinner_foreground_color]
|
||||
|
||||
if type(spinner_background_color) is str:
|
||||
spinner_background_color = BackgroundColorEnum[spinner_background_color]
|
||||
|
||||
cls.write_line(message)
|
||||
cls.set_hold_back(True)
|
||||
spinner = SpinnerThread(len(message), spinner_foreground_color, spinner_background_color)
|
||||
spinner.start()
|
||||
|
||||
return_value = None
|
||||
try:
|
||||
return_value = call(*args, **kwargs)
|
||||
except KeyboardInterrupt:
|
||||
spinner.exit()
|
||||
cls.close()
|
||||
|
||||
spinner.stop_spinning()
|
||||
cls.set_hold_back(False)
|
||||
|
||||
cls.set_foreground_color(ForegroundColorEnum.default)
|
||||
cls.set_background_color(BackgroundColorEnum.default)
|
||||
|
||||
for call in cls._hold_back_calls:
|
||||
call.function(*call.args)
|
||||
|
||||
time.sleep(0.1)
|
||||
|
||||
return return_value
|
||||
|
||||
@classmethod
|
||||
def write(cls, *args, end=''):
|
||||
"""
|
||||
Prints in active line
|
||||
:param args:
|
||||
:param end:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write, args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
cls._output(string, end=end)
|
||||
|
||||
@classmethod
|
||||
def write_at(cls, x: int, y: int, *args):
|
||||
"""
|
||||
Prints at given position
|
||||
:param x:
|
||||
:param y:
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_at, x, y, args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
cls._output(string, x, y, end='')
|
||||
|
||||
@classmethod
|
||||
def write_line(cls, *args):
|
||||
"""
|
||||
Prints to new line
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line, args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
if not cls._is_first_write:
|
||||
cls._output('')
|
||||
cls._output(string, end='')
|
||||
|
||||
@classmethod
|
||||
def write_line_at(cls, x: int, y: int, *args):
|
||||
"""
|
||||
Prints new line at given position
|
||||
:param x:
|
||||
:param y:
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if cls._disabled:
|
||||
return
|
||||
|
||||
if cls._hold_back:
|
||||
cls._hold_back_calls.append(ConsoleCall(cls.write_line_at, x, y, args))
|
||||
return
|
||||
|
||||
string = ' '.join(map(str, args))
|
||||
if not cls._is_first_write:
|
||||
cls._output('', end='')
|
||||
cls._output(string, x, y, end='')
|
||||
@@ -1,14 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ForegroundColorEnum(Enum):
|
||||
|
||||
default = 'default'
|
||||
grey = 'grey'
|
||||
red = 'red'
|
||||
green = 'green'
|
||||
yellow = 'yellow'
|
||||
blue = 'blue'
|
||||
magenta = 'magenta'
|
||||
cyan = 'cyan'
|
||||
white = 'white'
|
||||
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.database'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_model import DatabaseModel
|
||||
from .database_settings import DatabaseSettings
|
||||
from .database_settings_name_enum import DatabaseSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_connection import DatabaseConnection
|
||||
from .database_connection_abc import DatabaseConnectionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,62 +0,0 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import engine, create_engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
|
||||
from cpl.database.database_settings import DatabaseSettings
|
||||
|
||||
|
||||
class DatabaseConnection(DatabaseConnectionABC):
|
||||
|
||||
def __init__(self, database_settings: DatabaseSettings):
|
||||
"""
|
||||
Represents an connection to a database
|
||||
:param database_settings:
|
||||
"""
|
||||
DatabaseConnectionABC.__init__(self)
|
||||
|
||||
self._db_settings = database_settings
|
||||
|
||||
self._engine: Optional[engine] = None
|
||||
self._session: Optional[Session] = None
|
||||
self._credentials: Optional[str] = None
|
||||
|
||||
@property
|
||||
def engine(self) -> engine:
|
||||
return self._engine
|
||||
|
||||
@property
|
||||
def session(self) -> Session:
|
||||
return self._session
|
||||
|
||||
def connect(self, connection_string: str):
|
||||
try:
|
||||
self._engine = create_engine(connection_string)
|
||||
|
||||
if self._db_settings.auth_plugin is not None:
|
||||
self._engine = create_engine(connection_string, connect_args={'auth_plugin': self._db_settings.auth_plugin})
|
||||
|
||||
if self._db_settings.encoding is not None:
|
||||
self._engine.encoding = self._db_settings.encoding
|
||||
|
||||
if self._db_settings.case_sensitive is not None:
|
||||
self._engine.case_sensitive = self._db_settings.case_sensitive
|
||||
|
||||
if self._db_settings.echo is not None:
|
||||
self._engine.echo = self._db_settings.echo
|
||||
|
||||
self._engine.connect()
|
||||
|
||||
db_session = sessionmaker(bind=self._engine)
|
||||
self._session = db_session()
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line(f'[{__name__}] Connected to database')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[{__name__}] Database connection failed -> {e}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
exit()
|
||||
@@ -1,27 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from sqlalchemy import engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
class DatabaseConnectionABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def engine(self) -> engine: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def session(self) -> Session: pass
|
||||
|
||||
@abstractmethod
|
||||
def connect(self, connection_string: str):
|
||||
"""
|
||||
Connects to a database by connection string
|
||||
:param connection_string:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.database.context'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .database_context import DatabaseContext
|
||||
from .database_context_abc import DatabaseContextABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,47 +0,0 @@
|
||||
from sqlalchemy import engine, Table
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.database.connection.database_connection import DatabaseConnection
|
||||
from cpl.database.connection.database_connection_abc import DatabaseConnectionABC
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.database.database_settings import DatabaseSettings
|
||||
from cpl.database.database_model import DatabaseModel
|
||||
|
||||
|
||||
class DatabaseContext(DatabaseContextABC):
|
||||
|
||||
def __init__(self, database_settings: DatabaseSettings):
|
||||
DatabaseContextABC.__init__(self)
|
||||
|
||||
self._db: DatabaseConnectionABC = DatabaseConnection(database_settings)
|
||||
self._tables: list[Table] = []
|
||||
|
||||
@property
|
||||
def engine(self) -> engine:
|
||||
return self._db.engine
|
||||
|
||||
@property
|
||||
def session(self) -> Session:
|
||||
return self._db.session
|
||||
|
||||
def connect(self, connection_string: str):
|
||||
self._db.connect(connection_string)
|
||||
self._create_tables()
|
||||
|
||||
def _create_tables(self):
|
||||
try:
|
||||
for subclass in DatabaseModel.__subclasses__():
|
||||
self._tables.append(subclass.__table__)
|
||||
|
||||
DatabaseModel.metadata.drop_all(self._db.engine, self._tables)
|
||||
DatabaseModel.metadata.create_all(self._db.engine, self._tables, checkfirst=True)
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line(f'[{__name__}] Created tables')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[{__name__}] Creating tables failed -> {e}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
exit()
|
||||
@@ -1,32 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from sqlalchemy import engine
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
|
||||
class DatabaseContextABC(ABC):
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def engine(self) -> engine: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def session(self) -> Session: pass
|
||||
|
||||
@abstractmethod
|
||||
def connect(self, connection_string: str):
|
||||
"""
|
||||
Connects to a database with connection string
|
||||
:param connection_string:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def _create_tables(self):
|
||||
"""
|
||||
Create all tables for application from database model
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,3 +0,0 @@
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
DatabaseModel: declarative_base = declarative_base()
|
||||
@@ -1,90 +0,0 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.database.database_settings_name_enum import DatabaseSettingsNameEnum
|
||||
|
||||
|
||||
class DatabaseSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._auth_plugin: Optional[str] = None
|
||||
self._connection_string: Optional[str] = None
|
||||
self._credentials: Optional[str] = None
|
||||
self._encoding: Optional[str] = None
|
||||
self._case_sensitive: Optional[bool] = None
|
||||
self._echo: Optional[bool] = None
|
||||
|
||||
@property
|
||||
def auth_plugin(self) -> str:
|
||||
return self._auth_plugin
|
||||
|
||||
@auth_plugin.setter
|
||||
def auth_plugin(self, auth_plugin: str):
|
||||
self._auth_plugin = auth_plugin
|
||||
|
||||
@property
|
||||
def connection_string(self) -> str:
|
||||
return self._connection_string
|
||||
|
||||
@connection_string.setter
|
||||
def connection_string(self, connection_string: str):
|
||||
self._connection_string = connection_string
|
||||
|
||||
@property
|
||||
def credentials(self) -> str:
|
||||
return self._credentials
|
||||
|
||||
@credentials.setter
|
||||
def credentials(self, credentials: str):
|
||||
self._credentials = credentials
|
||||
|
||||
@property
|
||||
def encoding(self) -> str:
|
||||
return self._encoding
|
||||
|
||||
@encoding.setter
|
||||
def encoding(self, encoding: str) -> None:
|
||||
self._encoding = encoding
|
||||
|
||||
@property
|
||||
def case_sensitive(self) -> bool:
|
||||
return self._case_sensitive
|
||||
|
||||
@case_sensitive.setter
|
||||
def case_sensitive(self, case_sensitive: bool) -> None:
|
||||
self._case_sensitive = case_sensitive
|
||||
|
||||
@property
|
||||
def echo(self) -> bool:
|
||||
return self._echo
|
||||
|
||||
@echo.setter
|
||||
def echo(self, echo: bool) -> None:
|
||||
self._echo = echo
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._connection_string = settings[DatabaseSettingsNameEnum.connection_string.value]
|
||||
self._credentials = settings[DatabaseSettingsNameEnum.credentials.value]
|
||||
|
||||
if DatabaseSettingsNameEnum.auth_plugin.value in settings:
|
||||
self._auth_plugin = settings[DatabaseSettingsNameEnum.auth_plugin.value]
|
||||
|
||||
if DatabaseSettingsNameEnum.encoding.value in settings:
|
||||
self._encoding = settings[DatabaseSettingsNameEnum.encoding.value]
|
||||
|
||||
if DatabaseSettingsNameEnum.case_sensitive.value in settings:
|
||||
self._case_sensitive = bool(settings[DatabaseSettingsNameEnum.case_sensitive.value])
|
||||
|
||||
if DatabaseSettingsNameEnum.echo.value in settings:
|
||||
self._echo = bool(settings[DatabaseSettingsNameEnum.echo.value])
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
@@ -1,11 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class DatabaseSettingsNameEnum(Enum):
|
||||
|
||||
connection_string = 'ConnectionString'
|
||||
credentials = 'Credentials'
|
||||
encoding = 'Encoding'
|
||||
case_sensitive = 'CaseSensitive'
|
||||
echo = 'Echo'
|
||||
auth_plugin = 'AuthPlugin'
|
||||
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.dependency_injection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .service_abc import ServiceABC
|
||||
from .service_provider import ServiceProvider
|
||||
from .service_provider_abc import ServiceProviderABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,122 +0,0 @@
|
||||
from collections import Callable
|
||||
from inspect import signature, Parameter
|
||||
from typing import Type, Optional, Union
|
||||
|
||||
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
|
||||
from cpl.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl.environment.environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class ServiceProvider(ServiceProviderABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC):
|
||||
"""
|
||||
Service for service providing
|
||||
:param runtime:
|
||||
"""
|
||||
ServiceProviderABC.__init__(self)
|
||||
self._configuration: ConfigurationABC = config
|
||||
self._runtime: ApplicationRuntimeABC = runtime
|
||||
self._database_context: Optional[DatabaseContextABC] = None
|
||||
|
||||
self._transient_services: dict[Type[ServiceABC], Callable[ServiceABC]] = {}
|
||||
self._scoped_services: dict[Type[ServiceABC], Callable[ServiceABC]] = {}
|
||||
self._singleton_services: dict[Type[ServiceABC], Callable[ServiceABC], ServiceABC] = {}
|
||||
|
||||
def _create_instance(self, service: Union[Callable[ServiceABC], ServiceABC]) -> Callable[ServiceABC]:
|
||||
"""
|
||||
Creates an instance of given type
|
||||
:param service:
|
||||
:return:
|
||||
"""
|
||||
sig = signature(service.__init__)
|
||||
params = []
|
||||
for param in sig.parameters.items():
|
||||
parameter = param[1]
|
||||
if parameter.name != 'self' and parameter.annotation != Parameter.empty:
|
||||
if issubclass(parameter.annotation, ApplicationRuntimeABC):
|
||||
params.append(self._runtime)
|
||||
|
||||
elif issubclass(parameter.annotation, ApplicationEnvironmentABC):
|
||||
params.append(self._configuration.environment)
|
||||
|
||||
elif issubclass(parameter.annotation, DatabaseContextABC):
|
||||
params.append(self._database_context)
|
||||
|
||||
elif issubclass(parameter.annotation, ConfigurationModelABC):
|
||||
params.append(self._configuration.get_configuration(parameter.annotation))
|
||||
|
||||
elif issubclass(parameter.annotation, ConfigurationABC):
|
||||
params.append(self._configuration)
|
||||
|
||||
elif issubclass(parameter.annotation, ServiceProviderABC):
|
||||
params.append(self)
|
||||
|
||||
else:
|
||||
params.append(self.get_service(parameter.annotation))
|
||||
|
||||
return service(*params)
|
||||
|
||||
def add_db_context(self, db_context: Type[DatabaseContextABC]):
|
||||
self._database_context = self._create_instance(db_context)
|
||||
|
||||
def get_db_context(self) -> Callable[DatabaseContextABC]:
|
||||
return self._database_context
|
||||
|
||||
def add_transient(self, service_type: Type[ServiceABC], service: Callable[ServiceABC] = None):
|
||||
if service is None:
|
||||
self._transient_services[service_type] = service_type
|
||||
else:
|
||||
self._transient_services[service_type] = service
|
||||
|
||||
def add_scoped(self, service_type: Type[ServiceABC], service: Callable[ServiceABC] = None):
|
||||
if service is None:
|
||||
self._scoped_services[service_type] = service_type
|
||||
else:
|
||||
self._scoped_services[service_type] = service
|
||||
|
||||
def add_singleton(self, service_type: Type[ServiceABC], service: Callable[ServiceABC] = None):
|
||||
for known_service in self._singleton_services:
|
||||
if type(known_service) == service_type:
|
||||
raise Exception(f'Service with type {service_type} already exists')
|
||||
|
||||
if service is None:
|
||||
self._singleton_services[service_type] = self._create_instance(service_type)
|
||||
else:
|
||||
self._singleton_services[service_type] = self._create_instance(service)
|
||||
|
||||
def get_service(self, instance_type: Type) -> Callable[ServiceABC]:
|
||||
if issubclass(instance_type, ServiceProviderABC):
|
||||
return self
|
||||
|
||||
for service in self._transient_services:
|
||||
if service == instance_type and isinstance(self._transient_services[service], type(instance_type)):
|
||||
return self._create_instance(self._transient_services[service])
|
||||
|
||||
for service in self._scoped_services:
|
||||
if service == instance_type and isinstance(self._scoped_services[service], type(instance_type)):
|
||||
return self._create_instance(self._scoped_services[service])
|
||||
|
||||
for service in self._singleton_services:
|
||||
if service == instance_type and isinstance(self._singleton_services[service], instance_type):
|
||||
return self._singleton_services[service]
|
||||
|
||||
def remove_service(self, instance_type: Type[ServiceABC]):
|
||||
for service in self._transient_services:
|
||||
if service == instance_type and isinstance(self._transient_services[service], type(instance_type)):
|
||||
del self._transient_services[service]
|
||||
return
|
||||
|
||||
for service in self._scoped_services:
|
||||
if service == instance_type and isinstance(self._scoped_services[service], type(instance_type)):
|
||||
del self._scoped_services[service]
|
||||
return
|
||||
|
||||
for service in self._singleton_services:
|
||||
if service == instance_type and isinstance(self._singleton_services[service], instance_type):
|
||||
del self._singleton_services[service]
|
||||
return
|
||||
@@ -1,81 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
from collections import Callable
|
||||
from typing import Type
|
||||
|
||||
from cpl.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
|
||||
|
||||
class ServiceProviderABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC for service providing
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_db_context(self, db_context: Type[DatabaseContextABC]):
|
||||
"""
|
||||
Adds database context
|
||||
:param db_context:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_db_context(self) -> Callable[DatabaseContextABC]:
|
||||
""""
|
||||
Returns database context
|
||||
:return Callable[DatabaseContextABC]:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_transient(self, service_type: Type, service: Callable = None):
|
||||
"""
|
||||
Adds a service with transient lifetime
|
||||
:param service_type:
|
||||
:param service:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_scoped(self, service_type: Type, service: Callable = None):
|
||||
"""
|
||||
Adds a service with scoped lifetime
|
||||
:param service_type:
|
||||
:param service:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_singleton(self, service_type: Type, service: Callable = None):
|
||||
"""
|
||||
Adds a service with singleton lifetime
|
||||
:param service_type:
|
||||
:param service:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_service(self, instance_type: Type) -> Callable[ServiceABC]:
|
||||
"""
|
||||
Returns instance of given type
|
||||
:param instance_type:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def remove_service(self, instance_type: type):
|
||||
"""
|
||||
Removes service
|
||||
:param instance_type:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.environment'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .environment_abc import ApplicationEnvironmentABC
|
||||
from .environment_name_enum import EnvironmentNameEnum
|
||||
from .application_environment import ApplicationEnvironment
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,57 +0,0 @@
|
||||
from socket import gethostname
|
||||
from typing import Optional
|
||||
|
||||
from cpl.environment.environment_abc import ApplicationEnvironmentABC
|
||||
from cpl.environment.environment_name_enum import EnvironmentNameEnum
|
||||
|
||||
|
||||
class ApplicationEnvironment(ApplicationEnvironmentABC):
|
||||
|
||||
def __init__(self, name: EnvironmentNameEnum = EnvironmentNameEnum.production, crp: str = './'):
|
||||
"""
|
||||
Represents environment of the application
|
||||
:param name:
|
||||
:param crp:
|
||||
"""
|
||||
ApplicationEnvironmentABC.__init__(self)
|
||||
|
||||
self._environment_name: Optional[EnvironmentNameEnum] = name
|
||||
self._app_name: Optional[str] = None
|
||||
self._customer: Optional[str] = None
|
||||
self._content_root_path: Optional[str] = crp
|
||||
|
||||
@property
|
||||
def environment_name(self) -> str:
|
||||
return str(self._environment_name.value)
|
||||
|
||||
@environment_name.setter
|
||||
def environment_name(self, environment_name: str):
|
||||
self._environment_name = EnvironmentNameEnum(environment_name)
|
||||
|
||||
@property
|
||||
def application_name(self) -> str:
|
||||
return self._app_name if self._app_name is not None else ''
|
||||
|
||||
@application_name.setter
|
||||
def application_name(self, application_name: str):
|
||||
self._app_name = application_name
|
||||
|
||||
@property
|
||||
def customer(self) -> str:
|
||||
return self._customer if self._customer is not None else ''
|
||||
|
||||
@customer.setter
|
||||
def customer(self, customer: str):
|
||||
self._customer = customer
|
||||
|
||||
@property
|
||||
def content_root_path(self) -> str:
|
||||
return self._content_root_path
|
||||
|
||||
@content_root_path.setter
|
||||
def content_root_path(self, content_root_path: str):
|
||||
self._content_root_path = content_root_path
|
||||
|
||||
@property
|
||||
def host_name(self):
|
||||
return gethostname()
|
||||
@@ -1,47 +0,0 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ApplicationEnvironmentABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC of application environment
|
||||
"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def environment_name(self) -> str: pass
|
||||
|
||||
@environment_name.setter
|
||||
@abstractmethod
|
||||
def environment_name(self, environment_name: str): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def application_name(self) -> str: pass
|
||||
|
||||
@application_name.setter
|
||||
@abstractmethod
|
||||
def application_name(self, application_name: str): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def customer(self) -> str: pass
|
||||
|
||||
@customer.setter
|
||||
@abstractmethod
|
||||
def customer(self, customer: str): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def content_root_path(self) -> str: pass
|
||||
|
||||
@content_root_path.setter
|
||||
@abstractmethod
|
||||
def content_root_path(self, content_root_path: str): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def host_name(self) -> str: pass
|
||||
@@ -1,9 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class EnvironmentNameEnum(Enum):
|
||||
|
||||
production = 'production'
|
||||
staging = 'staging'
|
||||
testing = 'testing'
|
||||
development = 'development'
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.logging'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .logger_service import Logger
|
||||
from .logger_abc import LoggerABC
|
||||
from .logging_level_enum import LoggingLevelEnum
|
||||
from .logging_settings import LoggingSettings
|
||||
from .logging_settings_name_enum import LoggingSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,84 +0,0 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
|
||||
|
||||
class LoggerABC(ServiceABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC for logging
|
||||
"""
|
||||
ServiceABC.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def header(self, string: str):
|
||||
"""
|
||||
Writes a header message
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def trace(self, name: str, message: str):
|
||||
"""
|
||||
Writes a trace message
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def debug(self, name: str, message: str):
|
||||
"""
|
||||
Writes a debug message
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def info(self, name: str, message: str):
|
||||
"""
|
||||
Writes an information
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def warn(self, name: str, message: str):
|
||||
"""
|
||||
Writes an warning
|
||||
:param name:
|
||||
:param message:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def error(self, name: str, message: str, ex: Exception = None):
|
||||
"""
|
||||
Writes an error
|
||||
:param name:
|
||||
:param message:
|
||||
:param ex:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def fatal(self, name: str, message: str, ex: Exception = None):
|
||||
"""
|
||||
Writes an error and exits
|
||||
:param name:
|
||||
:param message:
|
||||
:param ex:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,12 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class LoggingLevelEnum(Enum):
|
||||
|
||||
OFF = 0 # Nothing
|
||||
FATAL = 1 # Error that cause exit
|
||||
ERROR = 2 # Non fatal error
|
||||
WARN = 3 # Error that can later be fatal
|
||||
INFO = 4 # Normal information's
|
||||
DEBUG = 5 # Detailed app state
|
||||
TRACE = 6 # Detailed app information's
|
||||
@@ -1,62 +0,0 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.logging.logging_level_enum import LoggingLevelEnum
|
||||
from cpl.logging.logging_settings_name_enum import LoggingSettingsNameEnum
|
||||
|
||||
|
||||
class LoggingSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
self._path: Optional[str] = None
|
||||
self._filename: Optional[str] = None
|
||||
self._console: Optional[LoggingLevelEnum] = None
|
||||
self._level: Optional[LoggingLevelEnum] = None
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@path.setter
|
||||
def path(self, path: str) -> None:
|
||||
self._path = path
|
||||
|
||||
@property
|
||||
def filename(self) -> str:
|
||||
return self._filename
|
||||
|
||||
@filename.setter
|
||||
def filename(self, filename: str) -> None:
|
||||
self._filename = filename
|
||||
|
||||
@property
|
||||
def console(self) -> LoggingLevelEnum:
|
||||
return self._console
|
||||
|
||||
@console.setter
|
||||
def console(self, console: LoggingLevelEnum) -> None:
|
||||
self._console = console
|
||||
|
||||
@property
|
||||
def level(self) -> LoggingLevelEnum:
|
||||
return self._level
|
||||
|
||||
@level.setter
|
||||
def level(self, level: LoggingLevelEnum) -> None:
|
||||
self._level = level
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._path = settings[LoggingSettingsNameEnum.path.value]
|
||||
self._filename = settings[LoggingSettingsNameEnum.filename.value]
|
||||
self._console = LoggingLevelEnum[settings[LoggingSettingsNameEnum.console_level.value]]
|
||||
self._level = LoggingLevelEnum[settings[LoggingSettingsNameEnum.file_level.value]]
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
@@ -1,9 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class LoggingSettingsNameEnum(Enum):
|
||||
|
||||
path = 'Path'
|
||||
filename = 'Filename'
|
||||
console_level = 'ConsoleLogLevel'
|
||||
file_level = 'FileLogLevel'
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.mailing'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .email import EMail
|
||||
from .email_client_service import EMailClient
|
||||
from .email_client_abc import EMailClientABC
|
||||
from .email_client_settings import EMailClientSettings
|
||||
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,31 +0,0 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl.dependency_injection.service_abc import ServiceABC
|
||||
from cpl.mailing.email import EMail
|
||||
|
||||
|
||||
class EMailClientABC(ServiceABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
"""
|
||||
ABC to send emails
|
||||
"""
|
||||
ServiceABC.__init__(self)
|
||||
|
||||
@abstractmethod
|
||||
def connect(self):
|
||||
"""
|
||||
Connects to server
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def send_mail(self, email: EMail):
|
||||
"""
|
||||
Sends email
|
||||
:param email:
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
@@ -1,84 +0,0 @@
|
||||
import ssl
|
||||
from smtplib import SMTP
|
||||
from typing import Optional
|
||||
|
||||
from cpl.environment.environment_abc import ApplicationEnvironmentABC
|
||||
from cpl.logging.logger_abc import LoggerABC
|
||||
from cpl.mailing.email import EMail
|
||||
from cpl.mailing.email_client_abc import EMailClientABC
|
||||
from cpl.mailing.email_client_settings import EMailClientSettings
|
||||
from cpl.utils.credential_manager import CredentialManager
|
||||
|
||||
|
||||
class EMailClient(EMailClientABC):
|
||||
|
||||
def __init__(self, environment: ApplicationEnvironmentABC, logger: LoggerABC, mail_settings: EMailClientSettings):
|
||||
"""
|
||||
Service to send emails
|
||||
:param environment:
|
||||
:param logger:
|
||||
:param mail_settings:
|
||||
"""
|
||||
EMailClientABC.__init__(self)
|
||||
|
||||
self._environment = environment
|
||||
self._mail_settings = mail_settings
|
||||
self._logger = logger
|
||||
|
||||
self._server: Optional[SMTP] = None
|
||||
|
||||
self.create()
|
||||
|
||||
def create(self):
|
||||
"""
|
||||
Creates connection
|
||||
:return:
|
||||
"""
|
||||
self._logger.trace(__name__, f'Started {__name__}.create')
|
||||
self.connect()
|
||||
self._logger.trace(__name__, f'Stopped {__name__}.create')
|
||||
|
||||
def connect(self):
|
||||
self._logger.trace(__name__, f'Started {__name__}.connect')
|
||||
try:
|
||||
self._logger.debug(__name__, f'Try to connect to {self._mail_settings.host}:{self._mail_settings.port}')
|
||||
self._server = SMTP(self._mail_settings.host, self._mail_settings.port)
|
||||
self._logger.info(__name__, f'Connected to {self._mail_settings.host}:{self._mail_settings.port}')
|
||||
|
||||
self._logger.debug(__name__, 'Try to start tls')
|
||||
self._server.starttls(context=ssl.create_default_context())
|
||||
self._logger.info(__name__, 'Started tls')
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Cannot connect to mail server', e)
|
||||
|
||||
self._logger.trace(__name__, f'Stopped {__name__}.connect')
|
||||
|
||||
def login(self):
|
||||
"""
|
||||
Login to server
|
||||
:return:
|
||||
"""
|
||||
self._logger.trace(__name__, f'Started {__name__}.login')
|
||||
try:
|
||||
self._logger.debug(__name__, f'Try to login {self._mail_settings.user_name}@{self._mail_settings.host}:{self._mail_settings.port}')
|
||||
self._server.login(self._mail_settings.user_name, CredentialManager.decrypt(self._mail_settings.credentials))
|
||||
self._logger.info(__name__, f'Logged on as {self._mail_settings.user_name} to {self._mail_settings.host}:{self._mail_settings.port}')
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Cannot login to mail server', e)
|
||||
|
||||
self._logger.trace(__name__, f'Stopped {__name__}.login')
|
||||
|
||||
def send_mail(self, email: EMail):
|
||||
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}')
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Cannot send mail to {email.receiver_list}', e)
|
||||
self._logger.trace(__name__, f'Stopped {__name__}.send_mail')
|
||||
@@ -1,59 +0,0 @@
|
||||
import traceback
|
||||
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.mailing.email_client_settings_name_enum import EMailClientSettingsNameEnum
|
||||
|
||||
|
||||
class EMailClientSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._host: str = ''
|
||||
self._port: int = 0
|
||||
self._user_name: str = ''
|
||||
self._credentials: str = ''
|
||||
|
||||
@property
|
||||
def host(self) -> str:
|
||||
return self._host
|
||||
|
||||
@host.setter
|
||||
def host(self, host: str) -> None:
|
||||
self._host = host
|
||||
|
||||
@property
|
||||
def port(self) -> int:
|
||||
return self._port
|
||||
|
||||
@port.setter
|
||||
def port(self, port: int) -> None:
|
||||
self._port = port
|
||||
|
||||
@property
|
||||
def user_name(self) -> str:
|
||||
return self._user_name
|
||||
|
||||
@user_name.setter
|
||||
def user_name(self, user_name: str) -> None:
|
||||
self._user_name = user_name
|
||||
|
||||
@property
|
||||
def credentials(self) -> str:
|
||||
return self._credentials
|
||||
|
||||
@credentials.setter
|
||||
def credentials(self, credentials: str) -> None:
|
||||
self._credentials = credentials
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._host = settings[EMailClientSettingsNameEnum.host.value]
|
||||
self._port = settings[EMailClientSettingsNameEnum.port.value]
|
||||
self._user_name = settings[EMailClientSettingsNameEnum.user_name.value]
|
||||
self._credentials = settings[EMailClientSettingsNameEnum.credentials.value]
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class EMailClientSettingsNameEnum(Enum):
|
||||
|
||||
host = 'Host'
|
||||
port = 'Port'
|
||||
user_name = 'UserName'
|
||||
credentials = 'Credentials'
|
||||
@@ -1,27 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.time'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .time_format_settings import TimeFormatSettings
|
||||
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,61 +0,0 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl.console.console import Console
|
||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl.time.time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
||||
|
||||
|
||||
class TimeFormatSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
self._date_format: Optional[str] = None
|
||||
self._time_format: Optional[str] = None
|
||||
self._date_time_format: Optional[str] = None
|
||||
self._date_time_log_format: Optional[str] = None
|
||||
|
||||
@property
|
||||
def date_format(self) -> str:
|
||||
return self._date_format
|
||||
|
||||
@date_format.setter
|
||||
def date_format(self, date_format: str) -> None:
|
||||
self._date_format = date_format
|
||||
|
||||
@property
|
||||
def time_format(self) -> str:
|
||||
return self._time_format
|
||||
|
||||
@time_format.setter
|
||||
def time_format(self, time_format: str):
|
||||
self._time_format = time_format
|
||||
|
||||
@property
|
||||
def date_time_format(self) -> str:
|
||||
return self._date_time_format
|
||||
|
||||
@date_time_format.setter
|
||||
def date_time_format(self, date_time_format: str) -> None:
|
||||
self._date_time_format = date_time_format
|
||||
|
||||
@property
|
||||
def date_time_log_format(self):
|
||||
return self._date_time_log_format
|
||||
|
||||
@date_time_log_format.setter
|
||||
def date_time_log_format(self, date_time_now_format: str) -> None:
|
||||
self._date_time_log_format = date_time_now_format
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._date_format = settings[TimeFormatSettingsNamesEnum.date_format.value]
|
||||
self._time_format = settings[TimeFormatSettingsNamesEnum.time_format.value]
|
||||
self._date_time_format = settings[TimeFormatSettingsNamesEnum.date_time_format.value]
|
||||
self._date_time_log_format = settings[TimeFormatSettingsNamesEnum.date_time_log_format.value]
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
@@ -1,9 +0,0 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class TimeFormatSettingsNamesEnum(Enum):
|
||||
|
||||
date_format = 'DateFormat'
|
||||
time_format = 'TimeFormat'
|
||||
date_time_format = 'DateTimeFormat'
|
||||
date_time_log_format = 'DateTimeLogFormat'
|
||||
@@ -1,28 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl.utils'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .credential_manager import CredentialManager
|
||||
from .string import String
|
||||
from .pip import Pip
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
@@ -1,36 +0,0 @@
|
||||
import base64
|
||||
|
||||
|
||||
class CredentialManager:
|
||||
"""
|
||||
Handles credentials
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def encrypt(string: str) -> str:
|
||||
"""
|
||||
Encode with base64
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
return base64.b64encode(string.encode('utf-8')).decode('utf-8')
|
||||
|
||||
@staticmethod
|
||||
def decrypt(string: str) -> str:
|
||||
"""
|
||||
Decode with base64
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
return base64.b64decode(string).decode('utf-8')
|
||||
|
||||
@staticmethod
|
||||
def build_string(string: str, credentials: str):
|
||||
"""
|
||||
Builds string with credentials in it
|
||||
:param string:
|
||||
:param credentials:
|
||||
:return:
|
||||
"""
|
||||
return string.replace('$credentials', CredentialManager.decrypt(credentials))
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
import subprocess
|
||||
import sys
|
||||
from contextlib import suppress
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Pip:
|
||||
"""
|
||||
Executes pip commands
|
||||
"""
|
||||
_executable = sys.executable
|
||||
|
||||
"""
|
||||
Getter
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_executable(cls) -> str:
|
||||
return cls._executable
|
||||
|
||||
"""
|
||||
Setter
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def set_executable(cls, executable: str):
|
||||
"""
|
||||
Sets the executable
|
||||
:param executable:
|
||||
:return:
|
||||
"""
|
||||
if executable is not None:
|
||||
cls._executable = executable
|
||||
|
||||
@classmethod
|
||||
def reset_executable(cls):
|
||||
"""
|
||||
Resets the executable to system standard
|
||||
:return:
|
||||
"""
|
||||
cls._executable = sys.executable
|
||||
|
||||
"""
|
||||
Public utils functions
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def get_package(cls, package: str) -> Optional[str]:
|
||||
"""
|
||||
Gets given package py local pip list
|
||||
:param package:
|
||||
:return:
|
||||
"""
|
||||
result = None
|
||||
with suppress(Exception):
|
||||
result = subprocess.check_output([cls._executable, "-m", "pip", "show", package], stderr=subprocess.DEVNULL)
|
||||
|
||||
if result is None:
|
||||
return None
|
||||
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def get_outdated(cls) -> bytes:
|
||||
"""
|
||||
Gets table of outdated packages
|
||||
:return:
|
||||
"""
|
||||
return subprocess.check_output([cls._executable, "-m", "pip", "list", "--outdated"])
|
||||
|
||||
@classmethod
|
||||
def install(cls, package: str, *args, source: str = None, stdout=None, stderr=None):
|
||||
"""
|
||||
Installs given package
|
||||
:param package:
|
||||
:param args:
|
||||
:param source:
|
||||
:param stdout:
|
||||
:param stderr:
|
||||
:return:
|
||||
"""
|
||||
pip_args = [cls._executable, "-m", "pip", "install"]
|
||||
|
||||
for arg in args:
|
||||
pip_args.append(arg)
|
||||
|
||||
if source is not None:
|
||||
pip_args.append(f'--extra-index-url')
|
||||
pip_args.append(source)
|
||||
|
||||
pip_args.append(package)
|
||||
subprocess.run(pip_args, stdout=stdout, stderr=stderr)
|
||||
|
||||
@classmethod
|
||||
def uninstall(cls, package: str, stdout=None, stderr=None):
|
||||
"""
|
||||
Uninstalls given package
|
||||
:param package:
|
||||
:param stdout:
|
||||
:param stderr:
|
||||
:return:
|
||||
"""
|
||||
subprocess.run([cls._executable, "-m", "pip", "uninstall", "--yes", package], stdout=stdout, stderr=stderr)
|
||||
@@ -1,37 +0,0 @@
|
||||
import re
|
||||
|
||||
|
||||
class String:
|
||||
"""
|
||||
Useful functions for strings
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def convert_to_snake_case(name: str) -> str:
|
||||
"""
|
||||
Converts string to snake case
|
||||
:param name:
|
||||
:return:
|
||||
"""
|
||||
pattern1 = re.compile(r'(.)([A-Z][a-z]+)')
|
||||
pattern2 = re.compile(r'([a-z0-9])([A-Z])')
|
||||
file_name = re.sub(pattern1, r'\1_\2', name)
|
||||
return re.sub(pattern2, r'\1_\2', file_name).lower()
|
||||
|
||||
@staticmethod
|
||||
def first_to_upper(string: str) -> str:
|
||||
"""
|
||||
Converts first char to upper
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
return f'{string[0].upper()}{string[1:]}'
|
||||
|
||||
@staticmethod
|
||||
def first_to_lower(string: str) -> str:
|
||||
"""
|
||||
Converts first char to lower
|
||||
:param string:
|
||||
:return:
|
||||
"""
|
||||
return f'{string[0].lower()}{string[1:]}'
|
||||
26
src/cpl_cli/.cpl/__init__.py
Normal file
26
src/cpl_cli/.cpl/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "cpl_cli"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
69
src/cpl_cli/.cpl/project_console.py
Normal file
69
src/cpl_cli/.cpl/project_console.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from cpl_cli.abc.project_type_abc import ProjectTypeABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class Console(ProjectTypeABC):
|
||||
def __init__(
|
||||
self,
|
||||
base_path: str,
|
||||
project_name: str,
|
||||
workspace: WorkspaceSettings,
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
project_file_data: dict,
|
||||
):
|
||||
from project_file import ProjectFile
|
||||
from project_file_appsettings import ProjectFileAppsettings
|
||||
from project_file_code_application import ProjectFileApplication
|
||||
from project_file_code_main import ProjectFileMain
|
||||
from project_file_code_startup import ProjectFileStartup
|
||||
from project_file_readme import ProjectFileReadme
|
||||
from project_file_license import ProjectFileLicense
|
||||
from schematic_init import Init
|
||||
|
||||
ProjectTypeABC.__init__(
|
||||
self,
|
||||
base_path,
|
||||
project_name,
|
||||
workspace,
|
||||
use_application_api,
|
||||
use_startup,
|
||||
use_service_providing,
|
||||
use_async,
|
||||
project_file_data,
|
||||
)
|
||||
|
||||
project_path = f'{base_path}{String.convert_to_snake_case(project_name.split("/")[-1])}/'
|
||||
|
||||
self.add_template(ProjectFile(project_name.split("/")[-1], project_path, project_file_data))
|
||||
if workspace is None:
|
||||
self.add_template(ProjectFileLicense(""))
|
||||
self.add_template(ProjectFileReadme(""))
|
||||
self.add_template(Init("", "init", f"{base_path}tests/"))
|
||||
|
||||
self.add_template(Init("", "init", project_path))
|
||||
self.add_template(ProjectFileAppsettings(project_path))
|
||||
|
||||
if use_application_api:
|
||||
self.add_template(
|
||||
ProjectFileApplication(project_path, use_application_api, use_startup, use_service_providing, use_async)
|
||||
)
|
||||
|
||||
if use_startup:
|
||||
self.add_template(
|
||||
ProjectFileStartup(project_path, use_application_api, use_startup, use_service_providing, use_async)
|
||||
)
|
||||
|
||||
self.add_template(
|
||||
ProjectFileMain(
|
||||
project_name.split("/")[-1],
|
||||
project_path,
|
||||
use_application_api,
|
||||
use_startup,
|
||||
use_service_providing,
|
||||
use_async,
|
||||
)
|
||||
)
|
||||
13
src/cpl_cli/.cpl/project_file.py
Normal file
13
src/cpl_cli/.cpl/project_file.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import json
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
|
||||
|
||||
class ProjectFile(FileTemplateABC):
|
||||
def __init__(self, name: str, path: str, code: dict):
|
||||
FileTemplateABC.__init__(self, "", path, "{}")
|
||||
self._name = f"{name}.json"
|
||||
self._code = code
|
||||
|
||||
def get_code(self) -> str:
|
||||
return json.dumps(self._code, indent=2)
|
||||
29
src/cpl_cli/.cpl/project_file_appsettings.py
Normal file
29
src/cpl_cli/.cpl/project_file_appsettings.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileAppsettings(FileTemplateABC):
|
||||
def __init__(self, path: str):
|
||||
FileTemplateABC.__init__(self, "", path, "{}")
|
||||
self._name = "appsettings.json"
|
||||
|
||||
def get_code(self) -> str:
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "ERROR",
|
||||
"FileLogLevel": "WARN"
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
56
src/cpl_cli/.cpl/project_file_code_application.py
Normal file
56
src/cpl_cli/.cpl/project_file_code_application.py
Normal file
@@ -0,0 +1,56 @@
|
||||
from cpl_cli.abc.code_file_template_abc import CodeFileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileApplication(CodeFileTemplateABC):
|
||||
def __init__(
|
||||
self, path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool, use_async: bool
|
||||
):
|
||||
CodeFileTemplateABC.__init__(
|
||||
self, "application", path, "", use_application_api, use_startup, use_service_providing, use_async
|
||||
)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
if self._use_async:
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
async def configure(self):
|
||||
pass
|
||||
|
||||
async def main(self):
|
||||
Console.write_line('Hello World')
|
||||
"""
|
||||
)
|
||||
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World')
|
||||
"""
|
||||
)
|
||||
107
src/cpl_cli/.cpl/project_file_code_main.py
Normal file
107
src/cpl_cli/.cpl/project_file_code_main.py
Normal file
@@ -0,0 +1,107 @@
|
||||
from cpl_cli.abc.code_file_template_abc import CodeFileTemplateABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class ProjectFileMain(CodeFileTemplateABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
path: str,
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
):
|
||||
CodeFileTemplateABC.__init__(
|
||||
self, "main", path, "", use_application_api, use_startup, use_service_providing, use_async
|
||||
)
|
||||
|
||||
import textwrap
|
||||
|
||||
import_pkg = f"{String.convert_to_snake_case(name)}."
|
||||
|
||||
self._main_with_application_host_and_startup = textwrap.dedent(
|
||||
f"""\
|
||||
{"import asyncio" if self._use_async else ''}
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
from {import_pkg}startup import Startup
|
||||
|
||||
|
||||
{self._async()}def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.use_startup(Startup)
|
||||
{"app: Application = await app_builder.build_async()" if self._use_async else ""}
|
||||
{"await app.run_async()" if self._use_async else "app_builder.build().run()"}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
{"asyncio.run(main())" if self._use_async else "main()"}
|
||||
"""
|
||||
)
|
||||
self._main_with_application_base = textwrap.dedent(
|
||||
f"""\
|
||||
{"import asyncio" if self._use_async else ''}
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
|
||||
|
||||
{self._async()}def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
{"app: Application = await app_builder.build_async()" if self._use_async else ""}
|
||||
{"await app.run_async()" if self._use_async else "app_builder.build().run()"}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
{"asyncio.run(main())" if self._use_async else "main()"}
|
||||
"""
|
||||
)
|
||||
|
||||
self._main_with_dependency_injection = textwrap.dedent(
|
||||
f"""\
|
||||
{"import asyncio" if self._use_async else ''}
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
|
||||
{self._async()}def configure_configuration() -> ConfigurationABC:
|
||||
config = Configuration()
|
||||
return config
|
||||
|
||||
|
||||
{self._async()}def configure_services(config: ConfigurationABC) -> ServiceProviderABC:
|
||||
services = ServiceCollection(config)
|
||||
return services.build_service_provider()
|
||||
|
||||
|
||||
{self._async()}def main():
|
||||
config = {self._async()}configure_configuration()
|
||||
provider = {self._async()}configure_services(config)
|
||||
Console.write_line('Hello World')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
{"asyncio.run(main())" if self._use_async else "main()"}
|
||||
"""
|
||||
)
|
||||
|
||||
def _async(self) -> str:
|
||||
if self._use_async:
|
||||
return "async "
|
||||
return ""
|
||||
|
||||
def get_code(self) -> str:
|
||||
if self._use_application_api and self._use_startup:
|
||||
return self._main_with_application_host_and_startup
|
||||
|
||||
if self._use_application_api:
|
||||
return self._main_with_application_base
|
||||
|
||||
if self._use_service_providing:
|
||||
return self._main_with_dependency_injection
|
||||
|
||||
return self._main_with_application_base
|
||||
34
src/cpl_cli/.cpl/project_file_code_startup.py
Normal file
34
src/cpl_cli/.cpl/project_file_code_startup.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from cpl_cli.abc.code_file_template_abc import CodeFileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileStartup(CodeFileTemplateABC):
|
||||
def __init__(
|
||||
self, path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool, use_async: bool
|
||||
):
|
||||
CodeFileTemplateABC.__init__(
|
||||
self, "startup", path, "", use_application_api, use_startup, use_service_providing, use_async
|
||||
)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
return services.build_service_provider()
|
||||
"""
|
||||
)
|
||||
66
src/cpl_cli/.cpl/project_file_code_test_application.py
Normal file
66
src/cpl_cli/.cpl/project_file_code_test_application.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from cpl_cli.abc.code_file_template_abc import CodeFileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileTestApplication(CodeFileTemplateABC):
|
||||
def __init__(
|
||||
self, path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool, use_async: bool
|
||||
):
|
||||
CodeFileTemplateABC.__init__(
|
||||
self, "application", path, "", use_application_api, use_startup, use_service_providing, use_async
|
||||
)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
if self._use_async:
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
async def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
async def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
"""
|
||||
)
|
||||
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
"""
|
||||
)
|
||||
44
src/cpl_cli/.cpl/project_file_code_test_case.py
Normal file
44
src/cpl_cli/.cpl/project_file_code_test_case.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from cpl_cli.abc.code_file_template_abc import CodeFileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileTestCase(CodeFileTemplateABC):
|
||||
def __init__(
|
||||
self, path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool, use_async: bool
|
||||
):
|
||||
CodeFileTemplateABC.__init__(
|
||||
self, "test_case", path, "", use_application_api, use_startup, use_service_providing, use_async
|
||||
)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
if self._use_async:
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
async def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
async def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
"""
|
||||
)
|
||||
|
||||
return textwrap.dedent(
|
||||
"""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
"""
|
||||
)
|
||||
10
src/cpl_cli/.cpl/project_file_license.py
Normal file
10
src/cpl_cli/.cpl/project_file_license.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileLicense(FileTemplateABC):
|
||||
def __init__(self, path: str):
|
||||
FileTemplateABC.__init__(self, "", path, "")
|
||||
self._name = "LICENSE"
|
||||
|
||||
def get_code(self) -> str:
|
||||
return self._code
|
||||
10
src/cpl_cli/.cpl/project_file_readme.py
Normal file
10
src/cpl_cli/.cpl/project_file_readme.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
|
||||
|
||||
class ProjectFileReadme(FileTemplateABC):
|
||||
def __init__(self, path: str):
|
||||
FileTemplateABC.__init__(self, "", path, "")
|
||||
self._name = "README.md"
|
||||
|
||||
def get_code(self) -> str:
|
||||
return self._code
|
||||
46
src/cpl_cli/.cpl/project_library.py
Normal file
46
src/cpl_cli/.cpl/project_library.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.abc.project_type_abc import ProjectTypeABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class Library(ProjectTypeABC):
|
||||
def __init__(
|
||||
self,
|
||||
base_path: str,
|
||||
project_name: str,
|
||||
workspace: WorkspaceSettings,
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
project_file_data: dict,
|
||||
):
|
||||
from project_file import ProjectFile
|
||||
from project_file_readme import ProjectFileReadme
|
||||
from project_file_license import ProjectFileLicense
|
||||
from schematic_init import Init
|
||||
from schematic_class import Class
|
||||
|
||||
ProjectTypeABC.__init__(
|
||||
self,
|
||||
base_path,
|
||||
project_name,
|
||||
workspace,
|
||||
use_application_api,
|
||||
use_startup,
|
||||
use_service_providing,
|
||||
use_async,
|
||||
project_file_data,
|
||||
)
|
||||
|
||||
project_path = f'{base_path}{String.convert_to_snake_case(project_name.split("/")[-1])}/'
|
||||
|
||||
self.add_template(ProjectFile(project_name.split("/")[-1], project_path, project_file_data))
|
||||
if workspace is None:
|
||||
self.add_template(ProjectFileLicense(""))
|
||||
self.add_template(ProjectFileReadme(""))
|
||||
|
||||
self.add_template(Init("", "init", project_path))
|
||||
self.add_template(Class("Class1", "class", project_path))
|
||||
64
src/cpl_cli/.cpl/project_unittest.py
Normal file
64
src/cpl_cli/.cpl/project_unittest.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.abc.project_type_abc import ProjectTypeABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class Unittest(ProjectTypeABC):
|
||||
def __init__(
|
||||
self,
|
||||
base_path: str,
|
||||
project_name: str,
|
||||
workspace: WorkspaceSettings,
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
project_file_data: dict,
|
||||
):
|
||||
from project_file import ProjectFile
|
||||
from project_file_code_application import ProjectFileApplication
|
||||
from project_file_code_main import ProjectFileMain
|
||||
from project_file_code_test_case import ProjectFileTestCase
|
||||
from project_file_readme import ProjectFileReadme
|
||||
from project_file_license import ProjectFileLicense
|
||||
from schematic_init import Init
|
||||
|
||||
ProjectTypeABC.__init__(
|
||||
self,
|
||||
base_path,
|
||||
project_name,
|
||||
workspace,
|
||||
use_application_api,
|
||||
use_startup,
|
||||
use_service_providing,
|
||||
use_async,
|
||||
project_file_data,
|
||||
)
|
||||
|
||||
project_path = f'{base_path}{String.convert_to_snake_case(project_name.split("/")[-1])}/'
|
||||
|
||||
self.add_template(ProjectFile(project_name.split("/")[-1], project_path, project_file_data))
|
||||
if workspace is None:
|
||||
self.add_template(ProjectFileLicense(""))
|
||||
self.add_template(ProjectFileReadme(""))
|
||||
self.add_template(Init("", "init", f"{base_path}tests/"))
|
||||
|
||||
self.add_template(Init("", "init", project_path))
|
||||
self.add_template(
|
||||
ProjectFileApplication(project_path, use_application_api, use_startup, use_service_providing, use_async)
|
||||
)
|
||||
self.add_template(
|
||||
ProjectFileMain(
|
||||
project_name.split("/")[-1],
|
||||
project_path,
|
||||
use_application_api,
|
||||
use_startup,
|
||||
use_service_providing,
|
||||
use_async,
|
||||
)
|
||||
)
|
||||
self.add_template(
|
||||
ProjectFileTestCase(project_path, use_application_api, use_startup, use_service_providing, use_async)
|
||||
)
|
||||
27
src/cpl_cli/.cpl/schematic_abc.py
Normal file
27
src/cpl_cli/.cpl/schematic_abc.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class ABC(GenerateSchematicABC):
|
||||
def __init__(self, name: str, schematic: str, path: str):
|
||||
GenerateSchematicABC.__init__(self, name, schematic, path)
|
||||
self._class_name = name
|
||||
if name != "":
|
||||
self._class_name = f'{String.first_to_upper(name.replace(schematic, ""))}ABC'
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class $Name(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "abc", ["a", "A"])
|
||||
34
src/cpl_cli/.cpl/schematic_application.py
Normal file
34
src/cpl_cli/.cpl/schematic_application.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Application(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class $Name(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World')
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "application", ["app", "APP"])
|
||||
31
src/cpl_cli/.cpl/schematic_application_extension.py
Normal file
31
src/cpl_cli/.cpl/schematic_application_extension.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class ApplicationExtension(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.application import ApplicationExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class $Name(ApplicationExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationExtensionABC.__init__(self)
|
||||
|
||||
def run(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=String.convert_to_camel_case(self._class_name))
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "application-extension", ["appex", "APPEX"])
|
||||
23
src/cpl_cli/.cpl/schematic_class.py
Normal file
23
src/cpl_cli/.cpl/schematic_class.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class Class(GenerateSchematicABC):
|
||||
def __init__(self, name: str, schematic: str, path: str):
|
||||
GenerateSchematicABC.__init__(self, name, schematic, path)
|
||||
self._name = f"{String.convert_to_snake_case(name)}.py"
|
||||
self._class_name = f"{String.first_to_upper(name)}"
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
class $Name:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "class", ["c", "C"])
|
||||
35
src/cpl_cli/.cpl/schematic_configmodel.py
Normal file
35
src/cpl_cli/.cpl/schematic_configmodel.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class ConfigModel(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class $Name(ConfigurationModelABC):
|
||||
|
||||
def __init__(self, atr: str = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._atr = atr
|
||||
|
||||
@property
|
||||
def atr(self) -> str:
|
||||
return self._atr
|
||||
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "settings", ["st", "ST"])
|
||||
25
src/cpl_cli/.cpl/schematic_enum.py
Normal file
25
src/cpl_cli/.cpl/schematic_enum.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Enum(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
|
||||
code = textwrap.dedent(
|
||||
"""\
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class $Name(Enum):
|
||||
|
||||
atr = 0
|
||||
"""
|
||||
)
|
||||
return self.build_code_str(code, Name=self._class_name)
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "enum", ["e", "E"])
|
||||
20
src/cpl_cli/.cpl/schematic_init.py
Normal file
20
src/cpl_cli/.cpl/schematic_init.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Init(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
self._name = f"__init__.py"
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
# imports
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "init", [])
|
||||
27
src/cpl_cli/.cpl/schematic_pipe.py
Normal file
27
src/cpl_cli/.cpl/schematic_pipe.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Pipe(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class $Name(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: any, *args):
|
||||
return value
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "pipe", ["p", "P"])
|
||||
46
src/cpl_cli/.cpl/schematic_schematic.py
Normal file
46
src/cpl_cli/.cpl/schematic_schematic.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class Schematic(GenerateSchematicABC):
|
||||
def __init__(self, name: str, path: str, schematic: str):
|
||||
GenerateSchematicABC.__init__(self, name, path, schematic)
|
||||
self._name = f"schematic_{String.convert_to_snake_case(name)}.py"
|
||||
self._path = ".cpl/"
|
||||
self._class_name = String.convert_to_camel_case(name)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class $Name(GenerateSchematicABC):
|
||||
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
import textwrap
|
||||
code = textwrap.dedent(\"\"\"\\
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class $Name(Enum):
|
||||
|
||||
atr = 0
|
||||
\"\"\")
|
||||
return self.build_code_str(code, Name=self._class_name)
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(
|
||||
cls,
|
||||
'$NameLower',
|
||||
[]
|
||||
)
|
||||
"""
|
||||
return self.build_code_str(code, Name=self._class_name, NameLower=self._class_name.lower())
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "schematic", ["scheme", "SCHEME"])
|
||||
22
src/cpl_cli/.cpl/schematic_service.py
Normal file
22
src/cpl_cli/.cpl/schematic_service.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Service(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
class $Name:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "service", ["s", "S"])
|
||||
34
src/cpl_cli/.cpl/schematic_startup.py
Normal file
34
src/cpl_cli/.cpl/schematic_startup.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Startup(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
|
||||
class $Name(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
return services.build_service_provider()
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "startup", ["stup", "STUP"])
|
||||
35
src/cpl_cli/.cpl/schematic_startup_extension.py
Normal file
35
src/cpl_cli/.cpl/schematic_startup_extension.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class StartupExtension(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
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
|
||||
|
||||
|
||||
class $Name(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=String.convert_to_camel_case(self._class_name))
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "startup-extension", ["stupex", "STUPEX"])
|
||||
28
src/cpl_cli/.cpl/schematic_test_case.py
Normal file
28
src/cpl_cli/.cpl/schematic_test_case.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class TestCase(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
import unittest
|
||||
|
||||
|
||||
class $Name(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
"""
|
||||
return self.build_code_str(code, Name=String.convert_to_camel_case(self._class_name))
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "test-case", ["tc", "TC"])
|
||||
28
src/cpl_cli/.cpl/schematic_thread.py
Normal file
28
src/cpl_cli/.cpl/schematic_thread.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Thread(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
import threading
|
||||
|
||||
|
||||
class $Name(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
def run(self) -> None:
|
||||
pass
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "thread", ["t", "T"])
|
||||
28
src/cpl_cli/.cpl/schematic_validator.py
Normal file
28
src/cpl_cli/.cpl/schematic_validator.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
|
||||
|
||||
|
||||
class Validator(GenerateSchematicABC):
|
||||
def __init__(self, *args: str):
|
||||
GenerateSchematicABC.__init__(self, *args)
|
||||
|
||||
def get_code(self) -> str:
|
||||
code = """\
|
||||
from cpl_core.configuration.validator_abc import ValidatorABC
|
||||
|
||||
|
||||
class $Name(ValidatorABC):
|
||||
|
||||
def __init__(self):
|
||||
ValidatorABC.__init__(self)
|
||||
|
||||
def validate(self) -> bool:
|
||||
return True
|
||||
"""
|
||||
x = self.build_code_str(code, Name=self._class_name)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def register(cls):
|
||||
GenerateSchematicABC.register(cls, "validator", ["v", "V"])
|
||||
@@ -1,32 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'sh_cpl.cpl_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1.post15'
|
||||
__title__ = "cpl_cli"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
from .cli import CLI
|
||||
from .command_abc import CommandABC
|
||||
from .command_handler_service import CommandHandler
|
||||
from .command_model import CommandModel
|
||||
from .error import Error
|
||||
from .main import main
|
||||
from .startup import Startup
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2021', minor='04', micro='01-15')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
|
||||
26
src/cpl_cli/_templates/__init__.py
Normal file
26
src/cpl_cli/_templates/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "cpl_cli._templates"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
26
src/cpl_cli/_templates/build/__init__.py
Normal file
26
src/cpl_cli/_templates/build/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "cpl_cli._templates.build"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
@@ -2,10 +2,10 @@ import textwrap
|
||||
|
||||
|
||||
class InitTemplate:
|
||||
|
||||
@staticmethod
|
||||
def get_init_py() -> str:
|
||||
string = textwrap.dedent("""\
|
||||
string = textwrap.dedent(
|
||||
"""\
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
\"\"\"
|
||||
@@ -19,18 +19,20 @@ class InitTemplate:
|
||||
|
||||
\"\"\"
|
||||
|
||||
__title__ = '$Title'
|
||||
__author__ = '$Author'
|
||||
__license__ = '$LicenseName'
|
||||
__copyright__ = 'Copyright (c) $CopyrightDate $CopyrightName'
|
||||
__version__ = '$Version'
|
||||
__title__ = "$Title"
|
||||
__author__ = "$Author"
|
||||
__license__ = "$LicenseName"
|
||||
__copyright__ = "Copyright (c) $CopyrightDate $CopyrightName"
|
||||
__version__ = "$Version"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
$Imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='$Major', minor='$Minor', micro='$Micro')
|
||||
""")
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="$Major", minor="$Minor", micro="$Micro")
|
||||
"""
|
||||
)
|
||||
|
||||
return string
|
||||
26
src/cpl_cli/_templates/publish/__init__.py
Normal file
26
src/cpl_cli/_templates/publish/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "cpl_cli._templates.publish"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
@@ -2,10 +2,10 @@ import textwrap
|
||||
|
||||
|
||||
class SetupTemplate:
|
||||
|
||||
@staticmethod
|
||||
def get_setup_py() -> str:
|
||||
string = textwrap.dedent("""\
|
||||
string = textwrap.dedent(
|
||||
"""\
|
||||
\"\"\"
|
||||
This file is generated by CPL CLI
|
||||
\"\"\"
|
||||
@@ -27,6 +27,7 @@ class SetupTemplate:
|
||||
entry_points=$EntryPoints,
|
||||
package_data=$PackageData
|
||||
)
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
return string
|
||||
@@ -2,18 +2,21 @@ from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class TemplateFileABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str: pass
|
||||
def name(self) -> str:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def path(self) -> str: pass
|
||||
def path(self) -> str:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def value(self) -> str: pass
|
||||
def value(self) -> str:
|
||||
pass
|
||||
26
src/cpl_cli/abc/__init__.py
Normal file
26
src/cpl_cli/abc/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2024 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = "cpl_cli.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2024 sh-edraft.de"
|
||||
__version__ = "2024.10.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2024", minor="10", micro="0")
|
||||
23
src/cpl_cli/abc/code_file_template_abc.py
Normal file
23
src/cpl_cli/abc/code_file_template_abc.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class CodeFileTemplateABC(FileTemplateABC):
|
||||
@abstractmethod
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
path: str,
|
||||
code: str,
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
):
|
||||
FileTemplateABC.__init__(self, name, path, code)
|
||||
self._use_application_api = use_application_api
|
||||
self._use_startup = use_startup
|
||||
self._use_service_providing = use_service_providing
|
||||
self._use_async = use_async
|
||||
34
src/cpl_cli/abc/file_template_abc.py
Normal file
34
src/cpl_cli/abc/file_template_abc.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class FileTemplateABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self, name: str, path: str, code: str):
|
||||
self._name = f"{String.convert_to_snake_case(name)}.py"
|
||||
self._path = path
|
||||
self._code = code
|
||||
|
||||
def __repr__(self):
|
||||
return f"<{type(self).__name__} {self._path}{self._name}>"
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@path.setter
|
||||
def path(self, value: str):
|
||||
self._path = value
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self.get_code()
|
||||
|
||||
@abstractmethod
|
||||
def get_code(self) -> str:
|
||||
pass
|
||||
40
src/cpl_cli/abc/generate_schematic_abc.py
Normal file
40
src/cpl_cli/abc/generate_schematic_abc.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import textwrap
|
||||
from abc import abstractmethod
|
||||
from string import Template
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
from cpl_cli.configuration.schematic_collection import SchematicCollection
|
||||
from cpl_core.utils import String
|
||||
|
||||
|
||||
class GenerateSchematicABC(FileTemplateABC):
|
||||
def __init__(self, name: str, schematic: str, path: str):
|
||||
FileTemplateABC.__init__(self, name, path, "")
|
||||
self._name = f"{String.convert_to_snake_case(name)}_{schematic}.py"
|
||||
if schematic in name.lower():
|
||||
self._name = f"{String.convert_to_snake_case(name)}.py"
|
||||
|
||||
self._class_name = name
|
||||
if name != "":
|
||||
self._class_name = f"{String.first_to_upper(name)}{String.first_to_upper(schematic)}"
|
||||
|
||||
if schematic in name.lower():
|
||||
self._class_name = f"{String.first_to_upper(name)}"
|
||||
|
||||
@property
|
||||
def class_name(self) -> str:
|
||||
return self._class_name
|
||||
|
||||
@abstractmethod
|
||||
def get_code(self) -> str:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def build_code_str(cls, code: str, **kwargs) -> str:
|
||||
text = textwrap.dedent(code)
|
||||
return Template(text).substitute(**kwargs)
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def register(cls, *args):
|
||||
SchematicCollection.register(*args)
|
||||
36
src/cpl_cli/abc/project_type_abc.py
Normal file
36
src/cpl_cli/abc/project_type_abc.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.abc.file_template_abc import FileTemplateABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
|
||||
|
||||
class ProjectTypeABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(
|
||||
self,
|
||||
base_path: str,
|
||||
project_name: str,
|
||||
workspace: Optional[WorkspaceSettings],
|
||||
use_application_api: bool,
|
||||
use_startup: bool,
|
||||
use_service_providing: bool,
|
||||
use_async: bool,
|
||||
project_file_data: dict,
|
||||
):
|
||||
self._templates: list[FileTemplateABC] = []
|
||||
self._base_path = base_path
|
||||
self._project_name = project_name
|
||||
self._workspace = workspace
|
||||
self._use_application_api = use_application_api
|
||||
self._use_startup = use_startup
|
||||
self._use_service_providing = use_service_providing
|
||||
self._use_async = use_async
|
||||
self._project_file_data = project_file_data
|
||||
|
||||
@property
|
||||
def templates(self) -> list[FileTemplateABC]:
|
||||
return self._templates
|
||||
|
||||
def add_template(self, t: FileTemplateABC):
|
||||
self._templates.append(t)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user