2 # Copyright (C) 2009-2011 Canonical
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.
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
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
20 # take time stamp as early as python allows this
22 time_entering_main = time.time()
25 from gi.repository import Gtk, GObject
34 from softwarecenter.enums import *
35 from softwarecenter.paths import XAPIAN_BASE_PATH
36 from softwarecenter.utils import (
37 ExecutionTime, mangle_paths_if_running_in_local_checkout)
38 from softwarecenter.version import *
40 import softwarecenter.log
41 import softwarecenter.paths
43 from softwarecenter.distro import get_distro
45 from optparse import OptionParser
47 # Enable Xapian's CJK tokenizer (see LP: #745243)
48 os.environ['XAPIAN_CJK_NGRAM'] = '1'
50 LOG = logging.getLogger("softwarecenter")
52 if __name__ == "__main__":
54 parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]",
55 version="%prog "+VERSION)
56 parser.add_option("--debug", action="store_true",
57 help="enable debug mode", default=False)
58 parser.add_option("--debug-filter",
59 help="show only specific messages. supported currently: "
60 "'softwarecenter.performance'")
61 parser.add_option("--force-rtl", action="store_true",
62 help="force rtl mode (useful for debugging)",
64 parser.add_option("--display-navlog", action="store_true",
65 help="display a navigation history log (useful for debugging)",
67 # FIXME: REMOVE THIS option once launchpad integration is enabled
69 parser.add_option("--enable-lp", action="store_true",
70 help="enable launchpad integration (for development use)",
72 parser.add_option("--disable-buy", action="store_true",
73 help="disable support to buy software",
75 parser.add_option("--disable-apt-xapian-index", action="store_true",
76 help="disable support for apt-xapian-index (technical items)",
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",
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",
84 parser.add_option("--aptd-backend", action="store_true",
85 help="use APTDaemon backend)",
88 (options, args) = parser.parse_args()
90 # statup time measure implies "performance" in debug filters
91 if options.measure_startup_time:
92 options.debug_filter = "performance,traceback"
94 if options.debug_filter:
95 softwarecenter.log.add_filters_from_string(options.debug_filter)
96 # implies general debug
100 softwarecenter.log.root.setLevel(level=logging.DEBUG)
102 softwarecenter.log.root.setLevel(level=logging.INFO)
104 # Enable the PackageKit backend by default
105 softwarecenter.enums.USE_PACKAGEKIT_BACKEND = True
108 if options.aptd_backend:
109 softwarecenter.enums.USE_PACKAGEKIT_BACKEND = False
111 if softwarecenter.enums.USE_PACKAGEKIT_BACKEND:
112 logging.info("Using PackageKit backend")
114 logging.info("Using Aptdaemon backend")
117 if options.dummy_backend:
119 from softwarecenter.testutils import start_dummy_backend, stop_dummy_backend
120 start_dummy_backend()
121 atexit.register(stop_dummy_backend)
123 # Use AXI only on Debian & Ubuntu
124 distro = get_distro()
125 options.disable_apt_xapian_index = not distro.USE_AXI
127 # override text direction for testing purposes
128 if options.force_rtl:
129 Gtk.Widget.set_default_direction(Gtk.TextDirection.RTL)
131 # check if running locally
132 (datadir, xapian_base_path) = mangle_paths_if_running_in_local_checkout()
134 # ensure we can actually run
135 Gtk.init_check(sys.argv)
137 # set default ssl-ca-file here because it needs only be set once, but
138 # it can not be set in the global context as this will cause segfaults
139 # on exit. However its IMPORTANT to set it as libsoup is *not* secure
140 # by default (see bugzilla #666280 and #666276)
141 from gi.repository import WebKit as webkit
142 # enable certificates validation in webkit views unless specified otherwise
143 if not "SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK" in os.environ:
144 session = webkit.get_default_session()
145 if os.path.exists("/etc/ssl/certs/ca-certificates.crt"):
146 session.set_property("ssl-ca-file", "/etc/ssl/certs/ca-certificates.crt")
148 session.set_property("ssl-ca-file", "/etc/ssl/ca-bundle.pem")
150 # WARN the user!! Do not remove this
151 LOG.warning("SOFTWARE_CENTER_FORCE_DISABLE_CERTS_CHECK " +
152 "has been specified, all purchase transactions " +
153 "are now INSECURE and UNENCRYPTED!!")
156 from softwarecenter.ui.gtk3.app import SoftwareCenterAppGtk3
157 with ExecutionTime("create SoftwareCenterApp"):
158 app = SoftwareCenterAppGtk3(datadir, xapian_base_path, options, args)
161 if options.measure_startup_time:
162 logger = logging.getLogger("softwarecenter.performance")
163 with ExecutionTime("show() & gtk events until visible"):
164 def are_we_there_yet():
165 """ small helper that monitors the main window appearance """
167 # useful to check how often this is run - not often :/
169 if not main_visible and app.window_main.get_visible():
170 logger.debug("** main window visible after: %s seconds" % (
171 time.time() - time_entering_main))
176 # run watcher for main window
178 GObject.timeout_add(100, are_we_there_yet)
181 # keep monitoring the loop
182 while not (app.available_pane.cat_view and
183 app.available_pane.cat_view.get_visible()):
184 Gtk.main_iteration_do(True)
186 time_to_ready = time.time() - time_entering_main
188 logger.debug("** main window fully ready after: %s seconds" % time_to_ready)