2239.1.2
by Gary Lasker
software-center now launches the gtk3 version, add software-center-gtk2 for those times you are feeling nostalgic |
1 |
#!/usr/bin/python
|
2 |
# Copyright (C) 2009 Canonical
|
|
3 |
#
|
|
4 |
# Authors:
|
|
5 |
# Michael Vogt
|
|
6 |
#
|
|
7 |
# This program is free software; you can redistribute it and/or modify it under
|
|
8 |
# the terms of the GNU General Public License as published by the Free Software
|
|
9 |
# Foundation; version 3.
|
|
10 |
#
|
|
11 |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
14 |
# details.
|
|
15 |
#
|
|
16 |
# You should have received a copy of the GNU General Public License along with
|
|
17 |
# this program; if not, write to the Free Software Foundation, Inc.,
|
|
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
||
20 |
# take time stamp as early as python allows this
|
|
21 |
import time |
|
22 |
time_entering_main = time.time() |
|
23 |
||
24 |
||
25 |
# NOTE: although Decimal is not used in this file, we need to import it here to
|
|
26 |
# work around bug LP: #607705
|
|
27 |
from decimal import Decimal |
|
28 |
||
29 |
# thread init is also required otherwise both gst and webkit are unhappy
|
|
30 |
import pygtk |
|
31 |
pygtk.require ("2.0") |
|
32 |
import gobject |
|
33 |
gobject.threads_init() |
|
34 |
import gtk |
|
35 |
||
36 |
import gettext |
|
37 |
import glob |
|
38 |
import logging |
|
39 |
import os |
|
40 |
import time |
|
41 |
import sys |
|
42 |
||
43 |
from softwarecenter.enums import * |
|
44 |
from softwarecenter.paths import XAPIAN_BASE_PATH |
|
45 |
from softwarecenter.version import * |
|
46 |
||
47 |
import softwarecenter.log |
|
48 |
import softwarecenter.paths |
|
49 |
||
50 |
from optparse import OptionParser |
|
51 |
||
52 |
# Enable Xapian's CJK tokenizer (see LP: #745243)
|
|
53 |
os.environ['XAPIAN_CJK_NGRAM'] = '1' |
|
54 |
||
55 |
if __name__ == "__main__": |
|
56 |
||
57 |
parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]", |
|
58 |
version="%prog "+VERSION) |
|
59 |
parser.add_option("--debug", action="store_true", |
|
60 |
help="enable debug mode", default=False) |
|
61 |
parser.add_option("--debug-filter", |
|
62 |
help="show only specific messages. supported currently: " |
|
63 |
"'softwarecenter.performance'") |
|
64 |
parser.add_option("--force-rtl", action="store_true", |
|
65 |
help="force rtl mode (useful for debugging)", |
|
66 |
default=False) |
|
67 |
# FIXME: REMOVE THIS option once launchpad integration is enabled
|
|
68 |
# by default
|
|
69 |
parser.add_option("--enable-lp", action="store_true", |
|
70 |
help="enable launchpad integration (for development use)", |
|
71 |
default=False) |
|
72 |
parser.add_option("--disable-buy", action="store_true", |
|
73 |
help="disable support to buy software", |
|
74 |
default=False) |
|
75 |
parser.add_option("--disable-apt-xapian-index", action="store_true", |
|
76 |
help="disable support for apt-xapian-index (technical items)", |
|
77 |
default=False) |
|
78 |
parser.add_option("--measure-startup-time", action="store_true", |
|
79 |
help="open and wait until the window is visible, then close, only useful for profiling", |
|
80 |
default=False) |
|
81 |
parser.add_option("--dummy-backend", action="store_true", |
|
82 |
help="run with a dummy backend, this will not actually install or remove anything and is useful for testing", |
|
83 |
default=False) |
|
84 |
(options, args) = parser.parse_args() |
|
85 |
||
86 |
# statup time measure implies "performance" in debug filters
|
|
87 |
if options.measure_startup_time: |
|
88 |
options.debug_filter = "performance" |
|
89 |
||
90 |
if options.debug_filter: |
|
91 |
softwarecenter.log.add_filters_from_string(options.debug_filter) |
|
92 |
# implies general debug
|
|
93 |
options.debug = True |
|
94 |
||
95 |
if options.debug: |
|
96 |
softwarecenter.log.root.setLevel(level=logging.DEBUG) |
|
97 |
else: |
|
98 |
softwarecenter.log.root.setLevel(level=logging.INFO) |
|
99 |
||
100 |
# dummy backend
|
|
101 |
if options.dummy_backend: |
|
102 |
import atexit |
|
103 |
from softwarecenter.testutils import start_dummy_backend, stop_dummy_backend |
|
104 |
start_dummy_backend() |
|
105 |
atexit.register(stop_dummy_backend) |
|
106 |
||
107 |
# override text direction for testing purposes
|
|
108 |
if options.force_rtl: |
|
109 |
gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL) |
|
110 |
||
111 |
# we are running in a local checkout, make life as easy as possible
|
|
112 |
# for this
|
|
113 |
if os.path.exists("./data/ui/gtk/SoftwareCenter.ui"): |
|
114 |
logging.getLogger("softwarecenter").info("Using data (UI, xapian) from current dir") |
|
115 |
# set pythonpath for the various helpers
|
|
116 |
if os.environ.get("PYTHONPATH", ""): |
|
117 |
os.environ["PYTHONPATH"]=os.path.abspath(".") + ":" + os.environ.get("PYTHONPATH","") |
|
118 |
else: |
|
119 |
os.environ["PYTHONPATH"]=os.path.abspath(".") |
|
120 |
datadir = "./data" |
|
121 |
xapian_base_path = datadir |
|
122 |
# set new global datadir
|
|
123 |
softwarecenter.paths.datadir = datadir |
|
124 |
# also alter the app-install path
|
|
125 |
path = "%s/desktop/software-center.menu" % softwarecenter.paths.APP_INSTALL_PATH |
|
126 |
if not os.path.exists(path): |
|
127 |
softwarecenter.paths.APP_INSTALL_PATH = './build/share/app-install' |
|
128 |
logging.warn("using local APP_INSTALL_PATH: %s" % softwarecenter.paths.APP_INSTALL_PATH) |
|
129 |
else: |
|
130 |
datadir = softwarecenter.paths.datadir |
|
131 |
xapian_base_path = XAPIAN_BASE_PATH |
|
132 |
||
133 |
# ensure we can actually run
|
|
134 |
gtk.init_check() |
|
135 |
||
136 |
# create the app
|
|
137 |
from softwarecenter.ui.gtk.app import SoftwareCenterApp |
|
138 |
from softwarecenter.utils import ExecutionTime |
|
139 |
||
140 |
with ExecutionTime("create SoftwareCenterApp"): |
|
141 |
app = SoftwareCenterApp(datadir, xapian_base_path, options, args) |
|
142 |
||
143 |
# DEBUG/PROFILE mode
|
|
144 |
if options.measure_startup_time: |
|
145 |
with ExecutionTime("show() & gtk events until visible"): |
|
146 |
# app.window_main.show_all()
|
|
147 |
while gtk.events_pending(): |
|
148 |
# test visible area
|
|
149 |
if (app.window_main.flags() & gtk.VISIBLE and |
|
150 |
app.available_pane.searchentry.flags() & gtk.VISIBLE and |
|
151 |
app.available_pane.back_forward.flags() & gtk.VISIBLE): |
|
152 |
break
|
|
153 |
gtk.main_iteration() |
|
154 |
time_to_visible = time.time() - time_entering_main |
|
155 |
print time_to_visible |
|
156 |
sys.exit(0) |
|
157 |
||
158 |
# run it normally
|
|
159 |
app.run(args) |