OpenCores
URL https://opencores.org/ocsvn/sdhc-sc-core/sdhc-sc-core/trunk

Subversion Repositories sdhc-sc-core

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /sdhc-sc-core/trunk
    from Rev 162 to Rev 163
    Reverse comparison

Rev 162 → Rev 163

/header.py
3,6 → 3,7
import sys
import getopt
import os
from os import linesep
from subprocess import *
 
def usage():
31,6 → 32,7
def parseArgs(opts):
extension = None
extended = False
outfile = None
 
for opt, arg in opts:
if opt in ("-h", "--help"):
40,13 → 42,42
(shortname, extension) = os.path.splitext(arg)
if opt in ("-e", "--extended"):
extended = True
if opt == "-i":
outfile = shortname + extension
if opt in ("-o", "--out"):
outfile = arg
 
if extension == None:
print("No extension found. Did you specify a file?")
sys.exit(2)
 
return (shortname,extension,extended)
return (shortname,extension,extended, outfile)
 
def checkStaticHeader(header, content):
 
for i in range(0, len(header)):
if header[i] != content[i]:
return False
 
return True
 
def checkDynamicHeader(header, content):
for i in range(0, len(header)):
if header[i].split(':')[0] != content[i].split(':')[0]:
return False
 
return True
 
def addSCMExtension(newFile, filename, comment, extended):
if extended == True:
newFile.append(comment + "Changelog:" + linesep)
gitlog = Popen(["git", "log", "-n 3", "--pretty=short", "--reverse", filename], stdout=PIPE)
lines = gitlog.communicate()[0].splitlines()
 
for idx in range(0, len(lines)):
lines[idx] = comment + lines[idx] + linesep
newFile.extend(lines)
 
def main(argv):
if len(argv) == 0:
usage()
53,49 → 84,80
sys.exit(2)
 
try:
opts, args = getopt.getopt(argv, "hef:", ["help","file=", "extended"])
opts, args = getopt.getopt(argv, "hef:io:", ["help","file=", "extended", "out="])
except getopt.GetoptError:
usage()
sys.exit(2)
 
(shortname, extension, extended) = parseArgs(opts);
(shortname, extension, extended, outfile) = parseArgs(opts);
comment = getComment(extension)
 
print(comment + "SDHC-SC-Core")
print(comment + "Secure Digital High Capacity Self Configuring Core")
print(comment)
print(comment + "(C) Copyright 2010 Rainer Kastl")
print(comment)
print(comment + "This file is part of SDHC-SC-Core.")
print(comment)
print(comment + "SDHC-SC-Core is free software: you can redistribute it and/or modify it")
print(comment + "under the terms of the GNU Lesser General Public License as published by")
print(comment + "the Free Software Foundation, either version 3 of the License, or (at")
print(comment + "your option) any later version.")
print(comment)
print(comment + "SDHC-SC-Core is distributed in the hope that it will be useful, but")
print(comment + "WITHOUT ANY WARRANTY; without even the implied warranty of")
print(comment + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU")
print(comment + "General Public License for more details.")
print(comment)
print(comment + "You should have received a copy of the GNU Lesser General Public License")
print(comment + "along with SDHC-SC-Core. If not, see http://www.gnu.org/licenses/.")
print(comment)
print(comment + "File : " + shortname + extension)
print(comment + "Owner : Rainer Kastl")
print(comment + "Description : ")
print(comment + "Links : ")
print(comment)
with open(shortname+extension) as f:
content = f.readlines()
 
if extended == True:
print(comment + "Changelog:")
gitlog = Popen(["git", "log", "-n 3", "--pretty=short", "--reverse", shortname+extension], stdout=PIPE)
output = gitlog.communicate()[0]
lines = output.splitlines()
staticheader = [
comment + "SDHC-SC-Core"+ linesep,
comment + "Secure Digital High Capacity Self Configuring Core"+ linesep,
comment+ linesep,
comment + "(C) Copyright 2010 Rainer Kastl"+ linesep,
comment+ linesep,
comment + "This file is part of SDHC-SC-Core."+ linesep,
comment+ linesep,
comment + "SDHC-SC-Core is free software: you can redistribute it and/or modify it"+ linesep,
comment + "under the terms of the GNU Lesser General Public License as published by"+ linesep,
comment + "the Free Software Foundation, either version 3 of the License, or (at" + linesep,
comment + "your option) any later version."+ linesep,
comment+ linesep,
comment + "SDHC-SC-Core is distributed in the hope that it will be useful, but" + linesep,
comment + "WITHOUT ANY WARRANTY; without even the implied warranty of"+ linesep,
comment + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU"+ linesep,
comment + "General Public License for more details."+ linesep,
comment+ linesep,
comment + "You should have received a copy of the GNU Lesser General Public License"+ linesep,
comment + "along with SDHC-SC-Core. If not, see http://www.gnu.org/licenses/." + linesep,
comment + linesep,
comment + "File : " + os.path.basename(shortname + extension) + linesep]
 
for line in lines:
print(comment + line)
dynamicheader = [comment + "Owner : " + linesep,
comment + "Description : " + linesep,
comment + "Links : " + linesep,
comment + linesep]
 
newFile = []
 
if checkStaticHeader(staticheader, content):
newFile.extend(content[0:len(staticheader)])
 
if checkDynamicHeader(dynamicheader, content[len(staticheader):]):
newFile.extend(content[len(staticheader):len(staticheader) + len(dynamicheader)])
content = content[len(staticheader)+len(dynamicheader):]
else:
dynamicheader[0] = dynamicheader[0].rstrip() + " Rainer Kastl" + linesep
newFile.extend(dynamicheader)
print("Header rewritten, you should check the file!")
 
addSCMExtension(newFile, shortname+extension, comment, extended)
else:
print("Header rewritten, you should check the file!")
newFile.extend(staticheader)
dynamicheader[0] = dynamicheader[0].rstrip() + " Rainer Kastl" + linesep
newFile.extend(dynamicheader)
addSCMExtension(newFile, shortname+extension, comment, extended)
newFile.append(linesep)
 
newFile.extend(content)
 
# write file
if outfile == None:
for line in newFile:
line = line.rstrip()
print(line)
else:
with open(outfile, mode='w') as a_file:
for line in newFile:
a_file.write(line)
 
if __name__ == "__main__":
main(sys.argv[1:])
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.