Commit a9e9d320 authored by Vitaly Lipatov's avatar Vitaly Lipatov

introduce epm print for print out package names and fields

parent d22e2cad
......@@ -264,6 +264,9 @@ check_command()
site|url) # HELPCMD: open package's site in a browser (use -p for open packages.altlinux.org site)
epm_cmd=site
;;
print) # HELPCMD: print various info, run epm print help for details
epm_cmd=print
;;
-V|checkpkg|integrity) # HELPCMD: check package file integrity (checksum)
epm_cmd=checkpkg
;;
......
#!/bin/sh
#
# Copyright (C) 2015 Etersoft
# Copyright (C) 2008, 2015 Vitaly Lipatov <lav@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Query variables from rpm package
# TODO: rpm only
query_package_field()
{
local FORMAT="%{$1}\n"
shift
local INSTALLED="-p"
# if not file, drop -p for get from rpm base
[ -e "$1" ] || INSTALLED=""
rpmquery $INSTALLED --queryformat "$FORMAT" "$@"
}
# build binary package list (1st - repo dir, 2st - pkgname)
# algorithm: list all files in PKGDIR, print packages with our source pkg name
print_binpkgfilelist()
{
local PKGDIR=$1
local PKGNAME=$(basename $2)
find "$PKGDIR" ! -name '*\.src\.rpm' -name '*\.rpm' -execdir \
rpmquery -p --qf='%{sourcerpm}\t%{name}-%{version}-%{release}.%{arch}.rpm\n' "{}" \; \
| grep "^$PKGNAME[[:space:]].*" | cut -f2 | xargs -n1 -I "{}" echo -n "$PKGDIR/{} "
}
PKGNAMEMASK="\(.*\)-\(.*\)-\(.*\)"
print_name()
{
echo "$@" | xargs -n1000 echo | sed -e "s|$PKGNAMEMASK|\1|g"
}
print_version()
{
echo "$1" | xargs -n1000 echo | sed -e "s|$PKGNAMEMASK|\2|g"
}
print_release()
{
echo "$1" | xargs -n1000 echo | sed -e "s|$PKGNAMEMASK|\3|g"
}
print_pkgname()
{
local i
for i in $@ ; do
# TODO: deb and other, arch string
echo "$(basename "$i") " | sed -e "s|\.[a-z_0-9]*\.rpm||g" -e "s|\(.*\)_\(.*\)_[a-z_0-9]*\.deb|\1-\2|g"
done
}
print_srcname()
{
print_name $(print_srcpkgname "$@")
}
print_srcpkgname()
{
query_package_field sourcerpm "$@"
}
__epm_print()
{
local WHAT="$1"
shift
local FNFLAG=
[ "$1" = "from" ] && shift
[ "$1" = "for" ] && shift
[ "$1" = "in" ] && shift
if [ "$1" = "filename" ] ; then
FNFLAG="$1"
shift
fi
case "$WHAT" in
"")
fatal "Use epm print help for get help."
;;
"-h"|"--help"|"help")
cat <<EOF
epm print name [from filename] NN print only name of package name or package file
epm print version [from filename] NN print only version of package name or package file
epm print release [from filename] NN print only release of package name or package file
epm print field FF for package NN print field of the package
epm print pkgname from filename NN print package name for package file
epm print srcname from filename NN print source name for package file
epm print srcpkgname from filename NN print source package name for the binary package file
epm print binpkgfilelist in DIR for NN list binary package(s) filename(s) from DIR for the source package file
EOF
;;
"name")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_name $(print_pkgname "$@")
else
print_name "$@"
fi
;;
"version")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_version $(print_pkgname "$@")
else
print_version "$@"
fi
;;
"release")
[ -n "$1" ] || fatal "Arg is missed"
if [ -n "$FNFLAG" ] ; then
print_release $(print_pkgname "$@")
else
print_release "$@"
fi
;;
"field")
[ -n "$1" ] || fatal "Arg is missed"
local FIELD="$1"
shift
[ "$1" = "for" ] && shift
query_package_field $FIELD "$@"
;;
"pkgname")
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
# TODO: drop_pkg_extensions
print_pkgname "$@"
;;
"srcname")
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
print_srcname "$@"
;;
"srcpkgname")
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
[ -n "$1" ] || fatal "Arg is missed"
print_srcpkgname "$@"
;;
"binpkgfilelist")
# TODO: rpm only
# TODO: replace get_binpkg_list
local DIR="$1"
shift
[ "$1" = "for" ] && shift
[ -n "$DIR" ] || fatal "DIR arg is missed"
[ -n "$1" ] || fatal "source package filename is missed"
print_binpkgfilelist "$DIR" "$1"
;;
*)
fatal "Unknown command $ epm print $WHAT. Use epm print help for get help."
;;
esac
}
epm_print()
{
[ -n "$pkg_filenames" ] || fatal "Missed args. Use epm print help for get help."
__epm_print $(eval echo $quoted_args)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment