Skip to content

Commit

Permalink
Add the fs status/diff commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-antill committed Feb 12, 2014
1 parent 5dd1241 commit 6e4a68c
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 6 deletions.
11 changes: 9 additions & 2 deletions docs/yum.8
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,19 @@ mainly for removing languages/documentation for minimal installs:
.br
.I \fR yum fs du [path]

.br
.I \fR yum fs status [path]

.br
.I \fR yum fs diff [path]


the first 3 being a simple interface to change yum.conf altering the tsflags
and override_install_langs configurations. The refilter command is an optimized
way of calling "yum reinstall" to reinstall the packages with the new filters
applied. The refilter-cleanup command is needed because rpm doesn't actually
remove the files on reinstall, as it should. And the du command is included so
you can easily see the space used/saved.
remove the files on reinstall, as it should. And the du/status/diff commands are
included so you can easily see the space used/saved and any other changes.

.IP
.IP "\fBcheck\fP"
Expand Down
112 changes: 108 additions & 4 deletions yumcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"""

import os
import sys
import cli
from yum import logginglevels
from yum import _, P_
Expand Down Expand Up @@ -4692,9 +4693,112 @@ def _fs_refilter_cleanup(self, base, extcmds):
misc.unlink_f(fname)

def _fs_diff(self, base, extcmds):
pass
def deal_with_file(fpath):
if fpath in pfr['norm']:
pass
elif fpath in pfr['ghost']:
pass
elif fpath in pfr['not']:
print >>sys.stderr, _('Not installed:'), fpath
elif fpath in pfr['miss']:
pass
elif fpath in pfr['mod']:
pkg = apkgs[pfr['mod'][fpath].pkgtup]
# Hacky ... but works.
sys.stdout.flush()
extract_cmd = "cd %s; rpm2cpio %s | cpio --quiet -id .%s"
extract_cmd = extract_cmd % (tmpdir, pkg.localPkg(), fpath)
os.system(extract_cmd)
diff_cmd = "diff -ru %s %s" % (tmpdir + fpath, fpath)
print diff_cmd
sys.stdout.flush()
os.system(diff_cmd)
else:
print >>sys.stderr, _('Not packaged?:'), fpath

prefix = "."
if extcmds:
prefix = extcmds[0]
extcmds = extcmds[1:]

pkgs = base.rpmdb.returnPackages(patterns=extcmds)

verbose = base.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)

pfr = self._fs_pkg_walk(pkgs, prefix, verbose=verbose, modified=True)

base.closeRpmDB() # C-c ftw.

apkgs = {}
downloadpkgs = []
for ipkg in set(pfr['mod'].values()):
for apkg in base.pkgSack.searchPkgTuple(ipkg.pkgtup):
iyi = ipkg.yumdb_info
if ('checksum_type' in iyi and
'checksum_data' in iyi and
iyi.checksum_type == apkg.checksum_type and
iyi.checksum_data == apkg.pkgId):
apkgs[ipkg.pkgtup] = apkg
downloadpkgs.append(apkg)
break
if ipkg.pkgtup not in apkgs:
raise yum.Errors.YumBaseError, _("Can't find package: %s") %ipkg

if downloadpkgs:
tmpdir = tempfile.mkdtemp()
problems = base.downloadPkgs(downloadpkgs, callback_total=base.download_callback_total_cb)
if len(problems) > 0:
errstring = ''
errstring += _('Error downloading packages:\n')
for key in problems:
errors = yum.misc.unique(problems[key])
for error in errors:
errstring += ' %s: %s\n' % (key, error)
raise yum.Errors.YumBaseError, errstring

for root, dirs, files in os.walk(prefix):
for fname in files:
fpath = os.path.normpath(root + '/' + fname)
if os.path.islink(fpath):
continue

deal_with_file(fpath)

def _fs_status(self, base, extcmds):
pass
def deal_with_file(fpath):
if fpath in pfr['norm']:
pass
elif fpath in pfr['ghost']:
pass
elif fpath in pfr['not']:
print _('Not installed:'), fpath
elif fpath in pfr['miss']:
pass
elif fpath in pfr['mod']:
print _('Modified:'), fpath
else:
print _('Not packaged?:'), fpath

prefix = "."
if extcmds:
prefix = extcmds[0]
extcmds = extcmds[1:]

pkgs = base.rpmdb.returnPackages(patterns=extcmds)

verbose = base.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)

pfr = self._fs_pkg_walk(pkgs, prefix, verbose=verbose, modified=True)

base.closeRpmDB() # C-c ftw.

for root, dirs, files in os.walk(prefix):
for fname in files:
fpath = os.path.normpath(root + '/' + fname)
if os.path.islink(fpath):
continue

deal_with_file(fpath)

def doCommand(self, base, basecmd, extcmds):
"""Execute this command.
Expand Down Expand Up @@ -4732,10 +4836,10 @@ def doCommand(self, base, basecmd, extcmds):
elif subcommand == 'refilter-cleanup':
ret = self._fs_refilter_cleanup(base, extcmds)

elif False and subcommand == 'diff':
elif subcommand == 'diff':
ret = self._fs_diff(base, extcmds)

elif False and subcommand == 'status':
elif subcommand == 'status':
ret = self._fs_status(base, extcmds)

else:
Expand Down

0 comments on commit 6e4a68c

Please sign in to comment.