1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#!/usr/bin/python
"""Thunk to support the low-level activity API.
Supports the following arguments:
-b, --bundle-id
Identifier of the activity bundle
-a, --activity-id
Identifier of the activity instance.
-o, --object-id
Identifier of the associated datastore object.
-u, --uri
URI to load.
As well as supporting the
http://wiki.laptop.org/go/Low-level_Activity_API"""
import os
# see http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
LANGUAGES=['af', 'ar', 'es_AR', 'mn', 'pt_BR']
"""List of languages we support. We download these language packs from
firefox upstream."""
def sanitize(lang):
"""Return one of `LANGUAGES` which is closest to the given `lang`."""
if '.' in lang: lang = lang.split('.', 1)[0] # strip off encoding if present
if lang in LANGUAGES:
return lang
else:
# try the base language.
if '_' in lang:
lang = lang.split('_', 1)[0]
if lang in LANGUAGES:
return lang
# now try an inflected lang.
valid = list(l for l in LANGUAGES if l.startswith(lang+'_'))
if valid: return valid[0] # arbitrarily chose 'first'
# nothing appropriate found; fall back to english
return "C"
def main():
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-b', '--bundle-id', dest='bundle_id', default=None,
help='Identifier of the activity bundle')
parser.add_option('-a', '--activity-id', dest='activity_id', default=None,
help='Identifier of the activity instance')
parser.add_option('-o', '--object-id', dest='object_id', default=None,
help='Identifier of the associated datastore object')
parser.add_option('-u', '--uri', dest='uri', default=None,
help='URI to load')
parser.add_option('--languages', action='store_true',
help='Print out the set of languages supported, and quit')
(options, args) = parser.parse_args()
if options.languages:
# firefox substitutes - for _
print ' '.join(l.replace('_','-') for l in LANGUAGES)
return
# XXX in the future we should do something with the -b/a/o args.
# if 'constant-uid' is enabled (stable build 758 and later),
# move $HOME down one level, to where we have persistent storage
if os.getuid() == os.getgid():
os.environ['HOME'] = os.environ['SUGAR_ACTIVITY_ROOT'] + '/data'
# sanitize LANG; firefox crashes if it sees a LANG it doesn't know.
os.environ['LANG'] = sanitize(os.environ['LANG'])+'.utf-8'
ff = [ './firefox' ]
if options.uri is not None:
ff += [ options.uri ]
print os.getgid()
os.execl(ff[0], *ff)
os.abort() # should never reach here.
if __name__ == '__main__': main ()
|