Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2010-03-09 23:22:13 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2010-03-09 23:22:13 (GMT)
commitd3cb04fc3ebb456abe6f9ca1226e4f94bf777789 (patch)
treec5ed692acf4de757da4ed1384334a3f78906d192
parentd7bd72f115037d6d39137245a49cdf3f6c20f7bd (diff)
Auto detect mime type in copy-to-journal #586 (tomeu)
-rwxr-xr-xbin/copy-to-journal13
1 files changed, 6 insertions, 7 deletions
diff --git a/bin/copy-to-journal b/bin/copy-to-journal
index d6ae6f3..ca6f872 100755
--- a/bin/copy-to-journal
+++ b/bin/copy-to-journal
@@ -17,10 +17,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",
@@ -54,17 +55,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: