From a99eb8f679133e66df484fe1eca19151b2e3b4a6 Mon Sep 17 00:00:00 2001 From: "steven.liatti" <steven@liatti.ch> Date: Sat, 17 Oct 2020 13:11:57 +0200 Subject: [PATCH] Refactor some code for compatibility with older than 3.9 python --- README.md | 2 +- pwm | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cb4dc07..54f9fd7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Le moment est venu de créer les dépôts git pour chaque groupe/étudiant suiva ## Utilisation de pwm -Ce programme est écrit en python et testé avec la version 3.9.0, avec les dépendances suivantes (voir `requirements.txt`) : +Ce programme est écrit en python et testé avec les versions 3.6, 3.7, 3.8 et 3.9, avec les dépendances suivantes (voir `requirements.txt`) : ``` requests diff --git a/pwm b/pwm index 51b0a32..9f85c32 100755 --- a/pwm +++ b/pwm @@ -281,7 +281,7 @@ if __name__ == '__main__': 'clone', help='Clone the repositories locally') group_clone = parser_clone.add_mutually_exclusive_group() group_clone.add_argument("-g", "--group", action="store_true", - help="Clone repositories from a group (with group_id) or forks of a project (with project_id) (default behavior).") + help="Clone repositories from a group (with group_id) (default behavior).") group_clone.add_argument("-f", "--forks", action="store_true", help="Clone forks of a project (with project_id).") parser_clone.add_argument( @@ -295,13 +295,16 @@ if __name__ == '__main__': args = parser.parse_args() if not args.token: - if os.path.isfile(path := os.environ.get('HOME') + '/.gitedu_token'): - with open(path) as file: - args.token = file.read().strip() + home = os.environ.get('HOME') + if home: + token_file = home + '/.gitedu_token' + if os.path.isfile(token_file): + with open(token_file) as file: + args.token = file.read().strip() elif os.environ.get('GITEDU_TOKEN'): args.token = os.environ.get('GITEDU_TOKEN') else: - print('Error: you must given a token') + print('Error: you must give a valid api token. Create a token here: https://gitedu.hesge.ch/profile/personal_access_tokens') exit(1) args.func(args) -- GitLab