From d3cb04fc3ebb456abe6f9ca1226e4f94bf777789 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Tue, 09 Mar 2010 23:22:13 +0000 Subject: Auto detect mime type in copy-to-journal #586 (tomeu) --- 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 -m MIMETYPE [-t TITLE] [-d DESC] [-T tag1 [-T tag2 ...]]" + usage = "Usage: %prog [-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: -- cgit v0.9.1