Skip to content

Instantly share code, notes, and snippets.

@johnfredcee
Created December 29, 2011 14:53
Show Gist options
  • Select an option

  • Save johnfredcee/1534432 to your computer and use it in GitHub Desktop.

Select an option

Save johnfredcee/1534432 to your computer and use it in GitHub Desktop.
Top Level Tag File Scanner
#!/usr/bin/python
import os
import tempfile
import shlex
import subprocess
import sys
def is_source(file, suffixes):
return os.path.isfile(file) and (os.path.splitext(file)[1] in suffixes)
def dirscan(sdir, suffixes):
return [ os.path.abspath(os.path.join(sdir,sfile)) for sfile in os.listdir(os.path.abspath(sdir)) if is_source(os.path.join(sdir,sfile), suffixes) ]
suffixes = [ ".cpp", ".c", ".h", ".hpp", ".inl" ]
tags = {
"OGRE" : [ "/usr/include/OGRE" ],
"OIS" : [ "/usr/include/OIS" ],
"Assimp" : [ "/usr/include/assimp" ]}
if __name__ == "__main__":
for (lib, dirs) in zip(tags.keys(), tags.values()):
# generate a temp file of all files to tag
filelist = [ dirscan(sdir, suffixes) for sdir in dirs ]
listfile = tempfile.NamedTemporaryFile(mode="w+", dir=os.getcwd(), delete=False)
listname = listfile.name
outfile = lib + ".TAGS"
for files in filelist:
for fline in files:
print >>listfile, fline
listfile.close()
# tag them
etagargs = shlex.split(r"ctags -e --verbose --c-kinds=+pxd --c++-kinds=+pxd --extra=+q -o Documents/%s -L %s" % (outfile,listname))
try:
retcode = subprocess.call(etagargs)
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
else:
print >>sys.stderr, "Child returned", retcode
except OSError, e:
print >>sys.stderr, "Execution failed:", e
os.remove(listname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment