Add file extension for MTP devices (bug 922)
[gpodder.git] / bin / gpodder
blob1cda1d44e278f03e5ea7999ea6f3e7ad9f3acd79
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 try:
41 import dbus
42 import dbus.glib
43 have_dbus = True
44 except ImportError:
45 print >>sys.stderr, """
46 Warning: python-dbus not found. Disabling D-Bus support.
47 """
48 have_dbus = False
50 from optparse import OptionParser
52 if __name__ == '__main__':
53 # Paths to important files
54 gpodder_script = sys.argv[0]
55 if os.path.islink(gpodder_script):
56 gpodder_script = os.readlink(gpodder_script)
57 gpodder_dir = os.path.join(os.path.dirname(gpodder_script), '..')
58 prefix = os.path.abspath(os.path.normpath(gpodder_dir))
60 src_dir = os.path.join(prefix, 'src')
61 data_dir = os.path.join(prefix, 'data')
62 locale_dir = os.path.join(prefix, 'share', 'locale')
63 ui_folder = os.path.join(prefix, 'share', 'gpodder', 'ui')
64 credits_file = os.path.join(prefix, 'share', 'gpodder', 'credits.txt')
65 images_folder = os.path.join(prefix, 'share', 'gpodder')
66 icon_file = os.path.join(prefix, 'share', 'icons', 'hicolor', 'scalable', 'apps', 'gpodder.svg')
68 # The existence of this file tells us we're running on Maemo
69 maemo_file = os.path.join(prefix, 'share', 'applications', 'hildon', 'gpodder.desktop')
71 if os.path.exists(src_dir) and os.path.exists(data_dir) and \
72 not prefix.startswith('/usr'):
73 # Run gPodder from local source folder (not installed)
74 print >>sys.stderr, 'Using modules from', src_dir
75 sys.path.insert(0, src_dir)
76 print >>sys.stderr, 'Using resources from', data_dir
77 locale_dir = os.path.join(data_dir, 'locale')
78 ui_folder = os.path.join(data_dir, 'ui')
79 credits_file = os.path.join(data_dir, 'credits.txt')
80 images_folder = os.path.join(data_dir, 'images')
81 icon_file = os.path.join(data_dir, 'gpodder.svg')
83 # Set up the path to translation files
84 gettext.bindtextdomain('gpodder', locale_dir)
86 import gpodder
88 # Enable i18n for gPodder translations
89 _ = gpodder.gettext
91 # Set up paths to folder with GtkBuilder files and gpodder.svg
92 gpodder.ui_folders.append(ui_folder)
93 gpodder.credits_file = credits_file
94 gpodder.images_folder = images_folder
95 gpodder.icon_file = icon_file
97 s_usage = 'usage: %%prog [options]\n\n%s' % ( __doc__.strip() )
98 s_version = '%%prog %s' % ( gpodder.__version__ )
100 parser = OptionParser( usage = s_usage, version = s_version)
102 parser.add_option("-v", "--verbose",
103 action="store_true", dest="verbose", default=False,
104 help=_("Print debugging output to stdout"))
106 parser.add_option("-m", "--maemo",
107 action="store_true", dest="diablo", default=False,
108 help=_("Start the Maemo 4 user interface"))
110 parser.add_option("-f", "--fremantle",
111 action="store_true", dest="fremantle", default=False,
112 help=_("Start the Maemo 5 user interface"))
114 parser.add_option('-s', '--subscribe', dest='subscribe', metavar='URL',
115 help=_('Subscribe to the given URL'))
117 (options, args) = parser.parse_args(sys.argv)
119 if options.fremantle or options.diablo:
120 gpodder.icon_file = gpodder.icon_file.replace('.svg', '.png')
122 if options.fremantle:
123 gpodder.ui.fremantle = True
124 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'frmntl'))
125 elif options.diablo or os.path.exists(maemo_file):
126 gpodder.ui.diablo = True
127 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'maemo'))
128 else:
129 gpodder.ui.desktop = True
130 gpodder.ui_folders.insert(0, os.path.join(ui_folder, 'desktop'))
132 if options.verbose:
133 from gpodder.liblogger import enable_verbose
134 enable_verbose()
136 if have_dbus:
137 # Try to find an already-running instance of gPodder
138 session_bus = dbus.SessionBus()
140 # Obtain a reference to an existing instance; don't call get_object if
141 # such an instance doesn't exist as it *will* create a new instance
142 if session_bus.name_has_owner(gpodder.dbus_bus_name):
143 try:
144 remote_object = session_bus.get_object(gpodder.dbus_bus_name, \
145 gpodder.dbus_gui_object_path)
146 except dbus.exceptions.DBusException:
147 remote_object = None
148 else:
149 remote_object = None
150 else:
151 # No D-Bus available :/
152 remote_object = None
154 if remote_object is not None:
155 # An instance of GUI is already running
156 print >>sys.stderr, 'Existing instance running - activating via D-Bus.'
157 remote_object.show_gui_window(dbus_interface=gpodder.dbus_interface)
158 if options.subscribe:
159 remote_object.subscribe_to_url(options.subscribe)
160 else:
161 # gPodder is not yet running - create new instance
162 from gpodder import gui
164 # check if we have an X11 connection (but not on Windows)
165 if platform.system() != 'Windows' and \
166 not os.environ.get('DISPLAY', None):
167 print >>sys.stderr, 'Cannot start gPodder: $DISPLAY is not set.'
168 sys.exit(1)
170 if gpodder.ui.maemo:
171 # Reduce our nice value to zero if we're on Maemo to
172 # make the tablet not kill itself while updating feeds
173 if os.nice(0) < 0:
174 os.nice(-os.nice(0))
176 gui.main(options)