예제 #1
0
파일: datatypes.py 프로젝트: hforge/ikaaro
def guess_mimetype(filename, default):
    """Override itools function 'guess_type' to intercept the encoding.
    """
    name, extension, language = FileName.decode(filename)
    filename = FileName.encode((name, extension, None))

    mimetype, encoding = guess_type(filename)
    return encoding_map.get(encoding, mimetype or default)
예제 #2
0
def guess_mimetype(filename, default):
    """Override itools function 'guess_type' to intercept the encoding.
    """
    name, extension, language = FileName.decode(filename)
    filename = FileName.encode((name, extension, None))

    mimetype, encoding = guess_type(filename)
    return encoding_map.get(encoding, mimetype or default)
예제 #3
0
    def get_new_resource_name(self, form):
        name = super(File_NewInstance, self).get_new_resource_name(form)
        if name:
            return name

        filename, mimetype, body = form['data']
        name, extension, language = FileName.decode(filename)

        if mimetype not in ('application/xhtml+xml', 'text/html'):
            name = FileName.encode((name, extension, None))

        return name
예제 #4
0
    def get_new_resource_name(self, form):
        name = super(File_NewInstance, self).get_new_resource_name(form)
        if name:
            return name

        filename, mimetype, body = form['data']
        name, extension, language = FileName.decode(filename)

        if mimetype not in ('application/xhtml+xml', 'text/html'):
            name = FileName.encode((name, extension, None))

        return name
예제 #5
0
 def test_FileName(self):
     map = {
         'index': ('index', None, None),
         'index.html': ('index', 'html', None),
         'index.html.en': ('index', 'html', 'en'),
         'index.html.en.gz': ('index.html.en', 'gz', None),
         'itools.tar': ('itools', 'tar', None),
         'itools.tar.gz': ('itools.tar', 'gz', None),
         'toto.en': ('toto', None, 'en'),
         'toto.gz': ('toto', 'gz', None),
         'toto.Z': ('toto', 'Z', None),
     }
     for name, result in map.iteritems():
         self.assertEqual(FileName.decode(name), result)
         self.assertEqual(FileName.encode(result), name)
예제 #6
0
파일: test_fs.py 프로젝트: kennym/itools
 def test_FileName(self):
     map = {
         'index': ('index', None, None),
         'index.html': ('index', 'html', None),
         'index.html.en': ('index', 'html', 'en'),
         'index.html.en.gz': ('index.html.en', 'gz', None),
         'itools.tar': ('itools', 'tar', None),
         'itools.tar.gz': ('itools.tar', 'gz', None),
         'toto.en': ('toto', None, 'en'),
         'toto.gz': ('toto', 'gz', None),
         'toto.Z': ('toto', 'Z', None),
         }
     for name, result in map.iteritems():
         self.assertEqual(FileName.decode(name), result)
         self.assertEqual(FileName.encode(result), name)
예제 #7
0
    def get_catalog_values(self):
        # Filename
        filename = basename(self.abspath)
        name, ext, lang = FileName.decode(filename)
        # Content
        with open(self.abspath) as f:
            data = f.read()
            data = unicode(data, 'utf-8')
        title = data.splitlines()[0]
        wolf = re.search('wolf', data, re.I) is not None
        count = [
            len(data.splitlines()),  # lines
            len(data.split()),  # words
            len(data)
        ]  # chars
        # Multilingual
        if lang:
            data = {lang: data}
            title = {lang: title}

        # Ok
        return {
            'abspath': filename,  # oid
            'name': name,
            'lang': lang,
            'title': title,
            'data': data,
            'count': count,
            'about_wolf': wolf,
            'is_long': count[2] > 1024
        }
