-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
83 lines (62 loc) · 2.21 KB
/
setup.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import sys
from sqlalchemy.sql.expression import text
import models
import settings
from database import Database
from models import Offer
def setup():
if not check_python():
print("This software needs Python 3.4 minimum")
return
print("Python version check OK")
if not check_chmods():
print("Please enable read and write access to", settings.PATH_CACHE_GEOCODER)
return
print("File permissions check OK")
if not check_database():
print("Please install PostgreSQL 9.5 and enable PostGIS")
return
print("PostgreSQL and PostGIS connection and version check OK")
# if not create_tables():
# print("Impossible to create the database tables. Please check the error above")
# return
# print("Database tables creation OK")
print("Run ./alembic upgrade to proceed with the tables creation, then")
print("everything's done! Run fetcher.py now then periodically to update your database!")
def check_python():
return sys.version_info >= (3, 4)
def check_chmods():
try:
test_path = os.path.join(settings.PATH_CACHE_GEOCODER, "testfile")
with open(test_path, "w") as file:
file.write("Test")
os.remove(test_path)
return True
except Exception as e:
print("ERROR", e)
return False
def check_database():
try:
database = Database()
connection, metadata = database.connect()
postgres_version = connection.execute(text("SHOW server_version;")).scalar().split('.')
postgres_version = tuple(map(int, postgres_version))
if postgres_version < (9, 5):
return False
postgis_version = connection.execute(text("SELECT PostGIS_Lib_Version();")).scalar().split('.')
postgis_version = tuple(map(int, postgis_version))
if postgis_version < (2, 2):
return False
return True
except Exception as e:
print("ERROR", e)
return False
def create_tables():
return #TODO remove
database = Database()
connection, metadata = database.connect()
print(Offer.__table__)
print(models.Base.metadata.create_all(connection))
if __name__ == "__main__":
setup()