From 7c6fa54271546201344591723fa1ba6bead2cf6b Mon Sep 17 00:00:00 2001 From: Florent Fayolle Date: Thu, 8 Nov 2018 21:23:28 +0100 Subject: [PATCH] Rework adl-submit.py so it can be used as a library --- public/adl-submit.py | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/public/adl-submit.py b/public/adl-submit.py index a86f357e..65958401 100755 --- a/public/adl-submit.py +++ b/public/adl-submit.py @@ -369,28 +369,33 @@ def SubmitEvent(event, testOutputFile): finally: curl.close() +def ensure_latest_version_is_used(): + # Check that we are running the latest version of the adl-submit + # script + contents = io.BytesIO() + curl = pycurl.Curl() + try: + curl.setopt(curl.WRITEDATA, contents) + curl.setopt (curl.URL, baseUrl + './adl-submit-latest-version') + curl.perform() + if curl.getinfo(curl.HTTP_CODE) == 200: + contents = contents.getvalue().decode() + if float(contents) != float('3.5'): + print("Votre script n'est plus à jour, merci de télécharger la nouvelle version à l'adresse") + print(("%sadl-submit.py") % baseUrl) + sys.exit(1) + finally: + curl.close() -if (len(sys.argv) <= 1) or sys.argv[1] == "--help": - Usage() -(event, testOutputFile) = ParseOptions(sys.argv[1:]) -# Check that we are running the latest version of the adl-submit -# script -contents = io.BytesIO() -curl = pycurl.Curl() -try: - curl.setopt(curl.WRITEDATA, contents) - curl.setopt (curl.URL, baseUrl + './adl-submit-latest-version') - curl.perform() - if curl.getinfo(curl.HTTP_CODE) == 200: - contents = contents.getvalue().decode() - if float(contents) != float('3.5'): - print("Votre script n'est plus à jour, merci de télécharger la nouvelle version à l'adresse") - print(("%sadl-submit.py") % baseUrl) - sys.exit(1) -finally: - curl.close() +if __name__ == "__main__": + if (len(sys.argv) <= 1) or sys.argv[1] == "--help": + Usage() -SubmitEvent(event, testOutputFile) + (event, testOutputFile) = ParseOptions(sys.argv[1:]) + + ensure_latest_version_is_used() + + SubmitEvent(event, testOutputFile)