Merge pull request #14 from leoheck/master

Adds CLI super powers
This commit is contained in:
John 2020-05-31 10:16:26 +01:00 committed by GitHub
commit 0e02423ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 140 additions and 78 deletions

View File

@ -1,6 +1,7 @@
# KiCad-Diff
This is a python program with a Tk interface for comparing KiCad PCB revisions.
This is a python program with a Tk interface for comparing KiCad PCB revisions.
The diffing strategy has been changed for this version and SVGs are generated directly rather than doing renderings in ImageMagick as in previous versions. This has made the rendering possible for all layers in a few seconds (compared to 20-60s+ depending on resolution and number of layers selected in previous version). The SVG images are layered together with a different feColorMatrix filter applied to each diff. This highlights areas where features have been added or removed.
The output is presented as a gallery of images of each layer. Each layer pair can be compared and the combined view highlights clearly where the layers differ from each other.
@ -10,65 +11,93 @@ The diff output can be scrolled and zoomed in and out for closer inspection. The
There is an additional 'Text Diff' which is helpful for identifying specific areas which have changed. Ongoing work to compare netlist directly.
This was originally written as a bash script, this newer GUI version has been rewritten in Python3 and supports Git, SVN and Fossil as SCM tools. I have also removed many of the dependencies.
![Cu difference view](/Documents/cu.png)
**Instructions**
* Check that the paths to your SCM tools are correct (lines 39-45). You do not need to install all of these but if you do not have one make sure that you set it to null e.g. if you don't have SVN installed, make sure you set svnProg=''.
* Ensure that you have python3 installed. Why? https://www.pythonclock.org
* Install 'plotPCB.py' in /usr/local/bin (or adjust path in lines 45 to suit) This needs to be executable. This program actually generates the necessary SVG files.
* MacOS requires a bit of tweaking - KiCad on macOS uses a locally installed version of python and NOT the system python. For other *nix operating systems, the site-packages are installed under the system python so don't need any further adjustment. For macOS, use the 'plotPCB_macOS.py' file. This also assumes that KiCad is installed normally in the 'Applications' folder
* Run the main script and select a pair of versions in a source controlled repository from the GUI. The GUI should show which SCM is in use.
* The terminal should give you some useful information on progress. Please include a copy of this if you have any issues.
* Hit Ctrl + C to terminate the webserver.
## Instructions
The script should build a series of svg files and display the diff in a webpage. If a web page doesn't open automatically, navigate to "http://127.0.0.1:9090/web/index.html" to view the output. You can adjust the port used (9090 by default) if this conflicts with your existing set-up.
- Check that the paths to your SCM tools are correct (lines 39-45). You do not need to install all of these but if you do not have one make sure that you set it to null e.g. if you don't have SVN installed, make sure you set svnProg=''.
- Ensure that you have Python3 installed. Why? https://www.pythonclock.org
- Install 'plotPCB.py' in /usr/local/bin (or adjust path in lines 45 to suit) This needs to be executable. This program actually generates the necessary SVG files.
- MacOS requires a bit of tweaking - KiCad on macOS uses a locally installed version of python and NOT the system python. For other *nix operating systems, the site-packages are installed under the system python so don't need any further adjustment. For macOS, use the 'plotPCB_macOS.py' file. This also assumes that KiCad is installed normally in the 'Applications' folder
- Run the main script and select a pair of versions in a source controlled repository from the GUI. The GUI should show which SCM is in use.
- The terminal should give you some useful information on progress. Please include a copy of this if you have any issues.
- Hit `Ctrl+C` to terminate the webserver.
***Debugging***
There should be some output in the launch terminal. Please copy this and include it in any issues posted. If the program is not working, please check that you can run the 'plotPCB.py' routine directly by invoking it from the command line and passing it two arguments (1) The name of a *.kicad_pcb file and (2) a test directory for the plots to end up in;
e.g. ```plotPCB.py TestBoard.kicad_pcb testdir```
The script should build a series of svg files and display the diff in a webpage. If a web page doesn't open automatically, navigate to "http://127.0.0.1:9090/web/index.html" to view the output. You can adjust the port used (9090 by default) if this conflicts with your existing set-up.
## Command Line Usage
```
➜ ./kidiff_linux.py -h
usage: kidiff_linux.py [-h] [-d DISPLAY] [-a COMMIT1] [-b COMMIT2] [-s SCM] [-g] [-p PORT] [-w] kicad_pcb
Kicad PCB visual diffs.
positional arguments:
kicad_pcb Kicad PCB
optional arguments:
-h, --help show this help message and exit
-d DISPLAY, --display DISPLAY
Set DISPLAY value, default :1.0
-a COMMIT1, --commit1 COMMIT1
Commit1
-b COMMIT2, --commit2 COMMIT2
Commit2
-s SCM, --scm SCM Select SCM (Git, SVN, Fossil)
-g, --gui Use gui
-p PORT, --port PORT Set webserver port
-w, --webserver-disable
Does not execute webserver (just generate images)
```
## Debugging
There should be some output in the launch terminal. Please copy this and include it in any issues posted. If the program is not working, please check that you can run the `plotPCB.py` routine directly by invoking it from the command line and passing it two arguments (1) The name of a `*.kicad_pcb` file and (2) a test directory for the plots to end up in;
```
plotPCB.py boar.kicad_pcb output_folder
```
## Next Steps
***Plans***
1. Improvement in parsing and meaning of text diffs.
2. Place all template text/css text in external files.
3. Improve display of artefacts in diff choice window.
3. Improve display of artifacts in diff choice window.
4. Consider changing GUI elements to wxPython.
5. Adjust for three pane output to have white outer border & pan-zoom control, not filter colour.
5. Adjust for three pane output to have white outer border & pan-zoom control, not filter color.
6. Improve three pane output layout, perhaps with diff tree on LHS and not underneath.
7. Consider adding 'Preferences' for this program.
***Screenshots***
# Screenshots
***GUI***
### GUI
![GUI](/Documents/gui.png)
![GUI](/Documents/gui2.png)
***Overview***
### Overview
![Overview](/Documents/Overview.png)
***Main view***
### Main view
![Main](/Documents/main1.png)
![Main](/Documents/main2.png)
***Diff***
### Diff
![Fab Layer Diff](/Documents/diff.png)
***Fab Layer***
### Fab Layer
![Fab layer side by side](/Documents/pair.png)
***F_Cu Layer***
### F_Cu Layer
![Cu difference view](/Documents/cu.png)
![Cu layer - 3 pane view](/Documents/composite.png)
***Text Diff***
### Text Diff
![Text Diff](/Documents/text.png)

