~mvo/software-center/refactor

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
1694.1.1 by Michael Vogt
rewrite get_reviews to use a external helper instead of multiprocessing, this should *finally* fix #743020 for good, but its really anoying to have to workaround this issue with the accessibility layer
47
import softwarecenter.log
48
import softwarecenter.paths
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
49
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
50
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 :-] )
51
17 by Michael Vogt
initial UI
52
if __name__ == "__main__":
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
53
867.2.56 by Kiwinote
Update man file to reflect apturl and gdebi capabilities
54
    parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]", 
284 by Michael Vogt
* setup.py:
55
                          version="%prog "+VERSION)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
56
    parser.add_option("--debug", action="store_true",
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
57
                      help="enable debug mode", default=False)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
58
    parser.add_option("--debug-filter", 
59
                      help="show only specific messages. supported currently: "
60
                           "'softwarecenter.performance'")
372 by Michael Vogt
* Merged from Matthew McGowan:
61
    parser.add_option("--force-rtl", action="store_true",
62
                      help="force rtl mode (useful for debugging)", 
63
                      default=False)
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
64
    # FIXME:  REMOVE THIS option once launchpad integration is enabled
65
    #         by default
66
    parser.add_option("--enable-lp", action="store_true",
841.1.3 by Gary Lasker
tweak help message to indicate this is a developer option
67
                      help="enable launchpad integration (for development use)", 
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
68
                      default=False)
1066 by Michael Vogt
really enable buy-something by default
69
    parser.add_option("--disable-buy", action="store_true",
915.1.62 by Kiwinote
softwareware typo
70
                      help="disable support to buy software",
1066 by Michael Vogt
really enable buy-something by default
71
                      default=False)
980 by Michael Vogt
merged lp:~mvo/software-center/buy-something, currently needs to
72
1277 by Michael Vogt
* test/test_startup.py:
73
    parser.add_option("--measure-startup-time", action="store_true",
74
                      help="open and wait until the window is visible, then close, only useful for profiling",
75
                      default=False)
76
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
77
    (options, args) = parser.parse_args()
1277 by Michael Vogt
* test/test_startup.py:
78
79
    # statup time measure implies "performance" in debug filters
80
    if options.measure_startup_time:
81
        options.debug_filter = "performance"
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
82
    
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
83
    if options.debug_filter:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
84
        softwarecenter.log.add_filters_from_string(options.debug_filter)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
85
        # implies general debug
86
        options.debug = True
87
        
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
88
    if options.debug:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
89
        softwarecenter.log.root.setLevel(level=logging.DEBUG)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
90
    else:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
91
        softwarecenter.log.root.setLevel(level=logging.INFO)
1538.2.8 by Michael Vogt
add --enable-weblive switch
92
372 by Michael Vogt
* Merged from Matthew McGowan:
93
    # override text direction for testing purposes
94
    if options.force_rtl:
95
        gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
96
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
97
    if os.path.exists("./data/ui/SoftwareCenter.ui"):
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
98
        logging.getLogger("softwarecenter").info("Using data (UI, xapian) from current dir")
68 by Michael Vogt
add copyrights information
99
        datadir = "./data"
242.1.1 by stuart.langridge at canonical
Allow running software-store uninstalled, direct from a bzr checkout
100
        xapian_base_path = datadir
1694.1.1 by Michael Vogt
rewrite get_reviews to use a external helper instead of multiprocessing, this should *finally* fix #743020 for good, but its really anoying to have to workaround this issue with the accessibility layer
101
        # set new global datadir
102
        softwarecenter.paths.datadir = datadir
68 by Michael Vogt
add copyrights information
103
    else:
1694.1.1 by Michael Vogt
rewrite get_reviews to use a external helper instead of multiprocessing, this should *finally* fix #743020 for good, but its really anoying to have to workaround this issue with the accessibility layer
104
        datadir = softwarecenter.paths.datadir
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
105
        xapian_base_path = XAPIAN_BASE_PATH
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
106
107
    # ensure we can actually run
108
    gtk.init_check()
109
1277 by Michael Vogt
* test/test_startup.py:
110
    # create the app
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
111
    from softwarecenter.app import SoftwareCenterApp
1303.1.4 by Michael Vogt
add more with ExecutionTime() for better profiling data
112
    with ExecutionTime("create SoftwareCenterApp"):
113
        app = SoftwareCenterApp(datadir, xapian_base_path, options, args)
1277 by Michael Vogt
* test/test_startup.py:
114
115
    # DEBUG/PROFILE mode 
116
    if options.measure_startup_time:
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
117
        with ExecutionTime("show() & gtk events until visible"):
1406.1.7 by Gary Lasker
tweak the startup time measurement code
118
#            app.window_main.show_all()
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
119
            while gtk.events_pending():
120
                # test visible area
121
                if (app.window_main.flags() & gtk.VISIBLE and
1406.1.7 by Gary Lasker
tweak the startup time measurement code
122
                    app.available_pane.searchentry.flags() & gtk.VISIBLE and
123
                    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
124
                    break
125
                gtk.main_iteration()
1277 by Michael Vogt
* test/test_startup.py:
126
        time_to_visible = time.time() - time_entering_main
127
        print time_to_visible
128
        sys.exit(0)
129
130
    # run it normally
442 by Michael Vogt
merge lp:~rugby471/software-center/software-store-andrew,
131
    app.run(args)
17 by Michael Vogt
initial UI
132