예제 #8
0
파일: folder.py 프로젝트: matrixorz/ikaaro
    def _make_file(self, name, filename, mimetype, body, default_language):
        from webpage import WebPage

        if type(name) is not str:
            raise TypeError, 'expected string, got %s' % repr(name)

        # Web Pages are first class citizens
        if mimetype == 'text/html':
            body = tidy_html(body)
            class_id = 'webpage'
        elif mimetype == 'application/xhtml+xml':
            class_id = 'webpage'
        else:
            class_id = mimetype
        cls = self.database.get_resource_class(class_id)

        # Special case: web pages
        kw = {'filename': filename, 'data': body}
        if issubclass(cls, WebPage):
            kk, kk, language = FileName.decode(filename)
            if language is None:
                text = XHTMLFile(string=body).to_text()
                language = guess_language(text) or default_language
            kw['data'] = {language: body}

        return self.make_resource(name, cls, **kw)
예제 #9
0
파일: review.py 프로젝트: hforge/shop
    def create_new_image(self, context, image):
        images = self.get_resource('images')
        query = [ PhraseQuery('parent_path', str(images.get_canonical_path())),
                  PhraseQuery('is_image', True) ]
        root = context.root
        results = root.search(AndQuery(*query))
        if len(results) == 0:
            name = '0'
        else:
            doc = results.get_documents(sort_by='name', reverse=True)[0]
            name = str(int(doc.name) + 1)

        # XXX Temp fix
        while images.get_resource(name, soft=True) is not None:
            name = int(name) + 1
            name = str(name)
        # End of temp fix

        filename, mimetype, body = image
        _name, type, language = FileName.decode(filename)
        cls = Image
        kw = {'format': mimetype,
              'filename': filename,
              'extension': type,
              'state': 'public'}
        return self.make_resource(cls, images, name, body, **kw)
예제 #10
0
    def get_catalog_values(self):
        # Filename
        filename = basename(self.abspath)
        name, ext, lang = FileName.decode(filename)
        # Content
        with open(self.abspath) as f:
            data = f.read()
            data = unicode(data, "utf-8")
        title = data.splitlines()[0]
        wolf = re.search("wolf", data, re.I) is not None
        count = [len(data.splitlines()), len(data.split()), len(data)]  # lines  # words  # chars
        # Multilingual
        if lang:
            data = {lang: data}
            title = {lang: title}

        # Ok
        return {
            "abspath": filename,  # oid
            "name": name,
            "lang": lang,
            "title": title,
            "data": data,
            "count": count,
            "about_wolf": wolf,
            "is_long": count[2] > 1024,
        }
예제 #11
0
    def _make_file(self, name, filename, mimetype, body, default_language):
        from webpage import WebPage

        if type(name) is not str:
            raise TypeError, 'expected string, got %s' % repr(name)

        # Web Pages are first class citizens
        if mimetype == 'text/html':
            body = tidy_html(body)
            class_id = 'webpage'
        elif mimetype == 'application/xhtml+xml':
            class_id = 'webpage'
        else:
            class_id = mimetype
        cls = self.database.get_resource_class(class_id)

        # Special case: web pages
        kw = {'filename': filename, 'data': body}
        if issubclass(cls, WebPage):
            kk, kk, language = FileName.decode(filename)
            if language is None:
                text = XHTMLFile(string=body).to_text()
                language = guess_language(text) or default_language
            kw['data'] = {language: body}

        return self.make_resource(name, cls, **kw)
예제 #12
0
    def create_new_image(self, context, image):
        images = self.get_resource('images')
        query = [
            PhraseQuery('parent_path', str(images.get_canonical_path())),
            PhraseQuery('is_image', True)
        ]
        root = context.root
        results = root.search(AndQuery(*query))
        if len(results) == 0:
            name = '0'
        else:
            doc = results.get_documents(sort_by='name', reverse=True)[0]
            name = str(int(doc.name) + 1)

        # XXX Temp fix
        while images.get_resource(name, soft=True) is not None:
            name = int(name) + 1
            name = str(name)
        # End of temp fix

        filename, mimetype, body = image
        _name, type, language = FileName.decode(filename)
        cls = Image
        kw = {
            'format': mimetype,
            'filename': filename,
            'extension': type,
            'state': 'public'
        }
        return self.make_resource(cls, images, name, body, **kw)
