Example #1
0
 def get_filename(self, handler, field_name, resource):
     mimetype = self.get_content_type(handler)
     extension = guess_extension(mimetype)
     language = self.context.get_query_value('language') or ''
     if language:
         language = '.%s' % language
     return '%s.%s%s%s' % (resource.name, field_name, language, extension)
Example #2
0
 def get_filename(self, handler, field_name, resource):
     mimetype = self.get_content_type(handler)
     extension = guess_extension(mimetype)
     language = self.context.get_query_value('language') or ''
     if language:
         language = '.%s' % language
     return '%s.%s%s%s' % (resource.name, field_name, language, extension)
Example #3
0
    def GET(self, resource, context):
        items = self.get_items(resource, context)
        issues = self.sort_and_batch(resource, context, items)
        # Get path of all attachment to add in zip
        dirname = '%s/zip' % mkdtemp('zip', 'ikaaro')
        zip = ZipFile(dirname, 'w')
        for issue in issues:
            attachment_name = issue.issue_last_attachment
            attachment = resource.get_resource('%s/%s' % (issue.name, attachment_name))
            attachment_uri = attachment.handler.uri[7:]
            # Get extension
            mimetype = attachment.get_content_type()
            ext = guess_extension(mimetype)[1:]
            #attachment_name = 'issue_%s_%s' % (issue.name, get_uri_name(attachment_uri))
            attachment_name = '%s_%s.%s' % (issue.name, issue.title, ext) 
            #print attachment_name, attachment_uri
            zip.write(attachment_uri, attachment_name)
        zip.close()
        # Create zip
        # Build zipname
        name = "LastAttachedImages"
        now = strftime("%y%d%m%H%M")
        #pprint("%s" % now)
        zipname = "%s_%s_%s.zip" % (resource.name, name, now)
        
        file = open(dirname)
        try:
            data = file.read()
        finally:
            file.close()
        
        vfs.remove(dirname)

        # Return the zip
        response = context.response
        response.set_header('Content-Type', 'application/zip')
        response.set_header('Content-Disposition',
                'attachment; filename=%s' % zipname)
        return data
Example #4
0
    def get_filename(self, handler, field_name, resource):
        mimetype = self.get_content_type(handler)
        extension = guess_extension(mimetype)

        return '%s.%s%s' % (resource.name, field_name, extension)
Example #5
0
 def update_20090705(self):
     """
     Encode the unencoded MOV or AVI file, and add the thumb, erase the
     original file.
     """
     from pprint import pprint
     from datetime import datetime
     from tempfile import mkdtemp
     from issue import Tchack_Issue
     from ikaaro.file import Video
     from ikaaro.exceptions import ConsistencyError
     from itools import vfs
     from itools.vfs import FileName
     from itools.core import guess_extension
     from itools.uri import get_uri_path
     from videoencoding import VideoEncodingToFLV
     from ikaaro.registry import get_resource_class
     
     for issue in self.search_resources(cls=Tchack_Issue):
     
         history = issue.get_history()
     
         for record in history.get_records():
         
             filename = record.file
             comment = record.comment
             is_video = False
             if not comment and not filename:
                 continue
             if filename:
                 file = issue.get_resource(filename)
                 is_video = isinstance(file, Video)
             
                 if not is_video:
                     continue
                 if is_video:
                     name = file.name
                     filename, ext, lang = FileName.decode(name)
                     if ext is None:
                         mimetype = file.get_content_type()
                         ext = guess_extension(mimetype)[1:]
                     if(mimetype == 'video/x-msvideo'
                         or mimetype == 'video/quicktime'):
                         pprint("The file %s.%s will be encoded in FLV, \
                             replaced by, then erased." % (filename, ext))
                         
                         handler_path = get_uri_path(issue.handler.uri)
                         
                         dirname = mkdtemp('videoencoding', 'ikaaro')
                         tempdir = vfs.open(dirname)
                         
                         # Paste the file in the tempdir
                         tmp_uri= "file:///%s/%s" % (dirname, filename)
                         vfs.copy(file.handler.uri, tmp_uri)
                         
                         # Encode to 512 of width
                         encoded = VideoEncodingToFLV(file).encode_avi_to_flv(
                              dirname, filename, name, 512)
                         
                         if encoded is not None:
                             flvfilename, flvmimetype,
                             flvbody, flvextension = encoded['flvfile']
                             thumbfilename, thumbmimetype,
                             thumbbody, thumbextension = encoded['flvthumb']
                         # Create the video FLV and thumbnail PNG resources
                         video = get_resource_class(flvmimetype)
                         thumbnail = get_resource_class(thumbmimetype)
                         # Remove the original files
                         if vfs.exists(file.handler.uri):
                             vfs.remove(file.handler.uri)
                         if vfs.exists(file.metadata.uri):
                             vfs.remove(file.metadata.uri)
                         
                         video.make_resource(video, issue, name,
                             body=flvbody, filename=flvfilename,
                             extension=flvextension, format=flvmimetype)
                         thumbnail.make_resource(thumbnail, issue, thumbfilename,
                             body=thumbbody, filename=thumbfilename,
                             extension=thumbextension, format=thumbmimetype)
                         
                         # Clean the temporary folder
                         vfs.remove(dirname)
                         
                         pprint("====================")
                     pprint("xxxxxxxxxxxxxxxx")
