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

« back to all changes in this revision

Viewing changes to setup/listmake.py

  • Committer: mattgiuca
  • Date: 2008-01-29 23:52:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:329
Converted Console from an "app" into a "plugin". It can now be plugged in to
any app.
Added "plugins" directory in www. Added "console" plugin. This contains all of
the functionality of what was previously the console app, but modularized so
it can be imported by another app.

apps/console: Removed most of the logic (moved to plugins/console). Replaced
with a simple import of the console plugin. Should behave exactly the same.
apps/tutorial: As proof of concept, imported the console plugin. It now
appears at the bottom of the page (yet to make it have "pop up" behaviour).

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
 
from setuputil import filter_mutate
33
 
 
34
 
# Mime types which will automatically be placed in the list by listmake.
35
 
# Note that listmake is not intended to be run by the final user (the system
36
 
# administrator who installs this), so the developers can customize the list
37
 
# as necessary, and include it in the distribution.
38
 
listmake_mimetypes = ['text/x-python', 'text/html',
39
 
    'application/x-javascript', 'application/javascript',
40
 
    'text/css', 'image/png', 'image/gif', 'application/xml']
41
 
 
42
 
def listmake(args):
43
 
    usage = """usage: %prog listmake [options]
44
 
(For developer use only)
45
 
Recurses through the source tree and builds a list of all files which should
46
 
be copied upon installation. This should be run by the developer before
47
 
cutting a distribution, and the listfile it generates should be included in
48
 
the distribution, avoiding the administrator having to run it."""
49
 
 
50
 
    # Parse arguments
51
 
    parser = optparse.OptionParser(usage)
52
 
    (options, args) = parser.parse_args(args)
53
 
 
54
 
    # Call the real function
55
 
    __listmake()
56
 
 
57
 
def __listmake():
58
 
    # We build two separate lists, by walking www and console
59
 
    list_www = build_list_py_files('www')
60
 
    list_lib = build_list_py_files('lib')
61
 
    list_subjects = build_list_py_files('subjects', no_top_level=True)
62
 
    list_exercises = build_list_py_files('exercises', no_top_level=True)
63
 
    list_scripts = [
64
 
        "scripts/python-console",
65
 
        "scripts/fileservice",
66
 
        "scripts/serveservice",
67
 
        "scripts/usrmgt-server",
68
 
        "scripts/diffservice",
69
 
    ]
70
 
    # Make sure that the files generated by conf are in the list
71
 
    # (since listmake is typically run before conf)
72
 
    if "lib/conf/conf.py" not in list_lib:
73
 
        list_lib.append("lib/conf/conf.py")
74
 
    # Write these out to a file
75
 
    cwd = os.getcwd()
76
 
    # the files that will be created/overwritten
77
 
    listfile = os.path.join(cwd, "install_list.py")
78
 
 
79
 
    try:
80
 
        file = open(listfile, "w")
81
 
 
82
 
        file.write("""# IVLE Configuration File
83
 
# install_list.py
84
 
# Provides lists of all files to be installed by `setup.py install' from
85
 
# certain directories.
86
 
# Note that any files with the given filename plus 'c' or 'o' (that is,
87
 
# compiled .pyc or .pyo files) will be copied as well.
88
 
 
89
 
# List of all installable files in www directory.
90
 
list_www = """)
91
 
        writelist_pretty(file, list_www)
92
 
        file.write("""
93
 
# List of all installable files in lib directory.
94
 
list_lib = """)
95
 
        writelist_pretty(file, list_lib)
96
 
        file.write("""
97
 
# List of all installable files in scripts directory.
98
 
list_scripts = """)
99
 
        writelist_pretty(file, list_scripts)
100
 
        file.write("""
101
 
# List of all installable files in subjects directory.
102
 
# This is to install sample subjects and material.
103
 
list_subjects = """)
104
 
        writelist_pretty(file, list_subjects)
105
 
        file.write("""
106
 
# List of all installable files in exercises directory.
107
 
# This is to install sample exercise material.
108
 
list_exercises = """)
109
 
        writelist_pretty(file, list_exercises)
110
 
 
111
 
        file.close()
112
 
    except IOError, (errno, strerror):
113
 
        print "IO error(%s): %s" % (errno, strerror)
114
 
        sys.exit(1)
115
 
 
116
 
    print "Successfully wrote install_list.py"
117
 
 
118
 
    print
119
 
    print ("You may modify the set of installable files before cutting the "
120
 
            "distribution:")
121
 
    print listfile
122
 
    print
123
 
 
124
 
    return 0
125
 
 
126
 
def build_list_py_files(dir, no_top_level=False):
127
 
    """Builds a list of all py files found in a directory and its
128
 
    subdirectories. Returns this as a list of strings.
129
 
    no_top_level=True means the file paths will not include the top-level
130
 
    directory.
131
 
    """
132
 
    pylist = []
133
 
    for (dirpath, dirnames, filenames) in os.walk(dir):
134
 
        # Exclude directories beginning with a '.' (such as '.svn')
135
 
        filter_mutate(lambda x: x[0] != '.', dirnames)
136
 
        # All *.py files are added to the list
137
 
        pylist += [os.path.join(dirpath, item) for item in filenames
138
 
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
139
 
    if no_top_level:
140
 
        for i in range(0, len(pylist)):
141
 
            _, pylist[i] = pylist[i].split(os.sep, 1)
142
 
    return pylist
143
 
 
144
 
def writelist_pretty(file, list):
145
 
    """Writes a list one element per line, to a file."""
146
 
    if list == []:
147
 
        file.write("[]\n")
148
 
    else:
149
 
        file.write('[\n')
150
 
        for elem in list:
151
 
            file.write('    %s,\n' % repr(elem))
152
 
        file.write(']\n')
153