예제 #13
0
파일: ws_odf.py 프로젝트: hforge/hforge
    def action_odf2tr(self, resource, context, form):
        odf_file_name, odf_file_mime_type, odf_file_data = form['odf_file']
        srx_file = form['srx_file']
        output_type = form['output_type']

        # Not a too big file
        if check_size(odf_file_data, context):
            return

        # Get the good "get_units"
        odf_handler = get_handler_class_by_mimetype(odf_file_mime_type)
        try:
            get_units = odf_handler(string=odf_file_data).get_units
        except AttributeError:
            context.message = ERROR(u'malformed ODF file')
            return

        # a SRX file ?
        if srx_file is not None:
            srx_file_data = srx_file[2]
            try:
                srx_handler = SRXFile(string=srx_file_data)
            except XMLError:
                context.message = ERROR(u'unexpected error, please verify '
                                        u'your input files')
                return
        else:
            srx_handler = None

        # The good handler for the output
        if output_type == 'PO':
            extension = 'po'
            out_handler = POFile()
        else:
            extension = 'xlf'
            out_handler = XLFFile()
        name = FileName.decode(odf_file_name)[0]
        out_filename = FileName.encode((name, extension, None))

        # Make the output
        for source, source_context, line in get_units(srx_handler=srx_handler):
            out_handler.add_unit(odf_file_name, source, source_context, line)

        # Return the result
        context.set_content_type(out_handler.class_mimetypes[0])
        context.set_content_disposition('inline', out_filename)
        return out_handler.to_str()
예제 #14
0
파일: mission_views.py 프로젝트: hforge/crm
 def set_value(self, resource, context, name, form):
     if name == 'tags':
         proxy = TagsAware_Edit
         return proxy.set_value(self, resource, context, name, form)
     elif name in ('attachment', 'alert_time'):
         return False
     if name == 'alert_date':
         alert_date = form[name]
         if alert_date:
             alert_time = form['alert_time'] or time(9, 0)
             value = datetime.combine(alert_date, alert_time)
         else:
             status = form['crm_m_status']
             if status not in ('finished', 'nogo'):
                 context.message = ERR_ALERT_MANDATORY
                 return True
             value = None
         resource.set_property('crm_m_alert', value)
         return False
     elif name == 'crm_m_nextaction':
         value = form[name]
         if not value:
             status = form['crm_m_status']
             if status not in ('finished', 'nogo'):
                 context.message = ERR_NEXTACTION_MANDATORY
                 return True
         resource.set_property('crm_m_nextaction', value)
         return False
     elif name == 'comment':
         value = form[name]
         # Attachment
         attachment = form['attachment']
         if attachment is None:
             if not value:
                 return False
         else:
             filename, mimetype, body = attachment
             # Find a non used name
             attachment = checkid(filename)
             attachment, extension, language = FileName.decode(attachment)
             attachment = generate_name(attachment, resource.get_names())
             # Add attachment
             cls = get_resource_class(mimetype)
             resource.make_resource(attachment, cls, body=body,
                 filename=filename, extension=extension,
                 format=mimetype)
             if not value:
                 value = DUMMY_COMMENT
         user = context.user
         author = user.name if user else None
         value = Property(value, date=context.timestamp, author=author,
                 attachment=attachment)
         resource.metadata.set_property(name, value)
         context.database.change_resource(resource)
         return False
     proxy = DBResource_Edit
     return proxy.set_value(self, resource, context, name, form)
예제 #15
0
 def rewrite(value):
     if value[0] == "#":
         return value
     ref = get_reference(value)
     if ref.scheme:
         return value
     name = ref.path.get_name()
     name, extension, langage = FileName.decode(name)
     if extension in ("png", "pdf"):
         name = "%s/;download" % name
     ref.path[-1] = name
     return "../%s" % ref
