/
__init__.py
157 lines (136 loc) · 4.66 KB
/
__init__.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- coding: utf-8 -*-
#
# gPodder - A media aggregator and podcast client
# Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
#
# gPodder is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
__author__ = 'Thomas Perl <thp@gpodder.org>'
__version__ = '2.10'
__date__ = '2010-11-28'
__copyright__ = '© 2005-2010 Thomas Perl and the gPodder Team'
__licence__ = 'GNU General Public License, version 3 or later'
__url__ = 'http://gpodder.org/'
import os
import sys
import platform
import gettext
import locale
# Check if real hard dependencies are available
try:
import feedparser
except ImportError:
print """
Error: Module "feedparser" not found. Please install "python-feedparser".
The feedparser module can be downloaded from www.feedparser.org.
"""
sys.exit(1)
del feedparser
try:
import mygpoclient
except ImportError:
print """
Error: Module "mygpoclient" not found. Please install "python-mygpoclient"
or download it from http://thp.io/2010/mygpoclient/
"""
sys.exit(1)
del mygpoclient
# The User-Agent string for downloads
user_agent = 'gPodder/%s (+%s)' % (__version__, __url__)
# Are we running in GUI, Maemo or console mode?
class UI(object):
def __init__(self):
self.desktop = False
self.diablo = False
self.fremantle = False
@property
def maemo(self):
return self.diablo or self.fremantle
ui = UI()
# D-Bus specific interface names
dbus_bus_name = 'org.gpodder'
dbus_gui_object_path = '/gui'
dbus_podcasts_object_path = '/podcasts'
dbus_interface = 'org.gpodder.interface'
dbus_podcasts = 'org.gpodder.podcasts'
dbus_session_bus = None
# Set "win32" to True if we are on Windows
win32 = (platform.system() == 'Windows')
# i18n setup (will result in "gettext" to be available)
# Use _ = gpodder.gettext in modules to enable string translations
textdomain = 'gpodder'
locale_dir = gettext.bindtextdomain(textdomain)
t = gettext.translation(textdomain, locale_dir, fallback=True)
gettext = t.ugettext
ngettext = t.ungettext
if win32:
# Workaround for bug 650
from gtk.glade import bindtextdomain
bindtextdomain(textdomain, locale_dir)
del bindtextdomain
del t
# Set up textdomain for gtk.Builder (this accesses the C library functions)
if hasattr(locale, 'bindtextdomain'):
locale.bindtextdomain(textdomain, locale_dir)
else:
# On Win32, the locale module does not have bindtextdomain. We use a
# small module that provides similar functionality here (from doc/dev/).
try:
import gtkbuilderi18n
gtkbuilderi18n.bindtextdomain(textdomain, locale_dir)
except ImportError, ioe:
pass
del locale_dir
# Set up socket timeouts to fix bug 174
SOCKET_TIMEOUT = 60
import socket
socket.setdefaulttimeout(SOCKET_TIMEOUT)
del socket
del SOCKET_TIMEOUT
# Variables reserved for GUI-specific use (will be set accordingly)
ui_folders = []
credits_file = None
icon_file = None
images_folder = None
user_hooks = None
# Episode states used in the database
STATE_NORMAL, STATE_DOWNLOADED, STATE_DELETED = range(3)
# Default locations for configuration and data files
default_home = os.path.expanduser(os.path.join('~', '.config', 'gpodder'))
home = os.environ.get('GPODDER_HOME', None)
if home is None:
home = default_home
else:
print >>sys.stderr, 'Using', home, 'to store data (GPODDER_HOME is set)'
subscription_file = os.path.join(home, 'channels.opml')
config_file = os.path.join(home, 'gpodder.conf')
database_file = os.path.join(home, 'database.sqlite')
# Plugins to load by default
DEFAULT_PLUGINS = ['gpodder.soundcloud', 'gpodder.xspf']
def load_plugins():
"""Load (non-essential) plugin modules
This loads a default set of plugins, but you can use
the environment variable "GPODDER_PLUGINS" to modify
the list of plugins."""
global DEFAULT_PLUGINS
PLUGINS = os.environ.get('GPODDER_PLUGINS', None)
if PLUGINS is None:
PLUGINS = DEFAULT_PLUGINS
else:
PLUGINS = PLUGINS.split()
for plugin in PLUGINS:
try:
__import__(plugin)
except Exception, e:
print >>sys.stderr, 'Cannot load plugin: %s (%s)' % (plugin, e)