diff --git a/i18n/cl_install_ru.mo b/i18n/cl_install_ru.mo index 5b018a2..9b4e74b 100644 Binary files a/i18n/cl_install_ru.mo and b/i18n/cl_install_ru.mo differ diff --git a/pym/__init__.py b/pym/__init__.py index 8d1c8b6..e69de29 100644 --- a/pym/__init__.py +++ b/pym/__init__.py @@ -1 +0,0 @@ - diff --git a/pym/cl_fill_install.py b/pym/cl_fill_install.py new file mode 100644 index 0000000..c7183a9 --- /dev/null +++ b/pym/cl_fill_install.py @@ -0,0 +1,36 @@ +#-*- 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. + +import os +import re +from cl_datavars import glob_attr + +class fillVars(object, glob_attr): + def get_cl_profile_path(self): + """list appied templates""" + profpath = [] + profPaths=['/usr/lib/calculate/calculate-install/templates', + '/var/calculate/remote/templates', + '/var/calculate/templates'] + for profPath in profPaths: + if os.path.isdir(profPath): + paths = os.listdir(profPath) + for path in paths: + ph = os.path.join(profPath,path) + if os.path.isdir(ph) and os.listdir(ph): + profpath.append(ph) + return profpath + diff --git a/pym/cl_install.py b/pym/cl_install.py index 042744a..c950de8 100644 --- a/pym/cl_install.py +++ b/pym/cl_install.py @@ -1,6 +1,6 @@ #-*- coding: utf-8 -*- -# Copyright 2008-2010 Mir Calculate Ltd. http://www.calculate-linux.org +# 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. @@ -14,23 +14,90 @@ # See the License for the specific language governing permissions and # limitations under the License. +__version__ = "2.2.0" +__version_info__ = tuple([ int(num) for num in __version__.split('.')]) +__app__ = "calculate-install" + import os import re import sys -import cl_base -import cl_profile -import cl_utils2 -import cl_utils - -Version = "calculate-install 2.2.0" +from cl_lang import lang +from cl_template import template +from cl_fill import clLocale +from cl_datavars import DataVars +from cl_print import color_print -tr = cl_base.lang() +tr = lang() +tr.setGlobalDomain('cl_install') tr.setLanguage(sys.modules[__name__]) -pcs = cl_utils.prettyColumnStr - class printNoColor: def colorPrint(self,attr,fg,bg,string): sys.stdout.write(string) +class DataVarsInstall(DataVars): + """Variable class for installation""" + + def flInstall(self, **args): + '''Заполнить конфигурацию переменных, для десктопа''' + # Имя секции в calculate.env + envSection = "calculate-install" + # заполнить переменные окружения алгоритмом по умолнанию + self.importData(envSection, ('cl_vars_install','cl_fill_install')) + +class cl_install(color_print): + """Primary class for templates appling and system installation""" + + def __init__(self): + self.clVars = None + self.clTemp = None + self.color = True + + def colorPrint(self,attr,fg,bg,string): + if self.color: + color_print.colorPrint(self,attr,fg,bg,string) + else: + sys.stdout.write(string) + sys.stdout.flush() + + def setNoColor(self): + self.color = False + + def initVars(self): + """Primary initialization of variables""" + self.clVars = DataVarsInstall() + self.clVars.flInstall() + self.clVars.flIniFile() + + def applyTemplatesForSystem(self): + """Apply templates for root of system.""" + self.clVars.Set("cl_root_path","/", True) + self.clTemp = template(self.clVars) + dirsFiles = self.clTemp.applyProfiles() + if self.clTemp.getError(): + return False + else: + return dirsFiles + + def installSystem(self): + """install System by current variable enviroment""" + pass + + def setAllLocaleByLang(self,lang): + """Set all locale variable by specified lang""" + locale = clLocale() + if not locale.isLangExists(lang): + return False + self.clVars.Set('os_locale_lang',lang, True) + self.clVars.Set('os_locale_locale', + locale.getFieldByLang('locale',lang), True) + self.clVars.Set('os_locale_language', + locale.getFieldByLang('language',lang), True) + self.clVars.Set('os_locale_keymap', + locale.getFieldByLang('keymap',lang), True) + self.clVars.Set('os_locale_dumpkeys', + locale.getFieldByLang('dumpkeys_charset',lang), True) + self.clVars.Set('os_locale_xkb', + locale.getFieldByLang('xkblayout',lang), True) + return True diff --git a/pym/cl_vars_install.py b/pym/cl_vars_install.py new file mode 100644 index 0000000..9df449b --- /dev/null +++ b/pym/cl_vars_install.py @@ -0,0 +1,35 @@ +#-*- 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. + +#Допустимые ключи значений +# mode - read only or writeable variable +# value - default variable value +# select - list of posible values for variable +# official - flag, if it is True, then the variable is not printable +# printval - print value of variable + +class Data: + # list of applied templates + cl_profile_path = {} + + # relative path for apply templates on files of system + cl_root_path = {} + + # program name + cl_name = {'value':'calculate-install'} + + # program version + cl_ver = {'value':'2.2.0'} diff --git a/pym/install_opt.py b/pym/install_opt.py new file mode 100644 index 0000000..1311957 --- /dev/null +++ b/pym/install_opt.py @@ -0,0 +1,116 @@ +#-*- 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, __app__, __version__ +from cl_opt import opt +import sys + +from cl_lang import lang +lang().setLanguage(sys.modules[__name__]) + +class install_opt(cl_install,opt): + """Class for work with cl_install by console""" + def __init__(self): + opt.__init__(self, + package=__app__, + version=__version__, + description=_("""\ +Utility for installation and configuration of Calculate Linux"""), + option_list=\ + [{'shortOption':"T", + 'longOption':"template", + 'optVal':"TEMPLATE", 'help':_("process template") + }, + {'shortOption':"l", + 'longOption':"lang", + 'optVal':"LANG", + 'help':_("set language") + }]\ + + self.variable_control\ + + self.color_control) + cl_install.__init__(self) + + def check_values(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: + self.error(_("installation yet is not exists")) + 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.Set(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 run(self,options,args): + """Processing of all receiving options""" + # variables printing + self.initVars() + if options.color == "never": + self.setNoColor() + if not options.l is None: + if not self.processSetLang(options.l): + return False + if options.set: + if not self.processSetVars(options.set): + return False + if not options.vars is None: + self.processDisplayVars(options.vars) + return True + elif not options.T is None: + return self.applyTemplatesForSystem() + else: + return False + diff --git a/scripts/cl-install b/scripts/cl-install index d18647b..347bf5a 100644 --- a/scripts/cl-install +++ b/scripts/cl-install @@ -1,7 +1,7 @@ #!/usr/bin/python #-*- coding: utf-8 -*- -# Copyright 2008-2010 Mir Calculate Ltd. http://www.calculate-linux.org +# 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. @@ -19,11 +19,18 @@ import sys import os sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-lib/pym')) sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-install/pym')) -import cl_base -import cl_install -tr = cl_base.lang() + +from install_opt import install_opt + +from cl_lang import lang +tr = lang() tr.setGlobalDomain('cl_install') tr.setLanguage(sys.modules[__name__]) if __name__ == "__main__": - pass + install = install_opt() + opts, args = install.parse_args() + if install.run(opts,args): + sys.exit(0) + else: + sys.exit(1)