Skip to content

Commit db5be28

Browse files
committed
2 parents 1960ad8 + 3da1a10 commit db5be28

23 files changed

+514
-134
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ docs/sphinxdocs/_build
99
.project
1010
.pydevproject
1111
asthelper.completions
12+
build

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# YUM development image
2+
3+
FROM centos:7
4+
5+
# Set up EPEL
6+
RUN yum install -y \
7+
epel-release
8+
9+
# Install useful stuff
10+
RUN yum install -y \
11+
python-pip \
12+
python-ipdb \
13+
ipython \
14+
vim \
15+
less
16+
RUN rpm -e --nodeps yum
17+
RUN rm -rf /var/cache/yum
18+
RUN pip install --upgrade pip && pip install pudb
19+
20+
# Use the yum checkout mounted from the host
21+
ENV PATH=/src/bin:$PATH \
22+
PYTHONPATH=/src:$PYTHONPATH
23+
RUN ln -s /src/etc/yum.conf /etc/yum.conf
24+
RUN ln -s /src/etc/version-groups.conf /etc/yum/version-groups.conf
25+
26+
VOLUME ["/src"]
27+
ENTRYPOINT ["/bin/bash"]

Makefile

+36-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ PYTHON=python
1111
WEBHOST = yum.baseurl.org
1212
WEB_DOC_PATH = /srv/projects/yum/web/download/docs/yum-api/
1313

14+
BUILDDIR = build
15+
MOCK_CONF = epel-7-x86_64
16+
PODMAN_IMAGE = yum-devel
17+
1418
all: subdirs
1519

