~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to utils/demotions.py

  • Committer: Michael Terry
  • Date: 2012-05-15 19:43:43 UTC
  • mto: This revision was merged to the branch mainline in revision 2428.
  • Revision ID: michael.terry@canonical.com-20120515194343-tocvo0awttmggie1
update several strings to match the software updater spec; most notably, rename from Update Manager to Software Updater

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
#
 
3
# FIXME: strip "TryExec" from the extracted menu files (and noDisplay)
 
4
#        
 
5
# TODO:
 
6
# - emacs21 ships it's icon in emacs-data, deal with this
 
7
# - some stuff needs to be blacklisted (e.g. gnome-about)
 
8
# - lots of packages have there desktop file in "-data", "-comon" (e.g. anjuta)
 
9
# - lots of packages have multiple desktop files for the same application
 
10
#   abiword, abiword-gnome, abiword-gtk
 
11
 
 
12
from __future__ import print_function
 
13
 
 
14
import os
 
15
import sys
 
16
import warnings
 
17
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
 
18
import apt
 
19
import apt_pkg
 
20
#import xdg.Menu
 
21
 
 
22
ARCHES = ["i386","amd64"]
 
23
#ARCHES = ["i386"]
 
24
 
 
25
# pkgs in main for the given dist
 
26
class Dist(object):
 
27
  def __init__(self,name):
 
28
    self.name = name
 
29
    self.pkgs_in_comp = {}
 
30
 
 
31
 
 
32
def get_replace(cache, pkgname):
 
33
  replaces = set()
 
34
  if not cache.has_key(pkgname):
 
35
    #print("can not find '%s'" % pkgname)
 
36
    return replaces
 
37
  pkg = cache[pkgname]
 
38
  ver = cache._depcache.get_candidate_ver(pkg._pkg)
 
39
  if not ver:
 
40
    return replaces
 
41
  depends = ver.depends_list
 
42
  for t in ["Replaces"]:
 
43
    if not depends.has_key(t):
 
44
      continue
 
45
    for depVerList in depends[t]:
 
46
      for depOr in depVerList:
 
47
        replaces.add(depOr.target_pkg.name)
 
48
  return replaces
 
49
 
 
50
 
 
51
if __name__ == "__main__":
 
52
 
 
53
  # init
 
54
  apt_pkg.config.set("Dir::state","./apt/")
 
55
  apt_pkg.config.set("Dir::Etc","./apt")
 
56
  apt_pkg.config.set("Dir::State::status","./apt/status")
 
57
  try:
 
58
    os.makedirs("apt/lists/partial")
 
59
  except OSError:
 
60
    pass
 
61
 
 
62
  old = Dist(sys.argv[1]) # Dist("gutsy")
 
63
  new = Dist(sys.argv[2]) # Dist("hardy")
 
64
  
 
65
  # go over the dists to find main pkgs
 
66
  for dist in [old, new]:
 
67
    
 
68
    for comp in ["main", "restricted", "universe", "multiverse"]:
 
69
      line = "deb http://archive.ubuntu.com/ubuntu %s %s\n" % (dist.name,comp)
 
70
      with open("apt/sources.list", "w") as sources_list:
 
71
        sources_list.write(line)
 
72
      dist.pkgs_in_comp[comp] = set()
 
73
 
 
74
      # and the archs
 
75
      for arch in ARCHES:
 
76
        apt_pkg.config.set("APT::Architecture",arch)
 
77
        cache = apt.Cache(apt.progress.base.OpProgress())
 
78
        prog = apt.progress.base.AcquireProgress() 
 
79
        cache.update(prog)
 
80
        cache.open(apt.progress.base.OpProgress())
 
81
        for pkg in cache:
 
82
          if ":" in pkg.name:
 
83
            continue
 
84
          dist.pkgs_in_comp[comp].add(pkg.name)
 
85
 
 
86
  # check what is no longer in main
 
87
  no_longer_main = old.pkgs_in_comp["main"] - new.pkgs_in_comp["main"]
 
88
  no_longer_main |= old.pkgs_in_comp["restricted"] - new.pkgs_in_comp["restricted"]
 
89
 
 
90
  # check what moved to universe and what was removed (or renamed)
 
91
  in_universe = lambda pkg: pkg in new.pkgs_in_comp["universe"] or pkg in new.pkgs_in_comp["multiverse"]
 
92
 
 
93
  # debug
 
94
  #print([pkg for pkg in no_longer_main if not in_universe(pkg)])
 
95
 
 
96
  # this stuff was demoted and is in universe
 
97
  demoted = [pkg for pkg in no_longer_main if in_universe(pkg)]
 
98
  demoted.sort()
 
99
 
 
100
  # remove items that are now in universe, but are replaced by something
 
101
  # in main (pidgin, gaim) etc
 
102
  #print("Looking for replaces")
 
103
  line = "deb http://archive.ubuntu.com/ubuntu %s %s\n" % (new.name, "main")
 
104
  with open("apt/sources.list", "w") as sources_list:
 
105
    sources_list.write(line)
 
106
  dist.pkgs_in_comp[comp] = set()
 
107
  for arch in ARCHES:
 
108
    apt_pkg.config.set("APT::Architecture",arch)
 
109
    cache = apt.Cache(apt.progress.base.OpProgress())
 
110
    prog = apt.progress.base.AcquireProgress() 
 
111
    cache.update(prog)
 
112
    cache.open(apt.progress.base.OpProgress())
 
113
    # go over the packages in "main" and check if they replaces something
 
114
    # that we think is a demotion
 
115
    for pkgname in new.pkgs_in_comp["main"]:
 
116
      replaces = get_replace(cache, pkgname)
 
117
      for r in replaces:
 
118
        if r in demoted:
 
119
          #print("found '%s' that is demoted but replaced by '%s'" % (r, pkgname))
 
120
          demoted.remove(r)
 
121
 
 
122
  #outfile = "demoted.cfg"
 
123
  #print("writing the demotion info to '%s'" % outfile)
 
124
  # write it out
 
125
  #out = open(outfile,"w")
 
126
  #out.write("# demoted packages\n")
 
127
  #out.write("\n".join(demoted))
 
128
  print("# demoted packages from %s to %s" % (sys.argv[1], sys.argv[2]))
 
129
  print("\n".join(demoted))