Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/sieve/cmd_test.py
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | def execute(*args, **kw): | ||||
sieveclient = sievelib.managesieve.Client(hostname, port, True) | sieveclient = sievelib.managesieve.Client(hostname, port, True) | ||||
sieveclient.connect(None, None, True) | sieveclient.connect(None, None, True) | ||||
sieveclient._plain_authentication(admin_login, admin_password, address) | sieveclient._plain_authentication(admin_login, admin_password, address) | ||||
sieveclient.authenticated = True | sieveclient.authenticated = True | ||||
active, scripts = sieveclient.listscripts() | active, scripts = sieveclient.listscripts() | ||||
print "%s (active)" % (active) | print("%s (active)" % (active)) | ||||
_all_scripts = [ active ] + scripts | _all_scripts = [ active ] + scripts | ||||
_used_scripts = [ active ] | _used_scripts = [ active ] | ||||
_included_scripts = [] | _included_scripts = [] | ||||
_a_script = sieveclient.getscript(active) | _a_script = sieveclient.getscript(active) | ||||
print _a_script | print(_a_script) | ||||
import sievelib.parser | import sievelib.parser | ||||
_a_parser = sievelib.parser.Parser(debug=True) | _a_parser = sievelib.parser.Parser(debug=True) | ||||
_a_parsed = _a_parser.parse(_a_script) | _a_parsed = _a_parser.parse(_a_script) | ||||
#print "%r" % (_a_parsed) | #print "%r" % (_a_parsed) | ||||
if not _a_parsed: | if not _a_parsed: | ||||
print _a_parser.error | print(_a_parser.error) | ||||
print "%r" % (_a_parser.result) | print("%r" % (_a_parser.result)) | ||||
for _a_command in _a_parser.result: | for _a_command in _a_parser.result: | ||||
print _a_command.name, _a_command.arguments | print(_a_command.name, _a_command.arguments) | ||||
if len(_a_command.children) > 0: | if len(_a_command.children) > 0: | ||||
for _a_child in _a_command.children: | for _a_child in _a_command.children: | ||||
print " ", _a_child.name, _a_child.arguments | print(" ", _a_child.name, _a_child.arguments) | ||||
if _a_command.name == "include": | if _a_command.name == "include": | ||||
if _a_command.arguments["script"].strip('"') in scripts: | if _a_command.arguments["script"].strip('"') in scripts: | ||||
print "OK" | print("OK") | ||||
_used_scripts.append(_a_command.arguments["script"].strip('"')) | _used_scripts.append(_a_command.arguments["script"].strip('"')) | ||||
else: | else: | ||||
print "Not OK" | print("Not OK") | ||||
for script in scripts: | for script in scripts: | ||||
print script | print(script) | ||||