Skip to content

Commit 6ec51d9

Browse files
committed
Initial commit
0 parents  commit 6ec51d9

10 files changed

Lines changed: 635 additions & 0 deletions

File tree

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.deps
2+
.dirstamp
3+
Makefile
4+
Makefile.in
5+
ar-lib
6+
aclocal.m4
7+
autom4te.cache
8+
config.log
9+
config.status
10+
configure
11+
depcomp
12+
install-sh
13+
missing
14+
py-compile
15+
stamp-h1
16+
*.log
17+
*~

COPYING

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

Makefile.am

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
dnfplugindir = $(pythondir)/dnf-plugins
2+
3+
dnfplugin_PYTHON = dnf-plugins/diff.py
4+
5+
libexec_SCRIPTS = \
6+
libexec/dnf-diff-changed-files \
7+
libexec/dnf-diff-rpm-filename
8+
9+
EXTRA_DIST = $(libexec_SCRIPTS)

README

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
dnf-plugin-diff - compare package contents against local changes
2+
================================================================
3+
4+
Typical use-case:
5+
6+
$ echo '# some change' >> \
7+
/usr/lib/python3.6/site-packages/dnf-plugins/diff.py
8+
$ dnf diff dnf-plugin-diff
9+
Last metadata expiration check: 0:04:12 ago on Mon 03 Sep 2018 05:12:09 PM CEST.
10+
--- /usr/lib/python3.6/site-packages/dnf-plugins/diff.py 2018-09-03 16:41:36.000000000 +0200
11+
+++ /usr/lib/python3.6/site-packages/dnf-plugins/diff.py 2018-09-03 17:16:17.476547131 +0200
12+
@@ -96,3 +96,5 @@
13+
else:
14+
self._diff_package(pkg, check_pkg,
15+
self._list_of_changed_files(check_pkg))
16+
+
17+
+# some change
18+
19+
20+
How to install
21+
--------------
22+
23+
$ dnf copr enable praiskup/dnf-plugin-diff
24+
$ dnf install dnf-plugins-diff
25+
26+
or build from source:
27+
28+
$ autoreconf -vfi && ./configure --prefix=/usr && sudo make install

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AC_INIT([dnf-plugin-diff], [0.0], [praiskup@redhat.com])
2+
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
3+
AM_PATH_PYTHON
4+
AC_CONFIG_FILES([Makefile])
5+
AC_OUTPUT

dnf-plugins/diff.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# supplies the 'diff' command.
2+
#
3+
# Copyright (C) 2018 Red Hat, Inc.
4+
#
5+
# This copyrighted material is made available to anyone wishing to use,
6+
# modify, copy, or redistribute it subject to the terms and conditions of
7+
# the GNU General Public License v.2, or (at your option) any later version.
8+
# This program is distributed in the hope that it will be useful, but WITHOUT
9+
# ANY WARRANTY expressed or implied, including the implied warranties of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
# Public License for more details. You should have received a copy of the
12+
# GNU General Public License along with this program; if not, write to the
13+
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14+
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
15+
# source code or documentation are not subject to the GNU General Public
16+
# License and may only be used or replicated with the express permission of
17+
# Red Hat, Inc.
18+
19+
from __future__ import print_function
20+
import os
21+
import dnf
22+
import rpm
23+
import subprocess
24+
25+
import logging
26+
from dnfpluginsextras import _, logger
27+
28+
@dnf.plugin.register_command
29+
class DiffCommand(dnf.cli.Command):
30+
aliases = ("diff",)
31+
summary = "Do blah."
32+
usage = "ahoj"
33+
34+
@staticmethod
35+
def set_argparser(parser):
36+
parser.add_argument('pkg')
37+
parser.add_argument('file', nargs='*')
38+
39+
def configure(self):
40+
# per https://bugzilla.redhat.com/1358245
41+
self.cli.redirect_logger(stdout=logging.WARNING, stderr=logging.INFO)
42+
self.base.conf.destdir = os.path.join(
43+
os.path.expanduser("~"),
44+
'.cache',
45+
'dnf-diff',
46+
)
47+
48+
def _resolve_local_package(self, name):
49+
self.base.fill_sack()
50+
subj = dnf.subject.Subject(name)
51+
q = subj.get_best_query(self.base.sack)
52+
q = q.available()
53+
q = q.latest()
54+
if len(q.run()) == 0:
55+
msg = _("No package %s available.") % (name)
56+
raise dnf.exceptions.PackageNotFoundError(msg)
57+
58+
return list(q)
59+
60+
61+
def _diff_package(self, package, package_name, files):
62+
for fname in files:
63+
if not fname in package.files:
64+
# Should not happen?
65+
logger.error(_("file '{0}' not found in '{1}'".format(fname,
66+
package_name)))
67+
continue
68+
69+
rpm_file_name = '{name}-{version}-{release}.{arch}.rpm'.format(
70+
name=package.name,
71+
version=package.version,
72+
release=package.release,
73+
arch=package.arch
74+
)
75+
76+
subprocess.call(['/usr/libexec/dnf-diff-rpm-filename',
77+
rpm_file_name,
78+
fname])
79+
80+
def _list_of_changed_files(self, package):
81+
proc = subprocess.Popen(
82+
['/usr/libexec/dnf-diff-changed-files', package],
83+
stdout=subprocess.PIPE,
84+
)
85+
lines = [x.decode('ascii').rstrip() for x in proc.stdout.readlines()]
86+
return lines
87+
88+
def run(self):
89+
to_download = self._resolve_local_package(self.opts.pkg)
90+
self.base.download_packages(to_download)
91+
92+
for pkg in to_download:
93+
check_pkg = '{0}.{1}'.format(pkg.name, pkg.arch)
94+
if self.opts.file:
95+
self._diff_package(pkg, check_pkg, self.opts.file)
96+
else:
97+
self._diff_package(pkg, check_pkg,
98+
self._list_of_changed_files(check_pkg))

