b4986813837bb1dbc23e3a1cb344dad3ad7e25b7
[integration/test.git] / test / tools / Robot_Tool / libraries / 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 import subprocess
17 from sys import argv
18
19 if len(argv) != 5:
20     suiteRoot = os.getenv("HOME")+'/integration/test/csit/suites'
21     libraryRoot = os.getenv("HOME")+'/integration/test/csit/libraries'
22     tmpSuite = '/tmp/RobotDocs/'
23     tmpLib = '/tmp/RobotLibs/'
24     print "All arguments are not passed....Using default arguments:"
25     print 'Suite Location: ' + suiteRoot
26     print 'Library Location: ' + libraryRoot
27     print 'Suite Doc Output Location: ' + tmpSuite
28     print 'Library Doc Output Location: ' + tmpLib
29 else:
30     script, suiteRoot, libraryRoot, tmpSuite, tmpLib = argv
31
32
33 def generate_docs(testDir, outputFolder, debug=False):
34     """
35     Generate Robot Documentation
36
37     Args:
38         testDir: The directory in which your robot files live (can be suites or libraries)
39         outputFolder: The directory where you want your generated docs to be placed.
40
41         This function will "walk" through each robot file in the given "suitelocation"
42         and "librarylocation" and will issue a python -m robot.testdoc|libdoc on each
43         of those files. The script will first determine if you've passed in a robot
44         suite location or robot library location. The outcome generates an HTML file
45         (our expected documents) to the given "suitedocoutputlocation"|"libdocoutputlocation".
46
47     :param debug: Default is false. Setting debug to true will print the output of each
48            command entered to generate a robot doc
49     """
50
51     if testDir == suiteRoot:
52         doctype = 'testdoc'
53     else:
54         doctype = 'libdoc'
55
56     for root, dirs, files, in os.walk(testDir):
57         for file in files:
58             if file.endswith(".robot"):
59                 cmd = 'python -m robot.' + doctype + ' ' + root + '/' + file + ' ' + outputFolder + file + '.html'
60                 print cmd
61                 p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62                 output, errors = p.communicate()
63                 if debug:
64                     print output, errors
65
66 tmpDirs = [tmpSuite, tmpLib]
67 for dirs in tmpDirs:
68     if not os.path.exists(dirs):
69         os.makedirs(dirs)
70
71 generate_docs(suiteRoot, tmpSuite)
72 generate_docs(libraryRoot, tmpLib)