Go Back   Scooter Forums > Beyond Compare 3 Discussion > Scripting
Register FAQ Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 10-Jul-2013, 12:03 PM
Elton Elton is offline
Visitor
 
Join Date: Jul 2013
Posts: 3
Default SLOC count with Python

Hi everyone,

I am new to Beyond Compare so bare with me. I am currently brainstorming a Python code that will read in all the source files from a directory (including source files from subfolders) in a network, take the physical SLOC (Source Line of Code) count for each file, then sum them up and output it on a xml file.

From what I have read on the "Automating with Scripts" page, it does not seem BC3 has a library set that I can use on other languages like Python. So what I will probably have to do is write a BC script to take in all the source files from a directory, then get and output the SLOC count. Then write a Python code to run the script, then parse the SLOC counts from the output file, add all the SLOC counts up (unless I can get the total SLOC count directly), and generate an xml file with that info. Do you think that is the most logical way of doing things?

I am not entirely sure what BC scripts are capable of, like what functions to use to get all the files from a directory. Also, I don't need to compare any files. I just need the SLOC counts. I guess I could name the same directory twice, but it seems redundant.

Any help is appreciated.

Thanks.

Elton
Reply With Quote
  #2  
Old 10-Jul-2013, 04:34 PM
Chris Chris is offline
Team Scooter
 
Join Date: Oct 2007
Location: Madison, WI
Posts: 3,898
Default

Beyond Compare doesn't have an API, you can only call scripts from the command line.

Here's an example script that will output statistics on important and unimportant lines of text in a single folder:

load c:\folder
expand all
select all.files
text-report layout:summary output-tout.txt

To run the above script, save it as a text file and use the command line:
bcompare.exe @c:\script.txt

The @ character tells Beyond Compare to run a file as a script rather than load it for comparison.

In the context of the report, unimportant lines are those that contain only whitespace and/or comments.

The summary layout is designed to be human readable. You can also use "text-report layout:statistics output-tout.txt" to output results as comma separated values. The statistics layout also includes a total at the end, summary doesn't report a total.
__________________
Chris K Scooter Software
Reply With Quote
  #3  
Old 11-Jul-2013, 01:46 PM
Elton Elton is offline
Visitor
 
Join Date: Jul 2013
Posts: 3
Default

Hi Chris,

Thank you for your suggestion! Much is appreciated! It really helped me a lot. Since there is no API, what I ended up doing on Python is to generate a bcscript.txt file and a batch file to execute the script, and it worked great. This is my output:



This is pretty much what I wanted. However, bcscript.txt, cmdBCScript.bat, rawSLOC.csv, and SLOCCounter.py should not be counted because those are not the source files. Those are files I am using to get my SLOC count. I was wondering if there are any BC script commands to filter specific files names. It should also not read in file with the *.txt extension, so I was wondering how to filter those out also. So really, the only file that should have been counted for is the findDup.cpp.

Thanks.

Elton
Reply With Quote
  #4  
Old 12-Jul-2013, 08:56 AM
Chris Chris is offline
Team Scooter
 
Join Date: Oct 2007
Location: Madison, WI
Posts: 3,898
Default

Use the filter command to limit the files affected by the script.

Example:

filter "-*.py;-*.txt;-*.bat;-*.csv"
load c:\folder
expand all
select all.files
text-report layout:summary output-tout.txt

Filters can be file masks or exact filenames, with multiple filters separated by semicolons.
__________________
Chris K Scooter Software
Reply With Quote
  #5  
Old 12-Jul-2013, 08:56 AM
Chris Chris is offline
Team Scooter
 
Join Date: Oct 2007
Location: Madison, WI
Posts: 3,898
Default

You can also use "filter *.cpp" to only see files with .cpp extensions.
__________________
Chris K Scooter Software
Reply With Quote
  #6  
Old 12-Jul-2013, 09:45 AM
Elton Elton is offline
Visitor
 
Join Date: Jul 2013
Posts: 3
Default

Thanks, Chris! My program is running perfectly. I just found the "Scripting Reference" page too at the support reference, so I will look more into it other scripting functions.

Thanks again.

Elton
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 11:00 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.