-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinvenio-symlink-installer
executable file
·89 lines (82 loc) · 2.93 KB
/
invenio-symlink-installer
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## This file is part of Invenio.
## Copyright (C) 2012 CERN.
##
## Invenio 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.
##
## Invenio 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 Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
import sys
import os
import getopt
__doc__ = """\
Simple GNU install drop-in replacement that creates symlinks instead of copying
file over.
Usage:
$ INSTALL=%s ./configure [CONFIGURE OPTIONS]
""" % sys.argv[0]
def usage():
"""
Print usage instruction and exit.
"""
print >> sys.stderr, __doc__
sys.exit(1)
def main():
"""
Parse the minimal set of GNU install CLI arguments in order to install
Invenio using symlinks.
"""
optlist, args = getopt.gnu_getopt(sys.argv[1:], 'bvVfFh:m:o:psS:t:TvZ:', ["backup=", "compare", "group=", "mode=", "owner=", "preserve-timestamps", "strip", "strip-program=", "target-directory=", "no-target-directory", "verbose", "preserve-context", "context=", "help", "version"])
files = args[:-1]
if args:
dd = args[-1]
else:
dd = None
cwd = os.getcwd()
verbose = False
try:
for opt, value in optlist:
if opt in ('-v', '--verbose'):
verbose = True
elif opt in ('-T', '--no-target-directory'):
dd = None
files = args
elif opt in ('-t', '--target-directory'):
dd = value
files = args
elif opt in ('-h', '--help'):
usage()
if dd:
if not os.path.exists(dd):
os.makedirs(dd)
for file in files:
from_file = os.path.join(cwd, file)
to_file = os.path.join(dd, file)
if os.path.exists(to_file):
os.remove(to_file)
os.symlink(from_file, to_file)
if verbose:
print "Linking %s to %s" % (from_file, to_file)
else:
from_file = os.path.join(cwd, args[0])
to_file = args[1]
if os.path.exists(to_file):
os.remove(to_file)
os.symlink(from_file, to_file)
if verbose:
print "Linking %s to %s" % (from_file, to_file)
except Exception, err:
print >> sys.stderr, "ERROR: in calling %s: %s" % (' '.join(sys.argv), err)
usage()
if __name__ == "__main__":
main()