Caffe2 - Python API
A deep learning, cross platform ML framework
process.py
1 
4 
5 import glob, os, shutil
6 
7 # Module caffe2...caffe2.python.control_test
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:
13  f2.write(docs)
14  f2.write(f.read())
15  os.rename('newfile.txt',originalfile)
16  else:
17  print('already inserted')
18 
19 # move up from /caffe2_root/doxygen
20 os.chdir("..")
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/.")
25 
26 for root, dirs, files in os.walk("."):
27  for file in files:
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)
39 
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")
43 else:
44  os.makedirs("doxygen/doxygen-python")
45 
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")
49 else:
50  os.makedirs("doxygen/doxygen-c")
51 
52 os.system("doxygen .Doxyfile-python")
53 os.system("doxygen .Doxyfile-c")
54