gPodder 3.5.1 "Nick of Time" released
[gpodder.git] / src / gpodder / __init__.py
blobfaba65aef5b88dde2a794d5513495e0dc36d11fa
1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2013 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 # This metadata block gets parsed by setup.py - use single quotes only
21 __tagline__ = 'Media aggregator and podcast client'
22 __author__ = 'Thomas Perl <thp@gpodder.org>'
23 __version__ = '3.5.1'
24 __date__ = '2013-04-10'
25 __relname__ = 'Nick of Time'
26 __copyright__ = '© 2005-2013 Thomas Perl and the gPodder Team'
27 __license__ = 'GNU General Public License, version 3 or later'
28 __url__ = 'http://gpodder.org/'
30 __version_info__ = tuple(int(x) for x in __version__.split('.'))
32 import os
33 import sys
34 import platform
35 import gettext
36 import locale
38 # Check if real hard dependencies are available
39 try:
40 import feedparser
41 except ImportError:
42 print """
43 Error: Module "feedparser" (python-feedparser) not found.
44 The feedparser module can be downloaded from
45 http://code.google.com/p/feedparser/
46 """
47 sys.exit(1)
48 del feedparser
50 try:
51 import mygpoclient
52 except ImportError:
53 print """
54 Error: Module "mygpoclient" (python-mygpoclient) not found.
55 The mygpoclient module can be downloaded from
56 http://thp.io/2010/mygpoclient/
57 """
58 sys.exit(1)
59 del mygpoclient
61 try:
62 import sqlite3
63 except ImportError:
64 print """
65 Error: Module "sqlite3" not found.
66 Build Python with SQLite 3 support or get it from
67 http://code.google.com/p/pysqlite/
68 """
69 sys.exit(1)
70 del sqlite3
73 # The User-Agent string for downloads
74 user_agent = 'gPodder/%s (+%s)' % (__version__, __url__)
76 # Are we running in GUI, MeeGo 1.2 Harmattan or console mode?
77 class UI(object):
78 def __init__(self):
79 self.harmattan = False
80 self.sailfish = False
81 self.gtk = False
82 self.qml = False
83 self.cli = False
86 ui = UI()
88 # D-Bus specific interface names
89 dbus_bus_name = 'org.gpodder'
90 dbus_gui_object_path = '/gui'
91 dbus_podcasts_object_path = '/podcasts'
92 dbus_interface = 'org.gpodder.interface'
93 dbus_podcasts = 'org.gpodder.podcasts'
94 dbus_session_bus = None
96 # Set "win32" to True if we are on Windows
97 ui.win32 = (platform.system() == 'Windows')
98 # Set "osx" to True if we are on Mac OS X
99 ui.osx = (platform.system() == 'Darwin')
101 # i18n setup (will result in "gettext" to be available)
102 # Use _ = gpodder.gettext in modules to enable string translations
103 textdomain = 'gpodder'
104 locale_dir = gettext.bindtextdomain(textdomain)
105 t = gettext.translation(textdomain, locale_dir, fallback=True)
107 try:
108 # Python 2
109 gettext = t.ugettext
110 ngettext = t.ungettext
111 except AttributeError:
112 # Python 3
113 gettext = t.gettext
114 ngettext = t.ngettext
116 if ui.win32:
117 try:
118 # Workaround for bug 650
119 from gtk.glade import bindtextdomain
120 bindtextdomain(textdomain, locale_dir)
121 del bindtextdomain
122 except:
123 # Ignore for QML UI or missing glade module
124 pass
125 del t
127 # Set up textdomain for gtk.Builder (this accesses the C library functions)
128 if hasattr(locale, 'bindtextdomain'):
129 locale.bindtextdomain(textdomain, locale_dir)
131 del locale_dir
133 # Set up socket timeouts to fix bug 174
134 SOCKET_TIMEOUT = 60
135 import socket
136 socket.setdefaulttimeout(SOCKET_TIMEOUT)
137 del socket
138 del SOCKET_TIMEOUT
140 # Variables reserved for GUI-specific use (will be set accordingly)
141 ui_folders = []
142 credits_file = None
143 icon_file = None
144 images_folder = None
145 user_extensions = None
147 # Episode states used in the database
148 STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
150 # Paths (gPodder's home folder, config, db, download and data prefix)
151 home = None
152 config_file = None
153 database_file = None
154 downloads = None
155 prefix = None
157 ENV_HOME, ENV_DOWNLOADS = 'GPODDER_HOME', 'GPODDER_DOWNLOAD_DIR'
159 # Function to set a new gPodder home folder
160 def set_home(new_home):
161 global home, config_file, database_file, downloads
162 home = os.path.abspath(new_home)
164 config_file = os.path.join(home, 'Settings.json')
165 database_file = os.path.join(home, 'Database')
166 if ENV_DOWNLOADS not in os.environ:
167 downloads = os.path.join(home, 'Downloads')
169 # Default locations for configuration and data files
170 default_home = os.path.expanduser(os.path.join('~', 'gPodder'))
171 set_home(os.environ.get(ENV_HOME, default_home))
173 if home != default_home:
174 print >>sys.stderr, 'Storing data in', home, '(GPODDER_HOME is set)'
176 if ENV_DOWNLOADS in os.environ:
177 # Allow to relocate the downloads folder (pull request 4, bug 466)
178 downloads = os.environ[ENV_DOWNLOADS]
179 print >>sys.stderr, 'Storing downloads in %s (%s is set)' % (downloads,
180 ENV_DOWNLOADS)
182 # Plugins to load by default
183 DEFAULT_PLUGINS = [
184 'gpodder.plugins.soundcloud',
185 'gpodder.plugins.xspf',
188 def load_plugins():
189 """Load (non-essential) plugin modules
191 This loads a default set of plugins, but you can use
192 the environment variable "GPODDER_PLUGINS" to modify
193 the list of plugins."""
194 PLUGINS = os.environ.get('GPODDER_PLUGINS', None)
195 if PLUGINS is None:
196 PLUGINS = DEFAULT_PLUGINS
197 else:
198 PLUGINS = PLUGINS.split()
199 for plugin in PLUGINS:
200 try:
201 __import__(plugin)
202 except Exception, e:
203 print >>sys.stderr, 'Cannot load plugin: %s (%s)' % (plugin, e)
206 def detect_platform():
207 global ui
209 try:
210 etc_issue = open('/etc/issue').read()
211 except Exception, e:
212 etc_issue = ''
214 ui.harmattan = ('MeeGo 1.2 Harmattan' in etc_issue)
215 ui.sailfish = ('Mer release' in etc_issue)
217 if ui.harmattan and ENV_HOME not in os.environ:
218 new_home = os.path.expanduser(os.path.join('~', 'MyDocs', 'gPodder'))
219 set_home(os.path.expanduser(new_home))