Opened 12 years ago

Closed 11 years ago

Last modified 7 years ago

#586 closed defect (fixed)

Auto detect mime type in copy-to-journal

Reported by: wadeb Owned by: alsroot
Priority: Unspecified by Maintainer Milestone:
Component: Sugar Version: 0.82.x
Severity: Major Keywords: r+ olpc-0.84
Cc: bert Distribution/OS: Unspecified
Bug Status: Needinfo

Description

I made a new release of Finance on my XO and wanted to upload it to activities.sugarlabs.org.

I used copy-to-journal dist/Finance-3.xo -m application/zip

Then in Browse, I selected the .xo file from the Journal. But what was ultimately uploaded was a randomly named .zip file in a strange directory.

The activities site complained about the filename, which had the .zip extension instead of .xo. It wouldn't have worked anyway, since the filename was not preserved.

Note that I had the same problem when downloading the .xo bundle *using* Browse from shell.sugarlabs.org and then trying to post it again.

I'm not sure which component this is most appropriate so I'm defaulting to Sugar.

Change History (19)

comment:1 in reply to: ↑ description Changed 12 years ago by tomeu

Replying to wadeb:

The activities site complained about the filename, which had the .zip extension instead of .xo. It wouldn't have worked anyway, since the filename was not preserved.

Is the file name really required by aslo? Or only the file extension?

comment:2 Changed 12 years ago by tomeu

  • Severity changed from Major to Blocker

comment:3 Changed 12 years ago by erikos

  • Milestone changed from Unspecified by Release Team to 0.84

comment:4 in reply to: ↑ description Changed 12 years ago by tomeu

Replying to wadeb:

I made a new release of Finance on my XO and wanted to upload it to activities.sugarlabs.org.

I used copy-to-journal dist/Finance-3.xo -m application/zip

Using that mime type causes the DS to give it the .zip extension. If you pass application/vnd.olpc-sugar instead, it will end with .xo.

I just uploaded a bundle (to activities-devel@…) and though the name was mangled (we should fix this for 0.86), the activity uploaded just fine and was able to make it public and download just fine.

comment:5 follow-up: Changed 12 years ago by wadeb

Oh, I didn't realize that we had a mime type for .xo bundles already.

Is there any way that copy-to-journal could automatically detect the mime type from the file extension? IE, is there a Unix command which can attempt to do that based on the MIME types DB?

comment:6 in reply to: ↑ 5 Changed 12 years ago by tomeu

Replying to wadeb:

Is there any way that copy-to-journal could automatically detect the mime type from the file extension?

Would this modification work? (I haven't tested it)

diff --git a/bin/copy-to-journal b/bin/copy-to-journal
index ce72f2b..1a3d14d 100755
--- a/bin/copy-to-journal
+++ b/bin/copy-to-journal
@@ -15,10 +15,11 @@ if os.path.exists("/tmp/olpc-session-bus"):
     os.environ["DBUS_SESSION_BUS_ADDRESS"] = "unix:path=/tmp/olpc-session-bus"
 
 from sugar.datastore import datastore
+from sugar import mime
 
 def build_option_parser():
 
-    usage = "Usage: %prog <file> -m MIMETYPE [-t TITLE] [-d DESC] [-T tag1 [-T tag2 ...]]"
+    usage = "Usage: %prog <file> [-m MIMETYPE] [-t TITLE] [-d DESC] [-T tag1 [-T tag2 ...]]"
     parser = optparse.OptionParser(usage=usage)
 
     parser.add_option("-t", "--title", action="store", dest="title",
@@ -52,17 +53,15 @@ if __name__ == "__main__":
         parser.print_help()
         exit(0)
 
-    if not options.mimetype:
-        print 'Error: No MIME-type given.'
-        parser.print_help()
-        exit(0)
-    
     try:
         entry = datastore.create()
         entry.set_file_path(absname)
 
         # Set the mimetype to the provided one.
-        entry.metadata['mime_type'] = options.mimetype
+        if options.mimetype is None:
+            entry.metadata['mime_type'] = mime.get_for_file(absname)
+        else:
+            entry.metadata['mime_type'] = options.mimetype
 
         # If no title is given, use the filename.
         if options.title:

IE, is there a Unix command which can attempt to do that based on the MIME types DB?

Should be one, maybe one of the xdg-* commands?

comment:7 Changed 12 years ago by tomeu

  • Milestone changed from 0.84 to 0.86
  • Severity changed from Blocker to Major

comment:8 Changed 11 years ago by tomeu

  • Bug Status changed from Unconfirmed to Needinfo

comment:9 Changed 11 years ago by alsroot

  • Component changed from sugar to sugar-datastore

on part of this issue could be fixed in #901,
patch for copy-to-journal is a ds stuff..

comment:10 Changed 11 years ago by alsroot

  • Owner changed from tomeu to alsroot
  • Status changed from new to assigned

comment:11 Changed 11 years ago by alsroot

  • Status changed from assigned to accepted
  • Summary changed from Browse cannot upload activity bundles to activities.sugarlabs.org because of Journal name scrambling. to Auto detect mime type in copy-to-journal

comment:12 Changed 11 years ago by bert

  • Cc bert added

A test case:

copy-to-journal /usr/share/etoys/ExampleEtoys/DemonCastle1.059.pr

should create a Journal entry that gets an Etoys icon and opens in Etoys. This is to verify it's not using the "file" database (see http://lists.sugarlabs.org/archive/sugar-devel/2010-January/022007.html).

comment:13 Changed 11 years ago by tomeu

  • Keywords r? added

So you have tested this patch and works, Bert?

comment:14 Changed 11 years ago by bert

No I did not - which patch do you mean?

comment:15 Changed 11 years ago by alsroot

  • Keywords r+ added; r? removed
  • Resolution set to fixed
  • Status changed from accepted to closed

Attached patch uses system mime db. To support .pr files as Etoys projects, Etoys activity should contain mimetypes.xml file like Memorize does, so on activity install, sugar will update mime db.

http://git.sugarlabs.org/projects/sugar-datastore/repos/mainline/commits/d3cb04fc3ebb456abe6f9ca1226e4f94bf777789

comment:16 Changed 11 years ago by alsroot

  • Keywords olpc-0.84 added

comment:17 Changed 11 years ago by bert

Actually the etoys rpm installs a system-wide mime file so it is recognized even in Gnome and other desktops. No need to provide another mime file in the activity.

comment:18 Changed 7 years ago by dnarvaez

  • Component changed from sugar-datastore to Sugar

comment:19 Changed 7 years ago by dnarvaez

  • Milestone 0.86 deleted

Milestone 0.86 deleted

Note: See TracTickets for help on using tickets.