4
# Miro - an RSS based video player application
5
# Copyright (C) 2005-2010 Participatory Culture Foundation
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
# In addition, as a special exception, the copyright holders give
22
# permission to link the code of portions of this program with the OpenSSL
25
# You must obey the GNU General Public License in all respects for all of
26
# the code used other than OpenSSL. If you modify file(s) with this
27
# exception, you may extend this exception to your version of the file(s),
28
# but you are not obligated to do so. If you do not wish to do so, delete
29
# this exception statement from your version. If you delete this exception
30
# statement from all source files in the program, then also delete it here.
33
# This comes first. Seriously.
34
from miro.plat import xlibhelper
35
if xlibhelper.XInitThreads() == 0:
36
print "WARNING: XInitThreads() failed!"
48
from miro.plat import upgrade
51
except glib.GError, ge:
52
# this handles when the user tries to run Miro but gconf isn't
53
# started or something along those lines. ge has the full
54
# message, so we print that out.
59
usage = "usage: %prog [options] [torrent files] [video files]"
60
parser = optparse.OptionParser(usage=usage)
61
parser.add_option('--version',
62
dest='version', action='store_true',
63
help='Print version info.')
64
parser.set_defaults(version=False)
66
parser.add_option('--theme',
67
dest='theme', metavar='<THEME>',
69
parser.add_option('--frontend',
70
dest='frontend', metavar='<FRONTEND>',
71
help='Frontend to use (widgets, cli, shell).')
72
parser.set_defaults(frontend="widgets")
74
group = optparse.OptionGroup(parser, "Settings options")
75
group.add_option('--list',
78
help="Lists all preferences that can be set by command line.")
79
parser.set_defaults(list_options=False)
80
group.add_option('--set',
85
help="Sets a preference and saves the new value for future Miro runs. Example: miro --set renderer=gstreamer")
86
parser.set_defaults(set_prefs=[])
87
parser.add_option_group(group)
89
group = optparse.OptionGroup(parser, "Debugging options")
90
group.add_option('--debug',
92
help='Starts Miro in a gdb session for better debugging.')
93
group.add_option('--unittest',
94
dest='unittest', action='store_true',
95
help='Run unittests instead of launching the program.')
96
parser.set_defaults(unittest=False)
97
group.add_option('--convert',
98
dest='convert', action='store_true',
99
help='Command line conversion.')
100
parser.set_defaults(unittest=False)
101
group.add_option('-v',
102
dest='unittest_verbose', action='store_true',
103
help='Run unittests in verbose mode.')
104
parser.set_defaults(unittest_verbose=False)
105
group.add_option('--profile',
107
help='Write profiling information to FILE.')
108
group.add_option('--bias',
109
metavar='<BIAS>', type=float,
110
help='Set profiling bias to BIAS.')
111
parser.set_defaults(bias=None)
112
group.add_option('--sync',
114
help='Use X synchronously.')
115
parser.set_defaults(sync=False)
116
group.add_option('--gconf-name',
119
help='Use a different name for gconf values than "miro"')
120
parser.set_defaults(gconf_name='miro')
121
parser.add_option_group(group)
123
(parsed_options, args) = parser.parse_args()
125
# Setup gconf_name early on so we can load config values
126
from miro.plat import options
127
options.gconf_name = parsed_options.gconf_name
129
from miro.plat import utils
130
utils.initialize_locale()
132
from miro import gtcache
135
# This fixes some/all problems with Python 2.6 support but should be
136
# re-addressed when we have a system with Python 2.6 to test with.
138
if sys.version_info[0] == 2 and sys.version_info[1] > 5:
139
import miro.feedparser
140
import miro.storedatabase
141
sys.modules['feedparser'] = miro.feedparser
142
sys.modules['storedatabase'] = miro.storedatabase
144
from miro import config
145
from miro import prefs
146
from miro import commandline
148
if '--unittest' in sys.argv:
149
# handle this outside optparse, because unittest has its own option set
150
sys.argv.remove('--unittest')
152
logging.basicConfig(level=logging.CRITICAL)
153
from miro import test
157
if '--convert' in sys.argv:
158
sys.argv.remove('--convert')
159
from miro.plat import clconverter
160
clconverter.convert(sys.argv[1:])
163
def load_frontend(globals_, locals_, frontend):
165
_temp = __import__(frontend, globals_, locals_, ['application'], -1)
166
return _temp.application
167
except ImportError, ie:
168
# this is goofy, but to quell messages that happen when
169
# trying to find which package the frontend is in
170
if "No module" not in str(ie):
171
print "ImportError on %s: %s" % (frontend, ie)
174
def startup(props_to_set):
175
frontend = parsed_options.frontend
176
goodchars = string.letters + "."
178
if c not in goodchars:
179
raise ValueError("Unknown frontend: %s" % parsed_options.frontend)
183
"miro.plat.frontends.%s" % frontend,
184
"miro.frontends.%s" % frontend,
189
application = load_frontend(globals(), locals(), att)
190
if application is not None:
193
raise ValueError("Cannot load frontend: %s" % frontend)
195
application.run_application(props_to_set, parsed_options.theme)
197
def get_keyval(keyval):
198
key, val = keyval.split("=")
199
if not key in options.PREFERENCES:
200
print "Option '%s' does not exist." % (key)
204
p = options.PREFERENCES[key]
207
defaulttype = type(p.default)
208
if defaulttype == unicode or defaulttype == str:
210
elif defaulttype == float:
212
elif defaulttype == int:
214
elif defaulttype == bool:
215
if val[0].lower() in ["t", "y", "1" ]:
220
print "Problem converting value to correct type: %s" % e
227
# Create miro directories in the user's home
228
support_dir = config.get(prefs.SUPPORT_DIRECTORY)
229
if not os.path.exists(support_dir):
230
os.makedirs(support_dir)
234
for mem in parsed_options.set_prefs:
235
p, val = get_keyval(mem)
236
props_to_set.append((p, val))
238
options.shouldSyncX = parsed_options.sync
239
options.frontend = parsed_options.frontend
240
if parsed_options.theme:
241
options.themeName = parsed_options.theme
242
print 'Theme is %s' % parsed_options.theme
244
for i in xrange(len(args)):
245
if args[i].startswith('file://'):
246
args[i] = args[i][len('file://'):]
248
commandline.set_command_line_args(args)
249
startup(props_to_set)
255
Miro comes with ABSOLUTELY NO WARRANTY.
257
This is free software, and you are welcome to redistribute it under certain
258
conditions. See license.txt for details.
259
""" % config.get(prefs.APP_VERSION)
261
if parsed_options.version:
264
elif parsed_options.list_options:
267
print "Options that can be set:"
268
for p in options.PREFERENCES.values():
269
print " %s\n %s\n" % (p.alias, p.helptext)
271
elif parsed_options.profile:
274
import cProfile as profile
275
sys.modules['profile'] = profile
278
from miro import eventloop
281
if (parsed_options.bias):
282
profile.Profile.bias = parsed_options.bias
283
eventloop.profile_file = parsed_options.profile
284
profile.run ('main()', parsed_options.profile)
289
from miro.plat import onetime
293
except dbus.NameExistsException:
294
bus = dbus.SessionBus()
295
proxy_obj = bus.get_object(
296
'org.participatoryculture.dtv.onetime',
297
'/org/participatoryculture/dtv/OneTime')
298
iface = dbus.Interface(
299
proxy_obj, 'org.participatoryculture.dtv.OneTimeIFace')
300
for i, arg in enumerate(args):
301
args[i] = arg.decode('latin1')
302
dbusargs = dbus.Array(args, signature="s")
305
iface.handle_args(dbusargs)
306
except dbus.DBusException:
308
except dbus.DBusException: