-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautopopulator.py
44 lines (38 loc) · 1.58 KB
/
autopopulator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
###########################################################################
# Copyright (C) 2003 by William Heymann
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################
from AccessControl import ClassSecurityInfo
import Globals
from autocreator import AutoCreator
class AutoPopulator(AutoCreator):
"auto object poluator class"
security = ClassSecurityInfo()
meta_type = "AutoPopulator"
security.declarePrivate('createTreeFromDataSource')
def createTreeFromDataSource(self, data):
"create a zope tree structure based on a data source"
try:
folder = self.restrictedTraverse(self.startFolder)
self.createDocuments(folder, data)
except AttributeError:
pass
security.declareProtected('Change CompoundDoc', 'createDocuments')
def createDocuments(self, folder, data):
"create documents at this path using this data"
if '\r\n' in data:
data = data.replace('\r\n', '\n')
entries = [entry.split('\n') for entry in data.split('\n\n\n')]
pathEntries = [(entry[0].split(' ', 1), entry[1:]) for entry in entries]
try:
for (path, profile), entries in pathEntries:
self.createCdocAtLocation(path, profile, folder, entries)
except ValueError: #Catches when the data format is wrong
pass
self.getCompoundDoc().processChanges()
Globals.InitializeClass(AutoPopulator)
import register
register.registerClass(AutoPopulator)