Reduced duplication between formatting scripts with Task base class (#80)

Also added scripts for EOF newline management and for removing trailing whitespace. configure.bat was rewritten to use CRLF line endings. Documentation for the existing scripts was also improved.
This commit is contained in:
Tyler Veness
2016-07-10 08:33:27 -07:00
committed by Peter Johnson
parent ea6876e81f
commit aafca4ed7f
57 changed files with 588 additions and 423 deletions

75
styleguide/task.py Normal file
View File

@@ -0,0 +1,75 @@
# Provides a task base class for use by format.py
from abc import *
import os
import re
sep = os.sep
# If directory separator is backslash, escape it for regexes
if sep == "\\":
sep += "\\"
# List of folder regexes which should be excluded from modification
folderExclude = \
[name + sep for name in [
"\.git",
"\.gradle",
"FRC_FPGA_ChipObject",
"NetworkCommunication",
"__pycache__",
"build",
"ctre",
"frccansae",
"gtest",
"i2clib",
"msgs",
"ni-libraries",
"ni" + sep + "vision",
"spilib",
"wpilibj" + sep + "src" + sep + "athena" + sep + "cpp" + sep + "include",
"wpilibj" + sep + "src" + sep + "athena" + sep + "cpp" + sep + "lib",
"wpilibj" + sep + "src" + sep + "athena" + sep + "cpp" + sep + "nivision",
"visa"]]
# List of file regexes which should be excluded from modification
fileExclude = [name + "$" for name in [
"CanTalonSRX\.h",
"NIIMAQdx\.h",
"can_proto\.h",
"nivision\.h",
"\.jar",
"\.patch",
"\.png",
"\.py",
"\.so"]]
# Regex of exclusions
regexExclude = re.compile("|".join(folderExclude + fileExclude))
class Task(object):
__metaclass__ = ABCMeta
def __init__(self):
self.regexInclude = re.compile("|".join(["\." + ext + "$" for ext in
self.getIncludeExtensions()]))
# Extensions of files which should be included in processing
def getIncludeExtensions(self):
return []
# Perform task on file with given name
@abstractmethod
def run(self, name):
return
# Returns True if file isn't generated (generated files are skipped)
@staticmethod
def notGeneratedFile(name):
return not regexExclude.search(name)
# Returns True if file has an extension this task can process
def fileMatchesExtension(self, name):
if self.getIncludeExtensions() != []:
return self.regexInclude.search(name)
else:
return True