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

2488.1.8 by Colin Watson
Switch #! lines over to python3, apart from dist-upgrader which needs to
1
#!/usr/bin/python3
454 by Michael Vogt
* do-release-upgrade:
2
2394 by Colin Watson
Use Python 3-style print functions.
3
from __future__ import print_function
4
454 by Michael Vogt
* do-release-upgrade:
5
import warnings
6
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
7
1701 by Michael Vogt
Added --version/-V to do-release-upgrade (similar to update-manager)
8
from DistUpgrade.DistUpgradeVersion import VERSION
9
455 by Michael Vogt
* split the package into update-manager and update-manager-core
10
from UpdateManager.Core.MetaRelease import MetaReleaseCore
454 by Michael Vogt
* do-release-upgrade:
11
from optparse import OptionParser
2278.1.3 by Gabor Kelemen
Fix i18n initialization.
12
import locale
2108.2.2 by Gabor Kelemen
Add gettext intialization to d-r-u, LP:775659
13
import gettext
1701 by Michael Vogt
Added --version/-V to do-release-upgrade (similar to update-manager)
14
15
import os
16
import sys
454 by Michael Vogt
* do-release-upgrade:
17
import time
2514 by Michael Terry
a couple more packaging gotchas
18
from UpdateManager.Core.utils import init_proxy
454 by Michael Vogt
* do-release-upgrade:
19
1699 by Michael Vogt
Check for release upgrade is now also possible with do-release-upgrade
20
RELEASE_AVAILABLE=0
21
NO_RELEASE_AVAILABLE=1
22
2516.1.1 by Michael Terry
allow do-release-upgrade to act with a gtk frontend, moving that code from u-m
23
24
def get_fetcher(frontend, new_dist, datadir):
25
    if frontend == "DistUpgradeViewGtk3":
26
        from DistUpgrade.DistUpgradeFetcher import DistUpgradeFetcherGtk
27
        from DistUpgrade.GtkProgress import GtkAcquireProgress
28
        progress = GtkAcquireProgress(
29
            None,
30
            datadir,
31
            _("Downloading the release upgrade tool"))
32
        return DistUpgradeFetcherGtk(new_dist=new_dist,
33
                                     progress=progress,
34
                                     parent=None,
35
                                     datadir=datadir)
36
    else:
37
        from DistUpgrade.DistUpgradeFetcherCore import DistUpgradeFetcherCore
38
        import apt
39
        progress = apt.progress.text.AcquireProgress()
