Re: [PATCH] CLI Interface to the Sugar Datastore

2008-03-31 Thread Martin Dengler
On Thu, Mar 27, 2008 at 01:46:36AM +0100, Michael Vorburger wrote:
 Hello,
 
 Attached a patch for copy-to-journal.py which adds auto-detection of
 the MIME type! 

I asked Phil about this feature; his target audience isn't well served
by this option (if I understand his stance correctly).  I personally
find the feature quite useful and never fail to use it.

 Hope you find this useful.

Attached are two patches of mine I've sent to Phil privately:

1) does what your patch does, but using /usr/bin/file instead of
mimetypes.guess_blah.  I use file because it actually looks at the
contents instead of just the filename extension. To each his own.

2) Does what Phil seemed to see as a useful compromise: add an option
(not enabled by default) to guess the mime-type.

People may also be interested in a third, independent, patch, that
enables copy-to-journal and other support-tools to be run from without
Sugar/X; for example, screen / vt console login.  I attach it just in
case as I think Phil may merge it soon.

Apropos of that, I think Phil's trying to get the whole set of
support-scripts merged into olpc-utils, and that that would be a real
nice thing to happen.  Anyone interested in supporting that could
probably chime in with a +1 or something, which might help move that
process along.

 Regards,
 Michael

Martin
From 07cb9c739ccca7af699a268e8475e7b2f63e7f72 Mon Sep 17 00:00:00 2001
From: Martin Dengler [EMAIL PROTECTED]
Date: Tue, 25 Mar 2008 05:24:00 +
Subject: [PATCH] guess mime-type for the user if none specified

---
 copy-to-journal |   18 ++
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/copy-to-journal b/copy-to-journal
index 65eaee2..7f8b72d 100755
--- a/copy-to-journal
+++ b/copy-to-journal
@@ -75,8 +75,18 @@ if __name__ == __main__:
 parser.print_help()
 exit(0)
 
-if not options.mimetype:
-print 'Error: No MIME-type given.'
+mime_type = options.mimetype
+if not mime_type:
+# mimetypes.guess_type() just uses the extension,
+# so we use 'file' instead
+try:
+guess_from_file = os.popen(file -bi %s % fname).readlines()
+mime_type = guess_from_file[0].split(;)[0].strip()
+except Exception, e:
+raise
+
+if not mime_type:
+print 'Error: No MIME-type given (and none could be determined).'
 parser.print_help()
 exit(0)
 
@@ -85,7 +95,7 @@ if __name__ == __main__:
 entry.set_file_path(absname)
 
 # Set the mimetype to the provided one.
-entry.metadata['mime_type'] = options.mimetype
+entry.metadata['mime_type'] = mime_type
 
 # If no title is given, use the filename.
 if options.title:
@@ -104,7 +114,7 @@ if __name__ == __main__:
 entry.metadata['tags'] = tag_string
 
 datastore.write(entry)
-print 'Created as %s' % (entry.object_id)
+print 'Created %s as %s (%s)' % (fname, entry.object_id, mime_type)
 
 entry.destroy()
 
-- 
1.5.3.3

From 75c51f83c8d91c2fd35e7e99e0f7bf787b692ce7 Mon Sep 17 00:00:00 2001
From: Martin Dengler [EMAIL PROTECTED]
Date: Mon, 31 Mar 2008 10:45:14 +
Subject: [PATCH] add -g / --guess_mimetype option instead of making that 
behavior the default

---
 copy-to-journal |   33 -
 1 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/copy-to-journal b/copy-to-journal
index 2d89158..a336fba 100755
--- a/copy-to-journal
+++ b/copy-to-journal
@@ -46,7 +46,7 @@ from sugar.datastore import datastore
 
 def build_option_parser():
 
-usage = Usage: %prog file -m MIMETYPE [-t TITLE] [-d DESC] [-T tag1 [-T 
tag2 ...]]
+usage = Usage: %prog file [-m MIMETYPE|-g|--guess-mimetype] [-t TITLE] 
[-d DESC] [-T tag1 [-T tag2 ...]]
 parser = optparse.OptionParser(usage=usage)
 
 parser.add_option(-t, --title, action=store, dest=title,
@@ -60,6 +60,10 @@ def build_option_parser():
  dest=mimetype, metavar=MIMETYPE,
  help=Set the file's MIME-type to MIMETYPE,
  default=None)
+parser.add_option(-g, --guess-mimetype, action=store_true,
+ dest=guess_mimetype, metavar=GUESS_MIMETYPE,
+ help=Guess the file's MIME-type instead of requiring it to be passed to 
-m,
+ default=None)
 parser.add_option(-T, --tag, action=append, dest=tag_list,
  help=Add tag TAG to the journal entry's tags; this option can be 
repeated,
  metavar=TAG)
@@ -82,18 +86,21 @@ if __name__ == __main__:
 
 mime_type = options.mimetype
 if not mime_type:
