Background loading, initially implemented for search window
[jamaendo] / jamaui / util.py
1 #!/usr/bin/env python
2 #
3 # This file is part of Jamaendo.
4 # Copyright (c) 2010 Kristoffer Gronlund
5 #
6 # Jamaendo is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Jamaendo is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Jamaendo.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Player code heavily based on http://thpinfo.com/2008/panucci/:
20 #  A resuming media player for Podcasts and Audiobooks
21 #  Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
22 #  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
23 #
24 import os
25 import simplejson
26
27 def string_in_file( filepath, string ):
28     try:
29         f = open( filepath, 'r' )
30         found = f.read().find( string ) != -1
31         f.close()
32     except:
33         found = False
34
35     return found
36
37 def get_platform():
38     if ( os.path.exists('/etc/osso_software_version') or
39          os.path.exists('/proc/component_version') or
40          string_in_file('/etc/issue', 'maemo') ):
41         return 'maemo'
42     else:
43         return 'linux'
44
45 platform = get_platform()
46
47 #def jsonprint(x):
48 #    print simplejson.dumps(x, sort_keys=True, indent=4)
49
50 def find_resource(name):
51     if os.path.isfile(os.path.join('data', name)):
52         return os.path.join('data', name)
53     elif os.path.isfile(os.path.join('/opt/jamaendo', name)):
54         return os.path.join('/opt/jamaendo', name)
55     elif os.path.isfile(os.path.join('/usr/share/jamaendo', name)):
56         return os.path.join('/usr/share/jamaendo', name)
57     else:
58         return None