예제 #16
0
파일: root_views.py 프로젝트: hforge/ikaaro
 def rewrite(value):
     if value[0] == '#':
         return value
     ref = get_reference(value)
     if ref.scheme:
         return value
     name = ref.path.get_name()
     name, extension, langage = FileName.decode(name)
     if extension in ('png', 'pdf'):
         name = '%s/;download' % name
     ref.path[-1] = name
     return '../%s' % ref
예제 #17
0
 def rewrite(value):
     if value[0] == '#':
         return value
     ref = get_reference(value)
     if ref.scheme:
         return value
     name = ref.path.get_name()
     name, extension, langage = FileName.decode(name)
     if extension in ('png', 'pdf'):
         name = '%s/;download' % name
     ref.path[-1] = name
     return '../%s' % ref
예제 #18
0
파일: ws_odf.py 프로젝트: hforge/hforge
    def action(self, resource, context, form):
        odf_file_name, odf_file_mimetype, odf_file_data = form['odf_file']

        # Not a too big file
        if check_size(odf_file_data, context):
            return

        # Load the handler
        odf_handler = get_handler_class_by_mimetype(odf_file_mimetype)
        odf_handler = odf_handler(string=odf_file_data)

        # Greek
        output = odf_handler.greek()

        # Add '-greek' to the filename
        name, extension, language = FileName.decode(odf_file_name)
        out_filename = FileName.encode((name + '-greek', extension, language))

        # Return the result
        context.set_content_type(odf_file_mimetype)
        context.set_content_disposition('inline', out_filename)
        return output
예제 #19
0
파일: form.py 프로젝트: leenaars/goodforms
 def save_file(self, filename, mimetype, body):
     name, extension, language = FileName.decode(filename)
     parent = self.parent
     used = parent.get_names()
     #name = checkid(name) or 'invalid'
     name = generate_name(name, used)
     context = get_context()
     cls = context.database.get_resource_class(mimetype)
     metadata = {
             'format': mimetype,
             'filename': filename,
             'extension': extension}
     parent.make_resource(name, cls, body=body, **metadata)
     return name
예제 #20
0
 def setUp(self):
     # Make database
     self.database = make_git_database("fables", 20, 20, Document.fields)
     self.database.worktree.git_add(".")
     self.database.worktree.git_commit("Initial commit")
     self.root = self.database.get_handler(".")
     # Index
     catalog = self.database.catalog
     fables = lfs.open("fables/database")
     for name in fables.get_names():
         _, ext, _ = FileName.decode(name)
         if ext == "txt":
             abspath = fables.get_absolute_path(name)
             document = Document(abspath)
             catalog.index_document(document)
     # Save
     catalog.save_changes()
예제 #21
0
 def setUp(self):
     # Make database
     self.database = make_git_database('fables', 20, 20, Document.fields)
     self.database.worktree.git_add('.')
     self.database.worktree.git_commit('Initial commit')
     self.root = self.database.get_handler('.')
     # Index
     catalog = self.database.catalog
     fables = lfs.open('fables/database')
     for name in fables.get_names():
         _, ext, _ = FileName.decode(name)
         if ext == 'txt':
             abspath = fables.get_absolute_path(name)
             document = Document(abspath)
             catalog.index_document(document)
     # Save
     catalog.save_changes()
예제 #22
0
    def action_upload(self, resource, context, form):
        filename, mimetype, body = form['file']
        name, type, language = FileName.decode(filename)

        # Check the filename is good
        title = form['title'].strip()
        name = checkid(title) or checkid(name)
        if name is None:
            context.message = messages.MSG_BAD_NAME
            return

        # Get the container
        container = context.root.get_resource(form['target_path'])

        # Check the name is free
        if container.get_resource(name, soft=True) is not None:
            context.message = messages.MSG_NAME_CLASH
            return

        # Check it is of the expected type
        cls = context.database.get_resource_class(mimetype)
        if not self.can_upload(cls):
            error = u'The given file is not of the expected type.'
            context.message = ERROR(error)
            return

        kw = {'data': body, 'filename': filename}

        # Add the image to the resource
        child = container.make_resource(name, cls, **kw)
        # The title
        language = resource.get_edit_languages(context)[0]
        title = Property(title, lang=language)
        child.metadata.set_property('title', title)
        # Get the path
        path = child.abspath
        action = self.get_resource_action(context)
        if action:
            path = '%s%s' % (path, action)
        # Return javascript
        scripts = self.get_scripts(context)
        context.add_script(*scripts)
        return self.get_javascript_return(context, path)
