Back to index

plone3  3.1.7
Functions | Variables
CMFEditions.StorageMigrationSupport Namespace Reference

Functions

def create
def edit
def editEvent
def editFile
def editFolder
def editImage
def editLink
def editNewsItem
def editDocument
def editTopic
def createTestHierarchy

Variables

tuple logger = logging.getLogger('CMFEditions')
dictionary editMethods
dictionary hierarchy

Function Documentation

def CMFEditions.StorageMigrationSupport.create (   context,
  type,
  name 
)

Definition at line 35 of file StorageMigrationSupport.py.

00035 
00036 def create(context, type, name):
00037     context.invokeFactory(type, name)
00038     obj = getattr(context, name)
00039     editMethods[type](obj, version=0)
00040     return obj

Definition at line 185 of file StorageMigrationSupport.py.

00185 
00186 def createTestHierarchy(context):
00187     startTime = time.time()
00188     repo = getToolByName(context, "portal_repository")
00189     testRoot = create(context,  "Folder", "CMFEditionsTestHierarchy")
00190     nbrOfObjects = 0
00191     nbrOfEdits = 0
00192     nbrOfSaves = 0
00193     for name, type in hierarchy.items():
00194         logger.log(logging.INFO, "createTestHierarchy: creating container %s(%s)" \
00195             % (name, type[0]))
00196         folder = create(testRoot, type[0], name)
00197         nbrOfObjects += 1
00198         logger.log(logging.INFO, "createTestHierarchy: save #0")
00199         repo.save(folder, comment="save #0")
00200         nbrOfSaves += 1
00201         for i in range(type[2]):
00202             if len(type) == 5:
00203                 ext = type[4]
00204             else:
00205                 ext = ""
00206                 
00207             # create and save
00208             objName = name[:-1]+str(i+1)+ext
00209             logger.log(logging.INFO, "createTestHierarchy: creating %s(%s)" \
00210                 % (objName, type[1]))
00211             obj = create(folder, type[1], objName)
00212             nbrOfObjects += 1
00213             logger.log(logging.INFO, "createTestHierarchy: save #0")
00214             repo.save(obj, comment="save #0")
00215             nbrOfSaves += 1
00216             
00217             # edit and save a number of times
00218             for j in range(1, type[3]):
00219                 logger.log(logging.INFO, "createTestHierarchy: editing")
00220                 edit(obj, j)
00221                 nbrOfEdits += 1
00222                 logger.log(logging.INFO, "createTestHierarchy: save #%s" % j)
00223                 repo.save(obj, comment="save #%s" % j)
00224                 nbrOfSaves += 1
00225                 
00226                 vers = j + i*(type[3]-1)
00227                 logger.log(logging.INFO, "createTestHierarchy: editing parent")
00228                 edit(folder, vers)
00229                 nbrOfEdits += 1
00230                 logger.log(logging.INFO, "createTestHierarchy: save parent #%s" % vers)
00231                 repo.save(folder, comment="save #%s" % vers)
00232                 nbrOfSaves += 1
00233     
00234     totalTime = time.time() - startTime
00235     logger.log(logging.INFO,
00236         "createTestHierarchy: created %s objects, edited them %s times and saved %s versions in total in %.1f seconds" \
00237         % (nbrOfObjects, nbrOfEdits, nbrOfSaves, round(totalTime, 1)))
00238     
00239     return testRoot

Here is the call graph for this function:

def CMFEditions.StorageMigrationSupport.edit (   obj,
  version 
)

Definition at line 41 of file StorageMigrationSupport.py.

00041 
00042 def edit(obj, version):
00043     type = obj.getPortalTypeName()
00044     editMethods[type](obj, version)

Here is the caller graph for this function:

def CMFEditions.StorageMigrationSupport.editDocument (   context,
  version = 0 
)

Definition at line 143 of file StorageMigrationSupport.py.

00143 
00144 def editDocument(context, version=0):
00145     title = context.Title()
00146     desc = context.Description()
00147     text = context.getText()
00148     name = context.getId()
00149     if not title:
00150         title = "0: %s document title" % name
00151         desc = "0: %s document description" % name
00152         text = "0: %s document body" % name
00153     else:
00154         title = "%s%s" % (version, title[1:])
00155         desc = "%s%s" % (version, desc[1:])
00156         text = "%s%s" % (version, text[1:])
00157     context.update(title=title, description=desc, text=text)
00158 

def CMFEditions.StorageMigrationSupport.editEvent (   context,
  version = 0 
)

Definition at line 45 of file StorageMigrationSupport.py.

00045 
00046 def editEvent(context, version=0):
00047     title = context.Title()
00048     desc = context.Description()
00049     eventType = context.Subject()
00050     location = context.location
00051     contact = context.contactName
00052     name = context.getId()
00053     if not title:
00054         title = "0: %s event title" % name
00055         desc = "0: %s event description" % name
00056         eventType = "Appointment"
00057         location = "0: %s event location" % name
00058         contact = "0: %s event contact" % name
00059     else:
00060         title = "%s%s" % (version, title[1:])
00061         desc = "%s%s" % (version, desc[1:])
00062         location = "%s%s" % (version, location[1:])
00063         contact = "%s%s" % (version, contact[1:])
00064     
00065     context.update(title=title, description=desc, 
00066                    eventType=eventType, location=location,
00067                    contactName=contact)

