Make all paths absolute

This commit is contained in:
Anton Zadvorny 2020-01-22 17:30:11 +03:00
parent fcccdc71aa
commit a065557028

View File

@ -53,16 +53,16 @@ def main():
) )
cursor = conn.cursor() cursor = conn.cursor()
if op.exists('codes.7z'): if op.exists('/opt/gtfs2qr/codes.7z'):
os.unlink('codes.7z') os.unlink('/opt/gtfs2qr/codes.7z')
shutil.rmtree('codes', ignore_errors=True) shutil.rmtree('/opt/gtfs2qr/codes', ignore_errors=True)
cursor.execute('SELECT * FROM routes ORDER BY route_short_name;') cursor.execute('SELECT * FROM routes ORDER BY route_short_name;')
for route in cursor.fetchall(): for route in cursor.fetchall():
for d in (0, 1): for d in (0, 1):
route_path = op.join( route_path = op.join(
'codes', '/opt/gtfs2qr/codes',
transport_type[route['transport_type']], transport_type[route['transport_type']],
route['route_short_name'], route['route_short_name'],
'туда' if d == 0 else 'обратно' 'туда' if d == 0 else 'обратно'
@ -96,7 +96,7 @@ def main():
img = qr.make_image(fill_color="black", back_color="white") img = qr.make_image(fill_color="black", back_color="white")
draw = ImageDraw.Draw(img) draw = ImageDraw.Draw(img)
font = ImageFont.truetype("Verdana.ttf", 12) font = ImageFont.truetype("/opt/gtfs2qr/Verdana.ttf", 12)
stop_name += ' (%i)' % stop['stop_id'] stop_name += ' (%i)' % stop['stop_id']
text_size = font.getsize(stop_name) text_size = font.getsize(stop_name)
draw.text(((img.size[0] - text_size[0]) / 2, img.size[1] - 25), stop_name, font=font) draw.text(((img.size[0] - text_size[0]) / 2, img.size[1] - 25), stop_name, font=font)
@ -106,13 +106,13 @@ def main():
qr.clear() qr.clear()
subprocess.run(['7za', 'a', 'codes', 'codes'], check=True) subprocess.run(['7za', 'a', '/opt/gtfs2qr/codes.7z', '/opt/gtfs2qr/codes'], check=True)
with ftplib.FTP(host=FTP_HOST, user=FTP_USER, passwd=FTP_PASS) as ftp: with ftplib.FTP(host=FTP_HOST, user=FTP_USER, passwd=FTP_PASS) as ftp:
if 'codes.7z' in ftp.nlst(): if 'codes.7z' in ftp.nlst():
ftp.delete('codes.7z') ftp.delete('codes.7z')
with open('codes.7z', 'rb') as arch: with open('/opt/gtfs2qr/codes.7z', 'rb') as arch:
ftp.storbinary('STOR codes.7z', arch) ftp.storbinary('STOR codes.7z', arch)