New year, big checkin
[jamaendo] / jamaui / util.py
1 import os
2 import simplejson
3
4 def string_in_file( filepath, string ):
5     try:
6         f = open( filepath, 'r' )
7         found = f.read().find( string ) != -1
8         f.close()
9     except:
10         found = False
11
12     return found
13
14 def get_platform():
15     if ( os.path.exists('/etc/osso_software_version') or
16          os.path.exists('/proc/component_version') or
17          string_in_file('/etc/issue', 'maemo') ):
18         return 'maemo'
19     else:
20         return 'linux'
21
22 platform = get_platform()
23
24 def jsonprint(x):
25     print simplejson.dumps(x, sort_keys=True, indent=4)
26
27 def find_resource(name):
28     if os.path.isfile(os.path.join('data', name)):
29         return os.path.join('data', name)
30     elif os.path.isfile(os.path.join('/opt/jaemendo', name)):
31         return os.path.join('/opt/jaemendo', name)
32     elif os.path.isfile(os.path.join('/usr/share/jaemendo', name)):
33         return os.path.join('/usr/share/jaemendo', name)
34     else:
35         return None
36