~mvo/software-center/refactor

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/python
# Copyright (C) 2009 Canonical
#
# Authors:
#  Michael Vogt
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# take time stamp as early as python allows this
import time
time_entering_main = time.time()


# NOTE: although Decimal is not used in this file, we need to import it here to
#       work around bug LP: #607705
from decimal import Decimal

# thread init is also required otherwise both gst and webkit are unhappy
import pygtk
pygtk.require ("2.0")
import gobject
gobject.threads_init()
import gtk

import gettext
import logging
import os
import time
import sys

from softwarecenter.enums import *
from softwarecenter.paths import XAPIAN_BASE_PATH
from softwarecenter.utils import ExecutionTime
from softwarecenter.version import *

import softwarecenter.log
import softwarecenter.paths

from optparse import OptionParser

if __name__ == "__main__":

    parser = OptionParser("usage: %prog [options] [package-name | apturl | deb-file]", 
                          version="%prog "+VERSION)
    parser.add_option("--debug", action="store_true",
                      help="enable debug mode", default=False)
    parser.add_option("--debug-filter", 
                      help="show only specific messages. supported currently: "
                           "'softwarecenter.performance'")
    parser.add_option("--force-rtl", action="store_true",
                      help="force rtl mode (useful for debugging)", 
                      default=False)
    # FIXME:  REMOVE THIS option once launchpad integration is enabled
    #         by default
    parser.add_option("--enable-lp", action="store_true",
                      help="enable launchpad integration (for development use)", 
                      default=False)
    parser.add_option("--disable-buy", action="store_true",
                      help="disable support to buy software",
                      default=False)

    parser.add_option("--measure-startup-time", action="store_true",
                      help="open and wait until the window is visible, then close, only useful for profiling",
                      default=False)

    (options, args) = parser.parse_args()

    # statup time measure implies "performance" in debug filters
    if options.measure_startup_time:
        options.debug_filter = "performance"
    
    if options.debug_filter:
        softwarecenter.log.add_filters_from_string(options.debug_filter)
        # implies general debug
        options.debug = True
        
    if options.debug:
        softwarecenter.log.root.setLevel(level=logging.DEBUG)
    else:
        softwarecenter.log.root.setLevel(level=logging.INFO)

    # override text direction for testing purposes
    if options.force_rtl:
        gtk.widget_set_default_direction(gtk.TEXT_DIR_RTL)

    if os.path.exists("./data/ui/SoftwareCenter.ui"):
        logging.getLogger("softwarecenter").info("Using data (UI, xapian) from current dir")
        datadir = "./data"
        xapian_base_path = datadir
        # set new global datadir
        softwarecenter.paths.datadir = datadir
    else:
        datadir = softwarecenter.paths.datadir
        xapian_base_path = XAPIAN_BASE_PATH

    # ensure we can actually run
    gtk.init_check()

    # create the app
    from softwarecenter.app import SoftwareCenterApp
    with ExecutionTime("create SoftwareCenterApp"):
        app = SoftwareCenterApp(datadir, xapian_base_path, options, args)

    # DEBUG/PROFILE mode 
    if options.measure_startup_time:
        with ExecutionTime("show() & gtk events until visible"):
#            app.window_main.show_all()
            while gtk.events_pending():
                # test visible area
                if (app.window_main.flags() & gtk.VISIBLE and
                    app.available_pane.searchentry.flags() & gtk.VISIBLE and
                    app.available_pane.back_forward.flags() & gtk.VISIBLE):
                    break
                gtk.main_iteration()
        time_to_visible = time.time() - time_entering_main
        print time_to_visible
        sys.exit(0)

    # run it normally
    app.run(args)