[Sugar-devel] Journal integration for Scratch

Bert Freudenberg bert at freudenbergs.de
Wed Jan 14 04:03:39 EST 2009


The script looks good, except for the name mangling magic (which is a  
bit hard to understand because of mis-indentations). This wouldn't  
even work with your XO's language set to non-English (which the  
majority of XOs use).

I would simply name the file "$object_id.sb".

- Bert -

On 14.01.2009, at 07:04, Philipp Kocher wrote:

> Hi John
>
> Yes, we need the mimetypes.xml file as well (thanks Tomeu I forgot  
> the USB flash drive use case). I have tested the attached  
> mimetypes.xml. It is working fine. Put it in the activity directory.
>
> Furthermore we have to change the scratch-activity script, so the  
> parameter with the scratch project object-id gets converted (copy- 
> from-journal) in a file and passed on to scratch. See the attached  
> scratch-activity script. I am not an expert with bash scripts, so  
> please give feedback.
>
> I would like to extend the script so project files in the journal  
> directory are copied back to the journal after exiting scratch, but  
> for opening project it should work fine.
>
> Best regards,
> Philipp
>
> John Maloney wrote:
>> Hi, Phillip.
>> Thanks for all your hard work in tracking this down. I had looked  
>> at several other packages, including EToys, and couldn't figure out  
>> from them how to do this.
>> I will make these changes to the next XO Scratch bundle.
>> Is that all I need to do? What about the mime types XML file  
>> similar to the one added by Etoys? Does that turn out to be  
>> unnecessary?
>>    -- John
>> On Jan 13, 2009, at 12:55 AM, Philipp Kocher wrote:
>>> Tomeu Vizoso wrote:
>>>> On Mon, Jan 12, 2009 at 18:50, Bert Freudenberg <bert at freudenbergs.de 
>>>> > wrote:
>>>>> On 12.01.2009, at 18:11, Tomeu Vizoso wrote:
>>>>>>> So what would the Scratch activity have to do so files put  
>>>>>>> into the
>>>>>>> Journal
>>>>>>> (maybe by downloading) are displayed using a Scratch icon  
>>>>>>> rather than the
>>>>>>> generic document icon?
>>>>>> Shipping a mimetypes.xml file inside the bundle as explained  
>>>>>> here:
>>>>>>
>>>>>> http://wiki.laptop.org/go/Activity_bundles#Bundle_Structure
>>>>>>
>>>>>> Sugar will call update-mime-database and will merge that file  
>>>>>> into the
>>>>>> xdg mime database.
>>>>>>
>>>>>> I think that John is already trying this.
>>>>>
>>>>> Guess I'm confused then - I thought that's exactly what Philipp  
>>>>> had done.
>>>> I think he just changed the mime_types field in the .info file.
>>>>> And I just checked and it does work with Etoys projects. When  
>>>>> downloading
>>>>> one it indeed gets an etoys icon (although at a smaller size -  
>>>>> why is that?)
>>>> No idea, though I think that the mime database is updated in the  
>>>> etoys
>>>> rpm and not in the bundle, am I right?
>>>> Regards,
>>>> Tomeu
>>>
>>> Thanks Tomeu to lead me to the /home/olpc/.local directory.  
>>> However, the
>>> mimetypes.xml is not necessary to get the icon in the journal. I  
>>> just
>>> had to copy the scratch icon file in the activity directory to
>>> "application-x-scratch-project.svg" (also in the scratch activity
>>> dirctory). The Memorize Activity is a good example for using that  
>>> feature.
>>> Sugar has to be restarted after installing Scratch to show the icon.
>>>
>>> John, could you please make the following changes in the next  
>>> Scratch
>>> version:
>>> - add the line "mime_types = application/x-scratch-project" to the
>>> activity.info file
>>> - copy the scratch icon to "application-x-scratch-project.svg" in  
>>> the
>>> activity directory
>>>
>>> Etoys gets configured by different packages. e.g. the rpm
>>> etoys-3.0.2153-1.noarch is adding the file
>>> /usr/share/mime/packges/etoys.xml and the rpm sugar- 
>>> artwork-0.82.3-1.olpc3 is
>>> adding the file
>>> /usr/share/icons/sugar/scalable/mimetypes/application-x-squake- 
>>> project.svg.
>>>
>>> Regards,
>>> Philipp
>>>
> <?xml version="1.0" encoding="UTF-8"?>
> <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info 
> ">
>   <mime-type type="application/x-scratch-project">
>     <comment>Scratch Project</comment>
>     <glob pattern="*.sb"/>
>   </mime-type>
> </mime-info>
> #!/bin/sh
> # Author: Bert Freudenberg
> # Modified by: John Maloney
> # Purpose: Run Scratch using the Squeak virtual machine
>
> echo "scratch-activity"
> echo "$@"
>
> echo "$0" "$@"
> echo
>
> # arguments are unordered, have to loop
> args=""
> while [ -n "$2" ] ; do
>    case "$1" in
>      	-b | --bundle-id)   bundle_id="$2"   ; args="$args BUNDLE_ID  
> $2" ;;
>      	-a | --activity-id) activity_id="$2" ; args="$args ACTIVITY_ID  
> $2";;
>      	-o | --object-id)   object_id="$2"   ; args="$args OBJECT_ID  
> $2";;
> 	-u | --uri)         uri="$2"         ; args="$args URI $2";;
> 	*) echo unknown argument $1 $2 ;;
>    esac
>    shift;shift
> done
>
> # really need bundle id and activity id
> if [ -z "$bundle_id" -o -z "$activity_id" ] ; then
>  echo ERROR: bundle-id and activity-id arguments required
>  echo Aborting
>  exit 1
> fi
>
> # some debug output
> echo launching $bundle_id instance $activity_id
> [ -n "$object_id" ] && echo with journal obj $object_id
> [ -n "$uri"       ] && echo loading uri $uri
> echo
>
> # do not crash on dbus errors
> export DBUS_FATAL_WARNINGS=0
>
> if [ -n "$object_id" ] ; then
> 	JOURNAL_DIR="$SUGAR_ACTIVITY_ROOT/data/Journal"
> 	mkdir -p "$JOURNAL_DIR"
> 	temp_filename="$JOURNAL_DIR/temp.sb"
> 	title=`copy-from-journal -o "$object_id" -m "$temp_filename" | grep  
> "title "`
> 	# title is something like this for files downloaded from server:
> 	#       title -> File do_math_3.sb from http://schoolserver/Scratch/do_math_3.sb 
> .
> 	# or like this if copied from USB flash drive:
> 	#       title -> do_math_3
> 	title=${title#*"title -> "} #cut off description
> 	echo "title: $title"
>
> 	# workaround for copy-from-journal bug (adds another dot before  
> fileextension)
> 	if [ -f "$JOURNAL_DIR/temp..sb" ] ; then
> 		mv "$JOURNAL_DIR/temp..sb" "$temp_filename"
> 	fi
>
> 	if [[ "$title" == File*from* ]] ; then # for files downloaded from  
> server
> 		filename=${title#*"File "} #cut off head until "File "
> 		filename=${filename%" from"*} #cut off tail from " from"
> 	        echo "filename: $filename"
>        	full_filename="$JOURNAL_DIR/$filename"
>        	echo "full_filename: $full_filename"
>        	mv "$temp_filename" "$full_filename"
> 	else # for files from USB flash drive
> 		full_filename="$JOURNAL_DIR/$title.sb"
>                echo "full_filename: $full_filename"
>                mv "$temp_filename" "$full_filename"
> 	fi
> else
> 	full_filename=""
> fi
> # run Squeak VM with Scratch image
> exec /usr/bin/squeak \
> 	-vm-display-X11 \
> 	-swapbtn \
> 	-sugarBundleId $bundle_id \
> 	-sugarActivityId $activity_id \
> 	ScratchXO.image \
> 	"$full_filename"





More information about the Sugar-devel mailing list