| | 1598 | |
|---|
| | 1599 | if doWeMigrate(old, '2.6.5'): |
|---|
| | 1600 | print >>out, "Starting migration from 2.6.4" |
|---|
| | 1601 | print >>out, "Migrating presentations to local File System" |
|---|
| | 1602 | import os, StringIO |
|---|
| | 1603 | WORK_DIR = os.path.join(EXTERNAL_RESOURCES, 'presentations') |
|---|
| | 1604 | pcatalog = getToolByName(self, 'portal_catalog') |
|---|
| | 1605 | from Products.Archetypes.config import REFERENCE_CATALOG |
|---|
| | 1606 | ref_catalog = getToolByName(self, REFERENCE_CATALOG) |
|---|
| | 1607 | |
|---|
| | 1608 | presentations = self.content.presentations.ObjectValues('PresentationMaterial') |
|---|
| | 1609 | |
|---|
| | 1610 | # Precess |
|---|
| | 1611 | # 1. Take presentation |
|---|
| | 1612 | # 2. Generate UID folder in LEMILL_RESOURCES/presentations |
|---|
| | 1613 | # 3. One by one look through pieces used (only change the ones that have type set as 'media_piece') |
|---|
| | 1614 | # If only used in presentation and nowhere else |
|---|
| | 1615 | # Move piece to slides and delete Piece for good (unlink with presentation) |
|---|
| | 1616 | # If used in other places |
|---|
| | 1617 | # Move to FS unlink with presentation, leave it be |
|---|
| | 1618 | # 4. Build new bodyText with EFS: links and save the presentation |
|---|
| | 1619 | |
|---|
| | 1620 | t = 0 |
|---|
| | 1621 | for p in presentations: |
|---|
| | 1622 | # Create presentation folder |
|---|
| | 1623 | pres_dir = os.path.join(WORK_DIR, o.UID()) |
|---|
| | 1624 | body = p.getBodyText() |
|---|
| | 1625 | new_body = [] |
|---|
| | 1626 | for num in range(body): |
|---|
| | 1627 | chapter = body[num] |
|---|
| | 1628 | if chapter[1] == 'media_piece' and not chapter[0].startswith('EFS:'):# Checking it just in case |
|---|
| | 1629 | # let us get the piece |
|---|
| | 1630 | results = pcatalog({'UID':chapter[0]}) |
|---|
| | 1631 | results = results[0] |
|---|
| | 1632 | piece = results.getObject() |
|---|
| | 1633 | file = piece.getFile() |
|---|
| | 1634 | # Converting it to jpg with PIL |
|---|
| | 1635 | from PIL import Image |
|---|
| | 1636 | im = Image.open(StringIO.StringIO(file.read())) |
|---|
| | 1637 | if im.mode != 'RGB': |
|---|
| | 1638 | im = im.convert('RGB') |
|---|
| | 1639 | s = StringIO.StringIO() |
|---|
| | 1640 | im.save(s, "JPEG") |
|---|
| | 1641 | s.seek(0) |
|---|
| | 1642 | name = 'slide-'str((num+2)/2)+'.jpg' |
|---|
| | 1643 | s_file = open(os.path.join(pres_dir, name), "w") |
|---|
| | 1644 | s_file.write(s.read()) |
|---|
| | 1645 | s_file.close() |
|---|
| | 1646 | s.close()# Useful memory dump? |
|---|
| | 1647 | # Creating different sizes |
|---|
| | 1648 | p._createThumbnails(name) |
|---|
| | 1649 | #Piece related stuff |
|---|
| | 1650 | resources = piece.getResourcesUsingPiece()# returns catalog objects |
|---|
| | 1651 | if len(resources) == 1: |
|---|
| | 1652 | # We delete the piece, also unlink |
|---|
| | 1653 | ref_catalog.deleteReference(self, chapter[0], p.relationship) |
|---|
| | 1654 | self.content.pieces._delObject(piece.getId()) |
|---|
| | 1655 | elif len(resources) > 1: |
|---|
| | 1656 | # We do not delete this one |
|---|
| | 1657 | ref_catalog.deleteReference(self, chapter[0], p.relationship) |
|---|
| | 1658 | # Appending new chapter to a bodyText |
|---|
| | 1659 | new_body.append(('EFS:'+name,'media_piece')) |
|---|
| | 1660 | else: |
|---|
| | 1661 | new_body.append(chapter) |
|---|
| | 1662 | # Setting the new bodyText |
|---|
| | 1663 | p.setBodyText(new_body) |
|---|
| | 1664 | # Setting new stuff in |
|---|
| | 1665 | p.slides_available = True |
|---|
| | 1666 | p.presentation_file = None |
|---|
| | 1667 | p.presentation_filename = None |
|---|
| | 1668 | |
|---|
| | 1669 | # Transaction portion |
|---|
| | 1670 | p.reindexObject()#XXX is this needed? |
|---|
| | 1671 | t = t + 1 |
|---|
| | 1672 | if t > 200: |
|---|
| | 1673 | print >>out, '*** committing transaction, 200 objects ***' |
|---|
| | 1674 | transaction.get().commit() |
|---|
| | 1675 | t = 0 |
|---|
| | 1676 | |
|---|
| | 1677 | print >>out, "*** presentations migrated ***" |
|---|
| | 1678 | print >>out, "Migration from 2.6.4 complete" |
|---|