From 554f7996f7064afcdce862cde35269f16fd3d37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B0=D0=BC=D0=BE=D1=83=D0=BA=D0=B8=D0=BD=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Tue, 1 Jun 2010 14:07:32 +0400 Subject: [PATCH] Added install and uninstall program --- pym/cl_client_cmd.py | 13 --------- pym/cl_install_cmd.py | 58 +++++++++++++++++++++++++++++++++++++++++ pym/cl_uninstall_cmd.py | 58 +++++++++++++++++++++++++++++++++++++++++ scripts/cl-client-2.2 | 8 ------ scripts/install | 52 ++++++++++++++++++++++++++++++++++++ scripts/uninstall | 54 ++++++++++++++++++++++++++++++++++++++ setup.py | 38 +++++++++++++++++++++++++-- 7 files changed, 258 insertions(+), 23 deletions(-) create mode 100644 pym/cl_install_cmd.py create mode 100644 pym/cl_uninstall_cmd.py create mode 100644 scripts/install create mode 100644 scripts/uninstall diff --git a/pym/cl_client_cmd.py b/pym/cl_client_cmd.py index 5664877..3957849 100644 --- a/pym/cl_client_cmd.py +++ b/pym/cl_client_cmd.py @@ -38,11 +38,6 @@ DESCRIPTION = _("Changes settings for connecting to domain") # Опции командной строки CMD_OPTIONS = [{'shortOption':"r", 'help':_("remove the settings for connecting to a domain")}, - {'longOption':"install", - 'help':_("add use of scripts this package for window manager")}, - {'longOption':"uninstall", - 'help':_("remove use of scripts this package for window \ - manager and, if necessary, removes from domain")}, {'longOption':"mount", 'help':_("mount [remote] resource for domain")}] @@ -124,14 +119,6 @@ class client_cmd(share_cmd): """Вывод из домена""" return self.logicObj.delDomain() - def install(self): - """Инсталяция""" - return self.logicObj.installClient() - - def uninstall(self): - """Удаление""" - return self.logicObj.uninstallClient() - def mountRemote(self): """Монтирование remote и домашней директории если компьютер в домене diff --git a/pym/cl_install_cmd.py b/pym/cl_install_cmd.py new file mode 100644 index 0000000..fe46252 --- /dev/null +++ b/pym/cl_install_cmd.py @@ -0,0 +1,58 @@ +#-*- 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_client import client, __app__, __version__ +from cl_opt import opt, TitledHelpFormatter +import sys +from cl_share_cmd import share_cmd + +# Перевод сообщений для программы +from cl_lang import lang +lang().setLanguage(sys.modules[__name__]) + +# Использование программы +USAGE = _("%prog [options]") + +# Описание программы (что делает программа) +DESCRIPTION = _("Configure the system to calculate-client package") + +class install_cmd(share_cmd): + def __init__(self): + # Объект опций командной строки + self.optobj = opt(\ + package=__app__, + version=__version__, + usage=USAGE, + description=DESCRIPTION, + option_list=opt.variable_control+opt.color_control, + formatter=TitledHelpFormatter(), + check_values=self.checkOpts) + # Создаем объект логики + self.logicObj = client() + # Создаем переменные + self.logicObj.createClVars() + + def checkOpts(self, optObj, args): + """Проверка опций командной строки""" + if args: + errMsg = _("invalid argument") + ":" + " %s" %" ".join(args) + self.optobj.error(errMsg) + return False + return optObj, args + + def installProg(self): + """Наложение шаблонов на систему при инсталяции""" + return self.logicObj.installClient() \ No newline at end of file diff --git a/pym/cl_uninstall_cmd.py b/pym/cl_uninstall_cmd.py new file mode 100644 index 0000000..078221b --- /dev/null +++ b/pym/cl_uninstall_cmd.py @@ -0,0 +1,58 @@ +#-*- 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_client import client, __app__, __version__ +from cl_opt import opt, TitledHelpFormatter +import sys +from cl_share_cmd import share_cmd + +# Перевод сообщений для программы +from cl_lang import lang +lang().setLanguage(sys.modules[__name__]) + +# Использование программы +USAGE = _("%prog [options]") + +# Описание программы (что делает программа) +DESCRIPTION = _("Configure the system to calculate-client package") + +class uninstall_cmd(share_cmd): + def __init__(self): + # Объект опций командной строки + self.optobj = opt(\ + package=__app__, + version=__version__, + usage=USAGE, + description=DESCRIPTION, + option_list=opt.variable_control+opt.color_control, + formatter=TitledHelpFormatter(), + check_values=self.checkOpts) + # Создаем объект логики + self.logicObj = client() + # Создаем переменные + self.logicObj.createClVars() + + def checkOpts(self, optObj, args): + """Проверка опций командной строки""" + if args: + errMsg = _("invalid argument") + ":" + " %s" %" ".join(args) + self.optobj.error(errMsg) + return False + return optObj, args + + def uninstallProg(self): + """Наложение шаблонов на систему при деинсталяции""" + return self.logicObj.uninstallClient() \ No newline at end of file diff --git a/scripts/cl-client-2.2 b/scripts/cl-client-2.2 index a20895a..1324d67 100644 --- a/scripts/cl-client-2.2 +++ b/scripts/cl-client-2.2 @@ -52,14 +52,6 @@ if __name__ == "__main__": # Вывод из домена if not obj.delDomain(): sys.exit(1) - elif opts.install: - # Инсталяция - if not obj.install(): - sys.exit(1) - elif opts.uninstall: - # Удаление - if not obj.uninstall(): - sys.exit(1) elif opts.mount: # Монтирование remote if not obj.mountRemote(): diff --git a/scripts/install b/scripts/install new file mode 100644 index 0000000..1483ba4 --- /dev/null +++ b/scripts/install @@ -0,0 +1,52 @@ +#!/usr/bin/python +#-*- 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 sys +import os +sys.path.insert(0,os.path.abspath('/usr/lib/calculate-2.2/calculate-lib/pym')) +sys.path.insert(0,\ + os.path.abspath('/usr/lib/calculate-2.2/calculate-client/pym')) + +from cl_install_cmd import install_cmd + +from cl_lang import lang +tr = lang() +tr.setGlobalDomain('cl_client') +tr.setLanguage(sys.modules[__name__]) + +if __name__ == "__main__": + obj = install_cmd() + ret = obj.optobj.parse_args() + if ret is False: + sys.exit(1) + opts, args = ret + # Установка цвета при печати сообщений + obj.setPrintNoColor(opts) + # Установка переменных + if not obj.setVars(opts): + sys.exit(1) + # Печать переменных + obj.printVars(opts) + # Если нет печати переменных выполняем логику программы + if not opts.vars: + # Наложение шаблонов на систему при инсталяции + if not obj.installProg(): + sys.exit(1) + # Запись переменных + if not obj.writeVars(opts): + sys.exit(1) + sys.exit(0) diff --git a/scripts/uninstall b/scripts/uninstall new file mode 100644 index 0000000..8b0aacb --- /dev/null +++ b/scripts/uninstall @@ -0,0 +1,54 @@ +#!/usr/bin/python +#-*- 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 sys +import os +sys.path.insert(0,os.path.abspath('/usr/lib/calculate-2.2/calculate-lib/pym')) +sys.path.insert(0,\ + os.path.abspath('/usr/lib/calculate-2.2/calculate-client/pym')) + +from cl_uninstall_cmd import uninstall_cmd + +from cl_lang import lang +tr = lang() +tr.setGlobalDomain('cl_client') +tr.setLanguage(sys.modules[__name__]) + +if __name__ == "__main__": + obj = uninstall_cmd() + ret = obj.optobj.parse_args() + if ret is False: + sys.exit(1) + opts, args = ret + # Установка цвета при печати сообщений + obj.setPrintNoColor(opts) + # Установка переменных + if not obj.setVars(opts): + sys.exit(1) + # Печать переменных + obj.printVars(opts) + # Если нет печати переменных выполняем логику программы + if not opts.vars: + # Наложение шаблонов на систему при деинсталяции + if not obj.uninstallProg(): + sys.exit(1) + # Запись переменных + if not obj.writeVars(opts): + sys.exit(1) + sys.exit(0) + + diff --git a/setup.py b/setup.py index bd100e9..c42a0bd 100755 --- a/setup.py +++ b/setup.py @@ -21,6 +21,9 @@ import os import stat from distutils.core import setup, Extension from distutils.command.install_data import install_data +from distutils.command.build_scripts import build_scripts +from distutils.command.install_scripts import install_scripts + __version__ = "2.2.0" __app__ = "calculate-client" @@ -99,6 +102,33 @@ class cl_install_data(install_data): if flagFound: os.chmod(path, mode) +class cl_build_scripts(build_scripts): + """Class for build scripts""" + def run (self): + scripts = ['./scripts/install', './scripts/uninstall'] + backup_build_dir = self.build_dir + backup_scripts = filter(lambda x: not x in scripts, self.scripts) + self.scripts = scripts + self.build_dir = self.build_dir + "-bin" + build_scripts.run(self) + self.scripts = backup_scripts + self.build_dir = backup_build_dir + build_scripts.run(self) + + +class cl_install_scripts(install_scripts): + """Class for install scripts""" + def run (self): + backup_install_dir = self.install_dir + backup_build_dir = self.build_dir + cl_cmd_obj = self.distribution.get_command_obj("install") + self.build_dir = self.build_dir + "-bin" + self.install_dir = os.path.join(cl_cmd_obj.install_platlib, __app__, + "bin") + install_scripts.run(self) + self.build_dir = backup_build_dir + self.install_dir = backup_install_dir + install_scripts.run(self) setup( name = __app__, @@ -112,10 +142,14 @@ setup( packages = ['calculate-client.pym'], data_files = data_files, scripts=["./scripts/cl-sync-2.2", - "./scripts/cl-client-2.2"], + "./scripts/cl-client-2.2", + "./scripts/install", + "./scripts/uninstall"], ext_modules = [Extension('calculate-client.pym._cl_keys', library_dirs = ['/usr/lib'], libraries = ['keyutils'], sources = ['./lib/cl_keys.i', './lib/cl_keys.c'])], - cmdclass={'install_data': cl_install_data}, + cmdclass={'install_data': cl_install_data, + 'build_scripts':cl_build_scripts, + 'install_scripts':cl_install_scripts}, )