Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2360)

Unified Diff: pydir/ifatts.py

Issue 659513005: Allow conditional lit tests in Subzero, based on build flags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Use REQUIRES when appropriate in lit tests. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pydir/ifatts.py
diff --git a/pydir/ifatts.py b/pydir/ifatts.py
new file mode 100755
index 0000000000000000000000000000000000000000..32c1e6c76e867ddfbfc36d2fe0145ae9108a022e
--- /dev/null
+++ b/pydir/ifatts.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python2
+
+import argparse
+import os
+import sys
+
+from utils import shellcmd
+
+def GetFileAttributes(Filename):
+ """Returns the set of names contained in file named Filename.
+ """
+ if not os.path.isfile(Filename):
+ raise RuntimeError("Can't open: %s" % Filename)
+ with open(Filename, 'r') as f:
+ return f.read().split()
+
+def HasFileAttributes(Filename, Attributes):
+ """Returns true if the set of names in Attributes also appear
+ in the set of names contained in file named Filename.
+ """
+ return set(Attributes) <= set(GetFileAttributes(Filename))
+
+def main():
+ """Check if the set attributes (i.e. names), contained in FILE,
+ contains the attributes defined by --att=ATTRIBUTE arguments. If
+ so, runs in a shell the command defined by the remaining
+ arguments
Jim Stichnoth 2014/10/21 21:58:41 end with a period.
Karl 2014/10/22 17:03:36 Done.
+ """
+ argparser = argparse.ArgumentParser(
+ description=' ' + main.__doc__,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ argparser.add_argument('file', metavar='FILE',
+ help='File defining attributes to check against.')
+ argparser.add_argument('--att', required=False, default=[],
+ action='append', metavar='ATTRIBUTE',
+ help='Attribute to check. May be repeated.')
+ argparser.add_argument('--echo-cmd', required=False,
+ action='store_true',
+ help='Trace the command before running.')
+ argparser.add_argument('--command', nargs=argparse.REMAINDER,
+ help='Command to run if attributes found.')
+
+ args = argparser.parse_args()
+
+ # Quit early if no command to run.
+ if not args.command:
+ raise RuntimeError("No command argument(s) specified for ifatts")
+
+ if HasFileAttributes(args.file, args.att):
+ stdout_result = shellcmd(args.command, echo=args.echo_cmd)
+ if not args.echo_cmd:
+ sys.stdout.write(stdout_result)
+
+if __name__ == '__main__':
+ main()
+ sys.exit(0)

Powered by Google App Engine
This is Rietveld 408576698