Change URI to specific ovsdb node
[integration/test.git] / tools / Robot_Tool / create_docs.py
1 """
2 Robot testdoc and testlib generator
3 Authors: Kailash Khalasi (kkhalasi@iix.net)
4 Created: 2015-07-21
5 This script will issue a command to all the robot suites and libraries in the given directories
6 to generate documentation using Robot's "testdoc" and "libdoc" tool.
7 ex usage: python create_docs.py suitelocation librarylocation suitedocoutputlocation libdocoutputlocation
8 ex values:
9 suitelocation:$HOME/integration/test/csit/suites
10 librarylocation:$HOME/integration/test/csit/libraries
11 suitedocoutputlocation:/tmp/RobotDocs
12 libdocoutputlocation: /tmp/RobotLibs
13 """
14
15 import os
16 from sys import argv
17 import robot.testdoc
18 import robot.libdoc
19
20 if len(argv) != 5:
21     suiteRoot = os.getenv("HOME")+'/integration/test/csit/suites'
22     libraryRoot = os.getenv("HOME")+'/integration/test/csit/libraries'
23     tmpSuite = '/tmp/RobotDocs/'
24     tmpLib = '/tmp/RobotLibs/'
25     print "All arguments are not passed....Using default arguments:"
26     print 'Suite Location: ' + suiteRoot
27     print 'Library Location: ' + libraryRoot
28     print 'Suite Doc Output Location: ' + tmpSuite
29     print 'Library Doc Output Location: ' + tmpLib
30 else:
31     script, suiteRoot, libraryRoot, tmpSuite, tmpLib = argv
32
33
34 def generate_docs(testDir, outputFolder, debug=False):
35     """
36     Generate Robot Documentation
37
38     Args:
39         testDir: The directory in which your robot files live (can be suites or libraries)
40         outputFolder: The directory where you want your generated docs to be placed.
41
42         This function will "walk" through each robot file in the given "suitelocation"
43         and "librarylocation" and will issue a python -m robot.testdoc|libdoc on each
44         of those files. The script will first determine if you've passed in a robot
45         suite location or robot library location. The outcome generates an HTML file
46         (our expected documents) to the given "suitedocoutputlocation"|"libdocoutputlocation".
47
48     :param debug: Default is false. Setting debug to true will print the output of each
49            command entered to generate a robot doc
50     """
51
52     if testDir == suiteRoot:
53         docFunction = robot.testdoc.testdoc
54     else:
55         docFunction = robot.libdoc.libdoc
56
57     for root, dirs, files, in os.walk(testDir):
58         for file in files:
59             if file.endswith(".robot"):
60                 inputFile = os.path.join(root, file)
61                 outputFile = os.path.join(outputFolder, file + ".html")
62                 docFunction(inputFile, outputFile)
63
64 tmpDirs = [tmpSuite, tmpLib]
65 for dirs in tmpDirs:
66     if not os.path.exists(dirs):
67         os.makedirs(dirs)
68
69 generate_docs(suiteRoot, tmpSuite)
70 generate_docs(libraryRoot, tmpLib)