~ubuntu-core-dev/ubuntu/xenial/ubuntu-release-upgrader/xenial

« back to all changes in this revision

Viewing changes to do-partial-upgrade

  • Committer: Michael Vogt
  • Date: 2014-04-08 08:21:17 UTC
  • mto: This revision was merged to the branch mainline in revision 2794.
  • Revision ID: michael.vogt@ubuntu.com-20140408082117-u102z1y26q7xxqlf
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set
* use setup_view from DistUpgradeMain to avoid code duplication of the 
  import magic
* detect if we run with a DISPLAY and pick appropriate frontend
* use setup_logging from DistUpgradeMain to get logging and backup
  of existing file, thanks to Brian Murray  (LP: #1302380)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
from __future__ import print_function
27
27
 
28
 
from gi.repository import Gtk
29
 
import gi
30
 
gi.require_version("Gtk", "3.0")
31
 
 
32
28
import os
33
29
import sys
34
30
 
35
31
from DistUpgrade.DistUpgradeVersion import VERSION
36
32
from DistUpgrade.DistUpgradeController import DistUpgradeController
 
33
from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig
 
34
from DistUpgrade.DistUpgradeMain import (
 
35
    setup_logging,
 
36
    setup_view,
 
37
)
37
38
import locale
38
39
import gettext
39
40
 
41
42
 
42
43
if __name__ == "__main__":
43
44
 
44
 
    Gtk.init_check(sys.argv)
45
 
    Gtk.Window.set_default_icon_name("system-software-update")
46
 
 
47
45
    #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
48
46
    #       correctly, see http://bugs.python.org/issue4391
49
47
    #       Should be resolved by Python3
60
58
    except:
61
59
        pass
62
60
 
 
61
    # gtk2 used to throw a exception when it failed to init the display,
 
62
    # so back then it was safe to try to import the frontend and fallback
 
63
    # to text if the import failed. this is no longer the case so we need
 
64
    # do figure it out here :/
 
65
    if "DISPLAY" in os.environ:
 
66
        default_frontend = "DistUpgradeViewGtk3"
 
67
    else:
 
68
        default_frontend = "DistUpgradeViewText"
 
69
 
63
70
    # Begin parsing of options
64
71
    parser = OptionParser()
65
72
    parser.add_option ("-V", "--version", action="store_true",
66
73
                       dest="show_version", default=False,
67
74
                       help=_("Show version and exit"))
68
 
    parser.add_option ("--data-dir", "", 
 
75
    parser.add_option ("--data-dir", "", dest="datadir",
69
76
                       default="/usr/share/ubuntu-release-upgrader/",
70
77
                       help=_("Directory that contains the data files"))
71
 
    parser.add_option ("-f", "--frontend", default="DistUpgradeViewText",
 
78
    parser.add_option ("-f", "--frontend", default=default_frontend,
72
79
                       dest="frontend", 
73
80
                       help=_("Run the specified frontend"))
74
81
 
75
82
    (options, args) = parser.parse_args()
76
83
 
77
 
    data_dir = os.path.normpath(options.data_dir)+"/"
 
84
    datadir = os.path.normpath(options.datadir)+"/"
78
85
 
79
86
    if options.show_version:
80
87
        print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))
81
88
        sys.exit(0)
82
89
 
83
 
    module_name = "DistUpgrade." + options.frontend
84
 
    module = __import__(module_name)
85
 
    submodule = getattr(module, options.frontend)
86
 
    view_class = getattr(submodule, options.frontend)
87
 
    view = view_class(data_dir)
 
90
    # we are by definition in partial upgrade mode
 
91
    options.partial = True
 
92
    config = DistUpgradeConfig(options.datadir)
 
93
    logdir = setup_logging(options, config)
 
94
    view = setup_view(options, config, logdir)
 
95
 
88
96
    if options.frontend == "DistUpgradeViewGtk3":
 
97
        from gi.repository import Gtk
 
98
        import gi
 
99
        gi.require_version("Gtk", "3.0")
 
100
        Gtk.init_check(sys.argv)
 
101
        Gtk.Window.set_default_icon_name("system-software-update")
89
102
        view.label_title.set_markup("<b><big>%s</big></b>" %
90
103
                                    _("Running partial upgrade"))
91
 
    controller = DistUpgradeController(view, datadir=data_dir)
 
104
    controller = DistUpgradeController(view, datadir=datadir)
92
105
    controller.doPartialUpgrade()