-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
94 lines (83 loc) · 4.17 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
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
from distutils.core import setup
from sys import exit
from os import chmod
from os import listdir
from os import getcwd
from os import path
from os import system as bash
import stat
'''
Installation script that sets up NichePy and installs the modules it depends on.
This should work on Unix-like systems including Cygwin on Windows.
To install:
python3 setup.py install
'''
def setupFunc():
print("\n Installing module nichefunc\n")
setup(name='nichefdunc',
version='1.1',
description='Functions for estimating niche overlap and resampling species occurrence data',
py_modules=['nichefunc'],
author='Mariya Shcheglovitova, Bastian Bentlage',
author_email='m.shcheglovitova@gmail.com, bastodian@gmail.com',
url='http://purl.org/NichePy',
license='GPL',
)
def setupArg():
print("\n Installing module argparse\n")
setup(name='argparse',
description='Module for writing user friendly command line interfaces',
py_modules=['argparse'],
author='Steven J. Bethard',
author_email='steven.bethard@gmail.com',
url='http://pypi.python.org/pypi/argparse',
license='Python License',
)
print("\nPlease choose your installation mode. Valid options are 1 or 2.\n\nIMPORTANT: Installation requires root privileges! Either change to the root account and run the script or use sudo.\n\n1 to make the scripts globally available. This will create symbolic links from the downloaded script files to /usr/bin.\n In addition the module containing functions for NichePy will be installed using Python's installer.\n\n2 to install in the same manner as 1 but also install the argparse module using Python's installer.\n This should only be necessary if you run Python3 < 3.2.\n\n")
### Ask for user input and create a list containing the python scripts to be installed
Install=input("\nPlease choose your installation mode: ")
Scripts=[path.join(getcwd(),x) for x in listdir(getcwd()) if "getMetric" in x or "nicheBack" in x or "nicheIdent" in x]
if int(Install)==1 or int(Install)==2:
### Where should the scripts be linked to?
ExecPath=input("\nPlease type the path to which executables will be linked. If no entry default will be used (DEFAULT = /usr/bin): ")
if len(ExecPath) == 0:
ExecPath='/usr/bin'
print('\nExecutable scripts will be linked to', ExecPath, 'to make them globally avalilable on your system')
### Install option no 1
if int(Install)==1:
print("\nMaking scripts executable.")
for file in Scripts:
chmod(file, stat.S_IRWXU)
NewFile=file.split('.')[0]
bash('mv ' + file + ' ' + NewFile)
bash('ln -s ' + file.split('.')[0] + ' ' + ExecPath)
print("\nInstalling module nichefunc, which contains functions for executable NichePy scripts.")
setupFunc()
bash('rm ' + 'nichefunc.py')
bash('rm ' + 'argparse.py')
print("\nInstallation complete. Scripts can be called by issuing the following commands:")
for i in listdir(getcwd()):
if "getMetric" in i or "nicheBack" in i or "nicheIdent" in i:
print("\n",i,"-h for brief guide of the script's usage")
### Install option no 2
else:
print("\nMaking scripts executable.")
for file in Scripts:
chmod(file, stat.S_IRWXU)
NewFile=file.split('.')[0]
bash('mv ' + file + ' ' + NewFile)
bash('ln -s ' + file.split('.')[0] + ' ' + ExecPath)
print("\nInstalling module nichefunc, which contains functions for executable NichePy scripts.")
setupFunc()
bash('rm ' + 'nichefunc.py')
setupArg()
bash('rm ' + 'argparse.py')
print("\nInstallation complete. Scripts can be called by issuing the following commands:")
for i in listdir(getcwd()):
if "getMetric" in i or "nicheBack" in i or "nicheIdent" in i:
print("\n",i,"-h for brief guide of the script's usage")
print("\nFor more details please refer to the manual of NichePy.\n")
else:
print("\nInvalid option entered. Please run installation script again!\n")
exit()