import os
import sys
+import re
import logging
from optparse import OptionParser
def getopts():
optp = OptionParser(usage=usage, version=__version__)
- optp.add_option('-n', '--name', dest='name', help=_('Service name'))
- optp.add_option('-e', '--enable', dest='enable', action="store_true", help=_('Enable autostart'))
- optp.add_option('-d', '--disable', dest='disable', action="store_true", help=_('Disable autostart'))
+ optp.add_option('-n', '--name', dest='name', help=_('Service name'), default=None)
+ optp.add_option('-e', '--enable', dest='enable', action="store_true", help=_('Enable autostart'), default=False)
+ optp.add_option('-d', '--disable', dest='disable', action="store_true", help=_('Disable autostart'), default=False)
return optp.parse_args()
def chkopts(opts):
- if opts.name is None:
+ reg = re.compile("[^a-zA-Z0-9\./_-]")
+
+ if opts.name:
+ if reg.search(opts.name):
+ raise KssCommandOptException('ERROR: Illigal option value. option=%s value=%s' % ('-n or --name', opts.name))
+ else:
raise KssCommandOptException('ERROR: %s option is required.' % '-n or --name')
- if opts.enable is None and opts.disable is None:
+
+ if opts.enable is False and opts.disable is False:
raise KssCommandOptException('ERROR: either %s options must be specified.' % '--enable or --disable')
- if opts.enable is not None and opts.disable is not None:
+ if opts.enable is True and opts.disable is True:
raise KssCommandOptException('ERROR: %s options are conflicted.' % '--enable and --disable')
class AutostartService(KssCommand):
(opts, args) = getopts()
chkopts(opts)
self.up_progress(10)
+
config = ServiceConfigParam(SERVICE_XML_FILE)
config.load_xml_config()
service = config.findby1service(opts.name)
+ if service is None:
+ raise KssCommandException("Service not found in xml file. service=%s" % (opts.name))
+
self.up_progress(10)
sysv = SysVInit_RH(service['system_name'], service['system_command'])
import os
import sys
+import re
import logging
import fcntl
from optparse import OptionParser
try:
import karesansui
from karesansui import __version__
- from karesansui.lib.utils import load_locale, execute_command, pipe_execute_command, generate_phrase
+ from karesansui.lib.utils import load_locale, execute_command, pipe_execute_command, generate_phrase, get_filesystem_info
from karesansui.lib.const import KARESANSUI_TMP_DIR, MOUNT_CMD, UMOUNT_CMD, FORMAT_CMD, YES_CMD
except ImportError:
else:
raise KssCommandOptException('ERROR: %s option is required.' % '-d or --dev')
- #TODO
- # check fs format type
- # hint.
- # /proc/filesystems
- # or
- # modprobe -l -t kernel/fs
+ if opts.type not in get_filesystem_info():
+ raise KssCommandOptException('ERROR: Unknown format type. type=%s' % (opts.type))
class ReadyMount(KssCommand):
def process(self):
(opts, args) = getopts()
chkopts(opts)
- self.up_progress(10)
+ self.up_progress(10)
try:
tmp_dir_name = generate_phrase(12,'abcdefghijklmnopqrstuvwxyz')
tmp_dir_path = "%s/%s" % (KARESANSUI_TMP_DIR, tmp_dir_name)
os.mkdir(tmp_dir_path)
- except Exception, e:
- self.logger.error('Failed to make tmpdir. path=%s' % (tmp_dir_path))
- print >>sys.stderr, _('Failed to make tmpdir. path=%s' % (tmp_dir_path))
- raise
+ except:
+ raise KssCommandException('Failed to make tmpdir. path=%s' % (tmp_dir_path))
try:
self.up_progress(10)
"""
return grp.getgrall()
+def get_filesystem_info():
+ """
+ <comment-ja>
+ 使用できるファイルシステムを取得する
+ </comment-ja>
+ <comment-en>
+ TODO: English Comment
+ </comment-en>
+ """
+ ret = []
+ _filesystem_path = "/etc/filesystems"
+ nodev_regex = re.compile("^nodev")
+
+ data = read_file(_filesystem_path)
+ if data:
+ for line in data.split("\n"):
+ line = line.strip()
+ if line == "":
+ continue
+ if nodev_regex.match(line):
+ continue
+
+ ret.append(line)
+
+ return ret
+
if __name__ == '__main__':
pass