2591.1.1 by Thomas Bechtold
Fix do-release-upgrade (LP: #1077938)
40
        return DistUpgradeFetcherCore(new_dist, progress)
2516.1.1 by Michael Terry
allow do-release-upgrade to act with a gtk frontend, moving that code from u-m
41
42
454 by Michael Vogt
* do-release-upgrade:
43
if __name__ == "__main__":
2278.1.3 by Gabor Kelemen
Fix i18n initialization.
44
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
45
  #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
46
  #       correctly, see http://bugs.python.org/issue4391
47
  #       Should be resolved by Python3
2444.1.2 by Michael Terry
first pass at converting update-manager source into ubuntu-release-upgrader
48
  gettext.bindtextdomain("ubuntu-release-upgrader", "/usr/share/locale")
49
  gettext.textdomain("ubuntu-release-upgrader")
2444.1.13 by Michael Terry
merge from lp:update-manager
50
  translation = gettext.translation("ubuntu-release-upgrader", fallback=True)
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
51
  if sys.version >= '3':
52
    _ = translation.gettext
53
  else:
54
    _ = translation.ugettext
2278.1.3 by Gabor Kelemen
Fix i18n initialization.
55
2108.2.2 by Gabor Kelemen
Add gettext intialization to d-r-u, LP:775659
56
  try:
57
    locale.setlocale(locale.LC_ALL, "")
58
  except:
59
    pass
454 by Michael Vogt
* do-release-upgrade:
60
1009 by Michael Vogt
* do-release-upgrade:
61
  init_proxy()
62
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
63
  # when run as "check-new-release" we go into "check only" mode
64
  check_only = sys.argv[0].endswith("check-new-release")
65
454 by Michael Vogt
* do-release-upgrade:
66
  parser = OptionParser()
1701 by Michael Vogt
Added --version/-V to do-release-upgrade (similar to update-manager)
67
  parser.add_option ("-V", "--version", action="store_true",
68
                     dest="show_version", default=False,
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
69
                     help=_("Show version and exit"))
454 by Michael Vogt
* do-release-upgrade:
70
  parser.add_option ("-d", "--devel-release", action="store_true",
71
                     dest="devel_release", default=False,
72
                     help=_("Check if upgrading to the latest devel release "
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
73
                          "is possible"))
2651 by Brian Murray
Add devel_release to options so that the fix for bug 1199157 really works
74
  parser.add_option ("--data-dir", "",
2516.1.1 by Michael Terry
allow do-release-upgrade to act with a gtk frontend, moving that code from u-m
75
                     default="/usr/share/ubuntu-release-upgrader/",
76
                     help=_("Directory that contains the data files"))
805 by Michael Vogt
* add --proposed to the options for do-release-upgrade
77
  parser.add_option ("-p", "--proposed", action="store_true",
78
                     dest="proposed_release", default=False,
79
                     help=_("Try upgrading to the latest release using "
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
80
                            "the upgrader from $distro-proposed"))
805 by Michael Vogt
* add --proposed to the options for do-release-upgrade
81
  parser.add_option ("-m", "--mode", default="server",
82
                     dest="mode", 
83
                     help=_("Run in a special upgrade mode.\n"
84
                            "Currently 'desktop' for regular upgrades of "
85
                            "a desktop system and 'server' for server "
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
86
                            "systems are supported."))
507 by Michael Vogt
* do-release-upgrade:
87
  parser.add_option ("-f", "--frontend", default="DistUpgradeViewText",
88
                     dest="frontend", 
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
89
                     help=_("Run the specified frontend"))
1170.2.8 by Michael Vogt
add --sandbox option to the dist-upgrade fetcher
90
  parser.add_option ("-s","--sandbox", action="store_true", default=False,
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
91
                     help=_("Test upgrade with a sandbox aufs overlay"))
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
92
  parser.add_option ("-c", "--check-dist-upgrade-only", action="store_true",
93
                     default=check_only,
94
                     help=_("Check only if a new distribution release is "
95
                            "available and report the result via the "
2458 by Colin Watson
Rearrange the OptionParser workaround from 1:0.154.5 to work with Python
96
                            "exit code"))
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
97
  parser.add_option ("-q", "--quiet", default=False, action="store_true",
98
                     dest="quiet")
507 by Michael Vogt
* do-release-upgrade:
99
454 by Michael Vogt
* do-release-upgrade:
100
  (options, args) = parser.parse_args()
101
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
102
1701 by Michael Vogt
Added --version/-V to do-release-upgrade (similar to update-manager)
103
  if options.show_version:
2394 by Colin Watson
Use Python 3-style print functions.
104
    print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))
1701 by Michael Vogt
Added --version/-V to do-release-upgrade (similar to update-manager)
105
    sys.exit(0)
106
2737 by Brian Murray
do-release-upgrade: indicate that -p and -d switches are mutually
107
  if options.devel_release and options.proposed_release:
108
    print(_("The options --devel-release and --proposed are"))
109
    print(_("mutually exclusive. Please use only one of them."))
110
    sys.exit(1)
111
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
112
  if not options.quiet:
2394 by Colin Watson
Use Python 3-style print functions.
113
    print(_("Checking for a new Ubuntu release"))
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
114
805 by Michael Vogt
* add --proposed to the options for do-release-upgrade
115
  m = MetaReleaseCore(useDevelopmentRelease=options.devel_release,
116
                      useProposed=options.proposed_release)