libexec/dnf-diff-changed-files

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#! /bin/sh
2+
3+
# Copyright (C) 2018 Red Hat, Inc.
4+
#
5+
# This copyrighted material is made available to anyone wishing to use,
6+
# modify, copy, or redistribute it subject to the terms and conditions of
7+
# the GNU General Public License v.2, or (at your option) any later version.
8+
# This program is distributed in the hope that it will be useful, but WITHOUT
9+
# ANY WARRANTY expressed or implied, including the implied warranties of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
# Public License for more details. You should have received a copy of the
12+
# GNU General Public License along with this program; if not, write to the
13+
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14+
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
15+
# source code or documentation are not subject to the GNU General Public
16+
# License and may only be used or replicated with the express permission of
17+
# Red Hat, Inc.
18+
19+
rpm -V "$1" | while read changed mode file; do
20+
case $changed in
21+
??5??????|S????????)
22+
if test -n "$file"; then
23+
echo "$file"
24+
else
25+
# hack, do better parsing
26+
echo "$mode"
27+
fi
28+
;;
29+
*)
30+
continue
31+
;;
32+
esac
33+
done
34+

libexec/dnf-diff-rpm-filename

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#! /bin/sh
2+
3+
# Copyright (C) 2018 Red Hat, Inc.
4+
#
5+
# This copyrighted material is made available to anyone wishing to use,
6+
# modify, copy, or redistribute it subject to the terms and conditions of
7+
# the GNU General Public License v.2, or (at your option) any later version.
8+
# This program is distributed in the hope that it will be useful, but WITHOUT
9+
# ANY WARRANTY expressed or implied, including the implied warranties of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11+
# Public License for more details. You should have received a copy of the
12+
# GNU General Public License along with this program; if not, write to the
13+
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
14+
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
15+
# source code or documentation are not subject to the GNU General Public
16+
# License and may only be used or replicated with the express permission of
17+
# Red Hat, Inc.
18+
19+
workdir=$HOME/.cache/dnf-diff
20+
mkdir -p "$workdir"
21+
22+
base=$1
23+
filename=$2
24+
rpmfile=$workdir/$base
25+
26+
die () { echo "FATAL: $*"; exit 1 ; }
27+
28+
case $filename in
29+
/*) ;;
30+
*) die "file '$filename' must be absolute" ;;
31+
esac
32+
33+
test -f "$rpmfile" || die "not such file '$rpmfile'"
34+
case $rpmfile in
35+
*.rpm) ;;
36+
*) die "not an rpm '$rpmfile'" ;;
37+
esac
38+
39+
case $(file -i "$rpmfile") in
40+
*application/x-rpm*) ;;
41+
*) die "$rpmfile must be application/x-rpm file" ;;
42+
esac
43+
44+
workdir=$HOME/.cache/dnf-diff
45+
46+
mkdir -p "$workdir"
47+
48+
cachedir=$workdir/${base%%.rpm}
49+
50+
test -d "$cachedir" || (
51+
mkdir -p "$cachedir"
52+
cd "$cachedir"
53+
rpm2cpio "$rpmfile" | cpio -idm &>/dev/null
54+
)
55+
56+
(
57+
cd "$cachedir"
58+
diff -ru ".$filename" "$filename" \
59+
| sed '1s/--- \./--- /g'
60+
)

rpm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.rpm
2+
*.tar.gz

rpm/dnf-plugin-diff.spec

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%global __python %__python3
2+
3+
Name: dnf-plugin-diff
4+
Version: 0.0
5+
Release: 1%{?dist}
6+
Summary: Diff changes in packages
7+
BuildArch: noarch
8+
9+
License: GPLv2+
10+
URL: https://github.com/praiskup/%{name}
11+
Source0: https://github.com/praiskup/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz
12+
13+
BuildRequires: python3-devel
14+
Requires: dnf
15+
Provides: dnf-command(diff)
16+
17+
18+
%description
19+
Attempt to diff packages against local changes.
20+
21+
22+
%prep
23+
%setup -q
24+
25+
26+
%build
27+
%configure PYTHON=python3
28+
%make_build
29+
30+
31+
%install
32+
%make_install
33+
34+
35+
%files
36+
%doc
37+
%_libexecdir/dnf-diff-*
38+
%python3_sitelib/dnf-plugins
39+
40+
41+
%changelog
42+
* Mon Sep 03 2018 Pavel Raiskup <praiskup@redhat.com>
43+
- no changelog in upstream git

0 commit comments

Comments
 (0)