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

« back to all changes in this revision

Viewing changes to setup/install.py

Quick port of fileservice to the new framework. It's still very much old-style,
though.

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