2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
1 |
#!/usr/bin/python3
|
2 |
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
|
|
3 |
#
|
|
4 |
# Copyright (c) 2004-2012 Canonical
|
|
5 |
# 2004-2008 Michael Vogt
|
|
6 |
# 2004 Michiel Sikkes
|
|
7 |
#
|
|
8 |
# Author: Michiel Sikkes <michiel@eyesopened.nl>
|
|
9 |
# Michael Vogt <mvo@debian.org>
|
|
10 |
#
|
|
11 |
# This program is free software; you can redistribute it and/or
|
|
12 |
# modify it under the terms of the GNU General Public License as
|
|
13 |
# published by the Free Software Foundation; either version 2 of the
|
|
14 |
# License, or (at your option) any later version.
|
|
15 |
#
|
|
16 |
# This program is distributed in the hope that it will be useful,
|
|
17 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 |
# GNU General Public License for more details.
|
|
20 |
#
|
|
21 |
# You should have received a copy of the GNU General Public License
|
|
22 |
# along with this program; if not, write to the Free Software
|
|
23 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
24 |
# USA
|
|
25 |
||
26 |
from __future__ import print_function |
|
27 |
||
28 |
import os |
|
3098.1.2
by Balint Reczey
Raise privileges in do-partial-upgrade early with pkexec and apply Wayland |
29 |
import subprocess |
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
30 |
import sys |
31 |
||
32 |
from DistUpgrade.DistUpgradeVersion import VERSION |
|
33 |
from DistUpgrade.DistUpgradeController import DistUpgradeController |
|
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
34 |
from DistUpgrade.DistUpgradeConfigParser import DistUpgradeConfig |
35 |
from DistUpgrade.DistUpgradeMain import ( |
|
36 |
setup_logging, |
|
37 |
setup_view, |
|
38 |
)
|
|
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
39 |
import locale |
40 |
import gettext |
|
41 |
||
42 |
from optparse import OptionParser |
|
43 |
||
44 |
if __name__ == "__main__": |
|
45 |
||
46 |
#FIXME: Workaround a bug in optparser which doesn't handle unicode/str
|
|
47 |
# correctly, see http://bugs.python.org/issue4391
|
|
48 |
# Should be resolved by Python3
|
|
49 |
gettext.bindtextdomain("ubuntu-release-upgrader", "/usr/share/locale") |
|
50 |
gettext.textdomain("ubuntu-release-upgrader") |
|
51 |
translation = gettext.translation("ubuntu-release-upgrader", fallback=True) |
|
52 |
if sys.version >= '3': |
|
53 |
_ = translation.gettext |
|
54 |
else: |
|
55 |
_ = translation.ugettext |
|
56 |
||
57 |
try: |
|
58 |
locale.setlocale(locale.LC_ALL, "") |
|
59 |
except: |
|
60 |
pass
|
|
61 |
||
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
62 |
# gtk2 used to throw a exception when it failed to init the display,
|
63 |
# so back then it was safe to try to import the frontend and fallback
|
|
64 |
# to text if the import failed. this is no longer the case so we need
|
|
65 |
# do figure it out here :/
|
|
66 |
if "DISPLAY" in os.environ: |
|
67 |
default_frontend = "DistUpgradeViewGtk3" |
|
68 |
else: |
|
69 |
default_frontend = "DistUpgradeViewText" |
|
70 |
||
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
71 |
# Begin parsing of options
|
72 |
parser = OptionParser() |
|
73 |
parser.add_option ("-V", "--version", action="store_true", |
|
74 |
dest="show_version", default=False, |
|
75 |
help=_("Show version and exit")) |
|
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
76 |
parser.add_option ("--data-dir", "", dest="datadir", |
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
77 |
default="/usr/share/ubuntu-release-upgrader/", |
78 |
help=_("Directory that contains the data files")) |
|
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
79 |
parser.add_option ("-f", "--frontend", default=default_frontend, |
2516.1.6
by Michael Terry
make do-partial-upgrade more generic (not just gtk) and add policy kit file to provide nice text for the sudo prompt |
80 |
dest="frontend", |
81 |
help=_("Run the specified frontend")) |
|
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
82 |
|
83 |
(options, args) = parser.parse_args() |
|
84 |
||
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
85 |
datadir = os.path.normpath(options.datadir)+"/" |
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
86 |
|
87 |
if options.show_version: |
|
88 |
print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION)) |
|
89 |
sys.exit(0) |
|
90 |
||
3098.1.2
by Balint Reczey
Raise privileges in do-partial-upgrade early with pkexec and apply Wayland |
91 |
# raise privileges when not started as root
|
92 |
if os.getuid() != 0: |
|
93 |
# apply workaround for Wayland
|
|
94 |
if ((options.frontend in {"DistUpgradeViewGtk3"} and |
|
95 |
'WAYLAND_DISPLAY' in os.environ)): |
|
96 |
subprocess.run(['xhost', '+si:localuser:root']) |
|
97 |
os.execv("/usr/bin/pkexec", ["pkexec"] + sys.argv) |
|
98 |
||
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
99 |
# we are by definition in partial upgrade mode
|
100 |
options.partial = True |
|
101 |
config = DistUpgradeConfig(options.datadir) |
|
102 |
logdir = setup_logging(options, config) |
|
103 |
view = setup_view(options, config, logdir) |
|
104 |
||
2516.1.6
by Michael Terry
make do-partial-upgrade more generic (not just gtk) and add policy kit file to provide nice text for the sudo prompt |
105 |
if options.frontend == "DistUpgradeViewGtk3": |
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
106 |
from gi.repository import Gtk |
107 |
import gi |
|
108 |
gi.require_version("Gtk", "3.0") |
|
109 |
Gtk.init_check(sys.argv) |
|
110 |
Gtk.Window.set_default_icon_name("system-software-update") |
|
2516.1.6
by Michael Terry
make do-partial-upgrade more generic (not just gtk) and add policy kit file to provide nice text for the sudo prompt |
111 |
view.label_title.set_markup("<b><big>%s</big></b>" % |
112 |
_("Running partial upgrade")) |
|
2764.1.2
by Michael Vogt
* do not import Gtk in the toplevel, this will crash if DISPLAY is not set |
113 |
controller = DistUpgradeController(view, datadir=datadir) |
2516.1.2
by Michael Terry
add do-dist-upgrade and move some config files so we can pass it --data-dir |
114 |
controller.doPartialUpgrade() |