~mmcg069/software-center/Bug477285

17 by Michael Vogt
initial UI
1
#!/usr/bin/python
68 by Michael Vogt
add copyrights information
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
325 by Michael Vogt
update license to GPLv3
9
# Foundation; version 3.
68 by Michael Vogt
add copyrights information
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
17 by Michael Vogt
initial UI
19
1277 by Michael Vogt
* test/test_startup.py:
20
# take time stamp as early as python allows this
21
import time
22
time_entering_main = time.time()
23
24
915.1.118 by Kiwinote
* software-center:
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
305 by Michael Vogt
* software-store:
29
# thread init is also required otherwise both gst and webkit are unhappy
303 by Michael Vogt
software-store: add import pygtk;pygtk.require header
30
import pygtk
31
pygtk.require ("2.0")
32
import gobject
33
gobject.threads_init()
372 by Michael Vogt
* Merged from Matthew McGowan:
34
import gtk
303 by Michael Vogt
software-store: add import pygtk;pygtk.require header
35
280 by Michael Vogt
add more missing gettext glue
36
import gettext
18 by Michael Vogt
make the installed/availabe view work
37
import logging
47 by Michael Vogt
* AppCenter/view/catview.py:
38
import os
1277 by Michael Vogt
* test/test_startup.py:
39
import time
40
import sys
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
41
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
42
from softwarecenter.enums import *
1487 by Michael Vogt
software-center: add missing import
43
from softwarecenter.paths import XAPIAN_BASE_PATH
1303.1.4 by Michael Vogt
add more with ExecutionTime() for better profiling data
44
from softwarecenter.utils import ExecutionTime
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
45
from softwarecenter.version import *
910.1.2 by Geliy Sokolov
Add log.py replacement for logging
46
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
47
import softwarecenter.log 
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
48
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
49
from optparse import OptionParser
128.1.7 by Andrew
added commandline argument handling infrastructure, added error message constrcutor and half the code to handle going to a package from the commandline (hopefully mvo and supply the other half :-] )
50
17 by Michael Vogt
initial UI
51
if __name__ == "__main__":
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
52
867.2.56 by Kiwinote
Update man file to reflect apturl and gdebi capabilities
53
    parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]", 
284 by Michael Vogt
* setup.py:
54
                          version="%prog "+VERSION)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
55
    parser.add_option("--debug", action="store_true",
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
56
                      help="enable debug mode", default=False)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
57
    parser.add_option("--debug-filter", 
58
                      help="show only specific messages. supported currently: "
59
                           "'softwarecenter.performance'")
372 by Michael Vogt
* Merged from Matthew McGowan:
60
    parser.add_option("--force-rtl", action="store_true",
61
                      help="force rtl mode (useful for debugging)", 
62
                      default=False)
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
63
    # FIXME:  REMOVE THIS option once launchpad integration is enabled
64
    #         by default
65
    parser.add_option("--enable-lp", action="store_true",
841.1.3 by Gary Lasker
tweak help message to indicate this is a developer option
66
                      help="enable launchpad integration (for development use)", 
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
67
                      default=False)
1066 by Michael Vogt
really enable buy-something by default
68
    parser.add_option("--disable-buy", action="store_true",
915.1.62 by Kiwinote
softwareware typo
69
                      help="disable support to buy software",
1066 by Michael Vogt
really enable buy-something by default
70
                      default=False)
980 by Michael Vogt
merged lp:~mvo/software-center/buy-something, currently needs to
71
1538.2.8 by Michael Vogt
add --enable-weblive switch
72
    parser.add_option("--with-weblive", action="store_true",
73
                      help="enable (experimental) weblive support, this needs the qtnx pacakge",
74
                      default=False)
75
1277 by Michael Vogt
* test/test_startup.py:
76
    parser.add_option("--measure-startup-time", action="store_true",
77
                      help="open and wait until the window is visible, then close, only useful for profiling",
78
                      default=False)
79
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
80
    (options, args) = parser.parse_args()
1277 by Michael Vogt
* test/test_startup.py:
81
82
    # statup time measure implies "performance" in debug filters
83
    if options.measure_startup_time:
84
        options.debug_filter = "performance"
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
85
    
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
86
    if options.debug_filter:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
87
        softwarecenter.log.add_filters_from_string(options.debug_filter)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
88
        # implies general debug
89
        options.debug = True
90
        
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
91
    if options.debug:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
92
        softwarecenter.log.root.setLevel(level=logging.DEBUG)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
93
    else:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
94
        softwarecenter.log.root.setLevel(level=logging.INFO)
1538.2.8 by Michael Vogt
add --enable-weblive switch
95
96
    if options.with_weblive:
97
        os.environ["SOFTWARE_CENTER_ENABLE_WEBLIVE"] = "1"
372 by Michael Vogt
* Merged from Matthew McGowan:
98
    
99
    # override text direction for testing purposes
100
    if options.force_rtl:
101
        gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
102
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
103
    if os.path.exists("./data/ui/SoftwareCenter.ui"):
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
104
        logging.getLogger("softwarecenter").info("Using data (UI, xapian) from current dir")
68 by Michael Vogt
add copyrights information
105
        datadir = "./data"
242.1.1 by stuart.langridge at canonical
Allow running software-store uninstalled, direct from a bzr checkout
106
        xapian_base_path = datadir
68 by Michael Vogt
add copyrights information
107
    else:
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
108
        datadir = "/usr/share/software-center/"
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
109
        xapian_base_path = XAPIAN_BASE_PATH
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
110
111
    # ensure we can actually run
112
    gtk.init_check()
113
1277 by Michael Vogt
* test/test_startup.py:
114
    # create the app
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
115
    from softwarecenter.app import SoftwareCenterApp
1303.1.4 by Michael Vogt
add more with ExecutionTime() for better profiling data
116
    with ExecutionTime("create SoftwareCenterApp"):
117
        app = SoftwareCenterApp(datadir, xapian_base_path, options, args)
1277 by Michael Vogt
* test/test_startup.py:
118
119
    # DEBUG/PROFILE mode 
120
    if options.measure_startup_time:
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
121
        with ExecutionTime("show() & gtk events until visible"):
1406.1.7 by Gary Lasker
tweak the startup time measurement code
122
#            app.window_main.show_all()
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
123
            while gtk.events_pending():
124
                # test visible area
125
                if (app.window_main.flags() & gtk.VISIBLE and
1406.1.7 by Gary Lasker
tweak the startup time measurement code
126
                    app.available_pane.searchentry.flags() & gtk.VISIBLE and
127
                    app.available_pane.back_forward.flags() & gtk.VISIBLE):
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
128
                    break
129
                gtk.main_iteration()
1277 by Michael Vogt
* test/test_startup.py:
130
        time_to_visible = time.time() - time_entering_main
131
        print time_to_visible
132
        sys.exit(0)
133
134
    # run it normally
442 by Michael Vogt
merge lp:~rugby471/software-center/software-store-andrew,
135
    app.run(args)
17 by Michael Vogt
initial UI
136