dfhack/travis/script-syntax.py

40 lines
1.2 KiB
Python

import argparse
import os
import subprocess
import sys
def main():
root_path = os.path.abspath(args.path)
cmd = args.cmd.split(' ')
if not os.path.exists(root_path):
print('Nonexistent path: %s' % root_path)
sys.exit(2)
err = False
for cur, dirnames, filenames in os.walk(root_path):
parts = cur.replace('\\', '/').split('/')
if '.git' in parts or 'depends' in parts:
continue
for filename in filenames:
if not filename.endswith(args.ext):
continue
full_path = os.path.join(cur, filename)
try:
subprocess.check_output(cmd + [full_path])
except subprocess.CalledProcessError:
err = True
except IOError:
# catch error if not in Travis and Lua/Ruby is not available
if os.environ.get('TRAVIS', False):
raise
sys.exit(int(err))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--path', default='.', help='Root directory')
parser.add_argument('--ext', help='Script extension', required=True)
parser.add_argument('--cmd', help='Command', required=True)
args = parser.parse_args()
main()