~straemer/ubuntu/quantal/update-manager/fix-for-1058070

« back to all changes in this revision

Viewing changes to do-release-upgrade

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-06-29 10:59:30 UTC
  • mfrom: (389.1.2 precise-security)
  • Revision ID: package-import@ubuntu.com-20120629105930-0oaj9vdvykmvkjum
Tags: 1:0.165
* Implementation of "update on start" feature from spec
  https://wiki.ubuntu.com/SoftwareUpdates
* Use a single main window that changes instead of having modal dialogs
* Implement several special-purpose dialogs like "No updates" or
  "Dist upgrade needed" accordingn to the above spec
* Split out release upgrader code and DistUpgrade module into a separate
  source package
* Drop python-update-manager, as it is unused
* debian/tests:
  - Add dep8 tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python3
2
 
 
3
 
from __future__ import print_function
4
 
 
5
 
import warnings
6
 
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
7
 
import apt
8
 
 
9
 
from DistUpgrade.DistUpgradeVersion import VERSION
10
 
 
11
 
from UpdateManager.Core.MetaRelease import MetaReleaseCore
12
 
from UpdateManager.Core.DistUpgradeFetcherCore import DistUpgradeFetcherCore
13
 
from optparse import OptionParser
14
 
import locale
15
 
import gettext
16
 
 
17
 
import os
18
 
import sys
19
 
import time
20
 
from DistUpgrade.utils import init_proxy
21
 
 
22
 
RELEASE_AVAILABLE=0
23
 
NO_RELEASE_AVAILABLE=1
24
 
 
25
 
if __name__ == "__main__":
26
 
 
27
 
  #FIXME: Workaround a bug in optparser which doesn't handle unicode/str
28
 
  #       correctly, see http://bugs.python.org/issue4391
29
 
  #       Should be resolved by Python3
30
 
  gettext.bindtextdomain("update-manager", "/usr/share/locale")
31
 
  gettext.textdomain("update-manager")
32
 
  translation = gettext.translation("update-manager", fallback=True)
33
 
  if sys.version >= '3':
34
 
    _ = translation.gettext
35
 
  else:
36
 
    _ = translation.ugettext
37
 
 
38
 
  try:
39
 
    locale.setlocale(locale.LC_ALL, "")
40
 
  except:
41
 
    pass
42
 
 
43
 
  init_proxy()
44
 
 
45
 
  # when run as "check-new-release" we go into "check only" mode
46
 
  check_only = sys.argv[0].endswith("check-new-release")
47
 
 
48
 
  parser = OptionParser()
49
 
  parser.add_option ("-V", "--version", action="store_true",
50
 
                     dest="show_version", default=False,
51
 
                     help=_("Show version and exit"))
52
 
  parser.add_option ("-d", "--devel-release", action="store_true",
53
 
                     dest="devel_release", default=False,
54
 
                     help=_("Check if upgrading to the latest devel release "
55
 
                          "is possible"))
56
 
  parser.add_option ("-p", "--proposed", action="store_true",
57
 
                     dest="proposed_release", default=False,
58
 
                     help=_("Try upgrading to the latest release using "
59
 
                            "the upgrader from $distro-proposed"))
60
 
  parser.add_option ("-m", "--mode", default="server",
61
 
                     dest="mode", 
62
 
                     help=_("Run in a special upgrade mode.\n"
63
 
                            "Currently 'desktop' for regular upgrades of "
64
 
                            "a desktop system and 'server' for server "
65
 
                            "systems are supported."))
66
 
  parser.add_option ("-f", "--frontend", default="DistUpgradeViewText",
67
 
                     dest="frontend", 
68
 
                     help=_("Run the specified frontend"))
69
 
  parser.add_option ("-s","--sandbox", action="store_true", default=False,
70
 
                     help=_("Test upgrade with a sandbox aufs overlay"))
71
 
  parser.add_option ("-c", "--check-dist-upgrade-only", action="store_true",
72
 
                     default=check_only,
73
 
                     help=_("Check only if a new distribution release is "
74
 
                            "available and report the result via the "
75
 
                            "exit code"))
76
 
  parser.add_option ("-q", "--quiet", default=False, action="store_true",
77
 
                     dest="quiet")
78
 
 
79
 
  (options, args) = parser.parse_args()
80
 
 
81
 
 
82
 
  if options.show_version:
83
 
    print("%s: version %s" % (os.path.basename(sys.argv[0]), VERSION))
84
 
    sys.exit(0)
85
 
 
86
 
  if not options.quiet:
87
 
    print(_("Checking for a new Ubuntu release"))
88
 
 
89
 
  m = MetaReleaseCore(useDevelopmentRelease=options.devel_release,
90
 
                      useProposed=options.proposed_release)
91
 
  # this will timeout eventually
92
 
  while m.downloading:
93
 
    time.sleep(0.5)
94
 
 
95
 
  # make sure to inform the user if his distro is no longer supported
96
 
  # this will make it appear in motd (that calls do-release-upgrade in
97
 
  #  chech-new-release mode)
98
 
  if m.no_longer_supported is not None:
99
 
    url = "http://www.ubuntu.com/releaseendoflife"
100
 
    print(_("Your Ubuntu release is not supported anymore."))
101
 
    print(_("For upgrade information, please visit:\n"
102
 
            "%(url)s\n") % { 'url' : url })
103
 
 
104
 
  # now inform about a new release
105
 
  if m.new_dist is None:
106
 
    if not options.quiet:
107
 
      print(_("No new release found"))
108
 
    sys.exit(NO_RELEASE_AVAILABLE)
109
 
 
110
 
  if m.new_dist.upgrade_broken:
111
 
    if not options.quiet:
112
 
      print(_("Release upgrade not possible right now"))
113
 
      print(_("The release upgrade can not be performed currently, "
114
 
              "please try again later. The server reported: '%s'") % m.new_dist.upgrade_broken)
115
 
    sys.exit(NO_RELEASE_AVAILABLE)
116
 
 
117
 
  # we have a new dist
118
 
  if options.check_dist_upgrade_only:
119
 
    print(_("New release '%s' available.") % m.new_dist.version)
120
 
    print(_("Run 'do-release-upgrade' to upgrade to it."))
121
 
    sys.exit(RELEASE_AVAILABLE)
122
 
 
123
 
  progress = apt.progress.text.AcquireProgress()
124
 
  fetcher = DistUpgradeFetcherCore(new_dist=m.new_dist,
125
 
                                   progress=progress)
126
 
  fetcher.run_options += ["--mode=%s" % options.mode,
127
 
                          "--frontend=%s" % options.frontend,
128
 
                          ]
129
 
  if options.sandbox:
130
 
    fetcher.run_options.append("--sandbox")
131
 
  fetcher.run()