identity_script_excluding_path.py 882 Bytes
Newer Older
1 2 3 4 5 6
from __future__ import print_function

import argparse
import os
import re

7
from fnmatch import fnmatch
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
from .runner_utils import *

def parseArgumentList():
  parser = argparse.ArgumentParser()
  parser.add_argument('--exclude-path', action='append', required=True)

  return parser.parse_args()

def calculateSignature():
  args = parseArgumentList()

  file_list = sys.stdin.read()
  file_list = file_list.split('\0')

  if not len(file_list):
    return 0

  result = re.match('^\.\/runner\/instance\/slappart(\d)', file_list[0])
  base_relative_path = result.group()
27
  excluded_path_list = ['./' + os.path.relpath(os.path.join(base_relative_path, path)) for path in args.exclude_path]
28 29 30

  filtered_file_list = [
    x for x in file_list
31
    if not any([fnmatch(x, excluded_path) for excluded_path in excluded_path_list])
32 33 34
  ]

  print('\n'.join(getSha256Sum(filtered_file_list)))