Edgewall Software
Modify

Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#2105 closed enhancement (fixed)

identify the mimetype

Reported by: Otavio Salvador Owned by: Christian Boos
Priority: high Milestone: 0.10
Component: general Version: devel
Severity: minor Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description (last modified by Christian Boos)

Would be great if trac identify the mime type also by reading the file header.

For example, debian/rules files has it's first line set to #!/usr/bin/make -f and is safe to use Makefile highlight for it. This apply too to shell scripts and others.

Thanks in advance,

Attachments (2)

mimeview-refactoring.patch (17.2 KB ) - added by Christian Boos 19 years ago.
Implementation of the feature, which required a bit of refactoring (mainly, get the content first, before it can be passed on to Mimeview.get_mimetype())
mimeview-inspect-r2500.patch (16.8 KB ) - added by Christian Boos 18 years ago.
Refactoring of the way the mimetype is associated to the file: This is now done after the content (or the first chunk of it) is seen, enabling all sorts of detection schemes (a simple shebang detection is done for now, more can be added later, why not in a "pluggable" way)

Download all attachments as: .zip

Change History (11)

comment:1 by Christian Boos, 19 years ago

Milestone: 0.9
Owner: changed from Jonas Borgström to Christian Boos
Severity: normalminor
Version: 0.8.4devel

Additional requirement: support Emacs mode specification, e.g.

# This is a -*- Makefile -*- 

foo: bar
       cp bar foo

by Christian Boos, 19 years ago

Attachment: mimeview-refactoring.patch added

Implementation of the feature, which required a bit of refactoring (mainly, get the content first, before it can be passed on to Mimeview.get_mimetype())

comment:2 by Christian Boos, 19 years ago

Description: modified (diff)
Milestone: 1.0
Status: newassigned

The above refactoring is a kind of follow-up to r2276: less duplicated mimeview related code in attachment.py, browser.py and now changeset.py, and put the common code in mimeview/api.py.

Not necessarily for 0.9, as it's just an enhancement.

comment:3 by Christian Boos, 19 years ago

In the previous comment, by the above refactoring, I was referring to the attachment:mimeview-refactoring.patch

That was not clear in the Trac-Ticket notification mail, since it displayed also my formatting change in the description…

comment:4 by Matthew Good, 19 years ago

Cboos before you start trying to build a mime inspection method into Trac there is already a Python module made to work similarly to the Unix "file" command: http://www.demonseed.net/~jp/code/magic.py

Unfortunately the file has a copyright statement, but no licensing terms, so I'm contacting the author to try to get an acceptable license for it.

There is another similar module listed in the Cheese Shop, but it's licensed under the GPL, so it's not usable for Trac now: http://www.python.org/pypi/pymagic/0.1

I know it's also possible to inspect mime types through the Python bindings to the Gnome libraries, which is not as portable, but could be used in combination with the magic module mentioned above.

I'll let you know what I hear about licencing on that module.

comment:5 by Christian Boos, 19 years ago

The above patch is not doing a mime inspection of the file, it only takes into account the shebang or the Emacs mode. But the refactoring done at that occasion would be benefitial to any other, more complex, auto-detection method.

by Christian Boos, 18 years ago

Refactoring of the way the mimetype is associated to the file: This is now done after the content (or the first chunk of it) is seen, enabling all sorts of detection schemes (a simple shebang detection is done for now, more can be added later, why not in a "pluggable" way)

comment:6 by Christian Boos, 18 years ago

Priority: normalhigh

Updated version of the patch added (attachment:mime-inspect-r2500.patch)

Please review.

comment:7 by Christian Boos, 18 years ago

Keywords: review added

The attachment's link was actually attachment:mimeview-inspect-r2500.patch

comment:8 by Christian Boos, 18 years ago

Keywords: review removed
Resolution: fixed
Status: assignedclosed

Patch applied in r2653.

comment:9 by Christopher Lenz, 18 years ago

Milestone: 1.00.10

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.