~gary-lasker/software-center/pyflakes-fixes

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")
2112.1.1 by Martin Pitt
software-center: Import the static gobject, not the GI module, as this
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
1799 by Michael Vogt
merged from lp:~alexeftimie/software-center/fix-runlocal-appinstall
37
import glob
18 by Michael Vogt
make the installed/availabe view work
38
import logging
47 by Michael Vogt
* AppCenter/view/catview.py:
39
import os
1277 by Michael Vogt
* test/test_startup.py:
40
import time
41
import sys
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
42
330 by Michael Vogt
renamed to "Ubuntu Software Center" and software-center (LP: #436648)
43
from softwarecenter.enums import *
1487 by Michael Vogt
software-center: add missing import
44
from softwarecenter.paths import XAPIAN_BASE_PATH
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
2232.1.4 by Gary Lasker
need to enable Xapian CJK in software-center-gtk3 and software-center also
52
# Enable Xapian's CJK tokenizer (see LP: #745243)
53
os.environ['XAPIAN_CJK_NGRAM'] = '1'
54
17 by Michael Vogt
initial UI
55
if __name__ == "__main__":
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
56
867.2.56 by Kiwinote
Update man file to reflect apturl and gdebi capabilities
57
    parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]", 
284 by Michael Vogt
* setup.py:
58
                          version="%prog "+VERSION)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
59
    parser.add_option("--debug", action="store_true",
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
60
                      help="enable debug mode", default=False)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
61
    parser.add_option("--debug-filter", 
62
                      help="show only specific messages. supported currently: "
63
                           "'softwarecenter.performance'")
372 by Michael Vogt
* Merged from Matthew McGowan:
64
    parser.add_option("--force-rtl", action="store_true",
65
                      help="force rtl mode (useful for debugging)", 
66
                      default=False)
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
67
    # FIXME:  REMOVE THIS option once launchpad integration is enabled
68
    #         by default
69
    parser.add_option("--enable-lp", action="store_true",
841.1.3 by Gary Lasker
tweak help message to indicate this is a developer option
70
                      help="enable launchpad integration (for development use)", 
841.1.1 by Gary Lasker
only enable LP integration when --enable-lp at startup
71
                      default=False)
1066 by Michael Vogt
really enable buy-something by default
72
    parser.add_option("--disable-buy", action="store_true",
915.1.62 by Kiwinote
softwareware typo
73
                      help="disable support to buy software",
1066 by Michael Vogt
really enable buy-something by default
74
                      default=False)
1809 by Michael Vogt
add new optional --disable-apt-xapian-index switch
75
    parser.add_option("--disable-apt-xapian-index", action="store_true",
76
                      help="disable support for apt-xapian-index (technical items)",
77
                      default=False)
1277 by Michael Vogt
* test/test_startup.py:
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)
2095.1.1 by Michael Vogt
add --dummy-backend option, add install progress test, not quite working yet because of some dbus oddness
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)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
84
    (options, args) = parser.parse_args()
1277 by Michael Vogt
* test/test_startup.py:
85
86
    # statup time measure implies "performance" in debug filters
87
    if options.measure_startup_time:
88
        options.debug_filter = "performance"
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
89
    
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
90
    if options.debug_filter:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
91
        softwarecenter.log.add_filters_from_string(options.debug_filter)
750 by Michael Vogt
make ExecutionTime() use the softwarecenter.performance logger
92
        # implies general debug
93
        options.debug = True
94
        
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
95
    if options.debug:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
96
        softwarecenter.log.root.setLevel(level=logging.DEBUG)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
97
    else:
935 by Michael Vogt
merged lp:~hellium/software-center/logging, thanks to
98
        softwarecenter.log.root.setLevel(level=logging.INFO)
1538.2.8 by Michael Vogt
add --enable-weblive switch
99
2095.1.1 by Michael Vogt
add --dummy-backend option, add install progress test, not quite working yet because of some dbus oddness
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
372 by Michael Vogt
* Merged from Matthew McGowan:
107
    # override text direction for testing purposes
108
    if options.force_rtl:
109
        gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)
143 by Michael Vogt
merge optparse support from rugby471 (thanks!)
110
1952 by Michael Vogt
software-center: automatically set PYTOHNPATH if running in the local checkout so that the helpers will work properly
111
    # we are running in a local checkout, make life as easy as possible
