/usr/share/pyshared/schooltool/paste/run.py is in python-schooltool 1:2.1.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2007, 2011 Shuttleworth Foundation
#
# 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""
SchoolTool run script.
"""
from __future__ import with_statement
import optparse
import os.path
import re
import sys
import paste.script.command
def parse_args():
"""Parse the command line arguments"""
parser = optparse.OptionParser(usage="usage: %prog INSTANCE [options]")
parser.add_option("--daemon",
action="store_true",
dest="start_daemon",
help="Run in daemon (background) mode")
parser.add_option('--pid-file',
dest='pid_file',
metavar='FILENAME',
help="Save PID to file (if running in daemon mode)")
parser.add_option('--log-file',
dest='log_file',
metavar='LOG_FILE',
help="Save output to the given log file (redirects stdout)")
parser.add_option("--stop-daemon",
action="store_true",
dest="stop_daemon",
help="Stop a daemonized server")
parser.add_option('--reload',
dest='reload',
action='store_true',
help="Use auto-restart file monitor")
parser.add_option('--reload-interval',
dest='reload_interval',
default=1,
help="Seconds between checking files (low number can cause significant CPU usage)")
parser.add_option('--monitor-restart',
dest='monitor_restart',
action='store_true',
help="Auto-restart server if it dies")
parser.add_option("--status",
action="store_true",
dest="show_status",
help="Show the status of the (presumably daemonized) server")
parser.add_option('--user',
dest='set_user',
metavar="USERNAME",
help="Set the user (usually only possible when run as root)")
parser.add_option('--group',
dest='set_group',
metavar="GROUP",
help="Set the group (usually only possible when run as root)")
options, args = parser.parse_args()
if len(args) != 1:
parser.error("""Missing instance to start up! You can create one using make-scooltool-instance.""")
instance_root = os.path.abspath(args[0])
conf_file = os.path.join(instance_root, "paste.ini")
if not os.path.exists(conf_file):
schooltool_ini = os.path.join(instance_root, 'schooltool.ini')
if os.path.exists(schooltool_ini):
try:
print >> sys.stderr, 'Updating instance files...'
update_instance(instance_root)
print >> sys.stderr, 'Done.'
except OSError, e:
print >> sys.stderr, 'Failed.'
if os.path.exists(schooltool_ini):
conf_file = schooltool_ini
else:
parser.error("This is not a schooltool instance: %s" % args[0])
args[0] = conf_file
if (options.start_daemon or
options.stop_daemon or
options.show_status):
if not options.pid_file:
options.pid_file = os.path.join(instance_root,
"var", "schooltool.pid")
if not options.log_file:
options.log_file = os.path.join(instance_root,
"log", "paster.log")
return options, args
# BBB since schooltool 1.6
def update_instance(instance_root):
"""Renames configuration files to match Ubuntu layout"""
os.rename(os.path.join(instance_root, 'schooltool.ini'),
os.path.join(instance_root, 'paste.ini'))
os.rename(os.path.join(instance_root, 'school.zcml'),
os.path.join(instance_root, 'site.zcml'))
with open(os.path.join(instance_root, 'schooltool.conf'), 'r') as f:
schooltool_conf = f.read()
instance = os.path.basename(instance_root)
schooltool_conf = re.sub(os.path.join(instance, 'school.zcml'),
os.path.join(instance, 'site.zcml'),
schooltool_conf, 1)
schooltool_conf = re.sub('Arial and Times New Roman',
'Liberation',
schooltool_conf, 1)
schooltool_conf = re.sub('msttcorefonts',
'ttf-liberation',
schooltool_conf)
# uncomment reportlab_fontdir
schooltool_conf = re.sub('\n#?(reportlab_fontdir.*)ttf-liberation\n',
r'\n\1ttf-liberation\n',
schooltool_conf, 1)
# comment out obsolete attendance-log-file option
schooltool_conf = re.sub('\n(attendance-log-file.*)\n',
r'\n#\1\n',
schooltool_conf, 1)
# specify absolute path to pid file
schooltool_conf = re.sub('\npid-file (var/schooltool.pid)\n',
r'\npid-file %(instance)s/\1\n' % {
'instance': instance_root},
schooltool_conf, 1)
with open(os.path.join(instance_root, 'schooltool.conf'), 'w') as f:
f.write(schooltool_conf)
def main():
options, args = parse_args()
conf_file = os.path.abspath(args[0])
extra_options = []
if options.start_daemon:
extra_options.append('--daemon')
if options.stop_daemon:
extra_options.append('--stop-daemon')
if options.reload:
extra_options.append('--reload')
if options.reload_interval:
extra_options.append('--reload-interval=%s' % options.reload_interval)
if options.monitor_restart:
extra_options.append('--monitor-restart')
if options.show_status:
extra_options.append('--status')
if options.set_user:
extra_options.append('--user=%s' % options.set_user)
if options.set_group:
extra_options.append('--group=%s' % options.set_group)
if (options.start_daemon or
options.stop_daemon or
options.show_status):
extra_options.extend(['--pid-file=%s' % options.pid_file,
'--log-file=%s' % options.log_file])
paste.script.command.run(['serve', conf_file] + extra_options)
|