Created
February 5, 2018 19:09
-
-
Save amorri40/6caea48c3343da6a9e4fd6354846849e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fnmatch | |
import os | |
import subprocess | |
def execute_command(bashCommand): | |
return subprocess.check_output(bashCommand.split(),stderr= subprocess.STDOUT) | |
libraries = {} | |
for root, dirnames, filenames in os.walk('libs'): | |
matches = [] | |
path_parts = root.split('/') | |
library_name=root | |
if (len(path_parts) > 1): | |
library_name = path_parts[1] | |
if not library_name in libraries: | |
libraries[library_name] = {'patfiles':[]} | |
print 'Library:', library_name | |
for filename in fnmatch.filter(filenames, '*.[aA]'): | |
print "Filename:", filename | |
full_path = (os.path.join(root, filename)) | |
output_path = full_path.replace(' ','_').replace('+','')+'.pat' | |
# bashCommand = './pelf '+full_path+' '+output_path | |
# print bashCommand | |
bashCommands = ['./pelf', full_path, output_path] | |
print bashCommands | |
output = subprocess.check_output(bashCommands,stderr= subprocess.STDOUT) | |
libraries[library_name]["patfiles"].append(output_path) | |
outputParts = output.split(' ') | |
skipped = outputParts[2] | |
total = outputParts[4] | |
print "A file: ",outputParts, skipped, total | |
matches.append(full_path+'.pat') | |
# print libraries | |
def moveOutputToGeneratedDirectory(libraryName, outputSigName, patternFiles): | |
outputDirectory = "./generated/"+libraryName+"/" | |
outputExcludedFile = libraryName+".exc" | |
execute_command("mkdir -p "+outputDirectory+"/patternfiles/") | |
execute_command("mv "+ outputSigName + " "+outputDirectory) | |
# | |
# make sure to only copy the exc file as otherwise changes will be overwritten | |
# | |
execute_command("cp "+ outputExcludedFile + " "+outputDirectory) | |
print "Pattern files:"+patternFiles | |
execute_command("cp "+ patternFiles + " "+outputDirectory+"/patternfiles/") | |
print "Now looping through libraries to create a single .sig file" | |
for libraryName in libraries: | |
library = libraries[libraryName] | |
if len(library['patfiles']) <1: | |
continue | |
print libraryName | |
outputSigName = libraryName+'.sig' | |
allPatternFilesAdded = '+'.join(library['patfiles']) | |
bashCommand = './sigmake -n'+libraryName+' '+allPatternFilesAdded+' '+outputSigName | |
print bashCommand | |
output="" | |
try: | |
output = subprocess.check_output(bashCommand.split(),stderr= subprocess.STDOUT) | |
except: | |
print output | |
outputExcludedFile = libraryName+".exc" | |
if os.path.isfile(outputSigName): | |
moveOutputToGeneratedDirectory(libraryName, outputSigName, ' '.join(library['patfiles'])) | |
print "Successfully Generated",outputSigName | |
elif os.path.isfile(outputExcludedFile): | |
print "Please edit ",outputExcludedFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment