You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-3-client/pym/cl_client_cmd.py

140 lines
5.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#-*- 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] domain")
# Коментарии к использованию программы
COMMENT_EXAMPLES = _("Adds settings for connecting to domain \
server.calculate.ru")
# Пример использования программы
EXAMPLES = _("%prog server.calculate.ru")
# Описание программы (что делает программа)
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")}]
class client_cmd(share_cmd):
def __init__(self):
# Объект опций командной строки
self.optobj = opt(\
package=__app__,
version=__version__,
usage=USAGE,
examples=EXAMPLES,
comment_examples=COMMENT_EXAMPLES,
description=DESCRIPTION,
option_list=CMD_OPTIONS + opt.variable_control+opt.color_control,
formatter=TitledHelpFormatter(),
check_values=self.checkOpts)
# Создаем объект логики
self.logicObj = client()
# Создаем переменные
self.logicObj.createClVars()
# Названия несовместимых опций
self.optionsNamesIncompatible = ["r", "install", "uninstall", "mount"]
# Названия опций несовмесимых с именем домена
self.optionsNamesNotDomain = self.optionsNamesIncompatible
def getOptionsNotDomain(self, optObj):
"""Получаем опции несовместимые с именем домена"""
retList = []
for nameOpt in self.optionsNamesNotDomain:
retList.append(getattr(optObj, nameOpt))
return retList
def _getNamesAllSetOptions(self):
"""Выдает словарь измененных опций"""
setOptDict = self.optobj.values.__dict__.items()
defaultOptDict = self.optobj.get_default_values().__dict__.items()
return dict(set(setOptDict) - set(defaultOptDict)).keys()
def getStringIncompatibleOptions(self):
"""Форматированная строка несовместимых опций разделенных ','"""
listOpt = list(set(self.optionsNamesIncompatible) &\
set(self._getNamesAllSetOptions()))
return ", ".join(map(lambda x: len(x) == 1 and "'-%s'"%x or "'--%s'"%x,\
listOpt))
def checkOpts(self, optObj, args):
"""Проверка опций командной строки"""
optionsNotDomain = self.getOptionsNotDomain(optObj)
if not args:
options = optionsNotDomain + [optObj.color, optObj.vars]
if not filter(lambda x: x, options):
errMsg = _("no such argument")+":"+" %s" %USAGE.split(" ")[-1]
self.optobj.error(errMsg)
return False
elif len(filter(lambda x: x, optionsNotDomain))>1:
errMsg = _("incompatible options")+":"+" %s"\
%self.getStringIncompatibleOptions()
self.optobj.error(errMsg)
return False
elif filter(lambda x: x, optionsNotDomain):
errMsg = _("unnecessary argument")+":"+" %s" %USAGE.split(" ")[-1]
self.optobj.error(errMsg)
return False
if len(args)>1:
errMsg = _("incorrect argument") + ":" + " %s" %" ".join(args)
self.optobj.error(errMsg)
return False
return optObj, args
def addDomain(self, domainName):
"""Ввод в домен"""
if domainName:
return self.logicObj.addDomain(domainName)
else:
self.printERROR(_('Not found argument domain name'))
return False
def delDomain(self):
"""Вывод из домена"""
return self.logicObj.delDomain()
def install(self):
"""Инсталяция"""
return self.logicObj.installClient()
def uninstall(self):
"""Удаление"""
return self.logicObj.uninstallClient()
def mountRemote(self):
"""Монтирование remote и домашней директории если компьютер в домене
а так-же ввод в домен если найдено имя хоста и пароль для подключения
"""
return self.logicObj.mountRemote()