Check for sqlite3 dependency + update README
[gpodder.git] / src / gpodder / __init__.py
blob2fc089240621a9c65813dbcb0a90d23c82674166
1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2012 Thomas Perl and the gPodder Team
6 # gPodder 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.
11 # gPodder 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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 __author__ = 'Thomas Perl <thp@gpodder.org>'
21 __version__ = '3.0.4'
22 __date__ = '2012-01-24'
23 __relname__ = 'Weekend Vampire'
24 __copyright__ = '© 2005-2012 Thomas Perl and the gPodder Team'
25 __license__ = 'GNU General Public License, version 3 or later'
26 __url__ = 'http://gpodder.org/'
28 __version_info__ = tuple(int(x) for x in __version__.split('.'))
30 import os
31 import sys
32 import platform
33 import gettext
34 import locale
36 # Check if real hard dependencies are available
37 try:
38 import feedparser
39 except ImportError:
40 print """
41 Error: Module "feedparser" (python-feedparser) not found.
42 The feedparser module can be downloaded from
43 http://code.google.com/p/feedparser/
44 """
45 sys.exit(1)
46 del feedparser
48 try:
49 import mygpoclient
50 except ImportError:
51 print """
52 Error: Module "mygpoclient" (python-mygpoclient) not found.
53 The mygpoclient module can be downloaded from
54 http://thp.io/2010/mygpoclient/
55 """
56 sys.exit(1)
57 del mygpoclient
59 try:
60 import sqlite3
61 except ImportError:
62 print """
63 Error: Module "sqlite3" not found.
64 Build Python with SQLite 3 support or get it from
65 http://code.google.com/p/pysqlite/
66 """
67 sys.exit(1)
68 del sqlite3
71 # The User-Agent string for downloads
72 user_agent = 'gPodder/%s (+%s)' % (__version__, __url__)
74 # Are we running in GUI, Maemo or console mode?
75 class UI(object):
76 def __init__(self):
77 self.desktop = False
78 self.fremantle = False
79 self.harmattan = False
80 self.gtk = False
81 self.qml = False
82 self.cli = False
85 ui = UI()
87 # D-Bus specific interface names
88 dbus_bus_name = 'org.gpodder'
89 dbus_gui_object_path = '/gui'
90 dbus_podcasts_object_path = '/podcasts'
91 dbus_interface = 'org.gpodder.interface'
92 dbus_podcasts = 'org.gpodder.podcasts'
93 dbus_session_bus = None
95 # Set "win32" to True if we are on Windows
96 win32 = (platform.system() == 'Windows')
97 # Set "osx" to True if we are on Mac OS X
98 osx = (platform.system() == 'Darwin')
100 # i18n setup (will result in "gettext" to be available)
101 # Use _ = gpodder.gettext in modules to enable string translations
102 textdomain = 'gpodder'
103 locale_dir = gettext.bindtextdomain(textdomain)
104 t = gettext.translation(textdomain, locale_dir, fallback=True)
106 try:
107 # Python 2
108 gettext = t.ugettext
109 ngettext = t.ungettext
110 except AttributeError:
111 # Python 3
112 gettext = t.gettext
113 ngettext = t.ngettext
115 if win32:
116 try:
117 # Workaround for bug 650
118 from gtk.glade import bindtextdomain
119 bindtextdomain(textdomain, locale_dir)
120 del bindtextdomain
121 except:
122 # Ignore for QML UI or missing glade module
123 pass
124 del t
126 # Set up textdomain for gtk.Builder (this accesses the C library functions)
127 if hasattr(locale, 'bindtextdomain'):
128 locale.bindtextdomain(textdomain, locale_dir)
130 del locale_dir
132 # Set up socket timeouts to fix bug 174
133 SOCKET_TIMEOUT = 60
134 import socket
135 socket.setdefaulttimeout(SOCKET_TIMEOUT)
136 del socket
137 del SOCKET_TIMEOUT
139 # Variables reserved for GUI-specific use (will be set accordingly)
140 ui_folders = []
141 credits_file = None
142 icon_file = None
143 images_folder = None
144 user_extensions = None
146 # Episode states used in the database
147 STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
149 # Paths (gPodder's home folder, config, db and download folder)
150 home = None
151 config_file = None
152 database_file = None
153 downloads = None
155 # Function to set a new gPodder home folder
156 def set_home(new_home):
157 global home, config_file, database_file, downloads
158 home = os.path.abspath(new_home)
160 config_file = os.path.join(home, 'Settings.json')
161 database_file = os.path.join(home, 'Database')
162 downloads = os.path.join(home, 'Downloads')
164 # Default locations for configuration and data files
165 default_home = os.path.expanduser(os.path.join('~', 'gPodder'))
166 set_home(os.environ.get('GPODDER_HOME', default_home))
168 if home != default_home:
169 print >>sys.stderr, 'Storing data in', home, '(GPODDER_HOME is set)'
171 # Plugins to load by default
172 DEFAULT_PLUGINS = [
173 'gpodder.plugins.soundcloud',
174 'gpodder.plugins.xspf',
177 def load_plugins():
178 """Load (non-essential) plugin modules
180 This loads a default set of plugins, but you can use
181 the environment variable "GPODDER_PLUGINS" to modify
182 the list of plugins."""
183 PLUGINS = os.environ.get('GPODDER_PLUGINS', None)
184 if PLUGINS is None:
185 PLUGINS = DEFAULT_PLUGINS
186 else:
187 PLUGINS = PLUGINS.split()
188 for plugin in PLUGINS:
189 try:
190 __import__(plugin)
191 except Exception, e:
192 print >>sys.stderr, 'Cannot load plugin: %s (%s)' % (plugin, e)
195 def detect_platform():
196 global ui
198 try:
199 ui.fremantle = ('Maemo 5' in open('/etc/issue').read())
200 if ui.fremantle:
201 print >>sys.stderr, 'Detected platform: Maemo 5 (Fremantle)'
202 except Exception, e:
203 ui.fremantle = False
205 try:
206 ui.harmattan = ('MeeGo 1.2 Harmattan' in open('/etc/issue').read())
207 except Exception, e:
208 ui.harmattan = False
210 ui.fremantle = ui.fremantle or ui.harmattan
211 ui.desktop = not ui.fremantle and not ui.harmattan
213 if ui.fremantle and 'GPODDER_HOME' not in os.environ:
214 new_home = os.path.expanduser(os.path.join('~', 'MyDocs', 'gPodder'))
215 set_home(os.path.expanduser(new_home))