1
# Copyright (C) 2009, 2010 Martin Pool
3
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
# use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
# License for the specific language governing permissions and limitations
15
# Part of Tribunal <https://launchpad.net/tribunal>
18
"""Main tribunal test app object."""
28
from tribunal import (
33
from tribunal.source import (
40
class ViewSubunitApp(object):
41
"""Application object.
43
Receives events from the window.
45
# the separation of concerns from the Window is: if we later support
46
# multiple windows looking at different results, there will be just one
47
# app across all of them
50
self._event_loop = eventloop.GtkLoop()
52
def _construct_and_show_window(self):
53
glade_filename = util.sibpath(tribunal.__file__, 'ui.glade')
54
glade_xml = gtk.glade.XML(glade_filename)
55
self._window = window.SubunitWindow(glade_xml)
56
glade_xml.signal_autoconnect(self)
57
self._set_default_icons()
58
self._window.show_all()
60
def on_quit_menuitem_activate(self, widget):
61
self._event_loop.stop()
63
def on_subunit_window_destroy(self, widget):
64
self._event_loop.stop()
67
"""Run the app: create a window, load the file, handle input.
72
parser = optparse.OptionParser()
73
parser.add_option('--testr',
74
help='read from a testrepository in the given directory')
76
opts, args = parser.parse_args(argv)
79
source = TestRepositorySource(opts.testr)
81
source = FileTestSource(sys.stdin)
83
if os.path.isdir(args[0]):
84
source = TestRepositorySource(".")
86
source = FileTestSource(file(args[0], 'rb'))
87
elif os.path.exists(os.path.join(args[0], ".testr.conf")):
88
dialog = gtk.Dialog(title="No testrepository present",
90
buttons=(gtk.STOCK_YES, gtk.RESPONSE_YES,
91
gtk.STOCK_NO, gtk.RESPONSE_NO))
92
label = gtk.Label("No test repository is present. Create one?")
93
dialog.vbox.pack_start(label, True, True, 0)
97
if resp == gtk.RESPONSE_YES:
98
import testrepository.repository.file
99
factory = testrepository.repository.file.RepositoryFactory()
100
factory.initialise(".")
101
source = TestRepositorySource(".")
105
print "usage: tribunal-subunit SUBUNIT_FILE"
106
print " tribunal-subunit --testr DIR"
109
self._construct_and_show_window()
110
self._window.set_source(source)
112
stream = source.get_subunit_stream()
113
except NoStreamPresent:
116
self._window.load_from_subunit_stream(stream)
117
self._event_loop.start()
119
def _set_default_icons(self):
120
# XXX: maybe should use pkgresources?
121
icon_pixbuf = gtk.gdk.pixbuf_new_from_file(
122
os.path.join(os.path.dirname(tribunal.__file__), 'gavel_64x64.jpg'))
123
gtk.window_set_default_icon_list(icon_pixbuf)