PackageInfo: Update for apt-file 3
This commit is contained in:
@ -22,7 +22,7 @@ import supybot
|
||||
import supybot.world as world
|
||||
from imp import reload
|
||||
|
||||
__version__ = "1.2.0"
|
||||
__version__ = "1.3.0"
|
||||
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
|
||||
__contributors__ = {
|
||||
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Concept'],
|
||||
|
@ -47,10 +47,15 @@ def apt_cache(aptdir, distro, cmd, pkg):
|
||||
|
||||
def apt_file(aptdir, distro, pkg):
|
||||
return subprocess.check_output(['apt-file',
|
||||
'-s', '%s/%s.list' % (aptdir, distro),
|
||||
'-c', '%s/apt-file/%s' % (aptdir, distro),
|
||||
'-l', '-i', '-a', 'amd64',
|
||||
'search', pkg]).decode('utf8')
|
||||
'-oAPT::Architecture=amd64',
|
||||
'-oAPT::Architectures::=i386',
|
||||
'-oAPT::Architectures::=amd64',
|
||||
'-oDir::State::Lists=%s/%s' % (aptdir, distro),
|
||||
'-oDir::State::Status=%s/%s.status' % (aptdir, distro),
|
||||
'-oDir::Etc::SourceList=%s/%s.list' % (aptdir, distro),
|
||||
'-oDir::Etc::SourceParts=""',
|
||||
'-oDir::Cache=%s/cache' % aptdir,
|
||||
'-l', '-i', 'search', pkg]).decode('utf8')
|
||||
|
||||
class Apt:
|
||||
def __init__(self, plugin):
|
||||
@ -91,10 +96,8 @@ class Apt:
|
||||
self.log.error("PackageInfo/packages: apt-file is not installed")
|
||||
return "Please use %s/ to search for files" % pkgTracURL
|
||||
if data[0] == 'E:': # No files in the cache dir
|
||||
self.log.error("PackageInfo/packages: Please run the 'update_apt_file' script")
|
||||
self.log.error("PackageInfo/packages: Please update the cache for %s" % distro)
|
||||
return "Cache out of date, please contact the administrator"
|
||||
if data[0] == "Use" and data[1] == "of":
|
||||
return "%s/search?searchon=contents&keywords=%s&mode=exactfilename&suite=%s&arch=any" % (pkgTracURL, utils.web.urlquote(pkg), distro)
|
||||
if len(data) > 10:
|
||||
return "File %s found in %s and %d others <%s/search?searchon=contents&keywords=%s&mode=exactfilename&suite=%s&arch=any>" % (pkg, ', '.join(data[:10]), len(data)-10, pkgTracURL, utils.web.urlquote(pkg), distro)
|
||||
return "File %s found in %s" % (pkg, ', '.join(data))
|
||||
|
@ -1,111 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Either set DIR to the same value as supybot.plugins.PackageInfo.aptdir,
|
||||
# or use the --dir command-line option.
|
||||
DIR=""
|
||||
|
||||
# Be quiet by default.
|
||||
VERBOSE=0
|
||||
|
||||
## Please don't change anything below this line, unless you really know what
|
||||
## you are doing and don't bother me with whatever errors it produces :)
|
||||
|
||||
# Print usage information.
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTION]...
|
||||
|
||||
Updates the apt-file cache for PackageInfo.
|
||||
|
||||
-d, --dir <DIR> Specify directory for apt-file cache.
|
||||
-v, --verbose Be more verbose than normal.
|
||||
-h, --help Display this message and exit.
|
||||
|
||||
Note:
|
||||
Please separate each option with a space, eg:
|
||||
$0 -v -d /home/bot/aptdir
|
||||
Rather than:
|
||||
$0 -vd /home/bot/aptdir
|
||||
|
||||
This script is intended to be run automatically (eg: cron), so it shows no output by default.
|
||||
You can make the script more verbose with the -v/--verbose option.
|
||||
The -d/--dir option sets the directory where this script looks for *.list files for apt-file.
|
||||
EOF
|
||||
}
|
||||
|
||||
# Prints an error message, usage (above), then exits with the specified exit value.
|
||||
error() {
|
||||
local exit_val=$1
|
||||
shift
|
||||
echo "$@" >&2
|
||||
usage >&2
|
||||
exit $exit_val
|
||||
}
|
||||
|
||||
# Runs apt-file update in the specified directory for the specified distribution.
|
||||
update_apt_file() {
|
||||
if [ $VERBOSE -eq 0 ]; then
|
||||
apt-file -N -l -c "$DIR/apt-file/$DIST" -s "$DIR/$DIST.list" -a amd64 update >/dev/null 2>&1
|
||||
else
|
||||
apt-file -N -l -c "$DIR/apt-file/$DIST" -s "$DIR/$DIST.list" -a amd64 update
|
||||
fi
|
||||
}
|
||||
|
||||
# Check command-line arguments
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
VERBOSE=1
|
||||
;;
|
||||
-d|--dir)
|
||||
[ -z "$2" ] && error 1 '"-d/--dir" requires an argument.'
|
||||
shift
|
||||
DIR="$1"
|
||||
;;
|
||||
--dir=*)
|
||||
DIR="${1:6}"
|
||||
[ -z "$DIR" ] && error 1 '"--dir" requires an argument.'
|
||||
;;
|
||||
-*)
|
||||
error 1 "Unknown option \"$1\"."
|
||||
;;
|
||||
*)
|
||||
error 1 "This script takes no non-argument parameters."
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Check if apt-file is installed and bail if not.
|
||||
if ! which apt-file >/dev/null 2>&1; then
|
||||
echo "ERROR: apt-file not found. Please install apt-file in your PATH." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$DIR" ]; then
|
||||
error 1 "ERROR: No DIR set in the script and no -d/--dir option given."
|
||||
fi
|
||||
|
||||
items=("$DIR"/*.list)
|
||||
[ ! -e "${items[0]}" ] && error 1 "ERROR: Could not find any *.list files in \"$DIR\"."
|
||||
|
||||
for DIST in "${items[@]}"; do
|
||||
[ -h "$DIST" ] && continue # Ignore symbolic links
|
||||
# Extract the distribution name from the .list file name.
|
||||
DIST=${DIST##*/}
|
||||
DIST=${DIST%.list}
|
||||
|
||||
[ $VERBOSE -gt 0 ] && echo "INFO: Processing $DIST"
|
||||
mkdir -p "$DIR/apt-file/$DIST" # Create apt-file directory if it doesn't exist
|
||||
update_apt_file # Update apt-file cache
|
||||
if [ $? -ne 0 ]; then
|
||||
[ $VERBOSE -eq 0 ] && echo "Try passing -v to get the error message." >&2
|
||||
echo "ERROR: apt-file update failed for $DIST." >&2
|
||||
exit_val=$?
|
||||
fi
|
||||
done
|
||||
exit $exit_val
|
Reference in New Issue
Block a user