Changeset 2767

Show
Ignore:
Timestamp:
01/21/09 14:30:10 (3 years ago)
Author:
pjotr
Message:

Created migration script for presentations, and tuned ExternalStorage? to serve different file types and try to guess the type

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Extensions/Install.py

    r2747 r2767  
    15961596    reinstall_all_types(self,out=out) 
    15971597    print >>out,'Started running maintenance methods' 
     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" 
    15981679         
    15991680    #makeCatalogFixReplace(self, out=out) 
  • trunk/ExternalStorage.py

    r2744 r2767  
    4444        except IndexError: 
    4545            # return 404 not found 
    46             print "r1" 
     46            #print "r1" 
    4747            return object() 
    4848        if subfolder not in EXTERNAL_SUBFOLDERS: 
    4949            # return 404 not found 
    50             print "r2" 
     50            #print "r2" 
    5151            return object() 
    5252        if stack: 
    5353            # return 404 not found 
    54             print "r3" 
     54            #print "r3" 
    5555            return object() 
    5656        # XXX: check fname? 
     
    6969         
    7070    def __call__(self, REQUEST): 
    71         print "__call__!" 
    72         print self._path 
     71        #print "__call__!" 
     72        #print self._path 
    7373        res = REQUEST.RESPONSE 
    74         res.setHeader('Content-Type', 'image/jpeg') 
     74        # Setting default type 
     75        c = 'applicaton/octet-stream' 
     76        # Trying to resolve the types we serve 
     77        if self._path.endswith('.jpg'): 
     78            c = 'image/jpeg' 
     79        elif self._path.endswith('.ppt'): 
     80            c = 'application/vnd.ms-powerpoint' 
     81        elif self._path.endswith('.odp'): 
     82            c = 'application/vnd.oasis.opendocument.presentation' 
     83        elif self._path.endswith('.pps'): 
     84            c = 'application/vnd.ms-powerpoint' 
     85        elif self._path.endswith('.pot'): 
     86            c = 'application/vnd.ms-powerpoint ' 
     87        elif self._path.endswith('.pdf'): 
     88            c = 'application/pdf' 
     89        res.setHeader('Content-Type', c) 
    7590        res.setHeader('Content-Length', os.path.getsize(self._path)) 
    7691        f = open(self._path, 'r') 
  • trunk/LeMillTool.py

    r2765 r2767  
    21102110            results = pcatalog({'UID':uid}) 
    21112111            pres = results[0] 
    2112             self.content.presentations.manage_delObjects([pres.getId]
     2112            self.content.presentations._delObject(pres.getId
    21132113        return 0 
    21142114 
  • trunk/version.txt

    r2725 r2767  
    1 2.6.4 
     12.6.5 
    22