initial commit
This commit is contained in:
2
source/scripts/.gitignore
vendored
Normal file
2
source/scripts/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
commit.pyc
|
||||
|
52
source/scripts/board_interface.py
Executable file
52
source/scripts/board_interface.py
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/python2
|
||||
# Used to create symlink for git hooks
|
||||
from sys import argv, exit
|
||||
from getopt import getopt
|
||||
from re import match, sub
|
||||
import os
|
||||
|
||||
def print_help():
|
||||
print "Help screen"
|
||||
|
||||
def parse_board_file(boardfile):
|
||||
f = open(boardfile, "r")
|
||||
rd = f.read().splitlines()
|
||||
ret = []
|
||||
for line in rd:
|
||||
if match("^.*struct driver.*$", line):
|
||||
line = sub("^.*struct driver", "", line).strip()
|
||||
line = sub(" .*$","",line).strip()
|
||||
ret.append(line)
|
||||
return ret
|
||||
|
||||
def create_board_interface(device_list, outfile):
|
||||
f = open(outfile, "w")
|
||||
f.write("/* Board devices include file */\n\n")
|
||||
f.write("#ifndef BOARD_DEVICES_H\n")
|
||||
f.write("#define BOARD_DEVICES_H\n\n")
|
||||
for device in device_list:
|
||||
f.write("extern const struct driver " + device + ";\n")
|
||||
f.write("\n#endif /* BOARD_DEVICES_H */\n")
|
||||
|
||||
def main(argv):
|
||||
options, remainder = getopt(argv, "hb:o:", ["help", "boardfile=", "outfile="])
|
||||
boardfile = ""
|
||||
outfile = ""
|
||||
if len(options) < 2:
|
||||
print_help()
|
||||
exit(-1)
|
||||
for opt, arg in options:
|
||||
if opt in ("-h", "--help"):
|
||||
print_help()
|
||||
exit(0)
|
||||
elif opt in ("-b", "--boardfile"):
|
||||
boardfile = arg
|
||||
elif opt in ("-o", "--outfile"):
|
||||
outfile = arg
|
||||
if (len(boardfile) == 0) or (len(outfile) == 0):
|
||||
print_help()
|
||||
exit(-1)
|
||||
create_board_interface(parse_board_file(boardfile), outfile)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(argv[1:])
|
46
source/scripts/commit.py
Normal file
46
source/scripts/commit.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from re import match, sub
|
||||
|
||||
class commit:
|
||||
def __init__(self, commit_list):
|
||||
self.__hash = ""
|
||||
self.__merge = ""
|
||||
self.__author = ""
|
||||
self.__date = ""
|
||||
self.__message = []
|
||||
|
||||
for line in commit_list:
|
||||
if match("^commit", line):
|
||||
line = sub("^commit", "", line)
|
||||
line = line.strip()
|
||||
self.__hash = line
|
||||
elif match("^Merge:", line):
|
||||
line = sub("^Merge:", "", line)
|
||||
line = line.strip()
|
||||
self.__merge = line
|
||||
elif match("^Author:", line):
|
||||
line = sub("^Author:", "", line)
|
||||
line = line.strip()
|
||||
self.__author = line
|
||||
elif match("^Date:", line):
|
||||
line = sub("^Date:", "", line)
|
||||
line = line.strip()
|
||||
self.__date = line
|
||||
else:
|
||||
line = line.strip()
|
||||
self.__message.append(line)
|
||||
|
||||
def hash(self):
|
||||
return self.__hash
|
||||
|
||||
def merge(self):
|
||||
return self.__merge
|
||||
|
||||
def author(self):
|
||||
return self.__author
|
||||
|
||||
def date(self):
|
||||
return self.__date
|
||||
|
||||
def message(self):
|
||||
return self.__message
|
||||
|
90
source/scripts/get_history.py
Executable file
90
source/scripts/get_history.py
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/python2
|
||||
from subprocess import Popen, PIPE
|
||||
from re import match, sub
|
||||
from sys import argv, getfilesystemencoding
|
||||
from getopt import getopt
|
||||
from commit import commit
|
||||
|
||||
def check_for_untracked():
|
||||
cmd = ["git", "status"]
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
res = stdout.split("\n")
|
||||
for line in res:
|
||||
line = line.strip()
|
||||
if(match("Untracked files:", line)):
|
||||
return True
|
||||
return False
|
||||
|
||||
def check_for_changes():
|
||||
cmd = ["git", "status"]
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
res = stdout.split("\n")
|
||||
for line in res:
|
||||
line = line.strip()
|
||||
if(match("Changes not staged for commit:", line)):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_git_log():
|
||||
cmd = ["git", "log", "--encoding=UTF-8", "-1"]
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
res = stdout.split("\n")
|
||||
ret = []
|
||||
for line in res:
|
||||
line = line.strip()
|
||||
ret.append(line)
|
||||
return ret
|
||||
|
||||
def get_commit_list(git_log):
|
||||
ret = []
|
||||
git_commit = []
|
||||
first_run = True
|
||||
for line in git_log:
|
||||
if match("^commit ", line):
|
||||
if first_run:
|
||||
first_run = False
|
||||
else:
|
||||
ret.append(commit(git_commit))
|
||||
git_commit = []
|
||||
if len(line) > 0:
|
||||
git_commit.append(line)
|
||||
ret.append(commit(git_commit))
|
||||
return ret
|
||||
|
||||
def generate_include_file(file_name, commit_list, local_changes, untracked_files):
|
||||
if(len(commit_list) > 0):
|
||||
f = open(file_name, "w")
|
||||
f.write("/* Generated include file */\n\n")
|
||||
f.write("#ifndef GIT_COMMIT_H\n")
|
||||
f.write("#define GIT_COMMIT_H\n\n")
|
||||
f.write("#define CURRENT_COMMIT\t")
|
||||
f.write("\"" + commit_list[0].hash() + "\"\n")
|
||||
f.write("#define AUTHOR\t\t")
|
||||
f.write("\"" + commit_list[0].author() + "\"\n")
|
||||
f.write("#define LOCAL_CHANGES\t")
|
||||
if(local_changes):
|
||||
f.write("\"YES\"\n")
|
||||
else:
|
||||
f.write("\"NO\"\n")
|
||||
f.write("#define UNTRACKED_FILES\t")
|
||||
if(untracked_files):
|
||||
f.write("\"YES\"\n")
|
||||
else:
|
||||
f.write("\"NO\"\n")
|
||||
f.write("\n#endif /* GIT_COMMIT_H */\n")
|
||||
f.close()
|
||||
|
||||
def main(argv):
|
||||
local_changes = check_for_changes()
|
||||
untracked_files = check_for_untracked()
|
||||
log_list = get_git_log()
|
||||
commit_list = get_commit_list(log_list)
|
||||
generate_include_file("source/firmware/git_commit.h", commit_list, local_changes, untracked_files)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(argv[1:])
|
||||
|
47
source/scripts/stack_interface.py
Executable file
47
source/scripts/stack_interface.py
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/python2
|
||||
# Used to create symlink for git hooks
|
||||
from sys import argv, exit
|
||||
from getopt import getopt
|
||||
from re import match, sub
|
||||
import os
|
||||
|
||||
def print_help():
|
||||
print "Help screen"
|
||||
|
||||
def parse_stack_file(stackfile):
|
||||
f = open(stackfile, "r")
|
||||
rd = f.read().splitlines()
|
||||
for line in rd:
|
||||
if match("^\s*typedef.*$", line) and match("^.*stack_t.*$", line):
|
||||
return line
|
||||
|
||||
def create_board_interface(stack_define, outfile):
|
||||
f = open(outfile, "w")
|
||||
f.write("/* Stack include file */\n\n")
|
||||
f.write("#ifndef STACK_H\n")
|
||||
f.write("#define STACK_H\n\n")
|
||||
f.write(stack_define + "\n")
|
||||
f.write("\n#endif /* STACK_H */\n")
|
||||
|
||||
def main(argv):
|
||||
options, remainder = getopt(argv, "hi:o:", ["help", "infile=", "outfile="])
|
||||
infile = ""
|
||||
outfile = ""
|
||||
if len(options) < 2:
|
||||
print_help()
|
||||
exit(-1)
|
||||
for opt, arg in options:
|
||||
if opt in ("-h", "--help"):
|
||||
print_help()
|
||||
exit(0)
|
||||
elif opt in ("-i", "--infile"):
|
||||
infile = arg
|
||||
elif opt in ("-o", "--outfile"):
|
||||
outfile = arg
|
||||
if (len(infile) == 0) or (len(outfile) == 0):
|
||||
print_help()
|
||||
exit(-1)
|
||||
create_board_interface(parse_stack_file(infile), outfile)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(argv[1:])
|
20
source/scripts/symlink_hooks.py
Executable file
20
source/scripts/symlink_hooks.py
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/python2
|
||||
# Used to create symlink for git hooks
|
||||
from sys import argv
|
||||
import os
|
||||
|
||||
def main(argv):
|
||||
pwd = os.getcwd()
|
||||
base_dir = pwd.replace("source/scripts", "")
|
||||
target_dir = base_dir + "config/git_hooks/"
|
||||
link_dir = base_dir + ".git/hooks/"
|
||||
hooks = ["post-commit", "post-merge"]
|
||||
for hook in hooks:
|
||||
target = target_dir + hook
|
||||
link = link_dir + hook
|
||||
if (os.path.islink(link)) or (os.path.isfile(link)):
|
||||
os.remove(link)
|
||||
os.symlink(target, link)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(argv[1:])
|
Reference in New Issue
Block a user