Eigenschaftsänderungen: debian ___________________________________________________________________ Hinzugefügt: svn:ignore + *.substvars *.debhelper *.log *.conffiles files Index: debian/changelog =================================================================== --- debian/changelog (Revision 22629) +++ debian/changelog (Arbeitskopie) @@ -1,3 +1,15 @@ +univention-directory-manager-module-example (2.0.8-1) unstable; urgency=low + + * Fix installation path of translation catalog (Bug #17915) + * Fix creating entry with immediate --redirect. + * Handle errors in ip-phone-tool. + * Parameter errors should exit with 2. + * debian/rules: Fix clean target. + * Fix quoting. + * Add simple script to test implementation. + + -- Philipp Hahn Thu, 17 Feb 2011 07:08:03 +0100 + univention-directory-manager-module-example (2.0.7-1) unstable; urgency=low * fix default value for TrueFalseUp syntax (Bug #17915) Index: debian/rules =================================================================== --- debian/rules (Revision 22629) +++ debian/rules (Arbeitskopie) @@ -44,7 +44,8 @@ PYVERS := $(shell pyversions -vr) -MO_FILES=$(shell find modules -name '*.po' | sed 's/\.po/\.mo/g') +PO_FILES := $(shell find modules -name '*.po') +MO_FILES := $(PO_FILES:%.po=%.mo) %.mo: %.po msgfmt -o $@ $< @@ -52,20 +53,20 @@ configure: configure-stamp configure-stamp: dh_testdir - touch configure-stamp + touch $@ -build: configure-stamp build-stamp $(MO_FILES) -build-stamp: +build: configure-stamp build-stamp +build-stamp: $(MO_FILES) dh_testdir - touch build-stamp + touch $@ clean: dh_testdir - dh_testroot dh_clean - rm -f build-stamp configure-stamp + $(RM) build-stamp configure-stamp $(RM) debian/*.conffiles - rm -f *~ + $(RM) $(MO_FILES) + $(RM) *~ install: build-stamp dh_testdir @@ -81,20 +82,20 @@ @for i in $(shell find modules/univention/admin/ -name '*.py'); do\ o=${D}/usr/share/pyshared/$${i#modules/};\ - install -d "`dirname $$o`";\ - install -m755 $$i $$o;\ + install -d "`dirname "$$o"`";\ + install -m755 "$$i" "$$o";\ done @for i in `find modules/univention/admin/handlers/ -name "*.png" -o -name "*.gif"`; do\ o=${D}/usr/share/univention-webui-style/icon/$${i#modules/univention/admin/handlers/};\ - install -d "`dirname $$o`";\ - install -m 644 $$i $$o;\ + install -d "`dirname "$$o"`";\ + install -m 644 "$$i" "$$o";\ done @for i in $(MO_FILES); do\ - lang=`basename $$i .mo`;\ - domain=`dirname $$i | sed 's,^modules/,,;s,/,-,g'`;\ - o=debian/${D}/usr/share/locale/$$lang/LC_MESSAGES/$$domain.mo;\ - install -d "`dirname $$o`";\ - install -m 644 $$i $$o;\ + lang=`basename "$$i" .mo`;\ + domain=`dirname "$$i" | sed 's,^modules/,,;s,/,-,g'`;\ + o=${D}/usr/share/locale/$$lang/LC_MESSAGES/$$domain.mo;\ + install -d "`dirname "$$o"`";\ + install -m 644 "$$i" "$$o";\ done # Install example script Index: test-implementation =================================================================== --- test-implementation (Revision 0) +++ test-implementation (Revision 0) @@ -0,0 +1,22 @@ +#!/bin/sh +# +# Test module and script +# +set -e + +ip-phone-tool set voip1 10.1.0.42 sip:user1@dom.local +ip-phone-tool set voip1 10.1.0.42 sip:user1@dom.local --redirect sip:otheruser@dom.local +ip-phone-tool set voip2 10.1.0.43 sip:user2@dom.local --redirect sip:otheruser@dom.local +ip-phone-tool clear_redirect voip1 +ip-phone-tool remove voip1 +ip-phone-tool remove voip2 + +udm test/ip_phone create --set name=voip1 --set ip=10.1.0.42 --set active=TRUE --set priuser=sip:user1@dom.local +dn=$(udm test/ip_phone list --filter name=voip1 | sed -ne 's/^DN: //p') +udm test/ip_phone modify --dn "$dn" --option redirection --set redirect_user=sip:otheruser@dom.local +udm test/ip_phone create --set name=voip2 --set ip=10.1.0.43 --set active=TRUE --set priuser=sip:user2@dom.local --option redirection --set redirect_user=sip:otheruser@dom.local +udm test/ip_phone modify --dn "$dn" --set redirect_user= +udm test/ip_phone remove --dn "$dn" +udm test/ip_phone remove --filter name=voip2 + +echo "Success." Index: scripts/ip-phone-tool =================================================================== --- scripts/ip-phone-tool (Revision 22629) +++ scripts/ip-phone-tool (Arbeitskopie) @@ -30,9 +30,10 @@ """Univention IP-Phone Example UDM Client.""" -import sys, os +import sys +import os import univention.debug -univention.debug.init('/var/log/univention/ip-phone-tool.log', 1, 0) +univention.debug.init('/var/log/univention/ip-phone-tool.log', univention.debug.FLUSH, univention.debug.NO_FUNCTION) import univention.config_registry import univention.admin.uldap @@ -45,9 +46,12 @@ from optparse import OptionParser, OptionValueError translation=univention.admin.localization.translation('univention.admin.handlers.test') ## missing in this example -_=translation.translate +_ = translation.translate class ipphonetool: + """Simple example demonstrating how to implement and how to use custom Univention Directory Manager modules. + This is an example tool to manage IP phones. + """ def __init__(self, options, ucr=None): """Initialize an authenticated LDAP connection @@ -63,13 +67,17 @@ binddn = ','.join(('cn=admin', self.ldap_base)) server_role = ucr.get('server/role', '') if server_role in ('domaincontroller_master', 'domaincontroller_backup'): - bindpw = open('/etc/ldap.secret','r').read().strip() + try: + bindpw = open('/etc/ldap.secret','r').read().strip() + except IOError, e: + print >>sys.stderr, "Could not read credentials." + sys.exit(1) else: print >>sys.stderr, "No credentials available" sys.exit(1) try: - self.lo=univention.admin.uldap.access(host=ldap_master, base=self.ldap_base, binddn=binddn, bindpw=bindpw, start_tls=2) + self.lo = univention.admin.uldap.access(host=ldap_master, base=self.ldap_base, binddn=binddn, bindpw=bindpw, start_tls=2) except Exception, e: univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) print 'authentication error: %s' % str(e) @@ -85,14 +93,14 @@ """This uses the lookup function of the udm module, allowing filtering in terms of UDM properties """ - filter=univention.admin.filter.expression('name', name) + filter = univention.admin.filter.expression('name', name) objs = self.module.lookup(self.co, self.lo, filter, scope='domain', base=self.position.getDomain(), unique=1) if objs: - obj=objs[0] + obj = objs[0] else: obj = self.module.object(self.co, self.lo, self.position) - obj['name']=name + obj['name'] = name if not ip == obj['ip']: obj['ip'] = ip @@ -100,7 +108,8 @@ obj['priuser'] = priuser if options.redirect: - obj.options.append('redirection') + if 'redirection' not in obj.options: + obj.options.append('redirection') obj['redirect_user'] = options.redirect else: ## if no redirection is given, this example removes the objectclass if 'redirection' in obj.options: @@ -108,45 +117,69 @@ obj['redirect_user'] = options.redirect if objs: - obj.modify() + try: + obj.modify() + except univention.admin.uexceptions.ldapError, e: + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'Could not modify entry: %s' % e) + print >>sys.stderr, 'Could not modify entry: %s' % name + sys.exit(1) else: - obj.create() + try: + obj.create() + except univention.admin.uexceptions.ldapError, e: + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'Could not create entry: %s' % e) + print >>sys.stderr, 'Could not create entry: %s' % name + sys.exit(1) def remove(self, name): """remove the object, no safty belt in this example""" - filter=univention.admin.filter.expression('name', name) + filter = univention.admin.filter.expression('name', name) objs = self.module.lookup(self.co, self.lo, filter, scope='domain', base=self.position.getDomain(), unique=1) if objs: - obj=objs[0] - obj.remove() + obj = objs[0] + try: + obj.remove() + except univention.admin.uexceptions.ldapError, e: + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'Could not remove entry: %s' % e) + print >>sys.stderr, 'Could not remove entry: %s' % name + sys.exit(1) + else: + print >>sys.stderr, 'Entry not found: %s' % name + sys.exit(1) def clear_redirect(self, name): """This example uses a raw LDAP search instead of performing a lookup to determine the dn """ try: filter = unicode('(&(cn=%s)(objectClass=testPhoneCallRedirect))' % name, 'utf8') - dn=self.lo.searchDn(filter=filter, base=self.ldap_base, unique=1) + dn = self.lo.searchDn(filter=filter, base=self.ldap_base, unique=1) if not dn: print "No object found matching filter %s" % filter sys.exit(1) - object=univention.admin.objects.get(self.module, self.co, self.lo, position=self.position, dn=dn[0]) + object = univention.admin.objects.get(self.module, self.co, self.lo, position=self.position, dn=dn[0]) object.open() ## open the object if 'redirection' in object.options: object.options.remove('redirection') - object['redirect_user']='' + object['redirect_user'] = '' univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'ip-phone-tool: redirect_user cleared, modify object') - dn=object.modify() + dn = object.modify() univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'ip-phone-tool: Redirection deactivated') except univention.admin.uexceptions.valueError, e: univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'error: invalid syntax (%s)' % e) + print >>sys.stderr, 'Could not modify entry: %s' % name + sys.exit(1) + except univention.admin.uexceptions.ldapError, e: + univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'Could not modify entry: %s' % e) + print >>sys.stderr, 'Could not modify entry: %s' % name + sys.exit(1) if __name__ == '__main__': @@ -185,7 +218,7 @@ action = 'store', dest = 'username', help = _('Username') ) - parser.add_option( '', '--redirect', + parser.add_option( '--redirect', action = 'store', dest = 'redirect', help = _('Redirect address') ) (options, arguments) = parser.parse_args() @@ -198,25 +231,25 @@ ucr.load() if len(arguments) < 1: - parser.print_help() - sys.exit(1) + parser.print_help(sys.stderr) + sys.exit(2) udm_ipphone = ipphonetool(options, ucr) if arguments[0] == 'set': if len(arguments) < 4: - parser.print_usage() - sys.exit(1) + parser.print_usage(sys.stderr) + sys.exit(2) udm_ipphone.set( options, arguments[1], arguments[2], arguments[3] ) elif arguments[0] == 'remove': if len(arguments) < 2: - parser.print_usage() - sys.exit(1) + parser.print_usage(sys.stderr) + sys.exit(2) udm_ipphone.remove( arguments[1] ) elif arguments[0] == 'clear_redirect': if len(arguments) < 2: - parser.print_usage() - sys.exit(1) + parser.print_usage(sys.stderr) + sys.exit(2) udm_ipphone.clear_redirect( arguments[1] ) else: - parser.print_usage() - sys.exit(0) + parser.print_usage(sys.stderr) + sys.exit(2) Index: modules/univention/admin/handlers/test/ip_phone.py =================================================================== --- modules/univention/admin/handlers/test/ip_phone.py (Revision 22629) +++ modules/univention/admin/handlers/test/ip_phone.py (Arbeitskopie) @@ -266,15 +266,18 @@ ## weitere Entscheidungen getroffen werden können. self.options = [] if self.oldattr.has_key('objectClass'): + # Das Objekt existiert bereits im LDAP und wurde von dort geladen ocs = set(self.oldattr['objectClass']) for opt in ('redirection', ): if options[opt].matches(ocs): self.options.append(opt) + self.old_options = copy.deepcopy(self.options) else: + # Das Objekt existiert nocht nicht im LDAP und wird neu angelegt. univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, '%s: reset options to default by _define_options' % module) self._define_options(options) + self.old_options = [] - self.old_options = copy.deepcopy(self.options) def exists(self): u"""Von SimpleLdap intern verwendete Methode, um zu entscheiden, ob ein @@ -285,7 +288,7 @@ u"""Öffnen des LDAP-Objekts.""" univention.admin.handlers.simpleLdap.open(self) - ## In dieser Methode können die Eigenschaften des Objekts in self.info dynamisch Vor-initialisiert werden. + ## In dieser Methode können die Eigenschaften des Objekts in self.info dynamisch vor-initialisiert werden. ## Das self.info Dictionary kann indirekt angesprochen werden, d.h. z.B. durch self['active'] = 1 ## Da der Basistyp von 'simpleLdap' (und damit von 'object') die Klasse 'base' ist, verhält sich ## 'self' wie ein spezielles Dictionary. Es überprüft Operationen anhand der 'property_descriptions' @@ -296,7 +299,6 @@ ## in self.oldinfo und self.oldpolicies gespeichert. Diese dienen später zum Vergleich mit dem ## aktualisierten Eigenschaften in self.info. self.save() - self.old_options = copy.deepcopy(self.options) # Optionen zum späteren Vergleich speichern. def _ldap_pre_create(self): u"""Wird vor dem Anlegen des LDAP Objektes aufgerufen.""" @@ -323,6 +325,8 @@ pass def _update_policies(self): + u""""Wird bim Anlegen und Modifizieren des Objekts aufgerufen, um ggf. + aktivierte Policies auf das Objekt anzuwenden.""" pass def _ldap_addlist(self): Index: refresh-i18n =================================================================== --- refresh-i18n (Revision 22629) +++ refresh-i18n (Arbeitskopie) @@ -33,35 +33,34 @@ po=de i18nfile=./modules/univention/admin/handlers/test/$po -xgettext -L Python -o $po.pot modules/univention/admin/handlers/test/*.py scripts/ip-phone-tool +xgettext -L Python -o "$po.pot" modules/univention/admin/handlers/test/*.py scripts/ip-phone-tool -grep "Content-Type: text/plain; charset=CHARSET" $po.pot - -if [ $? -eq 0 ]; then +if grep -qs "Content-Type: text/plain; charset=CHARSET" "$po.pot" +then echo "Rewriting encoding information from CHARSET to ISO-8859-15" - sed -i "s#Content-Type: text/plain; charset=CHARSET#Content-Type: text/plain; charset=ISO-8859-15#" $po.pot + sed -i "s#Content-Type: text/plain; charset=CHARSET#Content-Type: text/plain; charset=ISO-8859-15#" "$po.pot" fi echo "Merging old gettext data with newly introduced strings" -msgmerge $i18nfile.po $po.pot > $po.pox +msgmerge "$i18nfile.po" "$po.pot" > "$po.pox" echo "Now you need to fix up all "fuzzy" entries in your editor" read if [ -n "$EDITOR" ]; then - $EDITOR $po.pox + $EDITOR "$po.pox" else - nano $po.pox + sensible-editor "$po.pox" fi echo "Use this entry? (Y/n)" read yn -if [ -z "$yn" -o "$yn" = "y" ]; then +if [ -z "$yn" ] || [ "$yn" = "y" ]; then echo "Copying po file" - cp $po.pox $i18nfile.po + cp "$po.pox" "$i18nfile.po" echo "Regenerating mo file" - msgfmt -o $i18nfile.mo $i18nfile.po + msgfmt -o "$i18nfile.mo" "$i18nfile.po" fi -rm -rf $po.pot $po.pox +rm -rf "$po.pot" "$po.pox"