scripts + template header to determine repository state

This commit is contained in:
tkl 2016-07-26 11:44:06 +02:00
parent 17d5c70490
commit 6510d34e81
6 changed files with 160 additions and 0 deletions

View File

@ -5,6 +5,11 @@
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers> <triggers>clean,full,incremental,</triggers>
@ -23,5 +28,6 @@
<nature>org.eclipse.cdt.core.ccnature</nature> <nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

5
.pydevproject Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
</pydev_project>

View File

@ -0,0 +1,11 @@
/* Generated include file */
#ifndef GIT_COMMIT_H
#define GIT_COMMIT_H
#define CURRENT_COMMIT "0"
#define AUTHOR "tkl <tkl@blackfinn.de"
#define LOCAL_CHANGES "NO"
#define UNTRACKED_FILES "NO"
#endif /* GIT_COMMIT_H */

2
source/scripts/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
commit.pyc

46
source/scripts/commit.py Normal file
View 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
View 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("../firmware/git_commit.h", commit_list, local_changes, untracked_files)
if __name__ == "__main__":
main(argv[1:])