1
2
3
4
5
6
7
8
9
10
11
12
13
14 import os
15 import atexit
16 import socket
17 try:
18 import readline
19 import rlcompleter
20 except ImportError:
21 readline = rlcompleter = None
22 from pprint import pprint
23
24 import Globals
25 import transaction
26 from AccessControl.SecurityManagement import newSecurityManager
27 from AccessControl.SecurityManagement import noSecurityManager
28
29
30 from Products.ZenUtils.ZenScriptBase import ZenScriptBase
31 from Products.ZenUtils.Utils import zenPath
32
33 if readline:
34 zenHome = zenPath()
35 historyPath = zenPath('.pyhistory')
36 - def save_history(historyPath=historyPath):
37 import readline
38 readline.write_history_file(historyPath)
39
40 if os.path.exists(historyPath):
41 readline.read_history_file(historyPath)
42
45
46 if __name__ == '__main__':
47 zendmd = zendmd(connect=True)
48 dmd = zendmd.dmd
49 app = dmd.getPhysicalRoot()
50 zport = app.zport
51 find = dmd.Devices.findDevice
52 devices = dmd.Devices
53 sync = dmd._p_jar.sync
54 commit = transaction.commit
55 abort = transaction.abort
56 me = find(socket.getfqdn())
57
59 cmds = filter(lambda x: not x.startswith("_"), globals())
60 cmds.sort()
61 for cmd in cmds[2:]: print cmd
62
63
71
73 '''Logs in.'''
74 uf = zport.acl_users
75 user = uf.getUserById(name)
76 if not hasattr(user, 'aq_base'):
77 user = user.__of__(uf)
78 newSecurityManager(None, user)
79
81 '''Logs out.'''
82 noSecurityManager()
83
84 - def grepdir(obj, regex="", exact=""):
95
96 print "Welcome to zenoss dmd command shell!"
97 print "use zhelp() to list commands"
98
99 if readline:
100 atexit.register(save_history)
101 del os, atexit, readline, rlcompleter, save_history, historyPath
102