112
    # for this
1912 by Michael Vogt
* data/ui/*.ui:
113
    if os.path.exists("./data/ui/gtk/SoftwareCenter.ui"):
910.1.1 by Geliy Sokolov
Fix --debug-filter and --debug options
114
        logging.getLogger("softwarecenter").info("Using data (UI, xapian) from current dir")
1952 by Michael Vogt
software-center: automatically set PYTOHNPATH if running in the local checkout so that the helpers will work properly
115
        # set pythonpath for the various helpers
2099 by Michael Vogt
* software-center:
116
        if os.environ.get("PYTHONPATH", ""):
2095 by Michael Vogt
* software-center-gtk3, software-center:
117
            os.environ["PYTHONPATH"]=os.path.abspath(".") + ":" + os.environ.get("PYTHONPATH","")
118
        else:
119
            os.environ["PYTHONPATH"]=os.path.abspath(".")
68 by Michael Vogt
add copyrights information
120
        datadir = "./data"
242.1.1 by stuart.langridge at canonical
Allow running software-store uninstalled, direct from a bzr checkout
121
        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
122
        # set new global datadir
123
        softwarecenter.paths.datadir = datadir
1798.1.1 by Alex Eftimie
temporary fix for run_local, where u-s-c is not installed
124
        # also alter the app-install path
1803 by Michael Vogt
merged from lp:~alexeftimie/software-center/fix-runlocal-appinstall
125
        path =  "%s/desktop/software-center.menu" % softwarecenter.paths.APP_INSTALL_PATH
126
        if not os.path.exists(path):
1799 by Michael Vogt
merged from lp:~alexeftimie/software-center/fix-runlocal-appinstall
127
            softwarecenter.paths.APP_INSTALL_PATH = './build/share/app-install'
1801 by Michael Vogt
software-center: really fix using the local app-install path data now
128
            logging.warn("using local APP_INSTALL_PATH: %s" % softwarecenter.paths.APP_INSTALL_PATH)
68 by Michael Vogt
add copyrights information
129
    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
130
        datadir = softwarecenter.paths.datadir
259 by Michael Vogt
merged lp:~sil/software-store/run-uninstalled, many
131
        xapian_base_path = XAPIAN_BASE_PATH
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
132
133
    # ensure we can actually run
134
    gtk.init_check()
135
1277 by Michael Vogt
* test/test_startup.py:
136
    # create the app
1899 by Michael Vogt
move softwarecenter.app softwarecenter.ui.gtk.app as its not really generic but full of gtk2 code
137
    from softwarecenter.ui.gtk.app import SoftwareCenterApp
1864.2.7 by Alex Eftimie
added Version class (to be migrated into backend-refactor). can now be tested from within gui. hacking a cache since calling resolve each time is slow
138
    from softwarecenter.utils import ExecutionTime
1864.2.22 by Alex Eftimie
now the application shows up, still can't get packages to display
139
1303.1.4 by Michael Vogt
add more with ExecutionTime() for better profiling data
140
    with ExecutionTime("create SoftwareCenterApp"):
141
        app = SoftwareCenterApp(datadir, xapian_base_path, options, args)
1277 by Michael Vogt
* test/test_startup.py:
142
143
    # DEBUG/PROFILE mode 
144
    if options.measure_startup_time:
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
145
        with ExecutionTime("show() & gtk events until visible"):
1406.1.7 by Gary Lasker
tweak the startup time measurement code
146
#            app.window_main.show_all()
1327 by Michael Vogt
software-center: add gtk.init_check() & test visible elements on the main window
147
            while gtk.events_pending():
148
                # test visible area
149
                if (app.window_main.flags() & gtk.VISIBLE and
1406.1.7 by Gary Lasker
tweak the startup time measurement code
150
                    app.available_pane.searchentry.flags() & gtk.VISIBLE and
151
                    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
152
                    break
153
                gtk.main_iteration()
1277 by Michael Vogt
* test/test_startup.py:
154
        time_to_visible = time.time() - time_entering_main
155
        print time_to_visible
156
        sys.exit(0)
157
158
    # run it normally
442 by Michael Vogt
merge lp:~rugby471/software-center/software-store-andrew,
159
    app.run(args)