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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# IVLE - Informatics Virtual Learning Environment
# Copyright (C) 2007-2008 The University of Melbourne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

# Module: setup/listmake
# Author: Matt Giuca, Refactored by David Coles
# Date:   03/07/2008

# setup/listmake.py
# (for developer use only)
# Recurses through the source tree and builds a list of all files which should
# be copied upon installation. This should be run by the developer before
# cutting a distribution, and the listfile it generates should be included in
# the distribution, avoiding the administrator having to run it.

import optparse
import os
import mimetypes
import sys
from setuputil import filter_mutate

# Mime types which will automatically be placed in the list by listmake.
# Note that listmake is not intended to be run by the final user (the system
# administrator who installs this), so the developers can customize the list
# as necessary, and include it in the distribution.
listmake_mimetypes = ['text/x-python', 'text/html',
    'application/x-javascript', 'application/javascript',
    'text/css', 'image/png', 'image/gif', 'application/xml']

def listmake(args):
    usage = """usage: %prog listmake [options]
(For developer use only)
Recurses through the source tree and builds a list of all files which should
be copied upon installation. This should be run by the developer before
cutting a distribution, and the listfile it generates should be included in
the distribution, avoiding the administrator having to run it."""

    # Parse arguments
    parser = optparse.OptionParser(usage)
    (options, args) = parser.parse_args(args)

    # Call the real function
    __listmake()

def __listmake():
    # We build two separate lists, by walking www and console
    list_www = build_list_py_files('www')
    list_lib = build_list_py_files('lib')
    list_subjects = build_list_py_files('subjects', no_top_level=True)
    list_exercises = build_list_py_files('exercises', no_top_level=True)
    list_scripts = [
        "scripts/python-console",
        "scripts/fileservice",
        "scripts/serveservice",
        "scripts/interpretservice",
        "scripts/usrmgt-server",
        "scripts/diffservice",
        "scripts/svnlogservice",
    ]
    # Make sure that the files generated by conf are in the list
    # (since listmake is typically run before conf)
    if "lib/conf/conf.py" not in list_lib:
        list_lib.append("lib/conf/conf.py")
    # Write these out to a file
    cwd = os.getcwd()
    # the files that will be created/overwritten
    listfile = os.path.join(cwd, "install_list.py")

    try:
        file = open(listfile, "w")

        file.write("""# IVLE Configuration File
# install_list.py
# Provides lists of all files to be installed by `setup.py install' from
# certain directories.
# Note that any files with the given filename plus 'c' or 'o' (that is,
# compiled .pyc or .pyo files) will be copied as well.

# List of all installable files in www directory.
list_www = """)
        writelist_pretty(file, list_www)
        file.write("""
# List of all installable files in lib directory.
list_lib = """)
        writelist_pretty(file, list_lib)
        file.write("""
# List of all installable files in scripts directory.
list_scripts = """)
        writelist_pretty(file, list_scripts)
        file.write("""
# List of all installable files in subjects directory.
# This is to install sample subjects and material.
list_subjects = """)
        writelist_pretty(file, list_subjects)
        file.write("""
# List of all installable files in exercises directory.
# This is to install sample exercise material.
list_exercises = """)
        writelist_pretty(file, list_exercises)

        file.close()
    except IOError, (errno, strerror):
        print "IO error(%s): %s" % (errno, strerror)
        sys.exit(1)

    print "Successfully wrote install_list.py"

    print
    print ("You may modify the set of installable files before cutting the "
            "distribution:")
    print listfile
    print

    return 0

def build_list_py_files(dir, no_top_level=False):
    """Builds a list of all py files found in a directory and its
    subdirectories. Returns this as a list of strings.
    no_top_level=True means the file paths will not include the top-level
    directory.
    """
    pylist = []
    for (dirpath, dirnames, filenames) in os.walk(dir):
        # Exclude directories beginning with a '.' (such as '.svn')
        filter_mutate(lambda x: x[0] != '.', dirnames)
        # All *.py files are added to the list
        pylist += [os.path.join(dirpath, item) for item in filenames
            if mimetypes.guess_type(item)[0] in listmake_mimetypes]
    if no_top_level:
        for i in range(0, len(pylist)):
            _, pylist[i] = pylist[i].split(os.sep, 1)
    return pylist

def writelist_pretty(file, list):
    """Writes a list one element per line, to a file."""
    if list == []:
        file.write("[]\n")
    else:
        file.write('[\n')
        for elem in list:
            file.write('    %s,\n' % repr(elem))
        file.write(']\n')