1620
clean:
1721
rm -f *.pyc *.pyo *~ *.bak
22+
rm -f $(BUILDDIR)/SOURCES/* $(BUILDDIR)/SRPMS/* $(BUILDDIR)/RPMS/*
23+
mock -r $(MOCK_CONF) --clean
1824
for d in $(SUBDIRS); do make -C $$d clean ; done
1925
cd test; rm -f *.pyc *.pyo *~ *.bak
2026

@@ -31,7 +37,7 @@ install:
3137
$(PYTHON) -c "import compileall; compileall.compile_dir('$(DESTDIR)/usr/share/yum-cli', 1, '/usr/share/yum-cli', 1)"
3238

3339
mkdir -p $(DESTDIR)/usr/bin $(DESTDIR)/usr/sbin
34-
install -m 755 bin/yum.py $(DESTDIR)/usr/bin/yum
40+
install -m 755 bin/yum $(DESTDIR)/usr/bin/yum
3541
install -m 755 bin/yum-updatesd.py $(DESTDIR)/usr/sbin/yum-updatesd
3642

3743
mkdir -p $(DESTDIR)/var/cache/yum
@@ -58,7 +64,7 @@ transifex:
5864
make transifex-push
5965
git commit -a -m 'Transifex push, yum.pot update'
6066

61-
.PHONY: docs test
67+
.PHONY: docs test srpm rpm shell
6268

6369
DOCS = yum rpmUtils callback.py yumcommands.py shell.py output.py cli.py utils.py\
6470
yummain.py
@@ -113,12 +119,38 @@ _archive:
113119
@rm -rf ${PKGNAME}-%{VERSION}.tar.gz
114120
@rm -rf /tmp/${PKGNAME}-$(VERSION) /tmp/${PKGNAME}
115121
@dir=$$PWD; cd /tmp; git clone $$dir ${PKGNAME}
116-
lynx -dump 'http://yum.baseurl.org/wiki/WritingYumPlugins?format=txt' > /tmp/${PKGNAME}/PLUGINS
117-
lynx -dump 'http://yum.baseurl.org/wiki/Faq?format=txt' > /tmp/${PKGNAME}/FAQ
122+
@touch /tmp/${PKGNAME}/PLUGINS
123+
@touch /tmp/${PKGNAME}/FAQ
118124
@rm -f /tmp/${PKGNAME}/$(remove_spec)
119125
@rm -rf /tmp/${PKGNAME}/.git
120126
@mv /tmp/${PKGNAME} /tmp/${PKGNAME}-$(VERSION)
121127
@dir=$$PWD; cd /tmp; tar cvzf $$dir/${PKGNAME}-$(VERSION).tar.gz ${PKGNAME}-$(VERSION)
122128
@rm -rf /tmp/${PKGNAME}-$(VERSION)
123129
@echo "The archive is in ${PKGNAME}-$(VERSION).tar.gz"
124130

131+
### RPM packaging ###
132+
133+
$(BUILDDIR):
134+
@mkdir -p $@/SOURCES $@/SRPMS $@/RPMS
135+
136+
srpm: archive $(BUILDDIR)
137+
@cp $(PKGNAME)-$(VERSION).tar.gz $(BUILDDIR)/SOURCES/
138+
@rpmbuild --define '_topdir $(BUILDDIR)' -bs yum.spec
139+
140+
rpm: srpm
141+
@mock -r $(MOCK_CONF) --resultdir=$(BUILDDIR)/RPMS \
142+
--no-clean --no-cleanup-after \
143+
$(BUILDDIR)/SRPMS/$(PKGNAME)-$(VERSION)-$(RELEASE).src.rpm
144+
@echo "The RPMs are in $(BUILDDIR)/RPMS"
145+
146+
### Container-based development ###
147+
148+
$(BUILDDIR)/image: Dockerfile $(BUILDDIR)
149+
podman build -t $(PODMAN_IMAGE) .
150+
@touch $@
151+
152+
shell: $(BUILDDIR)/image
153+
@podman run \
154+
-v=$(CURDIR):/src:ro,z \
155+
--detach-keys="ctrl-@" \
156+
-it $(PODMAN_ARGS) $(PODMAN_IMAGE) || true

README

-35
This file was deleted.

README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# YUM
2+
3+
Yum is an automatic updater and installer for rpm-based systems.
4+
5+
Included programs:
6+
7+
/usr/bin/yum Main program
8+
9+
## Usage
10+
11+
Yum is run with one of the following options:
12+
13+
* `update [package list]`
14+
15+
If run without any packages, Yum will automatically upgrade every currently
16+
installed package. If one or more packages are specified, Yum will only
17+
update the packages listed.
18+
19+
* `install <package list>`
20+
21+
Yum will install the latest version of the specified package (don't specify
22+
version information).
23+
24+
* `remove <package list>`
25+
26+
Yum will remove the specified packages from the system.
27+
28+
* `list [package list]`
29+
30+
List available packages.
31+
32+
See the man page for more information (`man yum`). Also see:
33+
34+
* web page: http://yum.baseurl.org/
35+
36+
* wiki: http://yum.baseurl.org/wiki
37+
38+
```
39+
3.2.X Branch - yum-3_2_X
40+
Starting commit is roughly: a3c91d7f6a15f31a42d020127b2da2877dfc137d
41+
E.g. git diff a3c91d7f6a15f31a42d020127b2da2877dfc137d
42+
```
43+
44+
## Building
45+
46+
You can build an RPM package by running:
47+
48+
$ make rpm
49+
50+
**Note:** Make sure you have `mock` and `lynx` installed.
51+
52+
## Development
53+
54+
You can run Yum from the current checkout in a container as follows (make sure
55+
you have the `podman` package installed):
56+
57+
$ make shell
58+
59+
This will first build a CentOS 7 image (if not built already) and then run a
60+
container with a shell where you can directly execute Yum:
61+
62+
[root@bf03d3a43cbf /] yum
63+
64+
When you edit the code on your host, the changes you make will be immediately
65+
reflected inside the container since the checkout is bind-mounted.
66+
67+
**Warning:** There's a (probably) bug in podman at the moment which makes it
68+
not see symlinks in a freshly created container, which, in turn, makes Yum not
69+
see the `/etc/yum.conf` symlink when it runs for the first time. The
70+
workaround is to `touch /etc/yum.conf` or simply re-run Yum.
71+
72+
**Note:** When you exit the container, it is not deleted but just stopped. To
73+
re-attach to it, use (replace the ID appropriately):
74+
75+
$ podman start bf03d3a43cbf
76+
$ podman attach bf03d3a43cbf

bin/yum.py renamed to bin/yum

File renamed without changes.

cli.py

+65-19
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from optparse import OptionParser,OptionGroup,SUPPRESS_HELP
3030
import rpm
3131
import ctypes
32+
import glob
3233

3334
from weakref import proxy as weakref
3435

@@ -1747,26 +1748,10 @@ def cleanCli(self, userlist):
17471748
msg = self.fmtKeyValFill(_('Cleaning repos: '),
17481749
' '.join([ x.id for x in self.repos.listEnabled()]))
17491750
self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
1751+
msg = (_('Operating on %s (see CLEAN OPTIONS in yum(8) for details)')
1752+
% self.conf.cachedir)
1753+
self.verbose_logger.log(yum.logginglevels.DEBUG_3, msg)
17501754
if 'all' in userlist:
1751-
self.verbose_logger.log(yum.logginglevels.INFO_2,
1752-
_('Cleaning up everything'))
1753-
1754-
# Print a "maybe you want rm -rf" hint to compensate for the fact
1755-
# that yum clean all is often misunderstood. Don't do that,
1756-
# however, if cachedir is non-default as we would have to replace
1757-
# arbitrary yum vars with * and that could produce a harmful
1758-
# command, e.g. for /mydata/$myvar we would say rm -rf /mydata/*
1759-
cachedir = self.conf.cachedir
1760-
if cachedir.startswith(('/var/cache/yum', '/var/tmp/yum-')):
1761-
# Take just the first 3 path components
1762-
rmdir = '/'.join(cachedir.split('/')[:4])
1763-
self.verbose_logger.log(
1764-
yum.logginglevels.INFO_2,
1765-
_('Maybe you want: rm -rf %s, to also free up space taken '
1766-
'by orphaned data from disabled or removed repos'
1767-
% rmdir),
1768-
)
1769-
17701755
pkgcode, pkgresults = self.cleanPackages()
17711756
hdrcode, hdrresults = self.cleanHeaders()
17721757
xmlcode, xmlresults = self.cleanMetadata()
@@ -1779,6 +1764,67 @@ def cleanCli(self, userlist):
17791764
rpmresults)
17801765
for msg in results:
17811766
self.logger.debug(msg)
1767+
1768+
# Walk the cachedir, look for any leftovers and categorize them
1769+
cacheglob = self.getCachedirGlob(['basearch', 'releasever'])
1770+
paths = glob.glob(cacheglob + '/*')
1771+
table = ([], [], [], []) # (enabled, disabled, untracked, other)
1772+
repos = self.repos.repos
1773+
for path in paths:
1774+
base = os.path.basename(path)
1775+
if os.path.isdir(path):
1776+
# Repodir
1777+
if base not in repos:
1778+
col = 2
1779+
elif repos[base].enabled:
1780+
col = 0
1781+
else:
1782+
col = 1
1783+
# Recursively gather all files in this repodir
1784+
files = yum.misc.getFileList(path, '', [])
1785+
else:
1786+
# Ordinary file (such as timedhosts)
1787+
col = 3
1788+
files = [path]
1789+
usage = sum(map(os.path.getsize, files))
1790+
if usage > 0:
1791+
table[col].append((usage, path))
1792+
1793+
# Print the table (verbose mode only)
1794+
lines = [_('Disk usage of %s after cleanup:') % cacheglob]
1795+
headers = ('enabled repos', 'disabled repos', 'untracked repos',
1796+
'other data')
1797+
totals = [0, 0, 0, 0]
1798+
for col, header in enumerate(headers):
1799+
rows = []
1800+
total = 0
1801+
# Start with the biggest items
1802+
for usage, path in sorted(table[col], key=lambda x:x[0],
1803+
reverse=True):
1804+
rows.append(' %-5s %s'
1805+
% (self.format_number(usage), path))
1806+
total += usage
1807+
colon = ':' if rows else ''
1808+
lines += ['%-5s %s%s'
1809+
% (self.format_number(total), _(header), colon)]
1810+
lines += rows
1811+
totals[col] = total
1812+
lines += [_('%-5s total') % self.format_number(sum(totals))]
1813+
msg = '\n'.join(lines)
1814+
self.verbose_logger.log(yum.logginglevels.DEBUG_3, msg)
1815+
1816+
# Print a short hint for leftover repos specifically (non-verbose
1817+
# mode only)
1818+
total = sum(totals[:3])
1819+
if self.conf.debuglevel == 6 or not total:
1820+
return code, []
1821+
total = self.format_number(total)
1822+
if total[-1] == ' ':
1823+
total = total[:-1] + 'bytes'
1824+
msg = (_('Other repos take up %s of disk space '
1825+
'(use --verbose for details)') % total)
1826+
self.verbose_logger.log(yum.logginglevels.INFO_2, msg)
1827+
17821828
return code, []
17831829

17841830
if 'headers' in userlist:

docs/yum-shell.8

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ information. There are a few additional commands documented below.
3131
reset: reset (zero-out) the transaction
3232
solve: run the dependency solver on the transaction
3333
run: run the transaction
34+
.IP
35+
.IP "\fBexit\fP"
36+
Causes the shell to exit, setting the exit status as specified by the
37+
\fBshell_exit_status\fR option in \fIyum.conf(5)\fR.
38+
This command is also triggered when EOF is read (usually the C-d keystroke
39+
or end of script).
3440

3541
.PP
3642
.SH "Examples"

docs/yum.8

+32-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.SH "NAME"
44
yum \- Yellowdog Updater Modified
55
.SH "SYNOPSIS"
6-
\fByum\fP [options] [command] [package ...]
6+
\fByum\fP [options] COMMAND [package ...]
77
.SH "DESCRIPTION"
88
.PP
99
\fByum\fP is an interactive, rpm based, package manager. It can automatically
@@ -1031,11 +1031,37 @@ Or: \fByum list available 'foo*'\fP
10311031
.IP
10321032
.PP
10331033
.SH "CLEAN OPTIONS"
1034-
The following are the ways which you can invoke \fByum\fP in clean
1035-
mode. Note that "all files" in the commands below means
1036-
"all files in currently enabled repositories".
1037-
If you want to also clean any (temporarily) disabled repositories you need to
1038-
use \fB\-\-enablerepo='*'\fP option.
1034+
The following are the ways which you can invoke \fByum\fP in clean mode.
1035+
1036+
Note that these commands only operate on files in currently enabled
1037+
repositories.
1038+
If you use substitution variables (such as $releasever) in your \fBcachedir\fP
1039+
configuration, the operation is further restricted to the current values of
1040+
those variables.
1041+
1042+
For fine-grained control over what is being cleaned, you can use
1043+
\fB\-\-enablerepo\fP, \fB\-\-disablerepo\fP and \fB\-\-releasever\fP as
1044+
desired.
1045+
Note, however, that you cannot use \fB\-\-releasever='*'\fP to do the cleaning
1046+
for all values previously used.
1047+
Also note that untracked (no longer configured) repositories will not be
1048+
automatically cleaned.
1049+
1050+
To purge the entire cache in one go, the easiest way is to delete the files
1051+
manually.
1052+
Depending on your \fBcachedir\fP configuration, this usually means treating any
1053+
variables as shell wildcards and recursively removing matching directories.
1054+
For example, if your \fBcachedir\fP is /var/cache/yum/$basearch/$releasever,
1055+
then the whole /var/cache/yum directory has to be removed.
1056+
If you do this, \fByum\fP will rebuild the cache as required the next time it
1057+
is run (this may take a while).
1058+
1059+
As a convenience, when you run \fByum clean all\fP, a recursive lookup will be
1060+
done to detect any repositories not cleaned due to the above restrictions.
1061+
If some are found, a message will be printed stating how much disk space they
1062+
occupy and thus how much you can reclaim by cleaning them.
1063+
If you also supply \fB\-\-verbose\fP, a more detailed breakdown will be
1064+
printed.
10391065

10401066
.IP "\fByum clean expire-cache\fP"
10411067
Eliminate the local data saying when the metadata and mirrorlists were downloaded for each repo. This means yum will revalidate the cache for each repo. next time it is used. However if the cache is still valid, nothing significant was deleted.

0 commit comments

Comments
 (0)