|
|
|
#-*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2010 Mir Calculate Ltd. http://www.calculate-linux.org
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
from cl_install import cl_install, InstallError, __app__, __version__
|
|
|
|
from cl_opt import opt
|
|
|
|
from cl_share_cmd import share_cmd
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from cl_lang import lang
|
|
|
|
lang().setLanguage(sys.modules[__name__])
|
|
|
|
|
|
|
|
DESCRIPTION = _("Utility for installation and configuration of Calculate Linux")
|
|
|
|
CMD_OPTIONS = [{'shortOption':"T",
|
|
|
|
'longOption':"template",
|
|
|
|
'optVal':"TEMPLATE", 'help':_("process template")
|
|
|
|
},
|
|
|
|
{'shortOption':"l",
|
|
|
|
'longOption':"lang",
|
|
|
|
'optVal':"LANG",
|
|
|
|
'help':_("set language")
|
|
|
|
},
|
|
|
|
{'shortOption':"d",
|
|
|
|
'longOption':"disk",
|
|
|
|
'optVal':"DISK",
|
|
|
|
'help':_("the disk for installation")
|
|
|
|
},
|
|
|
|
{'shortOption':"s",
|
|
|
|
'longOption':"os",
|
|
|
|
'optVal':"SYSTEM",
|
|
|
|
'type':'choice',
|
|
|
|
'choices':['cld','cds','cls','css','cldg','cldx'],
|
|
|
|
'help':_("select operation system")
|
|
|
|
},
|
|
|
|
{'shortOption':"b",
|
|
|
|
'longOption':"build",
|
|
|
|
'help':_("installation for assembling")
|
|
|
|
}]
|
|
|
|
|
|
|
|
class install_cmd(cl_install,opt,share_cmd):
|
|
|
|
"""Class for work with cl_install by console"""
|
|
|
|
def __init__(self):
|
|
|
|
opt.__init__(self,
|
|
|
|
package=__app__,
|
|
|
|
version=__version__,
|
|
|
|
description=DESCRIPTION,
|
|
|
|
option_list= CMD_OPTIONS + opt.variable_control +
|
|
|
|
opt.color_control,
|
|
|
|
check_values=self.checkOpts)
|
|
|
|
cl_install.__init__(self)
|
|
|
|
|
|
|
|
def checkOpts(self, values, args):
|
|
|
|
"""Check values all specified options."""
|
|
|
|
if len(args) > 0:
|
|
|
|
self.error(_("unrecognized option") + ": %s"% "".join(args))
|
|
|
|
if values.T is None and \
|
|
|
|
values.vars is None and \
|
|
|
|
values.d is None:
|
|
|
|
self.error(_("need specify disk by '-d' option"))
|
|
|
|
if values.s:
|
|
|
|
choices = ['cld','cds','cls','css','cldg','cldx']
|
|
|
|
if not values.s.lower() in choices:
|
|
|
|
choices = ", ".join(map(repr, choices))
|
|
|
|
self.error(
|
|
|
|
_("option %s: invalid choice: %r (choose from %s)")
|
|
|
|
% (opt, values.s, choices))
|
|
|
|
if values.b:
|
|
|
|
self.error(_("builder mode yet hasn`t supported"))
|
|
|
|
if not values.T in [None,"all"]:
|
|
|
|
self.error(
|
|
|
|
_("defenition of a particular template yet is not supported"))
|
|
|
|
# check syntax --set
|
|
|
|
self.checkVarSyntax(values)
|
|
|
|
return (values, args)
|
|
|
|
|
|
|
|
def processSetLang(self,lang):
|
|
|
|
"""Process set locales by lang"""
|
|
|
|
if self.setAllLocaleByLang(lang):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
self.printERROR(_("specified lang %s is unsupported")%lang)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def processSetVars(self,vars):
|
|
|
|
"""Process setting values for variables"""
|
|
|
|
for vals in vars:
|
|
|
|
for val in vals.split(','):
|
|
|
|
k,o,v = val.partition('=')
|
|
|
|
if self.clVars.exists(k):
|
|
|
|
if not self.clVars.SetWriteVar(k,v):
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
self.printERROR(_('variable %s not found')%k)
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def processDisplayVars(self,vars):
|
|
|
|
"""Process displaying variables"""
|
|
|
|
terms = vars.split(",")
|
|
|
|
# if value of vars is "all" print all variables
|
|
|
|
if terms == ["all"]:
|
|
|
|
self.clVars.printVars()
|
|
|
|
# print only specified variables
|
|
|
|
else:
|
|
|
|
self.clVars.printVars(terms)
|
|
|
|
|
|
|
|
def processTemplateSelect(self,template):
|
|
|
|
"""Process template appling"""
|
|
|
|
if self.applyTemplatesForSystem():
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def installSystem(self):
|
|
|
|
if cl_install.installSystem(self,disk=self.values.d,
|
|
|
|
buildermode=self.values.b,osname=self.values.s):
|
|
|
|
print "installation complete"
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|