예제 #23
0
    def action_upload(self, resource, context, form):
        filename, mimetype, body = form['file']
        name, type, language = FileName.decode(filename)

        # Check the filename is good
        title = form['title'].strip()
        name = checkid(title) or checkid(name)
        if name is None:
            context.message = messages.MSG_BAD_NAME
            return

        # Get the container
        container = context.root.get_resource(form['target_path'])

        # Check the name is free
        if container.get_resource(name, soft=True) is not None:
            context.message = messages.MSG_NAME_CLASH
            return

        # Check it is of the expected type
        cls = context.database.get_resource_class(mimetype)
        if not self.can_upload(cls):
            error = u'The given file is not of the expected type.'
            context.message = ERROR(error)
            return

        kw = {'data': body, 'filename': filename}

        # Add the image to the resource
        child = container.make_resource(name, cls, **kw)
        # The title
        language = resource.get_edit_languages(context)[0]
        title = MetadataProperty(title, lang=language)
        child.metadata.set_property('title', title)
        # Get the path
        path = child.abspath
        action = self.get_resource_action(context)
        if action:
            path = '%s%s' % (path, action)
        # Return javascript
        scripts = self.get_scripts(context)
        context.add_script(*scripts)
        return self.get_javascript_return(context, path)
예제 #24
0
파일: folder_views.py 프로젝트: hforge/wiki
def _add_image(filename, document, resource):
    if type(filename) is unicode:
        filename = filename.encode('UTF-8')
    data = document.get_part('Pictures/%s' % filename)
    name, a_type, language = FileName.decode(filename)

    # Check the filename is good
    name = checkid(name)
    if name is None:
        return None

    # XXX If the resource exists, we assume it's the good resource
    if resource.get_resource(name, soft=True) is None:
        # Get mimetype / class
        mimetype = get_mimetype(filename)
        cls = get_context().database.get_resource_class(mimetype)
        # Add the image
        resource.make_resource(name, cls, body=data, format=mimetype,
                               filename=filename, extension=a_type)
    # All OK
    return name
예제 #25
0
파일: folder_views.py 프로젝트: hforge/wiki
def _save_template(context, a_file, target_path):
    """Save the imported template.
    """
    filename, mimetype, body = a_file
    name, type, language = FileName.decode(filename)
    # Check the filename is good
    name = checkid(name)
    if name is None:
        context.message = MSG_BAD_NAME
        return

    # Get the container
    container = context.root.get_resource(target_path)

    # Search for a free name
    names = container.get_names()
    name = generate_name(name, names)

    # Add the image to the resource
    cls = context.database.get_resource_class(mimetype)
    container.make_resource(name, cls, body=body, format=mimetype,
            filename=filename, extension=type)

    return name
