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 95934138202 for ; Fri, 11 Oct 2013 10:33:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id CFCF5E0AAC; Fri, 11 Oct 2013 10:33:14 +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 6EE4EE0AAC for ; Fri, 11 Oct 2013 10:33:14 +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 87D2633EEE2 for ; Fri, 11 Oct 2013 10:33:13 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 1DA62E5462 for ; Fri, 11 Oct 2013 10:33:11 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1381487029.305f0c4c5fc91e85d0e30a24f9097344f8efe097.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/xattr-helper.py X-VCS-Directories: bin/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 305f0c4c5fc91e85d0e30a24f9097344f8efe097 X-VCS-Branch: master Date: Fri, 11 Oct 2013 10:33:11 +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: 24a4cdfa-38d4-4ec7-a487-6b988b1cc327 X-Archives-Hash: d26e1f4dc4ad829ab794dbe5092125e5 commit: 305f0c4c5fc91e85d0e30a24f9097344f8efe097 Author: Mike Frysinger gentoo org> AuthorDate: Fri Oct 11 10:23:49 2013 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Fri Oct 11 10:23:49 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=305f0c4c xattr-helper: add docstrings to more places --- bin/xattr-helper.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/xattr-helper.py b/bin/xattr-helper.py index 6d33017..92bf1a2 100755 --- a/bin/xattr-helper.py +++ b/bin/xattr-helper.py @@ -2,6 +2,15 @@ # Copyright 2012-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +"""Dump and restore extended attributes. + +We use formats like that used by getfattr --dump. This is meant for shell +helpers to save/restore. If you're looking for a python/portage API, see +portage.util.movefile._copyxattr instead. + +https://en.wikipedia.org/wiki/Extended_file_attributes +""" + import array import os import re @@ -43,8 +52,12 @@ else: s = s.encode(_FS_ENCODING) return s + def quote(s, quote_chars): + """Convert all |quote_chars| in |s| to escape sequences + This is normally used to escape any embedded quotation marks. + """ quote_re = re.compile(b'[' + quote_chars + b']') result = [] pos = 0 @@ -63,8 +76,9 @@ def quote(s, quote_chars): return b"".join(result) -def unquote(s): +def unquote(s): + """Process all escape sequences in |s|""" result = [] pos = 0 s_len = len(s) @@ -88,7 +102,9 @@ def unquote(s): return b"".join(result) + def dump_xattrs(file_in, file_out): + """Dump the xattr data for files in |file_in| to |file_out|""" for pathname in file_in.read().split(b'\0'): if not pathname: @@ -107,7 +123,10 @@ def dump_xattrs(file_in, file_out): quote(xattr.get(pathname, attr), b'\0\n\r"\\\\') + b'"\n') def restore_xattrs(file_in): + """Read |file_in| and restore xattrs content from it + This expects textual data in the format written by dump_xattrs. + """ pathname = None for i, line in enumerate(file_in): if line.startswith(b'# file: '): @@ -173,6 +192,7 @@ def main(argv): return os.EX_OK + if __name__ == "__main__": rval = main(sys.argv[:]) sys.exit(rval)