-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
73 lines (63 loc) · 2.61 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
70
71
72
73
#!/usr/bin/python
# install.py
# A part of the latex-access project at https://github.com/SugarCaneNS/latex-access/
# Author: Daniel Dalton <[email protected]>
# Copyright (C) 2012 Daniel Dalton/latex-access Contributors
#
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation;
# either version 2 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with this program; if not, visit <http://www.gnu.org/licenses>
"""Latex-access installation script for unix based operating systems."""
from platform import python_version
import shutil, os, sys
# Usage info
usage="This script allows you to install latex-access.\n\nUsage:%s\nWhich installs to the default location, or:\n%s <dir to install latex-access to>" % (sys.argv[0], sys.argv[0])
pyver=python_version ()[:3] # the version of python
print "Found python version %s" % (pyver)
outdir=("/usr/lib/python"+pyver+"/dist-packages/latex_access/", "/usr/lib/python"+pyver+"/site-packages/latex_access/")
failed=False
if len(sys.argv) == 2:
if sys.argv[1] == '-h' or sys.argv[1] == '--help':
print usage
exit ()
else:
outdir = [sys.argv[1]]
for dirname in outdir:
if os.path.exists (dirname):
break
if not os.path.exists (dirname):
try:
os.mkdir (dirname)
print "Created directory, %s" % (dirname)
break
except:
continue
if not os.path.exists (dirname):
print "Couldn't create directory %s." % (dirname)
print "Installation failed."
exit (-1)
print "Installing to %s." % (dirname)
try:
for filename in os.listdir("latex_access/"): # copy the files into our path
try:
if filename[-3:] == '.py' or filename[-6:] == '.table': # we only want to install .py and .table files
try:
shutil.copyfile (os.path.join("latex_access/",filename), os.path.join(dirname, filename))
print "Copying %s" % (filename)
except:
failed=True
break
except:
continue
except:
print "Couldn't install latex-access to %s, perhaps you don't have permission?" % (dirname)
exit (-1)
if failed:
print "Couldn't copy files to %s, maybe you don't have permission" % (dirname)
exit (-1)
print "Copied files to %s." % (dirname)