-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform.py
53 lines (41 loc) · 1.23 KB
/
platform.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Abstraction layer for platform dependencies, useful e.g. for porting.
To port this to e.g. client-side JS, files could be replaced by localStorage
blobs.
"""
import os
from zipfile import ZipFile
def get_text_file_contents(path):
return open(path)
def read_file(path):
#print('read_file()')
#print(f'- path: {path}')
with open(path, 'r') as f:
return f.read()
def write_to_file(path, content):
with open(path, 'wb') as f:
f.write(content)
f.close()
def get_mtime(path):
return os.path.getmtime(path)
def resource_exists(path):
return os.path.exists(path)
def ensure_resource_path(path):
if not os.path.isdir(path):
os.makedirs(path)
def copy_file(src_path, dst_path):
os.system(f'cp {src_path} {dst_path}')
def unpack_zip(url, dst_path, files):
#print(f'storage.unpack_zip()')
#print(f'- url: {url}')
#print(f'- dst_path: {dst_path}')
#print(f'- files: {files}')
gtfs_zip = ZipFile(url)
for n in files:
#print(f'-- zip entry: {n}')
ze = gtfs_zip.open(n)
content = ze.read().decode('utf-8')
#print(f'++ name: {dst_path + n}')
with open(dst_path + n, 'w') as ff:
ff.write(content)
ff.close()