2 # -*- coding: utf-8 -*-
4 # This file is part of Karesansui.
6 # Copyright (C) 2009-2010 HDE, Inc.
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
18 from optparse import OptionParser
20 from ksscommand import KssCommand, KssCommandException, KssCommandOptException
26 from karesansui import __version__
27 from karesansui.lib.utils import load_locale, copy_file, remove_file
28 from karesansui.lib.const import LIGHTTPD_CONF_TEMP_DIR,\
29 LIGHTTPD_PORT_CONFIG, LIGHTTPD_ACCESS_CONFIG, LIGHTTPD_SSL_CONFIG
32 print >>sys.stderr, "[Error] karesansui package was not found."
37 usage = '%prog [options]'
40 opts = OptionParser(usage=usage, version=__version__)
41 opts.add_option('-d', '--dest', dest='dest', help=('copy destination directory'))
42 opts.add_option('-p', '--port', dest='tmp_port_conf', help=('port.conf temporary file path'))
43 opts.add_option('-s', '--ssl', dest='tmp_ssl_conf', help=('ssl.conf temporary file path'))
44 opts.add_option('-a', '--access', dest='tmp_access_conf', help=('access.conf temporary file path'))
45 return opts.parse_args()
50 raise KssCommandOptException('ERROR: -d or --dest option is required.')
51 elif not opts.tmp_port_conf:
52 raise KssCommandOptException('ERROR: -p or --port option is required.')
53 elif not opts.tmp_ssl_conf:
54 raise KssCommandOptException('ERROR: -s or --ssl option is required.')
55 elif not opts.tmp_access_conf:
56 raise KssCommandOptException('ERROR: -a or --access option is required.')
59 if os.path.isdir(opts.dest) is False:
60 raise KssCommandOptException('ERROR: Not directory dest=%s' % opts.dest)
61 elif os.path.isfile(opts.tmp_port_conf) is False:
62 raise KssCommandOptException('ERROR: Not exist temporary file tmp_port_conf=%s' % opts.tmp_port_conf)
63 elif os.path.isfile(opts.tmp_ssl_conf) is False:
64 raise KssCommandOptException('ERROR: Not exist temporary file tmp_ssl_conf=%s' % opts.tmp_ssl_conf)
65 elif os.path.isfile(opts.tmp_access_conf) is False:
66 raise KssCommandOptException('ERROR: Not exist temporary file tmp_access_conf=%s' % opts.tmp_access_conf)
68 class LighttpdConfigFile(KssCommand):
71 (opts, args) = getopts()
73 opts.dest = opts.dest.rstrip('/')
77 LIGHTTPD_PORT_CONFIG : opts.tmp_port_conf,
78 LIGHTTPD_SSL_CONFIG : opts.tmp_ssl_conf,
79 LIGHTTPD_ACCESS_CONFIG : opts.tmp_access_conf
83 for srcfile in tmp_configfiles.values():
84 if os.path.isfile(srcfile) is False:
85 raise KssCommandException(
86 'Temporary config file is not found. -path=%s' % srcfile)
90 for dest, src in tmp_configfiles.items():
91 copy_file(src, opts.dest + '/' + dest)
96 raise KssCommandException('Failed to copy config file -src=%s dest=%s' % (src, dest))
98 self.logger.info('Applied lighttpd settings.')
99 print >>sys.stdout, _('Applied lighttpd settings.')
103 if __name__ == "__main__":
104 target = LighttpdConfigFile()
105 sys.exit(target.run())