~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: William Grant
  • Date: 2012-06-28 01:52:02 UTC
  • Revision ID: me@williamgrant.id.au-20120628015202-f6ru7o367gt6nvgz
Hah

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import os
24
24
import sys
25
25
import functools
 
26
import distutils.sysconfig
26
27
 
27
28
from setup import util
28
29
 
29
 
PYTHON_VERSION = sys.version[:3]
30
 
 
31
30
def install(args):
32
31
    usage = """usage: %prog install [options]
33
32
(Requires root)
35
34
Create $target/bin.
36
35
Copy bin/trampoline/trampoline to $target/bin.
37
36
Copy bin/timount/timount to $target/bin.
38
 
Copy etc/ivle.conf to /etc/ivle/ivle.conf.
39
37
chown and chmod the installed trampoline.
40
 
Copy www/ to $target.
41
38
"""
42
39
 
43
40
    # Parse arguments
45
42
    parser.add_option("-n", "--dry",
46
43
        action="store_true", dest="dry",
47
44
        help="Print out the actions but don't do anything.")
48
 
    parser.add_option("-R", "--nosvnrevno",
49
 
        action="store_true", dest="nosvnrevno",
50
 
        help="Don't write out the Subversion revision to the share directory.")
51
45
    parser.add_option("--root",
52
46
        action="store", dest="rootdir",
53
47
        help="Install into a different root directory.",
59
53
    parser.add_option("--python-site-packages",
60
54
        action="store", dest="python_site_packages",
61
55
        help="Path to Python site packages directory.",
62
 
        default='/usr/local/lib/python%s/site-packages' % PYTHON_VERSION)
 
56
        default=None)
63
57
    (options, args) = parser.parse_args(args)
64
58
 
 
59
    # Prefix must be absolute (not really necessary, but since a relative
 
60
    # prefix will be taken relative to *root* not working directory, it is
 
61
    # confusing if we allow it).
 
62
    if options.prefix[:1] not in (os.path.sep, os.path.altsep):
 
63
        print >>sys.stderr, """prefix must be an absolute path.
 
64
    (This will be interpreted relative to root, so provide --root=. if you
 
65
    want a path relative to the working directory)."""
 
66
        return 1
 
67
 
 
68
    # Calculate python_site_packages using the supplied prefix
 
69
    if options.python_site_packages is None:
 
70
        options.python_site_packages = distutils.sysconfig.get_python_lib(
 
71
            prefix=options.prefix)
 
72
 
65
73
    # Call the real function
66
74
    return __install(prefix=options.prefix,
67
75
                     python_site_packages=options.python_site_packages,
68
 
                     dry=options.dry, rootdir=options.rootdir,
69
 
                     nosvnrevno=options.nosvnrevno)
 
76
                     dry=options.dry, rootdir=options.rootdir)
70
77
 
71
 
def __install(prefix, python_site_packages, dry=False, rootdir=None,
72
 
              nosvnrevno=False):
 
78
def __install(prefix, python_site_packages, dry=False, rootdir=None):
73
79
    install_list = util.InstallList()
74
80
 
75
81
    # We need to apply make_install_path with the rootdir to an awful lot of
91
97
        print >>sys.stderr, "Must be root to run install"
92
98
        return 1
93
99
 
 
100
    # Create the config directory.
 
101
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
 
102
 
94
103
    # Create lib and copy the compiled files there
95
104
    util.action_mkdir(lib_path, dry)
96
105
 
112
121
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
113
122
                         onlybasename=True)
114
123
 
115
 
    # Copy the www directory (using the list)
116
 
    util.action_copylist(install_list.list_www, share_path, dry)
117
 
 
118
 
    # Set appropriate permissions on the php directory
119
 
    forum_dir = "www/php/phpBB3"
120
 
    forum_path = os.path.join(share_path, forum_dir)
121
 
    print "chown -R www-data:www-data %s" % forum_path
122
 
    if not dry:
123
 
        os.system("chown -R www-data:www-data %s" % forum_path)
124
 
 
125
124
    # Copy the lib directory (using the list)
126
125
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
127
126
 
128
 
    # XXX We shouldn't have ivle.pth at all any more.
129
 
    # We may still need the www packages to be importable.
130
 
    # Anything from www that is needed from the outside should go to lib.
131
 
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
132
 
    try:
133
 
        file = open(ivle_pth, 'w')
134
 
        file.write(os.path.join(share_path, "www"))
135
 
        file.close()
136
 
    except (IOError, OSError):
137
 
        pass
138
 
 
139
 
    if not nosvnrevno:
140
 
        # Create the ivle working revision record file
141
 
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
142
 
        if not dry:
143
 
            try:
144
 
                conf = open(ivle_revision_file, "w")
145
 
 
146
 
                conf.write("""# SVN revision r%s
147
 
# Source tree location: %s
148
 
# Modified files:
149
 
""" % (util.get_svn_revision(), os.getcwd()))
150
 
 
151
 
                conf.close()
152
 
            except IOError, (errno, strerror):
153
 
                print "IO error(%s): %s" % (errno, strerror)
154
 
                sys.exit(1)
155
 
 
156
 
            os.system("svn status . >> %s" % ivle_revision_file)
157
 
 
158
 
        print "Wrote IVLE code revision status to %s" % ivle_revision_file
159
 
 
160
127
    return 0
161
128