5 import glob, os, shutil
8 def insert(originalfile,first_line,description):
9 with open(originalfile,
'r') as f: f1 = f.readline() 10 if(f1.find(first_line)<0): 11 docs = first_line + description + f1 12 with open('newfile.txt',
'w')
as f2:
15 os.rename(
'newfile.txt',originalfile)
17 print(
'already inserted')
21 os.system(
"git checkout caffe2/contrib/.")
22 os.system(
"git checkout caffe2/distributed/.")
23 os.system(
"git checkout caffe2/experiments/.")
24 os.system(
"git checkout caffe2/python/.")
26 for root, dirs, files
in os.walk(
"."):
28 if (file.endswith(
".py")
and not file.endswith(
"_test.py")
and not file.endswith(
"__.py")):
29 filepath = os.path.join(root, file)
30 print(
"filepath: " + filepath)
31 directory = os.path.dirname(filepath)[2:]
32 directory = directory.replace(
"/",
".")
33 print "directory: " + directory
34 name = os.path.splitext(file)[0]
35 first_line =
"## @package " + name
36 description =
"\n# Module " + directory +
"." + name +
"\n" 37 print first_line,description
38 insert(filepath,first_line,description)
40 if os.path.exists(
"doxygen/doxygen-python"):
41 print(
"Looks like you ran this before, so we need to cleanup those old files...")
42 shutil.rmtree(
"doxygen/doxygen-python")
44 os.makedirs(
"doxygen/doxygen-python")
46 if os.path.exists(
"doxygen/doxygen-c"):
47 print(
"Looks like you ran this before, so we need to cleanup those old files...")
48 shutil.rmtree(
"doxygen/doxygen-c")
50 os.makedirs(
"doxygen/doxygen-c")
52 os.system(
"doxygen .Doxyfile-python")
53 os.system(
"doxygen .Doxyfile-c")