-
Notifications
You must be signed in to change notification settings - Fork 84
/
miro.real
executable file
·335 lines (288 loc) · 11 KB
/
miro.real
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/env python
# Miro - an RSS based video player application
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011
# Participatory Culture Foundation
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
#
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
# This comes first. Seriously.
from miro.plat import xlibhelper
if xlibhelper.XInitThreads() == 0:
print "WARNING: XInitThreads() failed!"
import os.path
import sys
import optparse
import pygtk
pygtk.require('2.0')
import glib
from miro.plat import upgrade
try:
upgrade.upgrade()
except glib.GError, ge:
# this handles when the user tries to run Miro but gconf isn't
# started or something along those lines. ge has the full
# message, so we print that out.
print "Gconf error."
print str(ge)
sys.exit(1)
usage = "usage: miro [options] [torrent files] [video files]"
parser = optparse.OptionParser(usage=usage)
parser.add_option('--version',
dest='version', action='store_true',
help='Print version info.')
parser.set_defaults(version=False)
parser.add_option('--theme',
dest='theme', metavar='<THEME>',
help='Theme to use.')
parser.add_option('--frontend',
dest='frontend', metavar='<FRONTEND>',
help='Frontend to use (widgets, cli, shell).')
parser.set_defaults(frontend="widgets")
group = optparse.OptionGroup(parser, "Settings options")
group.add_option('--list',
action="store_true",
dest="list_options",
help="Lists all preferences that can be set by command line.")
parser.set_defaults(list_options=False)
group.add_option('--set',
action="append",
dest="set_prefs",
metavar="<PREF>",
nargs=1,
help="Sets a preference and saves the new value for "
"future Miro runs. Example: miro --set renderer=gstreamer")
parser.set_defaults(set_prefs=[])
parser.add_option('--window',
dest='window',
metavar='<WINDOW>',
help='<width>x<height> dimensions for the main window.')
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Tools")
group.add_option('--convert',
dest='convert', action='store_true',
help='Command line conversion.')
parser.set_defaults(convert=False)
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Debugging options")
group.add_option('--gdb',
action='store_true',
help='Runs Miro under gdb.')
group.add_option('--debug',
dest='debugmode',
metavar='<YESNO>',
help='Puts Miro in debug mode for easier debugging.')
parser.set_defaults(debugmode="")
group.add_option('--profile',
metavar='<FILE>',
help='Write profiling information to FILE.')
group.add_option('--bias',
metavar='<BIAS>', type=float,
help='Set profiling bias to BIAS.')
parser.set_defaults(bias=None)
group.add_option('--sync',
action="store_true",
help='Use X synchronously.')
parser.set_defaults(sync=False)
group.add_option('--g-fatal-warnings',
action="store_true")
# NOTE: we don't actually do anything with g-fatal-warnings, but it gets
# picked up by the GTK code.
group.add_option('--gconf-name',
dest='gconf_name',
metavar='<NAME>',
help='Use a different name for gconf values than "miro"')
parser.set_defaults(gconf_name='miro')
group.add_option('--home',
dest='user_home',
metavar='<DIR>',
help='Like setting $HOME env var, but only in Miro')
parser.set_defaults(user_home='~/')
group.add_option('--ignore-onetime',
dest='ignore_onetime',
action='store_true',
help="Don't check if another Miro is already running.")
parser.set_defaults(ignore_onetime=False)
parser.add_option_group(group)
group = optparse.OptionGroup(parser, "Unittest options")
group.add_option('--unittest',
dest='unittest', action='store_true',
help='Run unittests instead of launching the program.')
parser.set_defaults(unittest=False)
group.add_option('-v',
dest='unittest_verbose', action='store_true',
help='Run unittests in verbose mode.')
parser.set_defaults(unittest_verbose=False)
group.add_option('--failfast',
dest='unittest_failfast', action='store_true',
help='Run unittests and stop on first failure.')
parser.set_defaults(unittest_failfast=False)
parser.add_option_group(group)
(parsed_options, args) = parser.parse_args()
# Setup gconf_name and home early on so we can load config values
from miro.plat import options
options.user_home = parsed_options.user_home
options.gconf_name = parsed_options.gconf_name
from miro.plat import utils
utils.initialize_locale()
utils.register_exec_prefix()
from miro import bootstrap
bootstrap.bootstrap()
# This fixes some/all problems with Python 2.6 support but should be
# re-addressed when we have a system with Python 2.6 to test with.
# (bug 11262)
if sys.version_info[0] == 2 and sys.version_info[1] > 5:
import miro.feedparser
import miro.storedatabase
sys.modules['feedparser'] = miro.feedparser
sys.modules['storedatabase'] = miro.storedatabase
from miro import app
from miro import prefs
from miro import commandline
from miro import startfrontend
if '--unittest' in sys.argv:
# handle this outside optparse, because unittest has its own option set
sys.argv.remove('--unittest')
import logging
logging.basicConfig(level=logging.CRITICAL)
from miro import test
test.run_tests()
sys.exit(0)
if '--convert' in sys.argv:
sys.argv.remove('--convert')
from miro.plat import clconverter
clconverter.convert(sys.argv[1:])
sys.exit(0)
def get_keyval(keyval):
key, val = keyval.split("=")
if not key in options.PREFERENCES:
print "Option '%s' does not exist." % (key)
print "Exiting...."
sys.exit(1)
p = options.PREFERENCES[key]
try:
defaulttype = type(p.default)
if defaulttype == unicode or defaulttype == str:
pass
elif defaulttype == float:
val = float(val)
elif defaulttype == int:
val = int(val)
elif defaulttype == bool:
if val[0].lower() in ["t", "y", "1"]:
val = True
else:
val = False
except Exception, e:
print "Problem converting value to correct type: %s" % e
print "Exiting...."
sys.exit(1)
return p, val
def startapp():
# set debugmode
if parsed_options.debugmode:
if parsed_options.debugmode.lower() in ("y", "yes"):
app.debugmode = True
else:
app.debugmode = False
# create miro directories in the user's home
support_dir = app.config.get(prefs.SUPPORT_DIRECTORY)
if not os.path.exists(support_dir):
os.makedirs(support_dir)
props_to_set = []
for mem in parsed_options.set_prefs:
p, val = get_keyval(mem)
props_to_set.append((p, val))
options.shouldSyncX = parsed_options.sync
options.frontend = parsed_options.frontend
if parsed_options.theme:
options.themeName = parsed_options.theme
print 'Theme is %s' % parsed_options.theme
if parsed_options.window:
try:
width, height = [int(mem) for mem in parsed_options.window.split("x")]
width = max(800, width)
height = max(600, height)
options.override_dimensions = (width, height)
except ValueError:
print "'%s' is not a valid value." % parsed_options.window
print "Usage: --window=<width>x<height>"
sys.exit(1)
commandline.set_command_line_args(args)
startfrontend.run_application(parsed_options.frontend, props_to_set,
parsed_options.theme)
def print_version():
print """
Miro (%s)
Miro comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain
conditions. See license.txt for details.
""" % app.config.get(prefs.APP_VERSION)
if parsed_options.version:
print_version()
elif parsed_options.list_options:
print_version()
print "Options that can be set:"
for p in options.PREFERENCES.values():
print " %s\n %s\n" % (p.alias, p.helptext)
elif parsed_options.profile:
import sys
try:
import cProfile as profile
sys.modules['profile'] = profile
except ImportError:
import profile
from miro import eventloop
def main():
startapp()
if parsed_options.bias:
profile.Profile.bias = parsed_options.bias
eventloop.profile_file = parsed_options.profile
profile.run('main()', parsed_options.profile)
else:
try:
import dbus
from miro.plat import onetime
try:
if not parsed_options.ignore_onetime:
onetime.OneTime()
startapp()
except dbus.NameExistsException:
bus = dbus.SessionBus()
proxy_obj = bus.get_object(
'org.participatoryculture.dtv.onetime',
'/org/participatoryculture/dtv/OneTime')
iface = dbus.Interface(
proxy_obj, 'org.participatoryculture.dtv.OneTimeIFace')
for i, arg in enumerate(args):
args[i] = arg.decode('latin1')
dbusargs = dbus.Array(args, signature="s")
try:
iface.handle_args(dbusargs)
except dbus.DBusException:
startapp()
except dbus.DBusException:
startapp()
except ImportError:
startapp()