l10n: Updated Greek (el) translation to 35%
[gpodder.git] / bin / gpodder
blobeb3ecc8c114819812b56a72349c0bd21257e1daf
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
5 # gPodder - A media aggregator and podcast client
6 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
8 # gPodder is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # gPodder is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 """
23 gPodder enables you to subscribe to RSS feeds and download
24 podcast episodes from these feeds.
26 Downloaded podcasts can either be synchronized to portable
27 MP3 players (including iPods) or played back on the user's
28 desktop.
30 See gpo(1) for the command-line interface.
31 """
33 import sys
34 import os
35 import os.path
36 import platform
38 import gettext
40 import subprocess
42 try:
43 import dbus
44 import dbus.glib
45 have_dbus = True
46 except ImportError:
47 print >>sys.stderr, """
48 Warning: python-dbus not found. Disabling D-Bus support.
49 """
50 have_dbus = False
52 from optparse import OptionParser
54 if __name__ == '__main__':
55 # Paths to important files
56 gpodder_script = sys.argv[0]
57 while os.path.islink(gpodder_script):
58 gpodder_script = os.readlink(gpodder_script)
59 gpodder_dir = os.path.join(os.path.dirname(gpodder_script), '..')
60 prefix = os.path.abspath(os.path.normpath(gpodder_dir))
62 src_dir = os.path.join(prefix, 'src')
63 data_dir = os.path.join(prefix, 'data')
64 locale_dir = os.path.join(prefix, 'share', 'locale')
65 ui_folder = os.path.join(prefix, 'share', 'gpodder', 'ui')
66 credits_file = os.path.join(prefix, 'share', 'gpodder', 'credits.txt')
67 images_folder = os.path.join(prefix, 'share', 'gpodder')
68 icon_file = os.path.join(prefix, 'share', 'icons', 'hicolor', 'scalable', 'apps', 'gpodder.svg')
70 # The existence of this file tells us we're running on Maemo
71 maemo_file = os.path.join(prefix, 'share', 'applications', 'hildon', 'gpodder.desktop')
73 if os.path.exists(src_dir) and os.path.exists(data_dir) and \
74 not prefix.startswith('/usr'):
75 # Run gPodder from local source folder (not installed)
76 print >>sys.stderr, 'Using modules from', src_dir
77 sys.path.insert(0, src_dir)
78 print >>sys.stderr, 'Using resources from', data_dir
79 locale_dir = os.path.join(data_dir, 'locale')
80 ui_folder = os.path.join(data_dir, 'ui')
81 credits_file = os.path.join(data_dir, 'credits.txt')
82 images_folder = os.path.join(data_dir, 'images')
83 icon_file = os.path.join(data_dir, 'gpodder.svg')
85 # on Mac OS X, read from the defaults database the locale of the user
86 if platform.system() == 'Darwin' and 'LANG' not in os.environ:
87 locale_cmd = ('defaults', 'read', 'NSGlobalDomain', 'AppleLocale')
88 process = subprocess.Popen(locale_cmd, stdout=subprocess.PIPE)
89 output, error_output = process.communicate()
90 # the output is a string like 'fr_FR', and we need 'fr_FR.utf-8'
91 user_locale = output.strip() + '.UTF-8'
92 os.environ['LANG'] = user_locale
93 print >>sys.stderr, 'Setting locale to', user_locale
95 # Set up the path to translation files
96 gettext.bindtextdomain('gpodder', locale_dir)
98 import gpodder
100 # Enable i18n for gPodder translations
101 _ = gpodder.gettext
103 # Set up paths to folder with GtkBuilder files and gpodder.svg
104 gpodder.ui_folders.append(ui_folder)
105 gpodder.credits_file = credits_file
106 gpodder.images_folder = images_folder
107 gpodder.icon_file = icon_file
109 s_usage = 'usage: %%prog [options]\n\n%s' % ( __doc__.strip() )
110 s_version = '%%prog %s' % ( gpodder.__version__ )
112 parser = OptionParser( usage = s_usage, version = s_version)
114 parser.add_option("-v", "--verbose",
115 action="store_true", dest="verbose", default=False,
116 help=_("Print debugging output to stdout"))
118 parser.add_option("-m", "--maemo",
119 action="store_true", dest="diablo", default=False,
120 help=_("Start the Maemo 4 user interface"))
122 parser.add_option("-f", "--fremantle",
123 action="store_true", dest="fremantle", default=False,
124 help=_("Start the Maemo 5 user interface"))
126 parser.add_option('-s', '--subscribe', dest='subscribe', metavar='URL',
127 help=_('Subscribe to the given URL'))
129 # On Mac OS X, support the "psn" parameter for compatibility (bug 939)
130 if sys.platform == 'darwin':
131 parser.add_option('-p', '--psn', dest='macpsn', metavar='PSN',
132 help=_('Mac OS X application process number'))
134 (options, args) = parser.parse_args(sys.argv)
136 # Detect if we are running on Maemo 5 and if it's the case, do
137 # force the "fremantle" option on automatically, so that clueless
138 # users won't be reporting bogus bugs if they try to start gPodder
139 # from the command line without the "--fremantle" switch :)
140 if not options.fremantle and not options.diablo:
141 try:
142 etc_issue = open('/etc/issue').read()
143 if 'Maemo 5' in etc_issue:
144 options.fremantle = True
145 print >>sys.stderr, 'Auto-detected: Maemo 5 (--fremantle)'
146 elif 'Internet Tablet OS: maemo Linux based OS2008' in etc_issue:
147 options.diablo = True
148 print >>sys.stderr, 'Auto-detected: Maemo OS2008 (--maemo)'
150 del etc_issue
151 except:
152 pass
154 if options.fremantle or options.diablo:
155 gpodder.icon_file = gpodder.icon_file.replace('.svg', '.png')
157 if options.fremantle:
158 gpodder.ui.fremantle = True
159 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'frmntl'))
160 elif options.diablo or os.path.exists(maemo_file):
161 gpodder.ui.diablo = True
162 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'maemo'))
163 else:
164 gpodder.ui.desktop = True
165 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'desktop'))
167 if options.verbose:
168 from gpodder.liblogger import enable_verbose
169 enable_verbose()
171 if have_dbus:
172 # Try to find an already-running instance of gPodder
173 session_bus = dbus.SessionBus()
175 # Obtain a reference to an existing instance; don't call get_object if
176 # such an instance doesn't exist as it *will* create a new instance
177 if session_bus.name_has_owner(gpodder.dbus_bus_name):
178 try:
179 remote_object = session_bus.get_object(gpodder.dbus_bus_name, \
180 gpodder.dbus_gui_object_path)
181 except dbus.exceptions.DBusException:
182 remote_object = None
183 else:
184 remote_object = None
185 else:
186 # No D-Bus available :/
187 remote_object = None
189 if remote_object is not None:
190 # An instance of GUI is already running
191 print >>sys.stderr, 'Existing instance running - activating via D-Bus.'
192 remote_object.show_gui_window(dbus_interface=gpodder.dbus_interface)
193 if options.subscribe:
194 remote_object.subscribe_to_url(options.subscribe)
195 else:
196 # gPodder is not yet running - create new instance
197 from gpodder import gui
199 # check if we have an X11 connection (but not on Windows)
200 if platform.system() != 'Windows' and \
201 not os.environ.get('DISPLAY', None):
202 print >>sys.stderr, 'Cannot start gPodder: $DISPLAY is not set.'
203 sys.exit(1)
205 if gpodder.ui.maemo:
206 # Reduce our nice value to zero if we're on Maemo to
207 # make the tablet not kill itself while updating feeds
208 if os.nice(0) < 0:
209 os.nice(-os.nice(0))
211 gui.main(options)