This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
69 lines (52 loc) · 2.08 KB
/
install.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
import shutil
import glob
import sys
import subprocess
import os
from distutils.dir_util import copy_tree
def prRed(skk): print("\033[91m {}\033[00m" .format(skk))
def prGreen(skk): print("\033[92m {}\033[00m" .format(skk))
def prCyan(skk): print("\033[96m {}\033[00m" .format(skk))
def main():
prCyan('Checking for Python version')
if not sys.version_info >= (3, 5):
prRed('ERROR: pgcv installation requires Python3')
exit()
else:
prGreen('- Python3 found')
prCyan('Creating dist sql file')
outfilename = os.path.join('dist', 'pgcv--0.1.0.sql')
with open(outfilename, 'wb') as outfile:
for filename in sorted(glob.glob(os.path.join('sql', '*.sql'))):
if filename == outfilename:
continue
with open(filename, 'rb') as readfile:
shutil.copyfileobj(readfile, outfile)
prGreen('- File successfully created in ' + outfilename)
prCyan('Installing pgcv requirements')
subprocess.call([sys.executable, "-m", "pip",
"install", "numpy", "scipy", "pandas", "scikit-image", "Pillow"])
prGreen('- pgcv requirements satisfied')
prCyan('Looking for the Postgresql share directory')
extensionsharedir = ''
try:
processResult = subprocess.run(
["pg_config", "--sharedir"], capture_output=True)
if processResult.returncode is not 0:
raise Exception
sharedir = processResult.stdout.decode('ascii').replace('\n', '')
extensionsharedir = os.path.join(sharedir, 'extension')
prGreen('- Extension share directory found at ' + extensionsharedir)
except:
prRed("Something wen't wrong getting the share directory")
prCyan('Copying distribution folder to PostgreSQL share directory')
copy_tree('dist', extensionsharedir)
prGreen('- pgcv copied to target directory')
prCyan('''\n
pgcv successfully installed.
Connect to your PostgreSQL database and execute the following commands:
\tCREATE EXTENSION PLPYTHON3U;
\tCREATE EXTENSION PGCV;
''')
if __name__ == "__main__":
main()