Commits

Sheng Mao committed 0c772df

GenVSDir is a semi-automatic script which create Visual Studio 2010 project
filters the same like the directory structure.

Comments (0)

Files changed (1)

genvsdir/genvsdir.py

+__author__ = 'mao'
+
+import os, uuid, sys, string
+
+file_format = """<ClCompile Include="%s">
+    <Filter>%s</Filter>
+</ClCompile>"""
+
+file_decl_format = """<ClCompile Include="%s" />"""
+
+header_format = """<ClInclude Include="%s">
+    <Filter>%s</Filter>
+</ClInclude>"""
+
+header_decl_format = """<ClInclude Include="%s" />"""
+
+filter_format = """<Filter Include="%s">
+      <UniqueIdentifier>%s</UniqueIdentifier>
+</Filter>"""
+
+filter_list = {}
+file_list = []
+decl_list = []
+
+def GenDir (root_dir):
+    for root, dirs, files in os.walk(root_dir):
+        for file_name in files:
+            path = "%s\%s" % (root, file_name)
+            if filter_list.has_key(root):
+                pass
+            else:
+                filter_list[root] = uuid.uuid1()
+            # classify files
+            def GetFormat (file_name):
+                dot_parts = string.split(s = file_name, sep = ".")
+                if len(dot_parts) != 0:
+                    if string.lower(dot_parts[-1]) in ["c", "cpp", "cxx"]:
+                        return file_format, file_decl_format
+                return header_format, header_decl_format
+            # back to GenDir
+            frmt, decl = GetFormat(path)
+            file_list.append((path, root, frmt))
+            decl_list.append((path, decl))
+
+def PrintDir ():
+    for filter in filter_list.keys():
+        print filter_format % (filter, filter_list[filter])
+    print "<!-- End -->"
+    for file in file_list:
+        print file[2] % (file[0], file[1])
+    print "<!-- End -->"
+    for decl in decl_list:
+        print decl[1] % decl[0]
+
+GenDir(sys.argv[1])
+PrintDir()
+
+