R-2.9.12
This commit is contained in:
+10
-10
@@ -62,7 +62,7 @@ class refTable(object):
|
||||
rowSeparator = headerChar * (len(prefix) +len(postfix) + sum(maxWidths) +
|
||||
len(delim) * (len(maxWidths) - 1))
|
||||
|
||||
justify = {'center': str.center,
|
||||
justify = {'center': str.center,
|
||||
'right': str.rjust,
|
||||
'left': str.ljust
|
||||
}[justify.lower()]
|
||||
@@ -85,12 +85,12 @@ class refTable(object):
|
||||
hasHeader = False
|
||||
return output.getvalue()
|
||||
|
||||
def wrap_onspace(self, text, width):
|
||||
return reduce(lambda line, word, width=width: '%s%s%s' % (
|
||||
line,
|
||||
' ' if len(line.rsplit('\n')[-1]+word.split('\n')[0])>=width else '\n',
|
||||
def wrap_onspace(self, text, width):
|
||||
return reduce(lambda line, word, width=width: '%s%s%s' % (
|
||||
line,
|
||||
' ' if len(line.rsplit('\n')[-1]+word.split('\n')[0])>=width else '\n',
|
||||
word), text.split(' '))
|
||||
|
||||
|
||||
|
||||
def wrap_onspace_strict(self, text, width):
|
||||
wordRegex = re.compile(r'\S{' + str(width) + r',}')
|
||||
@@ -232,7 +232,7 @@ class console:
|
||||
fields.append(field.strip())
|
||||
|
||||
if len(invalidParams) > 0:
|
||||
print('the following parameter(s) is not valid\n%s' %
|
||||
print('the following parameter(s) is not valid\n%s' %
|
||||
','.join(invalidParams))
|
||||
else:
|
||||
try:
|
||||
@@ -341,10 +341,10 @@ style choices:
|
||||
print('%s has been created and populated with all available data from table %2\n' % (file, table))
|
||||
except Exception, err:
|
||||
print("EXCEPTION: could not create table %s\n%s" % (table, err))
|
||||
|
||||
|
||||
else:
|
||||
print('the following fields are not valid [%s]' % (','.join(filedNotFound)))
|
||||
|
||||
|
||||
|
||||
def cmd_help(self, *args):
|
||||
'''-3|help|Show's help'''
|
||||
@@ -477,7 +477,7 @@ class setCopyDB():
|
||||
|
||||
def delete_DB_tables(self, storageFolder, storageType):
|
||||
print 'delete_DB_tablesn\n\t%s\n\t%s' % (storageFolder, storageType)
|
||||
|
||||
|
||||
dataFiles = [storageType, "sql.log"]
|
||||
try:
|
||||
for f in os.listdir(storageFolder):
|
||||
|
||||
@@ -136,7 +136,7 @@ def define_field(conn, table, field, pks):
|
||||
else:
|
||||
f['type'] = "'blob'"
|
||||
f['comment'] = "'WARNING: Oracle Data Type %s was not mapped." % \
|
||||
str(field['DATA_TYPE']) + " Using 'blob' as fallback.'"
|
||||
str(field['DATA_TYPE']) + " Using 'blob' as fallback.'"
|
||||
|
||||
try:
|
||||
if field['COLUMN_DEFAULT']:
|
||||
|
||||
@@ -30,7 +30,7 @@ def fix_links(html,prefix):
|
||||
link = "{{=URL('static','%s/%s')}}" % (prefix,link)
|
||||
return '%s="%s"' % (href,link)
|
||||
return regex_link.sub(fix,html)
|
||||
|
||||
|
||||
def make_views(html_files,prefix):
|
||||
views = {}
|
||||
layout_name = os.path.join(prefix,'layout.html')
|
||||
@@ -76,13 +76,13 @@ def recursive_overwrite(src, dest, ignore=None):
|
||||
ignored = set()
|
||||
for f in files:
|
||||
if f not in ignored:
|
||||
recursive_overwrite(os.path.join(src, f),
|
||||
os.path.join(dest, f),
|
||||
recursive_overwrite(os.path.join(src, f),
|
||||
os.path.join(dest, f),
|
||||
ignore)
|
||||
else:
|
||||
shutil.copyfile(src, dest)
|
||||
|
||||
def convert(source, destination,prefix='imported'):
|
||||
def convert(source, destination,prefix='imported'):
|
||||
html_files = glob.glob(os.path.join(source,'*.html'))
|
||||
static_folder = os.path.join(destination,'static',prefix)
|
||||
recursive_overwrite(source,static_folder)
|
||||
@@ -96,7 +96,7 @@ def convert(source, destination,prefix='imported'):
|
||||
if not os.path.exists(os.path.split(fullname)[0]):
|
||||
os.makedirs(os.path.split(fullname)[0])
|
||||
open(fullname,'w').write(views[name])
|
||||
|
||||
|
||||
|
||||
|
||||
convert(sys.argv[1],sys.argv[2])
|
||||
|
||||
+32
-33
@@ -7,37 +7,37 @@ class LinuxService(ServiceBase):
|
||||
ServiceBase.__init__(self, name, label, stdout, stderr)
|
||||
self.pidfile = '/tmp/%s.pid' % name
|
||||
self.config_file = '/etc/%s.conf' % name
|
||||
|
||||
|
||||
def daemonize(self):
|
||||
"""
|
||||
do the UNIX double-fork magic, see Stevens' "Advanced
|
||||
do the UNIX double-fork magic, see Stevens' "Advanced
|
||||
Programming in the UNIX Environment" for details (ISBN 0201563177)
|
||||
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16
|
||||
"""
|
||||
try:
|
||||
pid = os.fork()
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# exit first parent
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror))
|
||||
return
|
||||
|
||||
|
||||
# decouple from parent environment
|
||||
os.chdir("/")
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
os.chdir("/")
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
# do second fork
|
||||
try:
|
||||
pid = os.fork()
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
# exit from second parent
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
sys.exit(0)
|
||||
except OSError, e:
|
||||
sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror))
|
||||
return
|
||||
|
||||
|
||||
# redirect standard file descriptors
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
@@ -47,25 +47,25 @@ class LinuxService(ServiceBase):
|
||||
os.dup2(si.fileno(), sys.stdin.fileno())
|
||||
os.dup2(so.fileno(), sys.stdout.fileno())
|
||||
os.dup2(se.fileno(), sys.stderr.fileno())
|
||||
|
||||
|
||||
def getpid(self):
|
||||
# Check for a pidfile to see if the daemon already runs
|
||||
try:
|
||||
try:
|
||||
pf = file(self.pidfile,'r')
|
||||
pid = int(pf.read().strip())
|
||||
pf.close()
|
||||
except IOError:
|
||||
pid = None
|
||||
|
||||
|
||||
return pid
|
||||
|
||||
|
||||
def status(self):
|
||||
pid = self.getpid()
|
||||
if pid:
|
||||
return 'Service running with PID %s.' % pid
|
||||
else:
|
||||
return 'Service is not running.'
|
||||
|
||||
|
||||
def check_permissions(self):
|
||||
if not os.geteuid() == 0:
|
||||
return (False, 'This script must be run with root permissions.')
|
||||
@@ -77,12 +77,12 @@ class LinuxService(ServiceBase):
|
||||
Start the daemon
|
||||
"""
|
||||
pid = self.getpid()
|
||||
|
||||
|
||||
if pid:
|
||||
message = "Service already running under PID %s\n"
|
||||
sys.stderr.write(message % self.pidfile)
|
||||
return
|
||||
|
||||
|
||||
# Start the daemon
|
||||
self.daemonize()
|
||||
self.run()
|
||||
@@ -92,13 +92,13 @@ class LinuxService(ServiceBase):
|
||||
Stop the daemon
|
||||
"""
|
||||
pid = self.getpid()
|
||||
|
||||
|
||||
if not pid:
|
||||
message = "Service is not running\n"
|
||||
sys.stderr.write(message)
|
||||
return # not an error in a restart
|
||||
|
||||
# Try killing the daemon process
|
||||
# Try killing the daemon process
|
||||
try:
|
||||
while 1:
|
||||
os.kill(pid, SIGTERM)
|
||||
@@ -118,19 +118,19 @@ class LinuxService(ServiceBase):
|
||||
"""
|
||||
self.stop()
|
||||
self.start()
|
||||
|
||||
|
||||
def run(self):
|
||||
atexit.register(self.terminate)
|
||||
|
||||
|
||||
args = self.load_configuration()[0]
|
||||
stdout = open(self.stdout, 'a+')
|
||||
stderr = open(self.stderr, 'a+')
|
||||
process = subprocess.Popen(args, stdout=stdout, stderr=stderr)
|
||||
file(self.pidfile,'w+').write("%s\n" % process.pid)
|
||||
process.wait()
|
||||
|
||||
|
||||
self.terminate()
|
||||
|
||||
|
||||
def terminate(self):
|
||||
try:
|
||||
os.remove(self.pidfile)
|
||||
@@ -152,7 +152,7 @@ class LinuxService(ServiceBase):
|
||||
install_command = self.get_service_installer_command(env)
|
||||
result = self.run_command(*install_command)
|
||||
self.start()
|
||||
|
||||
|
||||
def uninstall(self):
|
||||
self.stop()
|
||||
env = self.detect_environment()
|
||||
@@ -164,7 +164,7 @@ class LinuxService(ServiceBase):
|
||||
# remove link to the script from the service directory
|
||||
path = env['rc.d-path'] + self.name
|
||||
os.remove(path)
|
||||
|
||||
|
||||
def detect_environment(self):
|
||||
"""
|
||||
Returns a dictionary of command/path to the required command-line applications.
|
||||
@@ -196,7 +196,7 @@ class LinuxService(ServiceBase):
|
||||
env['rc.d-path'] = '/dev/null/'
|
||||
|
||||
return env
|
||||
|
||||
|
||||
def get_service_installer_command(self, env):
|
||||
"""
|
||||
Returns list of args required to set a service to run on boot.
|
||||
@@ -218,4 +218,3 @@ class LinuxService(ServiceBase):
|
||||
else:
|
||||
cmd = env['update-rc.d']
|
||||
return [cmd, self.name, 'remove']
|
||||
|
||||
|
||||
+28
-28
@@ -17,14 +17,14 @@ class ServiceBase(Base):
|
||||
self.stdout = stdout
|
||||
self.stderr = stderr
|
||||
self.config_file = None
|
||||
|
||||
|
||||
def load_configuration(self):
|
||||
"""
|
||||
Loads the configuration required to build the command-line string
|
||||
for running web2py. Returns a tuple (command_args, config_dict).
|
||||
"""
|
||||
s = os.path.sep
|
||||
|
||||
|
||||
default = dict(
|
||||
python = 'python',
|
||||
web2py = os.path.join(s.join(__file__.split(s)[:-3]), 'web2py.py'),
|
||||
@@ -38,14 +38,14 @@ class ServiceBase(Base):
|
||||
https_cert = '',
|
||||
password = '<recycle>',
|
||||
)
|
||||
|
||||
|
||||
config = default
|
||||
if self.config_file:
|
||||
try:
|
||||
f = open(self.config_file, 'r')
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
|
||||
|
||||
for line in lines:
|
||||
fields = line.split('=', 1)
|
||||
if len(fields) == 2:
|
||||
@@ -55,10 +55,10 @@ class ServiceBase(Base):
|
||||
config[key] = value
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
web2py_path = os.path.dirname(config['web2py'])
|
||||
os.chdir(web2py_path)
|
||||
|
||||
|
||||
args = [config['python'], config['web2py']]
|
||||
interfaces = []
|
||||
ports = []
|
||||
@@ -78,68 +78,68 @@ class ServiceBase(Base):
|
||||
ports.append(ports)
|
||||
if len(interfaces) == 0:
|
||||
sys.exit('Configuration error. Must have settings for http and/or https')
|
||||
|
||||
|
||||
password = config['password']
|
||||
if not password == '<recycle>':
|
||||
from gluon import main
|
||||
for port in ports:
|
||||
main.save_password(password, port)
|
||||
|
||||
|
||||
password = '<recycle>'
|
||||
|
||||
|
||||
args.append('-a "%s"' % password)
|
||||
|
||||
|
||||
interfaces = ';'.join(interfaces)
|
||||
args.append('--interfaces=%s' % interfaces)
|
||||
|
||||
|
||||
if 'log_filename' in config.key():
|
||||
log_filename = config['log_filename']
|
||||
args.append('--log_filename=%s' % log_filename)
|
||||
|
||||
|
||||
return (args, config)
|
||||
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
|
||||
def restart(self):
|
||||
pass
|
||||
|
||||
|
||||
def status(self):
|
||||
pass
|
||||
|
||||
|
||||
def run(self):
|
||||
pass
|
||||
|
||||
|
||||
def install(self):
|
||||
pass
|
||||
|
||||
|
||||
def uninstall(self):
|
||||
pass
|
||||
|
||||
|
||||
def check_permissions(self):
|
||||
"""
|
||||
Does the script have permissions to install, uninstall, start, and stop services?
|
||||
Return value must be a tuple (True/False, error_message_if_False).
|
||||
"""
|
||||
return (False, 'Permissions check not implemented')
|
||||
|
||||
|
||||
class WebServerBase(Base):
|
||||
def install(self):
|
||||
pass
|
||||
|
||||
|
||||
def uninstall(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def get_service():
|
||||
service_name = 'web2py'
|
||||
service_label = 'web2py Service'
|
||||
|
||||
|
||||
if sys.platform == 'linux2':
|
||||
from linux import LinuxService as Service
|
||||
from linux import LinuxService as Service
|
||||
elif sys.platform == 'darwin':
|
||||
# from mac import MacService as Service
|
||||
sys.exit('Mac OS X is not yet supported.\n')
|
||||
@@ -148,16 +148,16 @@ def get_service():
|
||||
sys.exit('Windows is not yet supported.\n')
|
||||
else:
|
||||
sys.exit('The following platform is not supported: %s.\n' % sys.platform)
|
||||
|
||||
|
||||
service = Service(service_name, service_label)
|
||||
return service
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
service = get_service()
|
||||
is_root, error_message = service.check_permissions()
|
||||
if not is_root:
|
||||
sys.exit(error_message)
|
||||
|
||||
|
||||
if len(sys.argv) >= 2:
|
||||
command = sys.argv[1]
|
||||
if command == 'start':
|
||||
|
||||
@@ -20,12 +20,12 @@ Typical usage:
|
||||
|
||||
# Delete all sessions regardless of expiry and exit.
|
||||
python web2py.py -S app -M -R scripts/sessions2trash.py -A -o -x 0
|
||||
|
||||
|
||||
# Delete session in a module (move to the modules folder)
|
||||
from sessions2trash import single_loop
|
||||
def delete_sessions():
|
||||
single_loop()
|
||||
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
Reference in New Issue
Block a user