import repository from arizona
[raven.git] / lib / ravenlib / files / pacgroups.py
1 import os
2 import time
3
4 class pacgroups:
5
6     def __init__(self):
7         self.reset()
8
9     def reset(self):
10         self.header = '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>\n' + \
11                   '<GROUPS>\n'
12         self.footer = '</GROUPS>\n'
13
14         self.contents = {}
15
16     def get_string(self):
17         return self.header + self.get_contents_string() + self.footer
18
19     def get_contents(self):
20         return self.contents
21
22     def get_contents_string(self):
23         contentsStr = ""
24         for key in self.contents.keys():
25             if key == "ALL":
26                 sectionHeader = '<GROUP>\n'
27             else:
28                 sectionHeader = '<GROUP NAME="' + key + '">\n'
29             sectionFooter = '</GROUP>\n'
30
31             contentsStr += sectionHeader
32
33             for item in self.contents[key]:
34                 line = '<' + item["action"] + ' NAME="' + item["name"] + '" />\n'
35                 contentsStr += line
36
37             contentsStr += sectionFooter
38
39         return contentsStr
40
41     def save(self, destFileName):
42         open(destFileName, "w").write(self.get_string())
43
44     def add(self, groupName, action, name):
45         key = groupName
46         list = self.contents.get(key, [])
47         list.append({"action": action, "name": name})
48         self.contents[key] = list
49
50