Modify

Opened 8 years ago

Closed 7 years ago

#12797 closed defect (fixed)

Invalid format string

Reported by: anonymous Owned by: Jun Omae
Priority: normal Component: MovieMacro
Severity: normal Keywords:
Cc: Trac Release:

Description (last modified by Ryan J Ollos)

I get the following error:

Error: Macro Movie(LarmaAv.webm) failed
Invalid format string

Trying to play an attachment to a wiki with

[[Movie(LarmaAv.webm)]]

Attachments (1)

t12797.diff (4.2 KB) - added by Jun Omae 7 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 8 years ago by Ryan J Ollos

Description: modified (diff)

comment:2 Changed 7 years ago by Ryan J Ollos

Resolution: worksforme
Status: newclosed

I can't reproduce. If you wish to continue debugging, please make sure you have the latest version of the plugin installed, provide your Trac version and check the logs.

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:3 Changed 7 years ago by anonymous

This bug is caused by L161 of movie.py

The usage of strftime("%s") is platform dependent and seems to not work on windows.

Python doesn't actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it's not in the list), the only reason it's working is because Python is passing the information to your system's strftime, which uses your local timezone.

comment:4 Changed 7 years ago by Jun Omae

You're right. Are you running Trac with the plugin on Windows? datetime.strftime() with %s doesn't work on Windows.

Another issue, resolution of datetime.now() is 0.010s through 0.016s on Windows. If the Movie macro is used more than once at a time, the same id might be generated by _generate_player_id on Windows.

Could you please try the following patch?

  • moviemacro/trunk/movie/macro.py

    diff --git a/moviemacro/trunk/movie/macro.py b/moviemacro/trunk/movie/macro.py
    index 2fe70a864..af9ab4070 100644
    a b  
    55    Embeds various online movies.
    66"""
    77import mimetypes
    8 from datetime import datetime
    98from os.path import join as pathjoin
    109from urlparse import urlparse
    1110
    from pkg_resources import resource_filename 
    1312from trac.core import TracError
    1413from trac.core import implements
    1514from trac.resource import Resource, get_resource_url
     15from trac.util import hex_entropy
    1616from trac.util.html import html as tag
    1717from trac.util.presentation import to_json
    1818from trac.web.api import IRequestFilter
    class MovieMacro(WikiMacroBase): 
    157157    # Private methods
    158158
    159159    def _generate_player_id(self):
    160         now = datetime.now()
    161         return 'player-%s-%s' % (now.strftime('%s'), now.microsecond)
     160        return 'player-' + hex_entropy()
    162161
    163162    def _get_absolute_url(self, req, url):
    164163        """ Generate an absolute url from the url with the special schemes

comment:5 Changed 7 years ago by Ryan J Ollos

Resolution: worksforme
Status: closedreopened

Changed 7 years ago by Jun Omae

Attachment: t12797.diff added

comment:6 Changed 7 years ago by Jun Omae

Owner: changed from Tetsuya Morimoto to Jun Omae
Status: reopenedaccepted

Proposed patch is t12797.diff. Unit tests pass with Trac 0.12, 1.0 and 1.2 on both Linux and Windows.

comment:7 Changed 7 years ago by Jun Omae

I noticed another issue, the macro is used backslash characters to create URL on Windows. The proposed patch is including for the issue.

comment:8 Changed 7 years ago by Jun Omae

Resolution: fixed
Status: acceptedclosed

In 16691:

TracMovieMacro 0.3: fix movie macro not working on Windows (closes #12797)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jun Omae.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.