From f52a1c8f46c976d92d30a6baffc27a58dda798a1 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Sat, 17 Aug 2013 14:46:16 -0400 Subject: [PATCH] Allow installation of local packages with pacman --- library/packaging/pacman | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/library/packaging/pacman b/library/packaging/pacman index cb5ae4aa42..81aa066c6b 100644 --- a/library/packaging/pacman +++ b/library/packaging/pacman @@ -79,6 +79,7 @@ EXAMPLES = ''' import json import shlex import os +import re import sys PACMAN_PATH = "/usr/bin/pacman" @@ -130,15 +131,20 @@ def remove_packages(module, packages): module.exit_json(changed=False, msg="package(s) already absent") -def install_packages(module, packages): +def install_packages(module, packages, package_files): install_c = 0 - for package in packages: + for i, package in enumerate(packages): if query_package(module, package): continue - rc = os.system("pacman -S %s --noconfirm > /dev/null" % (package)) + if package_files[i]: + params = '-U %s' % package_files[i] + else: + params = '-S %s' % package + + rc = os.system("pacman %s --noconfirm > /dev/null" % (params)) if rc != 0: module.fail_json(msg="failed to install %s" % (package)) @@ -172,8 +178,18 @@ def main(): pkgs = p["name"].split(",") + pkg_files = [] + for i, pkg in enumerate(pkgs): + if pkg.endswith('.pkg.tar.xz'): + # The package given is a filename, extract the raw pkg name from + # it and store the filename + pkg_files.append(pkg) + pkgs[i] = re.sub('-[0-9].*$', '', pkgs[i].split('/')[-1]) + else: + pkg_files.append(None) + if p["state"] == "installed": - install_packages(module, pkgs) + install_packages(module, pkgs, pkg_files) elif p["state"] == "absent": remove_packages(module, pkgs)