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-2.1-server/scripts/cl-useradd

77 lines
2.5 KiB

#!/usr/bin/python
#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#
# 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/calculate-lib/pym'))
sys.path.insert(0,os.path.abspath('/usr/lib/calculate/calculate-server/pym'))
import cl_base
tr = cl_base.lang()
tr.setGlobalDomain('cl_server')
tr.setLanguage(sys.modules[__name__])
import cl_ldap
class tstopt(cl_base.opt):
def __init__(self, obj):
self.obj =obj
self.shortOpt = self.obj.getAllOpt('short')
self.longOpt = self.obj.getAllOpt('long')
self.opt = []
self.sysArgv = sys.argv[1:]
self.__iter = 0
self.params = {}
cl_base.opt.__init__(self, self.shortOpt, self.longOpt)
if "h" in self.opt or not self.opt:
print self.obj.getHelp()
def handlerOpt(self,option,value):
# Обработчик (опция значение)
#print option, value
shortOpt = self.obj.getShortOpt(option)
if not shortOpt in self.opt:
self.opt.append(shortOpt)
if shortOpt=='p':
pass
def handlerErrOpt(self):
# Обработчик ошибок
argv = " ".join(sys.argv[1:])
print _("Unrecognized option") + ' "' + argv + '"\n' + \
_("Try") + ' "' + sys.argv[0].split("/")[-1] + ' --help" ' +\
_("for more information.")
def handlerParam(self,param):
# Обработчик хвостов (значение)
self.__iter += 1
# Достаем имя пользователя
if self.__iter == 1:
self.params['user'] = param
elif self.__iter == 2:
self.params['service'] = param
if __name__ == "__main__":
z = cl_ldap.cl_ldap("cl-useradd")
tst = tstopt(z)
if tst.params.has_key('user'):
print "USER =", tst.params['user']
if tst.params.has_key('service'):
print "SERVICE =", tst.params['service']