Example #6
0
    def get_namespace(self, resource, context):
        # Set Style & JS
        context.styles.append('/ui/tchacker/tracker.css')
        context.scripts.append('/ui/tchacker/tracker.js')
        context.styles.append('/ui/thickbox/thickbox.css')
        context.scripts.append('/ui/thickbox/thickbox.js')
        #context.scripts.append('/ui/flowplayer/script.js')
        context.scripts.append('/ui/flowplayer/flowplayer-3.1.1.min.js')
        context.scripts.append('/ui/flowplayer/flowplayer-3.1.1.swf')
        #context.scripts.append('/ui/flowplayer/flowplayer.controls-3.1.1.swf')
        # Build namespace
        namespace = Issue_Edit.get_namespace(self, resource, context)
        #namespace['comments'].reverse()

        # Local variables
        users = resource.get_resource('/users')
        history = resource.get_history()
        record = history.get_record(-1)

        # Build the namespace

        for comment in namespace['comments']:
            if comment['file']:
                attachment = resource.get_resource(comment['file'])
                #print type(attachment), attachment
                comment['is_image'] = isinstance(attachment, Image)
                comment['is_video'] = isinstance(attachment, Video)
                comment['width'] = 200
                comment['height'] = 200
                if comment['is_video']:
                    """
                    #pprint("i = %s and length = %s" % (i, length))
                    if (i == length ):
                        last_video = True
                        #pprint("LastVideo = %s" % last_video)
                    """
                    video = attachment #resource.get_resource(file)
                    base = video.metadata.uri
                    name = video.name
                    #pprint("name = %s" % name)
                    name, ext, lang = FileName.decode(name)
                    if ext is None:
                        mimetype = video.get_content_type()
                        ext = guess_extension(mimetype)[1:]
                    
                    #thumbnail = ("thumb_%s" % name)
                    #pprint("ext = %s, sortie de is_video" % ext)
                    
                    uri = resolve_uri(base, name)
                    #pprint("name = %s" % name)
                    #pprint("base = %s" % base)
                    #pprint("uri = %s.%s" % (uri, ext))
                    comment['width'], height, ratio = VideoEncodingToFLV(
                       resource).get_size_and_ratio(
                            "%s.%s" % (uri, ext))
                    # Add the Flowplayer menu's height
                    comment['height'] = int(height) + 24
                    #pprint("width x height & ratio = %s x %s & %s" % (width, height, ratio))
            else:
                comment['file'] = False
                comment['is_video'] = False
            #comment = record.comment
            #file = record.file
            ##thumb_low = ''
            ##thumb_high = ''
            #if not comment and not file:
            #    continue
            #rdatetime = record.datetime
            ## solid in case the user has been removed
            #username = record.username
            #user = users.get_resource(username, soft=True)
            #user_title = user and user.get_title() or username
            ## In case of an Image joined as file, show it as a preview
            ## (width="256", for now).
            #width, height = None, None
            #thumbnail = None 
            #
            #if file:
            #    is_image = False
            #    is_video = False
            #    last_video = False
            #    #pprint("file = %s" % file)
            #    # If file is an image return True
            #    is_image = isinstance(resource.get_resource(file), Image)
            #    is_video = isinstance(resource.get_resource(file), Video)
            #    
            #    #pprint("is_image = %s" % is_image)
            #    #pprint("is_video = %s" % is_video)
            #    
            #    if is_video:
            #        """
            #        #pprint("i = %s and length = %s" % (i, length))
            #        if (i == length ):
            #            last_video = True
            #            #pprint("LastVideo = %s" % last_video)
            #        """
            #        video = resource.get_resource(file)
            #        base = video.metadata.uri
            #        name = video.name
            #        #pprint("name = %s" % name)
            #        name, ext, lang = FileName.decode(name)
            #        if ext is None:
            #            mimetype = video.get_content_type()
            #            ext = guess_extension(mimetype)[1:]
            #        
            #        #thumbnail = ("thumb_%s" % name)
            #        #pprint("ext = %s, sortie de is_video" % ext)
            #        
            #        uri = resolve_uri(base, name)
            #        #pprint("name = %s" % name)
            #        #pprint("base = %s" % base)
            #        #pprint("uri = %s.%s" % (uri, ext))
            #        width, height, ratio = VideoEncodingToFLV(resource).get_size_and_ratio("%s.%s" % (uri, ext))
            #        # Add the Flowplayer menu's height
            #        height = int(height) + 24
            #        #pprint("width x height & ratio = %s x %s & %s" % (width, height, ratio))
            #if comment and not file: 
            #    is_image = False
            #    is_video = False

        return namespace
Example #7
0
    def get_filename(self, handler, field_name, resource):
        mimetype = self.get_content_type(handler)
        extension = guess_extension(mimetype)

        return '%s.%s%s' % (resource.name, field_name, extension)