1
2
3
4
5
6
7
8
9
10
11
12
13 import os
14 import transaction
15 import Globals
16
17 from Products.ZenUtils.ZCmdBase import ZCmdBase
18 from Products.ZenModel.Report import Report
19
21
23 ZCmdBase.buildOptions(self)
24 self.parser.add_option('-f', '--force', dest='force',
25 action='store_true', default=0,
26 help="Force load all the reports")
27
32
34 def normalize(f):
35 return f.replace("_", " ")
36 def toOrg(path):
37 path = normalize(path).split("/")
38 path = path[path.index("reports") + 1:]
39 return "/" + "/".join(path)
40 return [(toOrg(p), normalize(f[:-4]), os.path.join(p, f))
41 for p, ds, fs in os.walk(directory)
42 for f in fs
43 if f.endswith(".rpt")]
44
57
58
60 self.log.info("loading reports from:%s", repdir)
61 reproot = self.dmd.Reports
62 for orgpath, fid, fullname in self.reports(repdir):
63 rorg = reproot.createOrganizer(orgpath)
64 if getattr(rorg, fid, False):
65 if self.options.force:
66 rorg._delObject(fid)
67 else:
68 continue
69 self.log.info("loading: %s/%s", orgpath, fid)
70 self.loadFile(rorg, fid, fullname)
71
72
78
79
80 if __name__ == "__main__":
81 rl = ReportLoader()
82 rl.loadDatabase()
83