-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyum-distro-sync.patch
171 lines (160 loc) · 6.24 KB
/
yum-distro-sync.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
From c2a2564c17ed302949610853fec0c32254cb9678 Mon Sep 17 00:00:00 2001
From: James Antill <[email protected]>
Date: Thu, 4 Mar 2010 17:17:30 -0500
Subject: [PATCH 1/5] Add distro-sync command, to "force update" to the latest versions.
This should be safe to go in for 3.2.27, as it's an entirely self
contained command ... I've tried it here going on multiple directions,
and it WMF(tm).
---
cli.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
yumcommands.py | 22 +++++++++++++++++++
2 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/cli.py b/cli.py
index f5ed53d..a34d205 100644
--- a/cli.py
+++ b/cli.py
@@ -100,6 +100,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
self.registerCommand(yumcommands.VersionCommand())
self.registerCommand(yumcommands.HistoryCommand())
self.registerCommand(yumcommands.CheckRpmdbCommand())
+ self.registerCommand(yumcommands.DistroSyncCommand())
def registerCommand(self, command):
for name in command.getNames():
@@ -649,6 +650,68 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
else:
return 0, [_('No Packages marked for Update')]
+ # Note that we aren't in __init__ yet for a couple of reasons, but we
+ # probably will get there for 3.2.28.
+ def distroSyncPkgs(self, userlist):
+ """ This does either upgrade/downgrade, depending on if the latest
+ installed version is older or newer. We allow "selection" but not
+ local packages (use tmprepo, or something). """
+
+ dupdates = []
+ ipkgs = {}
+ for pkg in sorted(self.rpmdb.returnPackages(patterns=userlist)):
+ ipkgs[pkg.name] = pkg
+
+ obsoletes = []
+ if self.conf.obsoletes:
+ obsoletes = self.up.getObsoletesTuples(newest=1)
+
+ for (obsoleting, installed) in obsoletes:
+ if installed[0] not in ipkgs:
+ continue
+ dupdates.extend(self.update(pkgtup=installed))
+ for (obsoleting, installed) in obsoletes:
+ if installed[0] not in ipkgs:
+ continue
+ del ipkgs[installed[0]]
+
+ apkgs = {}
+ for pkg in self.pkgSack.returnNewestByName():
+ if pkg.name not in ipkgs:
+ continue
+ apkgs[pkg.name] = pkg
+
+ for ipkgname in ipkgs:
+ if ipkgname not in apkgs:
+ continue
+
+ ipkg = ipkgs[ipkgname]
+ apkg = apkgs[ipkgname]
+ if ipkg.verEQ(apkg):
+ continue
+ if self.allowedMultipleInstalls(apkg):
+ found = False
+ for napkg in self.rpmdb.searchNames([apkg.name]):
+ if napkg.verEQ(apkg):
+ found = True
+ elif napkg.verGT(apkg):
+ dupdates.extend(self.remove(po=napkg))
+ if found:
+ continue
+ dupdates.extend(self.install(pattern=apkg.name))
+ elif ipkg.verLT(apkg):
+ n,a,e,v,r = apkg.pkgtup
+ dupdates.extend(self.update(name=n, epoch=e, ver=v, rel=r))
+ else:
+ n,a,e,v,r = apkg.pkgtup
+ dupdates.extend(self.downgrade(name=n, epoch=e, ver=v, rel=r))
+
+ if dupdates:
+ msg = _('%d packages marked for Distribution Synchronization') % len(dupdates)
+ return 2, [msg]
+ else:
+ return 0, [_('No Packages marked for Distribution Synchronization')]
+
def erasePkgs(self, userlist):
"""take user commands and populate a transaction wrapper with packages
to be erased/removed"""
diff --git a/yumcommands.py b/yumcommands.py
index 35bd97c..88c047f 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -205,6 +205,28 @@ class UpdateCommand(YumCommand):
except yum.Errors.YumBaseError, e:
return 1, [str(e)]
+class DistroSyncCommand(YumCommand):
+ def getNames(self):
+ return ['distribution-synchronization', 'distro-sync']
+
+ def getUsage(self):
+ return _("[PACKAGE...]")
+
+ def getSummary(self):
+ return _("Synchronize installed packages to the latest available versions")
+
+ def doCheck(self, base, basecmd, extcmds):
+ checkRootUID(base)
+ checkGPGKey(base)
+
+ def doCommand(self, base, basecmd, extcmds):
+ self.doneCommand(base, _("Setting up Distribution Synchronization Process"))
+ try:
+ base.conf.obsoletes = 1
+ return base.distroSyncPkgs(extcmds)
+ except yum.Errors.YumBaseError, e:
+ return 1, [str(e)]
+
def _add_pkg_simple_list_lens(data, pkg, indent=''):
""" Get the length of each pkg's column. Add that to data.
This "knows" about simpleList and printVer. """
--
1.6.6.1
From c164a1bee69cc44b665bd3197f0630b8028b3a69 Mon Sep 17 00:00:00 2001
From: James Antill <[email protected]>
Date: Thu, 11 Mar 2010 11:54:41 -0500
Subject: [PATCH 2/5] Add documentation for distro-sync command.
---
docs/yum.8 | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/docs/yum.8 b/docs/yum.8
index 8d42d9d..ff7ed8f 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -27,6 +27,8 @@ gnome\-packagekit application\&.
.br
.I \fR * upgrade [package1] [package2] [\&.\&.\&.]
.br
+.I \fR * distribution-synchronization [package1] [package2] [\&.\&.\&.]
+.br
.I \fR * remove | erase package1 [package2] [\&.\&.\&.]
.br
.I \fR * list [\&.\&.\&.]
@@ -119,6 +121,13 @@ Running in verbose mode also shows obsoletes.
Is the same as the update command with the \-\-obsoletes flag set. See update
for more details.
.IP
+.IP "\fBdistribution-synchronization\fP" "\fBdistro-sync\fP"
+Synchronizes the installed package set with the latest packages available, this
+is done by either obsoleting, upgrading or downgrading as appropriate. This will
+"normally" do the same thing as the upgrade command however if you have the
+package FOO installed at version 4, and the latest available is only
+version 3, then this command will \fBdowngrade\fP FOO to version 3.
+.IP
.IP "\fBremove\fP or \fBerase\fP"
Are used to remove the specified packages from the system
as well as removing any packages which depend on the package being
--
1.6.6.1