예제 #26
0
파일: folder.py 프로젝트: matrixorz/ikaaro
    def extract_archive(self, handler, default_language, filter=None,
                        postproc=None, update=False):
        change_resource = self.database.change_resource
        for path_str in handler.get_contents():
            # 1. Skip folders
            path = Path(path_str)
            if path.endswith_slash:
                continue

            # Skip the owner file (garbage produced by microsoft)
            filename = path[-1]
            if filename.startswith('~$'):
                continue

            # 2. Create parent folders if needed
            folder = self
            for name in path[:-1]:
                name, title = process_name(name)
                subfolder = folder.get_resource(name, soft=True)
                if subfolder is None:
                    folder = folder.make_resource(name, Folder)
                    folder.set_value('title', title, default_language)
                elif not isinstance(subfolder, Folder):
                    raise RuntimeError, MSG_NAME_CLASH
                else:
                    folder = subfolder

            # 3. Find out the resource name and title, the file mimetype and
            # language
            mimetype = guess_mimetype(filename, 'application/octet-stream')
            name, extension, language = FileName.decode(filename)
            name, title = process_name(name)
            language = language or default_language
            # Keep the filename extension (except in webpages)
            if mimetype not in ('application/xhtml+xml', 'text/html'):
                name = FileName.encode((name, extension, None))

            # 4. The body
            body = handler.get_file(path_str)
            if filter:
                body = filter(path_str, mimetype, body)
                if body is None:
                    continue

            # 5. Update or make file
            file = folder.get_resource(name, soft=True)
            if file:
                if update is False:
                    msg = 'unexpected resource at {path}'
                    raise RuntimeError, msg.format(path=path_str)
                if mimetype == 'text/html':
                    body = tidy_html(body)
                    file_handler = file.get_handler(language)
                else:
                    file_handler = file.get_handler()
                old_body = file.handler.to_str()
                file_handler.load_state_from_string(body)
                if postproc:
                    postproc(file)
                # FIXME Comparing the bytes does not work for XML, so we use
                # this weak heuristic
                if len(old_body) != len(file.handler.to_str()):
                    change_resource(file)
            else:
                # Case 1: the resource does not exist
                file = folder._make_file(name, filename, mimetype, body,
                                         language)
                file.set_value('title', title, language=language)
                if postproc:
                    postproc(file)
예제 #27
0
    def extract_archive(self, handler, default_language, filter=None,
                        postproc=None, update=False):
        change_resource = self.database.change_resource
        for path_str in handler.get_contents():
            # 1. Skip folders
            clean_path = "/".join([
              checkid(x) or 'file'
              if x else 'file' for x in path_str.split("/")])
            path = Path(clean_path)
            if path.endswith_slash:
                continue

            # Skip the owner file (garbage produced by microsoft)
            filename = path[-1]
            if filename.startswith('~$'):
                continue

            # 2. Create parent folders if needed
            folder = self
            for name in path[:-1]:
                name, title = process_name(name)
                subfolder = folder.get_resource(name, soft=True)
                if subfolder is None:
                    folder = folder.make_resource(name, Folder)
                    folder.set_value('title', title, default_language)
                elif not isinstance(subfolder, Folder):
                    raise RuntimeError, MSG_NAME_CLASH
                else:
                    folder = subfolder

            # 3. Find out the resource name and title, the file mimetype and
            # language
            mimetype = guess_mimetype(filename, 'application/octet-stream')
            name, extension, language = FileName.decode(filename)
            name, title = process_name(name)
            language = language or default_language
            # Keep the filename extension (except in webpages)
            if mimetype not in ('application/xhtml+xml', 'text/html'):
                name = FileName.encode((name, extension, None))

            # 4. The body
            body = handler.get_file(path_str)
            if filter:
                body = filter(path_str, mimetype, body)
                if body is None:
                    continue

            # 5. Update or make file
            file = folder.get_resource(name, soft=True)
            if file:
                if update is False:
                    msg = 'unexpected resource at {path}'
                    raise RuntimeError, msg.format(path=path_str)
                if mimetype == 'text/html':
                    body = tidy_html(body)
                    file_handler = file.get_handler(language)
                else:
                    file_handler = file.get_handler()
                old_body = file.handler.to_str()
                file_handler.load_state_from_string(body)
                if postproc:
                    postproc(file)
                # FIXME Comparing the bytes does not work for XML, so we use
                # this weak heuristic
                if len(old_body) != len(file.handler.to_str()):
                    change_resource(file)
            else:
                # Case 1: the resource does not exist
                file = folder._make_file(name, filename, mimetype, body,
                                         language)
                file.set_value('title', title, language=language)
                if postproc:
                    postproc(file)
예제 #28
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