mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-25 19:44:13 +01:00
UTC calculation fix in setup.py
* Streamlined all date calculation based on git timestamps. * Removed incorrect utc_date calculation. * Minimised the code differences for Python versions (down to one line). * Changed the git show command to leverage the output displaying the number of seconds since the epoch. * Thus making the final UTC calculation simply a function of specifying that in a time.gmtime call instead of attempting offset based calculations (which the original code got wrong).
This commit is contained in:
parent
8981b225f1
commit
b6af3baf6d
20
setup.py
20
setup.py
@ -52,22 +52,18 @@ if path:
|
|||||||
VERSION_FILE = os.path.join('src', 'version.py')
|
VERSION_FILE = os.path.join('src', 'version.py')
|
||||||
version = None
|
version = None
|
||||||
try:
|
try:
|
||||||
proc = subprocess.Popen('git show HEAD --format=%ci', shell=True,
|
proc = subprocess.Popen('git show HEAD --format=%ct', shell=True,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
date = proc.stdout.readline()
|
date = proc.stdout.readline()
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
date = date.decode()
|
sdate = date.decode().strip()
|
||||||
date = time.strptime(date.strip(), '%Y-%m-%d %H:%M:%S %z')
|
|
||||||
utc_date = time.gmtime(time.mktime(date))
|
|
||||||
version = time.strftime('%Y.%m.%d', utc_date)
|
|
||||||
else:
|
else:
|
||||||
(date, timezone) = date.strip().rsplit(' ', 1)
|
sdate = date.strip()
|
||||||
date = datetime.datetime.strptime(date.strip(), '%Y-%m-%d %H:%M:%S')
|
idate = int(sdate)
|
||||||
offset = time.strptime(timezone[1:], '%H%M')
|
ldate = []
|
||||||
offset = datetime.timedelta(hours=offset.tm_hour,
|
for i in time.strptime(time.asctime(time.gmtime(idate)))[:3]:
|
||||||
minutes=offset.tm_min)
|
ldate.append(str(i).zfill(2))
|
||||||
utc_date = date - offset
|
version = ".".join(ldate)
|
||||||
version = utc_date.strftime('%Y.%m.%d')
|
|
||||||
except:
|
except:
|
||||||
if os.path.isfile(VERSION_FILE):
|
if os.path.isfile(VERSION_FILE):
|
||||||
from src.version import version
|
from src.version import version
|
||||||
|
Loading…
Reference in New Issue
Block a user