def CMFEditions.StorageMigrationSupport.editFile (   context,
  version = 0 
)

Definition at line 68 of file StorageMigrationSupport.py.

00068 
00069 def editFile(context, version=0):
00070     title = context.Title()
00071     desc = context.Description()
00072     file = context.index_html()
00073     name = context.getId()
00074     if not title:
00075         title = "0: %s file title" % name
00076         desc = "0: %s file description" % name
00077         file = 100 * ("0: %s file body\n" % name)
00078     else:
00079         title = "%s%s" % (version, title[1:])
00080         desc = "%s%s" % (version, desc[1:])
00081         file = 100 * ("%s%s" % (version, ": %s file body\n" % name))
00082     context.update(title=title, description=desc, file=file)

def CMFEditions.StorageMigrationSupport.editFolder (   context,
  version = 0 
)

Definition at line 83 of file StorageMigrationSupport.py.

00083 
00084 def editFolder(context, version=0):
00085     title = context.Title()
00086     desc = context.Description()
00087     name = context.getId()
00088     if not title:
00089         title = "0: %s folder title" % name
00090         desc = "0: %s folder description" % name
00091     title = "%s%s" % (version, title[1:])
00092     desc = "%s%s" % (version, desc[1:])
00093     context.folder_edit(title=title, description=desc)

def CMFEditions.StorageMigrationSupport.editImage (   context,
  version = 0 
)

Definition at line 94 of file StorageMigrationSupport.py.

00094 
00095 def editImage(context, version=0):
00096     title = context.Title()
00097     desc = context.Description()
00098     image = context.index_html()
00099     name = context.getId()
00100     if name.endswith(".gif"):
00101         name = name[:-4]
00102     filename = "%s_v%s.gif" % (name, version)
00103     path = os.path.join(PACKAGE_HOME, "tests", "images", filename)
00104     if not title:
00105         title = "0: %s image title" % name
00106         desc = "0: %s image description" % name
00107         image = open(path).read()
00108     else:
00109         title = "%s%s" % (version, title[1:])
00110         desc = "%s%s" % (version, desc[1:])
00111         image = open(path).read()
00112     context.update(title=title, description=desc, image=image)

def CMFEditions.StorageMigrationSupport.editLink (   context,
  version = 0 
)

Definition at line 113 of file StorageMigrationSupport.py.

00113 
00114 def editLink(context, version=0):
00115     title = context.Title()
00116     desc = context.Description()
00117     remoteUrl = context.remoteUrl
00118     name = context.getId()
00119     if not title:
00120         title = "0: %s link title" % name
00121         desc = "0: %s link description" % name
00122         remoteUrl = "http://www.plone.org/#%s_v0" % name
00123     else:
00124         title = "%s%s" % (version, title[1:])
00125         desc = "%s%s" % (version, desc[1:])
00126         remoteUrl = "%s%s" % (remoteUrl[:-1], version)
00127     context.update(title=title, description=desc, remoteUrl=remoteUrl)

def CMFEditions.StorageMigrationSupport.editNewsItem (   context,
  version = 0 
)

Definition at line 128 of file StorageMigrationSupport.py.

00128 
00129 def editNewsItem(context, version=0):
00130     title = context.Title()
00131     desc = context.Description()
00132     text = context.getText()
00133     name = context.getId()
00134     if not title:
00135         title = "0: %s news item title" % name
00136         desc = "0: %s news item description" % name
00137         text = "0: %s news item body" % name
00138     else:
00139         title = "%s%s" % (version, title[1:])
00140         desc = "%s%s" % (version, desc[1:])
00141         text = "%s%s" % (version, text[1:])
00142     context.update(title=title, description=desc, text=text)

def CMFEditions.StorageMigrationSupport.editTopic (   context,
  version = 0 
)

Definition at line 159 of file StorageMigrationSupport.py.

00159 
00160 def editTopic(context, version=0):
00161 #    import pdb; pdb.set_trace()
00162     pass


Variable Documentation

Initial value:
00001 {
00002     "Event": editEvent,
00003     "File": editFile,
00004     "Folder": editFolder,
00005     "Image": editImage,
00006     "Link": editLink,
00007     "News Item": editNewsItem,
00008     "Document": editDocument,
00009     "Topic": editTopic,
00010 }

Definition at line 163 of file StorageMigrationSupport.py.

Initial value:
00001 {
00002     "events": ("Folder", "Event", 4, 3),
00003     "files": ("Folder", "File", 4, 3),
00004     "folders": ("Folder", "Folder", 3, 3),
00005     "images": ("Folder", "Image", 2, 4, ".gif"),
00006     "links": ("Folder", "Link", 4, 3),
00007     "newsitems": ("Folder", "News Item", 4, 3),
00008     "documents": ("Folder", "Document", 4, 3),
00009     "topics": ("Folder", "Topic", 0, 0),
00010 }

Definition at line 174 of file StorageMigrationSupport.py.

tuple CMFEditions.StorageMigrationSupport.logger = logging.getLogger('CMFEditions')

Definition at line 33 of file StorageMigrationSupport.py.