Use the API derectly. Massive speed boost. Almost as fast as cower \m/

This commit is contained in:
Jack L. Frost 2015-01-27 23:12:56 +03:00
parent 5cd8546ece
commit 1fdde28724

68
zpac
View File

@ -19,13 +19,28 @@ usage() {
-h Show this message. -h Show this message.
-s Search for <package>. -s Search for <package>.
-d Get the package sources (default). -d Get the package sources (default).
-D If used with -d, makes $_self download the dependencies from AUR too.
EOF EOF
} }
aur.get() { aur.info() {
local pkg_aur_info=$( curl "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null ) local pkg_aur_info=$( curl "${cfg_aur_api}?type=info&arg=${1}" 2>/dev/null )
local pkg_base=$( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" ) local aur_query_result=$( jshon -e resultcount -u <<< "$pkg_aur_info" )
local tarball_path=$( jshon -e results -e URLPath -u <<< "$pkg_aur_info" )
if (( aur_query_result )); then
echo "$pkg_aur_info"
else
return 1
fi
}
aur.get() {
local dep_name aur_api_multireq aur_deps_api_data aur_deps_count aur_deps pkg_aur_info pkg_base tarball_path
read pkg_aur_info
pkg_base=$( jshon -e results -e PackageBase -u <<< "$pkg_aur_info" )
tarball_path=$( jshon -e results -e URLPath -u <<< "$pkg_aur_info" )
cd "$cfg_workdir" cd "$cfg_workdir"
@ -38,26 +53,37 @@ aur.get() {
echo ": ${cfg_workdir}/${pkg_base}" echo ": ${cfg_workdir}/${pkg_base}"
if (( flag_get_deps )); then if (( flag_get_deps )); then
unset depends makedepends
cd "${cfg_workdir}/${pkg_base}" cd "${cfg_workdir}/${pkg_base}"
source PKGBUILD source PKGBUILD
for i in "${depends[@]}" "${makedepends[@]}"; do for i in "${depends[@]}" "${makedepends[@]}"; do
dep_name="${i/[<>=]*}" dep_name="${i/[<>=]*}"
dep_repo=$( package-query -1 -A -f '%r' "${dep_name}" ) aur_api_multireq+="&arg\[\]=$dep_name"
if [[ "$dep_repo" == 'aur' ]]; then
[[ -d "${cfg_workdir}/${dep_name}" ]] || {
aur.get "$dep_name" || { return "$?"; }
}
fi
done done
aur_deps_api_data=$( curl "${cfg_aur_api}?type=multiinfo${aur_api_multireq}" )
aur_deps_count=$( jshon -e resultcount <<< "$aur_deps_api_data" )
if (( aur_deps_count )); then
aur_deps=$( jshon -e results -a -e Name -u <<< "$aur_deps_api_data" )
echo "${aur_deps[@]}"
for i in "${aur_deps[@]}"; do
aur.get < <(aur.info "$i") || {
return "$?"
}
done
fi
fi fi
} }
abs.get() { abs.get() {
local svn_repo local svn_repo
case "$package_repo" in case "$repo" in
(community|multilib) (community|multilib)
svn_repo='community';; svn_repo='community';;
(*) (*)
@ -90,7 +116,12 @@ main() {
action=${action:-"get"} action=${action:-"get"}
if [[ "$1" ]]; then
package="$1" package="$1"
else
usage
return 1
fi
case "$action" in case "$action" in
(get) (get)
@ -101,21 +132,26 @@ main() {
} }
} }
IFS='/' read repo _ < <( package-query -AS -f '%r/%n' "$package" ) pkg_aur_info=$( aur.info "$package" )
if [[ "$?" > 0 ]]; then if (( ! "$?" )); then
err "Can't find package: $package" repo='aur'
else
repo=$( package-query -S -f '%r' "$package" )
(( "$?" )) || {
err "Can't find package ${package}"
return 1 return 1
}
fi fi
echo "Found ${package} in ${repo}." echo "Found ${package} in ${repo}."
case "$repo" in case "$repo" in
(aur) (aur)
aur.get "$package";; aur.get <<< "$pkg_aur_info";;
(core|extra|community|multilib) (core|extra|community|multilib)
abs.get "$package";; abs.get "${package}" "";;
(*) (*)
err "Repository $repo not supported." err "Repository $repo not supported."