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

« back to all changes in this revision

Viewing changes to setup/install.py

  • Committer: Matt Giuca
  • Date: 2009-04-23 07:51:29 UTC
  • Revision ID: matt.giuca@gmail.com-20090423075129-94mf4vlwllpew0xn
ivle.svn: Added revision_is_dir (like os.path.isdir for revision history).
ivle.fileservice_lib.listing: Refactored such that the SVN revision is found
    in the top-level handler, and passed down into the individual handlers.
    This is done so that the revision information can be used to make the
    decisions (which will be required to fix the revision history browsing).
    This doesn't yet change the behaviour.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import optparse
23
23
import os
24
24
import sys
 
25
import functools
 
26
import distutils.sysconfig
25
27
 
26
28
from setup import util
27
29
 
33
35
Copy bin/trampoline/trampoline to $target/bin.
34
36
Copy bin/timount/timount to $target/bin.
35
37
chown and chmod the installed trampoline.
36
 
Copy www/ to $target.
37
 
Copy jail/ to jail_system directory (unless --nojail specified).
38
 
Copy subjects/ to subjects directory (unless --nosubjects specified).
39
38
"""
40
39
 
41
40
    # Parse arguments
43
42
    parser.add_option("-n", "--dry",
44
43
        action="store_true", dest="dry",
45
44
        help="Print out the actions but don't do anything.")
46
 
    parser.add_option("-J", "--nojail",
47
 
        action="store_true", dest="nojail",
48
 
        help="Don't copy jail/ to jail_system directory")
49
 
    parser.add_option("-S", "--nosubjects",
50
 
        action="store_true", dest="nosubjects",
51
 
        help="Don't copy subject/ to subjects directory.")
 
45
    parser.add_option("-R", "--nosvnrevno",
 
46
        action="store_true", dest="nosvnrevno",
 
47
        help="Don't write out the Subversion revision to the share directory.")
 
48
    parser.add_option("--root",
 
49
        action="store", dest="rootdir",
 
50
        help="Install into a different root directory.",
 
51
        default='/')
 
52
    parser.add_option("--prefix",
 
53
        action="store", dest="prefix",
 
54
        help="Base prefix to install IVLE into (default: /usr/local).",
 
55
        default='/usr/local')
 
56
    parser.add_option("--python-site-packages",
 
57
        action="store", dest="python_site_packages",
 
58
        help="Path to Python site packages directory.",
 
59
        default=None)
52
60
    (options, args) = parser.parse_args(args)
53
61
 
 
62
    # Prefix must be absolute (not really necessary, but since a relative
 
63
    # prefix will be taken relative to *root* not working directory, it is
 
64
    # confusing if we allow it).
 
65
    if options.prefix[:1] not in (os.path.sep, os.path.altsep):
 
66
        print >>sys.stderr, """prefix must be an absolute path.
 
