From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F08241381F3 for ; Fri, 21 Jun 2013 20:41:38 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7EAB3E0B66; Fri, 21 Jun 2013 20:41:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 06FB7E0B66 for ; Fri, 21 Jun 2013 20:41:37 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DF60133E5E8 for ; Fri, 21 Jun 2013 20:41:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 7E837E468F for ; Fri, 21 Jun 2013 20:41:35 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1371847277.0ca18b45ca14e94ba18a29c8cf897d82ee9eabfd.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/install.py X-VCS-Directories: bin/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 0ca18b45ca14e94ba18a29c8cf897d82ee9eabfd X-VCS-Branch: master Date: Fri, 21 Jun 2013 20:41:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 7bd69e42-70ba-4d62-8737-b7b53c13660b X-Archives-Hash: 2baf5f8dc196548c9b797c96fdf600bb commit: 0ca18b45ca14e94ba18a29c8cf897d82ee9eabfd Author: Anthony Basile gentoo org> AuthorDate: Fri Jun 21 20:41:17 2013 +0000 Commit: Zac Medico gentoo org> CommitDate: Fri Jun 21 20:41:17 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0ca18b45 install.py wrapper for xattrs, bug #465000 --- bin/install.py | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) diff --git a/bin/install.py b/bin/install.py new file mode 100755 index 0000000..6be3900 --- /dev/null +++ b/bin/install.py @@ -0,0 +1,210 @@ +#!/usr/bin/python +# Copyright 2013 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +import os +import sys +import argparse +import subprocess +import traceback + +from portage.util.movefile import _copyxattr +from portage.exception import OperationNotSupported + + +def parse_args(args): + """ + Parse the command line arguments using optparse for python 2.6 compatibility + Args: + args: a list of the white space delimited command line + Returns: + tuple of the Namespace of parsed options, and a list of order parameters + """ + parser = argparse.ArgumentParser(add_help=False) + + parser.add_argument( + "-b", + action="store_true", + dest="shortopt_b" + ) + parser.add_argument( + "--backup", + action="store", + dest="backup" + ) + parser.add_argument( + "-c", + action="store_true", + dest="shortopt_c" + ) + parser.add_argument( + "--compare", + "-C", + action="store_true", + dest="compare" + ) + parser.add_argument( + "--directory", + "-d", + action="store_true", + dest="directory" + ) + parser.add_argument( + "-D", + action="store_true", + dest="shortopt_D" + ) + parser.add_argument( + "--owner", + "-o", + action="store", + dest="owner" + ) + parser.add_argument( + "--group", + "-g", + action="store", + dest="group" + ) + parser.add_argument( + "--mode", + "-m", + action="store", + dest="mode" + ) + parser.add_argument( + "--preserve-timestamps", + "-p", + action="store_true", + dest="preserve_timestamps" + ) + parser.add_argument( + "--strip", + "-s", + action="store_true", + dest="strip" + ) + parser.add_argument( + "--strip-program", + action="store", + dest="strip_program" + ) + parser.add_argument( + "--suffix", + "-S", + action="store", + dest="suffix" + ) + parser.add_argument( + "--target-directory", + "-t", + action="store", + dest="target_directory" + ) + parser.add_argument( + "--no-target-directory", + "-T", + action="store_true", + dest="no_target_directory" + ) + parser.add_argument( + "--context", + "-Z", + action="store", + dest="context" + ) + parser.add_argument( + "--verbose", + "-v", + action="store_true", + dest="verbose" + ) + parser.add_argument( + "--help", + action="store_true", + dest="help" + ) + parser.add_argument( + "--version", + action="store_true", + dest="version" + ) + parsed_args = parser.parse_known_args() + + opts = parsed_args[0] + files = parsed_args[1] + files = [f for f in files if f != "--"] # filter out "--" + + return (opts, files) + + +def copy_xattrs(opts, files): + """ + Copy the extended attributes using portage.util.movefile._copyxattr + Args: + opts: Namespace of the parsed command line otions + files: list of ordered command line parameters which should be files/directories + Returns: + system exit code + """ + if opts.directory: + return os.EX_OK + + if opts.target_directory is None: + source, target = files[:-1], files[-1] + target_is_directory = os.path.isdir(target) + else: + source, target = files, opts.target_directory + target_is_directory = True + + try: + if target_is_directory: + for s in source: + abs_path = os.path.join(target, os.path.basename(s)) + _copyxattr(s, abs_path) + else: + _copyxattr(source[0], target) + return os.EX_OK + + except OperationNotSupported: + traceback.print_exc() + return os.EX_OSERR + + +def Which(filename, path=None, all=False): + """ + Find the absolute path of 'filename' in a given search 'path' + Args: + filename: basename of the file + path: colon delimited search path + all: return a list of all intances if true, else return just the first + """ + if path is None: + path = os.environ.get('PATH', '') + ret = [] + for p in path.split(':'): + p = os.path.join(p, filename) + if os.access(p, os.X_OK): + if all: + ret.append(p) + else: + return p + if all: + return ret + else: + return None + + +def main(args): + opts, files = parse_args(args) + path_installs = Which('install', all=True) + cmdline = path_installs[0:1] + cmdline += args + returncode = subprocess.call(cmdline) + if returncode == os.EX_OK: + returncode = copy_xattrs(opts, files) + return returncode + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:]))