forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.py
55 lines (48 loc) · 1.96 KB
/
process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python2
## @package process
# Module doxygen.process
# Script to insert preamble for doxygen and regen API docs
import glob, os, shutil
# Module caffe2...caffe2.python.control_test
def insert(originalfile,first_line,description):
with open(originalfile,'r') as f:
f1 = f.readline()
if(f1.find(first_line)<0):
docs = first_line + description + f1
with open('newfile.txt','w') as f2:
f2.write(docs)
f2.write(f.read())
os.rename('newfile.txt',originalfile)
else:
print('already inserted')
# move up from /caffe2_root/doxygen
os.chdir("..")
os.system("git checkout caffe2/contrib/.")
os.system("git checkout caffe2/distributed/.")
os.system("git checkout caffe2/experiments/.")
os.system("git checkout caffe2/python/.")
for root, dirs, files in os.walk("."):
for file in files:
if (file.endswith(".py") and not file.endswith("_test.py") and not file.endswith("__.py")):
filepath = os.path.join(root, file)
print("filepath: " + filepath)
directory = os.path.dirname(filepath)[2:]
directory = directory.replace("/",".")
print "directory: " + directory
name = os.path.splitext(file)[0]
first_line = "## @package " + name
description = "\n# Module " + directory + "." + name + "\n"
print first_line,description
insert(filepath,first_line,description)
if os.path.exists("doxygen/doxygen-python"):
print("Looks like you ran this before, so we need to cleanup those old files...")
shutil.rmtree("doxygen/doxygen-python")
else:
os.makedirs("doxygen/doxygen-python")
if os.path.exists("doxygen/doxygen-c"):
print("Looks like you ran this before, so we need to cleanup those old files...")
shutil.rmtree("doxygen/doxygen-c")
else:
os.makedirs("doxygen/doxygen-c")
os.system("doxygen .Doxyfile-python")
os.system("doxygen .Doxyfile-c")