add LGPL notices
[sugaredwine.git] / bin / sugar-start-uri
blob07c9fceef6bcd1a6c8c87e4e64449ed6d03f1873
1 #!/usr/bin/env python
2 # Copyright (C) 2008, Vincent Povirk for CodeWeavers
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
19 import sys
20 import os
21 import tempfile
22 import atexit
24 from sugar import profile
25 from sugar.datastore import datastore
26 from sugar.activity.activity import show_object_in_journal
28 uri = sys.argv[1]
30 dsobject = datastore.create()
32 atexit.register(dsobject.destroy)
34 dsobject.metadata['mime_type'] = 'text/uri-list'
35 dsobject.metadata['title'] = uri
37 try:
38 urifd, urifilename = tempfile.mkstemp(dir=os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'instance'))
39 except KeyError:
40 urifd, urifilename = tempfile.mkstemp()
42 atexit.register(os.unlink, urifilename)
44 def write_data(fd, data):
45 bytes_written = 0
46 while bytes_written < len(data):
47 bytes_written += os.write(fd, data[bytes_written:])
49 write_data(urifd, '%s\r\n' % uri)
51 os.close(urifd)
53 os.chmod(urifilename, int('644', 8))
55 dsobject.file_path = urifilename
57 datastore.write(dsobject)
59 show_object_in_journal(dsobject.object_id)