Commit cfd7a99f authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #25046 from dlorenc/boilerplate

Automatic merge from submit-queue Add several arguments to boilerplate.py This commit makes the root directory and boilerplate content directory configurable. The defaults have remained the same, so no behavior changes should be expected. cc @eparis ref https://github.com/kubernetes/minikube/pull/37
parents c66250dd bc9877be
...@@ -26,15 +26,20 @@ import sys ...@@ -26,15 +26,20 @@ import sys
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*') parser.add_argument("filenames", help="list of files to check, all files if unspecified", nargs='*')
args = parser.parse_args()
rootdir = os.path.dirname(__file__) + "/../../" rootdir = os.path.dirname(__file__) + "/../../"
rootdir = os.path.abspath(rootdir) rootdir = os.path.abspath(rootdir)
parser.add_argument("--rootdir", default=rootdir, help="root directory to examine")
default_boilerplate_dir = os.path.join(rootdir, "hack/boilerplate")
parser.add_argument("--boilerplate-dir", default=default_boilerplate_dir)
args = parser.parse_args()
def get_refs(): def get_refs():
refs = {} refs = {}
for path in glob.glob(os.path.join(rootdir, "hack/boilerplate/boilerplate.*.txt")): for path in glob.glob(os.path.join(args.boilerplate_dir, "boilerplate.*.txt")):
extension = os.path.basename(path).split(".")[1] extension = os.path.basename(path).split(".")[1]
ref_file = open(path, 'r') ref_file = open(path, 'r')
...@@ -100,7 +105,7 @@ def file_passes(filename, refs, regexs): ...@@ -100,7 +105,7 @@ def file_passes(filename, refs, regexs):
def file_extension(filename): def file_extension(filename):
return os.path.splitext(filename)[1].split(".")[-1].lower() return os.path.splitext(filename)[1].split(".")[-1].lower()
skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'cluster/env.sh'] skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'cluster/env.sh', 'vendor']
def normalize_files(files): def normalize_files(files):
newfiles = [] newfiles = []
for pathname in files: for pathname in files:
...@@ -109,7 +114,7 @@ def normalize_files(files): ...@@ -109,7 +114,7 @@ def normalize_files(files):
newfiles.append(pathname) newfiles.append(pathname)
for i, pathname in enumerate(newfiles): for i, pathname in enumerate(newfiles):
if not os.path.isabs(pathname): if not os.path.isabs(pathname):
newfiles[i] = os.path.join(rootdir, pathname) newfiles[i] = os.path.join(args.rootdir, pathname)
return newfiles return newfiles
def get_files(extensions): def get_files(extensions):
...@@ -117,7 +122,7 @@ def get_files(extensions): ...@@ -117,7 +122,7 @@ def get_files(extensions):
if len(args.filenames) > 0: if len(args.filenames) > 0:
files = args.filenames files = args.filenames
else: else:
for root, dirs, walkfiles in os.walk(rootdir): for root, dirs, walkfiles in os.walk(args.rootdir):
# don't visit certain dirs. This is just a performance improvement # don't visit certain dirs. This is just a performance improvement
# as we would prune these later in normalize_files(). But doing it # as we would prune these later in normalize_files(). But doing it
# cuts down the amount of filesystem walking we do and cuts down # cuts down the amount of filesystem walking we do and cuts down
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment