Create a web page capturing the Constructive Cost Model (COCOMO) Computation
Usage
The getCOCOMO script uses SLOCcount to look at all files in a directory treeand compute time and level of effort for STRS application repository metadata. This python script currently only works on a UNIX-based system where SLOCcount has been installed.
Alternately, one may use the script getSLOC.python.txt to compute the SLOC. Then divide by 1000 to obtain KLOC. Then use the web page COCOMO calculation.html
usage: getCOCOMO.python.txt [-h] [-t TITLE] [-w [WEBFILE]] [-s SUBDIRECTORY] directory positional arguments: directory Path to files to be analyzed. optional arguments: -h, --help show this help message and exit -t TITLE, --title TITLE Title used in web page output. -w [WEBFILE], --web [WEBFILE] Web page output file name. -s SUBDIRECTORY, --subdirectory SUBDIRECTORY Subdirectory to output web page file.
If the output WEBFILE is blank, “COCOMO.YYYYmmddHHMMSS.html” is created. If the output WEBFILE does not end in “.htm” or “.html”, “.html” is appended. If the output WEBFILE exists, it is overwritten.
- It is easier to cd to the somewhere at or below the directory of interest so that “../” does not appear.
- In a PC command window, the following was executed:
c:\python27\python getCOCOMO.python.txt ./
and it displayed:
Not implemented on Windows
The same thing occurred using Python 3.2. - In a Linux command window, the following was executed:
cd $HOME/strs/20120207
python27 getCOCOMO.python.txt -w COCOMO.20120913.27 ./STRS_Architecture_RI/WFCCN
…
Created web file: COCOMO.20120913.27.html
or
python32 getCOCOMO.python.txt -w COCOMO.20120913.32 ./STRS_Architecture_RI/WFCCN
…
Created web file: COCOMO.20120913.32.htmlNote that if there are any spaces in the command line options (e.g. title or file names), a single set of quotes are not sufficient to make python get the command line arguments as a single string.- Escaping the spaces in the command line did not work.
- Substituting for each space in the command line title worked by letting the browser transform them into the spaces in the title where the Linux Bourne shell and python see continuous characters. That wouldn’t work for a file name.
- On Linux, using mixed quotes around a title or file name with spaces works. One set of quotes is consumed by the Linux Bourne shell and the remaining set is recognized by python, where the quotes disappear when using argparse and it can’t find the end of the title or file name with spaces. However, only the inner set of quotes disappear which allowed a work-around where I parsed the command line and put the pieces back together until the quotes matched.
- Using Python 3.2, the following warning was observed:
subprocess.py:389: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads. “program uses threads.”, RuntimeWarning)
however, there didn’t appear to be any bad effects.
- Note that the getCOCOMO script has been tested using “Python 2.7.3” and “Python 3.2.3”. If you have an older version, it may not work. To determine which version of python you are using, type python (or equivalent) on a command line. It will return the version in an interactive mode. To exit, type “exit()” or “quit()” or Ctrl-Z plus Return.
- Note that if you install python, python must be started so that it can find the corresponding python-related files. On Linux, for example, the PATH variable needed to be changed and the easiest way to do this was to create a Bourne shell script. For example, to execute python in $HOME/python-2.7.3, I created $HOME/bin/python27 (where $HOME/bin is already in the PATH variable) containing:
#!/bin/sh # python27 ... PATH=$HOME/Python-2.7.3:$PATH python $*
Then I made $HOME/bin/python27 executable (chmod +x $HOME/bin/python27) and executed the following, after reinitializing the command window shell:
python27 getCOCOMO.python.txt ./
which worked fine.