454 by Michael Vogt
* do-release-upgrade:
117
  # this will timeout eventually
2714.1.1 by Anders Kaseorg
Use new MetaReleaseCore.downloaded event
118
  m.downloaded.wait()
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
119
1963 by Michael Vogt
* do-release-upgrade:
120
  # make sure to inform the user if his distro is no longer supported
2077 by Michael Vogt
* UpdateManager/UpdateManager.py, do-release-upgrade:
121
  # this will make it appear in motd (that calls do-release-upgrade in
2648 by Brian Murray
typo fixes
122
  #  check-new-release mode)
1963 by Michael Vogt
* do-release-upgrade:
123
  if m.no_longer_supported is not None:
2077 by Michael Vogt
* UpdateManager/UpdateManager.py, do-release-upgrade:
124
    url = "http://www.ubuntu.com/releaseendoflife"
2394 by Colin Watson
Use Python 3-style print functions.
125
    print(_("Your Ubuntu release is not supported anymore."))
126
    print(_("For upgrade information, please visit:\n"
127
            "%(url)s\n") % { 'url' : url })
1963 by Michael Vogt
* do-release-upgrade:
128
129
  # now inform about a new release
454 by Michael Vogt
* do-release-upgrade:
130
  if m.new_dist is None:
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
131
    if not options.quiet:
2394 by Colin Watson
Use Python 3-style print functions.
132
      print(_("No new release found"))
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
133
    sys.exit(NO_RELEASE_AVAILABLE)
1699 by Michael Vogt
Check for release upgrade is now also possible with do-release-upgrade
134
1824 by Michael Vogt
* UpdateManager/Core/MetaRelease.py:
135
  if m.new_dist.upgrade_broken:
136
    if not options.quiet:
2394 by Colin Watson
Use Python 3-style print functions.
137
      print(_("Release upgrade not possible right now"))
138
      print(_("The release upgrade can not be performed currently, "
139
              "please try again later. The server reported: '%s'") % m.new_dist.upgrade_broken)
1824 by Michael Vogt
* UpdateManager/Core/MetaRelease.py:
140
    sys.exit(NO_RELEASE_AVAILABLE)
141
454 by Michael Vogt
* do-release-upgrade:
142
  # we have a new dist
1703 by Michael Vogt
* DistUpgrade/xorg_fix_proprietary.py:
143
  if options.check_dist_upgrade_only:
2394 by Colin Watson
Use Python 3-style print functions.
144
    print(_("New release '%s' available.") % m.new_dist.version)
145
    print(_("Run 'do-release-upgrade' to upgrade to it."))
1789 by Michael Vogt
* do-release-upgrade:
146
    sys.exit(RELEASE_AVAILABLE)
1699 by Michael Vogt
Check for release upgrade is now also possible with do-release-upgrade
147
2516.1.1 by Michael Terry
allow do-release-upgrade to act with a gtk frontend, moving that code from u-m
148
  fetcher = get_fetcher(options.frontend, m.new_dist, options.data_dir)
510 by Michael Vogt
- added option --frontend, --mode
149
  fetcher.run_options += ["--mode=%s" % options.mode,
507 by Michael Vogt
* do-release-upgrade:
150
                          "--frontend=%s" % options.frontend,
455 by Michael Vogt
* split the package into update-manager and update-manager-core
151
                          ]
1170.2.8 by Michael Vogt
add --sandbox option to the dist-upgrade fetcher
152
  if options.sandbox:
153
    fetcher.run_options.append("--sandbox")
2651 by Brian Murray
Add devel_release to options so that the fix for bug 1199157 really works
154
  if options.devel_release:
155
    fetcher.run_options.append("--devel-release")
454 by Michael Vogt
* do-release-upgrade:
156
  fetcher.run()