6
env.sh Normal file
View File

@ -0,0 +1,6 @@
#!/bin/bash
# Usage: Source this file as:
# $> source ./env.sh
export PATH=$(pwd):$PATH

View File

@ -29,6 +29,8 @@ import http.server
import socketserver
socketserver.TCPServer.allow_reuse_address = True
import argparse
if sys.version_info[0] >= 3:
unicode = str
@ -43,29 +45,20 @@ def _escape_string( val ):
return ''.join(val.splitlines())
# -------------------------------------------------------------------------
# NOTE Adjust these paths to suit your setup
# If you do not use one (or more) of these SCMs, please set to ''
# This program attempts to auto-identify which SCM is in use.
# In the event of multiple SCMs being in use in one repository, the order of priority
# is Fossil > Git > SVN.
gitProg = '/usr/bin/git'
fossilProg = ''
svnProg = '/usr/bin/svn'
# Tools should be on the PATH
# Much more flexible approach
# To add plotPCB.py, kidiff_linux.py and kidiff_gui.py to the path use the following example
# Example: source ./env.sh
gitProg = 'git'
fossilProg = 'fossil'
svnProg = 'svn'
diffProg = 'diff'
grepProg = 'grep'
plotProg = 'plotPCB.py'
plotDir = '/plots'
webDir = '/web'
diffProg = '/usr/bin/diff'
plotProg = executablePath + '/plotPCB.py'
# plotProg = '/usr/local/bin/plotPCB.py'
# plotProg = '/usr/local/bin/plotPCB_macOS.py'
grepProg = '/usr/bin/grep'
# -------------------------------------------------------------------------
# NOTE Adjust this port to suit your requirements. Must be >1000.
PORT = 9092
# -------------------------------------------------------------------------
# NOTE Please adjust these colours to suit your requirements.
@ -1543,45 +1536,81 @@ class Select(tk.Toplevel):
self.quit()
def startWebServer():
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
webbrowser.open('http://127.0.0.1:' + str(PORT) + '/web/index.html')
def startWebServer(port):
with socketserver.TCPServer(("", port), Handler) as httpd:
print("serving at port", port)
webbrowser.open('http://127.0.0.1:' + str(port) + '/web/index.html')
httpd.serve_forever()
def parse_cli_args():
parser = argparse.ArgumentParser(description='Kicad PCB visual diffs.')
parser.add_argument('-d', "--display", type=str, help="Set DISPLAY value, default :1.0", default=':1.0')
parser.add_argument('-a', "--commit1", type=str, help="Commit1", default='HEAD')
parser.add_argument('-b', "--commit2", type=str, help="Commit2", default='HEAD')
parser.add_argument('-s', "--scm", type=str, help="Select SCM (Git, SVN, Fossil)")
parser.add_argument('-g', "--gui", action='store_true', help="Use gui")
parser.add_argument('-p', "--port", type=int, help="Set webserver port", default=9092)
parser.add_argument('-w', "--webserver-disable", action='store_true', help="Does not execute webserver (just generate images)")
parser.add_argument("kicad_pcb", help="Kicad PCB")
args = parser.parse_args()
print(args)
return args
if __name__ == "__main__":
args = parse_cli_args()
SCMS = scmAvailable()
if (SCMS == ""):
print("You need to have at least one SCM program path identified in lines 32 - 40")
exit()
gui = tk.Tk(':0.0', SCMS)
gui.withdraw()
gui.update()
Select = Select(gui)
Select.destroy()
prjctPath, prjctName = getProject()
gui.update()
gui.deiconify()
scm = getSCM(_escape_string(prjctPath))
gui.destroy()
prjctPath = os.path.dirname(os.path.realpath(args.kicad_pcb))
prjctName = os.path.basename(os.path.realpath(args.kicad_pcb))
print("prjctPath", prjctPath)
print("prjctName", prjctName)
if scm == 'Git':
artifacts = gitDiff(_escape_string(prjctPath), prjctName)
if scm == 'Fossil':
artifacts = fossilDiff(_escape_string(prjctPath), prjctName)
if scm == 'SVN':
artifacts = svnDiff(_escape_string(prjctPath), prjctName)
if scm == '':
print("This project is either not under version control or you have not set the path to the approriate SCM program in lines 32-40")
sys.exit(0)
if args.scm:
scm = args.scm
if args.gui:
d1, d2 = tkUI.runGUI(artifacts, prjctName, prjctPath, 'Git')
gui = tk.Tk(args.display, SCMS)
gui.withdraw()
gui.update()
Select = Select(gui)
Select.destroy()
gui.update()
gui.deiconify()
scm = getSCM(_escape_string(prjctPath))
gui.destroy()
if args.commit1 == "" and args.commit2 == "":
if scm == 'Git':
artifacts = gitDiff(_escape_string(prjctPath), prjctName)
if scm == 'Fossil':
artifacts = fossilDiff(_escape_string(prjctPath), prjctName)
if scm == 'SVN':
artifacts = svnDiff(_escape_string(prjctPath), prjctName)
if scm == '':
print("This project is either not under version control or you have not set the path to the approriate SCM program in lines 32-40")
sys.exit(0)
d1, d2 = tkUI.runGUI(artifacts, prjctName, prjctPath, scm)
else:
artifacts = []
d1 = args.commit1
d2 = args.commit2
print("Commit1", d1)
print("Commit2", d2)
@ -1597,14 +1626,12 @@ if __name__ == "__main__":
d2 = a2[1:]
times = getSVNDiff(d1, d2, prjctName, prjctPath)
svgDir1, svgDir2, boardDims1, boardDims2 = makeSVG(d1, d2, prjctName, prjctPath)
makeSupportFiles(prjctName, prjctPath)
makeOutput(svgDir1, svgDir2, prjctName, prjctPath, times, boardDims1, boardDims2)
startWebServer()
webbrowser.open(
'http://127.0.0.1:' + str(PORT) + '/web/index.html')
if not args.webserver_disable:
startWebServer(args.port)
webbrowser.open('http://127.0.0.1:' + str(args.port) + '/web/index.html')