74 lines
2 KiB
Python
74 lines
2 KiB
Python
import argparse
|
|
import os
|
|
import sys
|
|
|
|
|
|
# Directories to exclude from blob
|
|
excludedDirs = { "projects", "doc", "extern", "math_v2", "stl" }
|
|
|
|
|
|
def filterDirs(dirs):
|
|
""" Remove directories present in the exclusion list
|
|
"""
|
|
newDirs = list( set(dirs) - excludedDirs)
|
|
newDirs.sort()
|
|
return newDirs
|
|
|
|
|
|
def filterFilesOnExtension(files, ext):
|
|
""" Filter files based on their extension
|
|
"""
|
|
def filterPredicate(filename):
|
|
fExt = filename[filename.find('.')+1:]
|
|
return fExt != None and fExt.lower() == ext.lower()
|
|
|
|
return filter( filterPredicate, files )
|
|
|
|
|
|
def filterFilesOnContent(files):
|
|
skipSPUTag = '@skipspu'
|
|
|
|
basePath = os.getcwd() + '/'
|
|
|
|
""" Filter the file based on whether its first line contains skipSPUTag or not.
|
|
"""
|
|
def filterPredicate(filename):
|
|
with open(basePath + filename, 'r') as file:
|
|
firstLine = file.readline()
|
|
tagLocation = firstLine.lower().find(skipSPUTag)
|
|
tagFound = tagLocation != -1
|
|
|
|
if tagFound:
|
|
detail = firstLine[tagLocation + len(skipSPUTag):].strip()
|
|
|
|
print 'Skipping the file "%s". Detail: "%s"' % (filename, detail if len(detail) > 0 else 'None given')
|
|
|
|
return not tagFound
|
|
|
|
return True
|
|
|
|
return filter( filterPredicate, files )
|
|
|
|
|
|
def findAllFiles(root, ext):
|
|
"""Example findAllFiles('../../gear_core','cpp')
|
|
will find all .cpp in gear_core
|
|
"""
|
|
# Root has to be excluded
|
|
satelliteDirName, subdirs, rootFiles = os.walk(root).next()
|
|
subdirs = filterDirs(subdirs)
|
|
allFiles = []
|
|
|
|
for subdir in subdirs:
|
|
for dirname, dirs, files in os.walk( os.path.join( root, subdir ) ):
|
|
if os.path.split(dirname)[1] in excludedDirs:
|
|
continue
|
|
|
|
fixedDirName = dirname.replace('\\','/')
|
|
|
|
files = filterFilesOnExtension(files, ext)
|
|
allFiles += map( lambda f: fixedDirName + '/' + f, files )
|
|
|
|
allFiles = filterFilesOnContent(allFiles)
|
|
|
|
return allFiles
|