comparison scripts/hvresources/uploader.py @ 540:67a746eea29e prerelease

Updated uploader.py
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 24 Jun 2016 02:12:35 +0100
parents a084456960c9
children ff0e9e827dcd
comparison
equal deleted inserted replaced
539:b486344aa796 540:67a746eea29e
1 # Copyright 2015,2016 Enzien Audio, Ltd. All Rights Reserved. 1 # Copyright 2015,2016 Enzien Audio, Ltd. All Rights Reserved.
2 2
3 import argparse 3 import argparse
4 import datetime
4 import getpass 5 import getpass
5 import json 6 import json
6 import os 7 import os
7 import requests 8 import requests
8 import shutil 9 import shutil
128 129
129 tick = time.time() 130 tick = time.time()
130 131
131 # parse the optional release argument 132 # parse the optional release argument
132 if args.release: 133 if args.release:
134 try:
135 # check the validity of the current release
136 releases_json = requests.get(urlparse.urljoin(domain, "/a/releases")).json()
137 if args.release in releases_json:
138 today = datetime.datetime.now()
139 valid_until = datetime.datetime.strptime(releases_json[args.release]["validUntil"], "%Y-%m-%d")
140 if today > valid_until:
141 print "{0}Warning:{1} The release \"{2}\" expired on {3}. It may be removed at any time!".format(
142 Colours.yellow, Colours.end,
143 args.release,
144 releases_json[args.release]["validUntil"])
145 elif (valid_until - today) <= datetime.timedelta(weeks=4):
146 print "{0}Warning:{1} The release \"{2}\" will expire soon on {3}.".format(
147 Colours.yellow, Colours.end,
148 args.release,
149 releases_json[args.release]["validUntil"])
150 else:
151 print "{0}Error:{1} The release \"{2}\" is not available. Available releases are:".format(
152 Colours.red, Colours.end,
153 args.release)
154 for k,v in releases_json.items():
155 print "* {0} ({1})".format(
156 k,
157 v["releaseDate"])
158 return
159 except:
160 pass # if the /a/releases request fails for whatever reason, just move on
161
133 post_data["release"] = args.release 162 post_data["release"] = args.release
134 163
135 # make a temporary directory 164 # make a temporary directory
136 temp_dir = tempfile.mkdtemp(prefix="lroyal-") 165 temp_dir = tempfile.mkdtemp(prefix="lroyal-")
137 166