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

« back to all changes in this revision

Viewing changes to setup/listmake.py

  • Committer: mattgiuca
  • Date: 2008-02-01 08:15:24 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:377
dispatch/html: Changed the "welcome line" at the top of the page.
    It now says your "nick", with your login name in parentheses. Looks noice!
    (It reads your "nick", which came from the request session, which was written
    there by login, which it got from the DB, which lay in the house that Jack
    built).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2008 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
# Module: setup/listmake
19
 
# Author: Matt Giuca, Refactored by David Coles
20
 
# Date:   03/07/2008
21
 
 
22
 
# setup/listmake.py
23
 
# (for developer use only)
24
 
# Recurses through the source tree and builds a list of all files which should
25
 
# be copied upon installation. This should be run by the developer before
26
 
# cutting a distribution, and the listfile it generates should be included in
27
 
# the distribution, avoiding the administrator having to run it.
28
 
 
29
 
import optparse
30
 
import os
31
 
import mimetypes
32
 
import sys
33
 
from setuputil import filter_mutate
34
 
 
35
 
# Mime types which will automatically be placed in the list by listmake.
36
 
# Note that listmake is not intended to be run by the final user (the system
37
 
# administrator who installs this), so the developers can customize the list
38
 
# as necessary, and include it in the distribution.
39
 
listmake_mimetypes = ['text/x-python', 'text/html',
40
 
    'application/x-javascript', 'application/javascript',
41
 
    'text/css', 'image/png', 'image/gif', 'application/xml']
42
 
 
43
 
def listmake(args):
44
 
    usage = """usage: %prog listmake [options]
45
 
(For developer use only)
46
 
Recurses through the source tree and builds a list of all files which should
47
 
be copied upon installation. This should be run by the developer before
48
 
cutting a distribution, and the listfile it generates should be included in
49
 
the distribution, avoiding the administrator having to run it."""
50
 
 
51
 
    # Parse arguments
52
 
    parser = optparse.OptionParser(usage)
53
 
    (options, args) = parser.parse_args(args)
54
 
 
55
 
    # Call the real function
56
 
    __listmake()
57
 
 
58
 
def __listmake():
59
 
    # We build two separate lists, by walking www and console
60
 
    list_www = build_list_py_files('www')
61
 
    list_lib = build_list_py_files('lib')
62
 
    list_subjects = build_list_py_files('subjects', no_top_level=True)
63
 
    list_exercises = build_list_py_files('exercises', no_top_level=True)
64
 
    list_scripts = [
65
 
        "scripts/python-console",
66
 
        "scripts/fileservice",
67
 
        "scripts/serveservice",
68
 
        "scripts/usrmgt-server",
69
 
        "scripts/diffservice",
70
 
        "scripts/svnlogservice",
71
 
    ]
72
 
    # Make sure that the files generated by conf are in the list
73
 
    # (since listmake is typically run before conf)
74
 
    if "lib/conf/conf.py" not in list_lib:
75
 
        list_lib.append("lib/conf/conf.py")
76
 
    # Write these out to a file
77
 
    cwd = os.getcwd()
78
 
    # the files that will be created/overwritten
79
 
    listfile = os.path.join(cwd, "install_list.py")
80
 
 
81
 
    try:
82
 
        file = open(listfile, "w")
83
 
 
84
 
        file.write("""# IVLE Configuration File
85
 
# install_list.py
86
 
# Provides lists of all files to be installed by `setup.py install' from
87
 
# certain directories.
88
 
# Note that any files with the given filename plus 'c' or 'o' (that is,
89
 
# compiled .pyc or .pyo files) will be copied as well.
90
 
 
91
 
# List of all installable files in www directory.
92
 
list_www = """)
93
 
        writelist_pretty(file, list_www)
94
 
        file.write("""
95
 
# List of all installable files in lib directory.
96
 
list_lib = """)
97
 
        writelist_pretty(file, list_lib)
98
 
        file.write("""
99
 
# List of all installable files in scripts directory.
100
 
list_scripts = """)
101
 
        writelist_pretty(file, list_scripts)
102
 
        file.write("""
103
 
# List of all installable files in subjects directory.
104
 
# This is to install sample subjects and material.
105
 
list_subjects = """)
106
 
        writelist_pretty(file, list_subjects)
107
 
        file.write("""
108
 
# List of all installable files in exercises directory.
109
 
# This is to install sample exercise material.
110
 
list_exercises = """)
111
 
        writelist_pretty(file, list_exercises)
112
 
 
113
 
        file.close()
114
 
    except IOError, (errno, strerror):
115
 
        print "IO error(%s): %s" % (errno, strerror)
116
 
        sys.exit(1)
117
 
 
118
 
    print "Successfully wrote install_list.py"
119
 
 
120
 
    print
121
 
    print ("You may modify the set of installable files before cutting the "
122
 
            "distribution:")
123
 
    print listfile
124
 
    print
125
 
 
126
 
    return 0
127
 
 
128
 
def build_list_py_files(dir, no_top_level=False):
129
 
    """Builds a list of all py files found in a directory and its
130
 
    subdirectories. Returns this as a list of strings.
131
 
    no_top_level=True means the file paths will not include the top-level
132
 
    directory.
133
 
    """
134
 
    pylist = []
135
 
    for (dirpath, dirnames, filenames) in os.walk(dir):
136
 
        # Exclude directories beginning with a '.' (such as '.svn')
137
 
        filter_mutate(lambda x: x[0] != '.', dirnames)
138
 
        # All *.py files are added to the list
139
 
        pylist += [os.path.join(dirpath, item) for item in filenames
140
 
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
141
 
    if no_top_level:
142
 
        for i in range(0, len(pylist)):
143
 
            _, pylist[i] = pylist[i].split(os.sep, 1)
144
 
    return pylist
145
 
 
146
 
def writelist_pretty(file, list):
147
 
    """Writes a list one element per line, to a file."""
148
 
    if list == []:
149
 
        file.write("[]\n")
150
 
    else:
151
 
        file.write('[\n')
152
 
        for elem in list:
153
 
            file.write('    %s,\n' % repr(elem))
154
 
        file.write(']\n')
155