67
    (This will be interpreted relative to root, so provide --root=. if you
 
68
    want a path relative to the working directory)."""
 
69
        return 1
 
70
 
 
71
    # Calculate python_site_packages using the supplied prefix
 
72
    if options.python_site_packages is None:
 
73
        options.python_site_packages = distutils.sysconfig.get_python_lib(
 
74
            prefix=options.prefix)
 
75
 
54
76
    # Call the real function
55
 
    return __install(options.dry, options.nojail, options.nosubjects)
 
77
    return __install(prefix=options.prefix,
 
78
                     python_site_packages=options.python_site_packages,
 
79
                     dry=options.dry, rootdir=options.rootdir,
 
80
                     nosvnrevno=options.nosvnrevno)
56
81
 
57
 
def __install(dry=False,nojail=False,nosubjects=False):
58
 
    # We need to import the one in the working copy, not in the system path.
59
 
    confmodule = __import__("ivle/conf/conf")
 
82
def __install(prefix, python_site_packages, dry=False, rootdir=None,
 
83
              nosvnrevno=False):
60
84
    install_list = util.InstallList()
61
85
 
62
 
    # Pull the required varibles out of the config
63
 
    lib_path = confmodule.lib_path
64
 
    share_path = confmodule.share_path
65
 
    bin_path = confmodule.bin_path
66
 
    python_site_packages = confmodule.python_site_packages
67
 
    jail_base = confmodule.jail_base
68
 
    jail_system = confmodule.jail_system
69
 
    subjects_base = confmodule.subjects_base
70
 
    exercises_base = confmodule.exercises_base
 
86
    # We need to apply make_install_path with the rootdir to an awful lot of
 
87
    # config variables, so make it easy:
 
88
    mip = functools.partial(util.make_install_path, rootdir)
 
89
 
 
90
    # Compute the lib_path, share_path and bin_path (copied from
 
91
    # ivle/conf/conf.py).
 
92
    lib_path = mip(os.path.join(prefix, 'lib/ivle'))
 
93
    share_path = mip(os.path.join(prefix, 'share/ivle'))
 
94
    bin_path = mip(os.path.join(prefix, 'bin'))
 
95
    python_site_packages = mip(python_site_packages)
71
96
 
72
97
    # Must be run as root or a dry run  
73
98
    if dry:
74
99
        print "Dry run (no actions will be executed)\n"
75
100
    
76
101
    if not dry and os.geteuid() != 0:
77
 
        print >>sys.stderr, "Must be root to run build"
78
 
        print >>sys.stderr, "(I need to chown)."
 
102
        print >>sys.stderr, "Must be root to run install"
79
103
        return 1
80
104
 
81
 
    # Make some directories for data.
82
 
    util.action_mkdir(confmodule.log_path, dry)
83
 
    util.action_mkdir(confmodule.data_path, dry)
84
 
    util.action_mkdir(confmodule.jail_base, dry)
85
 
    util.action_mkdir(confmodule.jail_src_base, dry)
86
 
    util.action_mkdir(confmodule.content_path, dry)
87
 
    util.action_mkdir(confmodule.notices_path, dry)
88
 
    util.action_mkdir(os.path.join(confmodule.data_path, 'sessions'), dry)
89
 
    util.action_mkdir(confmodule.svn_path, dry)
90
 
    util.action_mkdir(confmodule.svn_repo_path, dry)
91
 
    util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'users'), dry)
92
 
    util.action_mkdir(os.path.join(confmodule.svn_repo_path, 'groups'), dry)
93
 
 
94
 
    util.action_chown(confmodule.log_path, util.wwwuid, util.wwwuid, dry)
95
 
    util.action_chown(os.path.join(confmodule.data_path, 'sessions'),
96
 
                      util.wwwuid, util.wwwuid, dry)
97
 
    util.action_chown(os.path.join(confmodule.svn_repo_path, 'users'),
98
 
                      util.wwwuid, util.wwwuid, dry)
99
 
    util.action_chown(os.path.join(confmodule.svn_repo_path, 'groups'),
100
 
                      util.wwwuid, util.wwwuid, dry)
 
105
    # Create the config directory.
 
106
    util.action_mkdir(mip('/etc/ivle/plugins.d'), dry)
101
107
 
102
108
    # Create lib and copy the compiled files there
103
109
    util.action_mkdir(lib_path, dry)
110
116
    timountpath = os.path.join(lib_path, 'timount')
111
117
    util.action_copyfile('bin/timount/timount', timountpath, dry)
112
118
 
113
 
    # Create a services directory to put the usrmgt-server in.
114
 
    util.action_mkdir(os.path.join(share_path, 'services'), dry)
115
 
 
 
119
    # Copy in the services (only usrmgt-server is needed on the host, but
 
120
    # the jail build requires the rest).
 
121
    util.action_copylist(install_list.list_services, share_path, dry)
116
122
    usrmgtpath = os.path.join(share_path, 'services/usrmgt-server')
117
 
    util.action_copyfile('services/usrmgt-server', usrmgtpath, dry)
118
123
    util.action_chmod_x(usrmgtpath, dry)
119
124
 
120
125
    # Copy the user-executable binaries using the list.
121
126
    util.action_copylist(install_list.list_user_binaries, bin_path, dry,
122
127
                         onlybasename=True)
123
128
 
124
 
    # Copy the www and lib directories using the list
125
 
    util.action_copylist(install_list.list_www, share_path, dry)
 
129
    # Copy the lib directory (using the list)
126
130
    util.action_copylist(install_list.list_ivle_lib, python_site_packages, dry)
127
 
    
128
 
    # Make the config file private
129
 
    # XXX Get rid of lib
130
 
    configpath = os.path.join(python_site_packages, 'ivle/conf/conf.py')
131
 
    util.action_make_private(configpath, dry)
132
 
 
133
 
    # Copy the php directory
134
 
    forum_dir = "www/php/phpBB3"
135
 
    forum_path = os.path.join(share_path, forum_dir)
136
 
    util.action_copytree(forum_dir, forum_path, dry)
137
 
    print "chown -R www-data:www-data %s" % forum_path
138
 
    if not dry:
139
 
        os.system("chown -R www-data:www-data %s" % forum_path)
140
 
 
141
 
    if not nojail:
142
 
        # Copy the local jail directory built by the build action
143
 
        # to the jail_system directory (it will be used to help build
144
 
        # all the students' jails).
145
 
        util.action_copytree('jail', jail_system, dry)
146
 
 
147
 
    if not nosubjects:
148
 
        # Copy the subjects and exercises directories across
149
 
        util.action_mkdir(subjects_base, dry)
150
 
        util.action_copylist(install_list.list_subjects, subjects_base, dry,
151
 
            srcdir="./subjects")
152
 
        util.action_mkdir(exercises_base, dry)
153
 
        util.action_copylist(install_list.list_exercises, exercises_base, dry,
154
 
            srcdir="./exercises")
155
 
 
156
 
    # XXX We shouldn't have ivle.pth at all any more.
157
 
    # We may still need the www packages to be importable.
158
 
    # Anything from www that is needed from the outside should go to lib.
159
 
    ivle_pth = os.path.join(python_site_packages, "ivle.pth")
160
 
    try:
161
 
        file = open(ivle_pth, 'w')
162
 
        file.write(os.path.join(share_path, "www"))
163
 
        file.close()
164
 
    except (IOError, OSError):
165
 
        pass
166
 
 
167
 
    # Create the ivle working revision record file
168
 
    ivle_revision_record_file = os.path.join(share_path, 'ivle-revision.txt')
169
 
    if not dry:
170
 
        try:
171
 
            conf = open(ivle_revision_record_file, "w")
172
 
 
173
 
            conf.write("""# SVN revision r%s
 
131
 
 
132
    if not nosvnrevno:
 
133
        # Create the ivle working revision record file
 
134
        ivle_revision_file = os.path.join(share_path, 'revision.txt')
 
135
        if not dry:
 
136
            try:
 
137
                conf = open(ivle_revision_file, "w")
 
138
 
 
139
                conf.write("""# SVN revision r%s
174
140
# Source tree location: %s
175
141
# Modified files:
176
142
""" % (util.get_svn_revision(), os.getcwd()))
177
143
 
178
 
            conf.close()
179
 
        except IOError, (errno, strerror):
180
 
            print "IO error(%s): %s" % (errno, strerror)
181
 
            sys.exit(1)
182
 
 
183
 
        os.system("svn status . >> %s" % ivle_revision_record_file)
184
 
 
185
 
    print "Wrote IVLE code revision status to %s" % ivle_revision_record_file
 
144
                conf.close()
 
145
            except IOError, (errno, strerror):
 
146
                print "IO error(%s): %s" % (errno, strerror)
 
147
                sys.exit(1)
 
148
 
 
149
            os.system("svn status . >> %s" % ivle_revision_file)
 
150
 
 
151
        print "Wrote IVLE code revision status to %s" % ivle_revision_file
186
152
 
187
153
    return 0
188
154