From 037f3a9a5e63a3273508a69387477c1019b99f9d Mon Sep 17 00:00:00 2001 From: Vasek Sraier Date: Sun, 24 Mar 2019 13:46:16 +0100 Subject: [PATCH] improved persistent configuration management --- README.md | 4 ++++ config.py | 3 --- config_default.py | 5 +++++ register.py | 15 ++++++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) delete mode 100644 config.py create mode 100644 config_default.py diff --git a/README.md b/README.md index 711b3c8..363d76b 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ pipenv run python register.py --help Snaha je, aby se co nejvíce dokumentace nacházelo v kódu. Vysvětlení proto získáte zavoláním programu s argumentem `--help`. Žádné další informace by k tomu neměly být potřeba. +## Konfigurace + +Pro perzistentní konfiguraci je možné použít soubor `config.py` zkopírováním z `config_default.py`. + ## Dokumentace API Gitei Gitea má specifikaci API popsanou dle specifikace OpenAPI 2.0 (dříve nazýváno Swagger). Pokud není explicitně řečeno diff --git a/config.py b/config.py deleted file mode 100644 index 070b55d..0000000 --- a/config.py +++ /dev/null @@ -1,3 +0,0 @@ -# Zde je mozne nastavit vychozi hodnoty -HOST = 'https://gitea.url/api/v1' -ADMIN_TOKEN = '' diff --git a/config_default.py b/config_default.py new file mode 100644 index 0000000..f24d817 --- /dev/null +++ b/config_default.py @@ -0,0 +1,5 @@ +# base URL adresa pro API +HOST = 'https://try.gitea.io/api/v1' + +# autorizacni token administratora +ADMIN_TOKEN = '' diff --git a/register.py b/register.py index e369f8d..bd2ef9e 100644 --- a/register.py +++ b/register.py @@ -13,6 +13,16 @@ import random import string +# load configuration +try: + import config +except ImportError: + import config_default as config + +HOST = config.HOST +ADMIN_TOKEN = config.ADMIN_TOKEN + + def rand_str(n) -> str: return ''.join([random.choice(string.ascii_lowercase) for _ in range(n)]) @@ -118,11 +128,6 @@ def reset_password(email: str): raise ApiException(status=resp.status_code, reason=resp.reason, http_resp='Form submission failed.') -import config -HOST = config.HOST -ADMIN_TOKEN = config.ADMIN_TOKEN - - @click.command() @click.option('-a', '--admin-token', help='Admin access token') @click.option('-h', '--host', help='Gitea URL (default: {})'.format(HOST))