-# mimetypes.guess_type() just uses the extension,
-# so we use 'file' instead
-try:
-guess_from_file = os.popen(file -bi %s % fname).readlines()
-mime_type = guess_from_file[0].split(;)[0].strip()
-except Exception, e:
-raise
-
-if not mime_type:
-print 'Error: No MIME-type given (and none could be determined).'
-

Re: [PATCH] CLI Interface to the Sugar Datastore

2008-03-26 Thread Michael Vorburger
Hello,

Attached a patch for copy-to-journal.py which adds auto-detection of
the MIME type! Hope you find this useful. This has been suggested in
the thread How to create a new MIME type for a Sugar activity?, and
may be elsewhere, and probably makes sense in order to make
copy-to-journal more end-user friendly.

Sorry for not providing a real git diff; this form was easier for me.
I'll get to git, promise. (Actually - how does one get a git account
on dev.laptop.org anyways? Just asking.)

Once you commit this,
http://wiki.laptop.org/go/Copy_to_and_from_the_Journal needs to be
updated. I can do it if you want after you've applied the diff to git.


A MIME stuff unrelated problem report / question: With big (e.g. 70
MB) files, I get a Error: org.freedesktop.DBus.Error.NoReply: Did not
receive a reply. Possible causes include: the remote application did
not send a reply, the message bus security policy blocked the reply,
the reply timeout expired, or the network connection was broken. from
copy-to-journal. Should some DBus timeout (what? where? how?) be
increased somehow for this to work more reliably?

Also noticed that Journal or the API isn't particularly
transactional - that's probably normal and doesn't surprised you
guys, or is this not normal? (The presumably only partially imported
file shows up in the Journal... I would have expected it not to, as
the 'import' failed with an error.)

Minor: The attached patch also has a really minor bugfix, destroy
should be in finally; found that when looking into above NoReply
Error.

Regards,
Michael


On Mon, Dec 24, 2007 at 6:14 PM, Phil Bordelon [EMAIL PROTECTED] wrote:
 Reinier Heeres wrote:
   Hi,
  
   I just added a simple script to do this to the ticket about fetching
   objects from the datastore (#5571).
  
   Please feel free to extend it!

  Thanks for proving me wrong on the complexity front. :)

  I didn't change much of your code here; I just spruced up the text to
  look more like copy-to-journal, and added comments throughout so that
  later generations of code-spelunkers can understand what the heck we
  are doing in the program.

  Thanks so much for taking the time to do this; copy-from-journal is
  easily one of the most requested features in #olpc-help.



  Phil
  ___
  Devel mailing list
  Devel@lists.laptop.org
  http://lists.laptop.org/listinfo/devel




-- 
___
Michael Vorburger
http://www.vorburger.ch


copy-to-journal.py.diff
Description: Binary data
___
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel


Re: [PATCH] CLI Interface to the Sugar Datastore

2007-12-24 Thread Phil Bordelon
Reinier Heeres wrote:
 Hi,
 
 I just added a simple script to do this to the ticket about fetching
 objects from the datastore (#5571).
 
 Please feel free to extend it!

Thanks for proving me wrong on the complexity front. :)

I didn't change much of your code here; I just spruced up the text to
look more like copy-to-journal, and added comments throughout so that
later generations of code-spelunkers can understand what the heck we
are doing in the program.

Thanks so much for taking the time to do this; copy-from-journal is
easily one of the most requested features in #olpc-help.

Phil
___
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel


Re: [PATCH] CLI Interface to the Sugar Datastore

2007-12-23 Thread Walter Bender
Is there a corresponding copy from datastore? (It sure would make
installing Java simpler for the faint of heart.)

-walter

On Dec 21, 2007 9:45 PM, Phil Bordelon [EMAIL PROTECTED] wrote:

 Hey there, folks.

 With the wonderful help of m_stone on IRC, I've managed to take a
 script I banged on (copy-to-datastore, originated by rwh) and have
 at:

http://dev.laptop.org/ticket/5571

 and put it in a Git repository, built RPMs for the ship.2 build,
 and so on.  The patch follows; the RPMs are at:

http://teach.laptop.org/~phil/

 Specifically:


 http://teach.laptop.org/~phil/sugar-datastore-0.2.2.1-0.40.20071221git.d9bf5f08e7.noarch.rpm

 http://teach.laptop.org/~phil/sugar-datastore-0.2.2.1-0.40.20071221git.d9bf5f08e7.src.rpm

 Hopefully others will find copy-to-datastore useful.

 Many thanks to m_stone for all the help in getting me to this
 point!

 Phil
 ___
 Devel mailing list
 Devel@lists.laptop.org
 http://lists.laptop.org/listinfo/devel




-- 
Walter Bender
One Laptop per Child
http://laptop.org
___
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel


Re: [PATCH] CLI Interface to the Sugar Datastore

2007-12-23 Thread Phil Bordelon
Walter Bender wrote:
 Is there a corresponding copy from datastore? (It sure would make
 installing Java simpler for the faint of heart.)

Not yet, although I have plans to work on something like that.  It's
considerably more complex, though, as the Sugar datastore is a much
more opaque beast than a UNIX filesystem.

Phil
___
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel