From 82e0f101e0df6510b4ba898383e23e3a0f65734a Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 13:35:53 -0300 Subject: [PATCH 1/8] Initial tests to make it cli oriented --- kidiff_linux.py | 124 ++++++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 47 deletions(-) diff --git a/kidiff_linux.py b/kidiff_linux.py index ac58754..a747423 100755 --- a/kidiff_linux.py +++ b/kidiff_linux.py @@ -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,83 @@ 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 bisual 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("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 == "" or 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) + + else: + artifacts = [] + + # d1, d2 = tkUI.runGUI(artifacts, prjctName, prjctPath, 'Git') + + # How to get the hash when the branch was created + # git reflog show yardbird-0.3.2-ci2 | grep Created + + d1 = args.commit1 + d2 = args.commit2 print("Commit1", d1) print("Commit2", d2) @@ -1597,14 +1628,13 @@ 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() + startWebServer(args.port) webbrowser.open( - 'http://127.0.0.1:' + str(PORT) + '/web/index.html') + 'http://127.0.0.1:' + str(args.port) + '/web/index.html') From 28959e5ac53e3381a869f01052cb2a5d08f051ca Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 13:36:10 -0300 Subject: [PATCH 2/8] Initial script to add tools to the path --- env.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 env.sh diff --git a/env.sh b/env.sh new file mode 100644 index 0000000..9f97334 --- /dev/null +++ b/env.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Usage: Source this file as: +# $> source ./env.sh + +export PATH=$(pwd):$PATH From 79f7e361ec2750b183cb2718b0bbb0449e4c9859 Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 13:46:25 -0300 Subject: [PATCH 3/8] Fix typo --- kidiff_linux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kidiff_linux.py b/kidiff_linux.py index a747423..e9ce276 100755 --- a/kidiff_linux.py +++ b/kidiff_linux.py @@ -1544,7 +1544,7 @@ def startWebServer(port): def parse_cli_args(): - parser = argparse.ArgumentParser(description='Kicad PCB bisual diffs.') + 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') From 6cddbf9a8025d8b84df67f588a231213cf2a9005 Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 14:13:11 -0300 Subject: [PATCH 4/8] Add a flag to disable webserver --- kidiff_linux.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kidiff_linux.py b/kidiff_linux.py index e9ce276..2677fff 100755 --- a/kidiff_linux.py +++ b/kidiff_linux.py @@ -1551,6 +1551,7 @@ def parse_cli_args(): 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) @@ -1634,7 +1635,6 @@ if __name__ == "__main__": makeOutput(svgDir1, svgDir2, prjctName, prjctPath, times, boardDims1, boardDims2) - startWebServer(args.port) - - webbrowser.open( - 'http://127.0.0.1:' + str(args.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') From 2f9840ffdd2e50ed65676e00ff4153b0284c31a3 Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 17:23:03 -0300 Subject: [PATCH 5/8] Minor fix when using GUI --- kidiff_linux.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kidiff_linux.py b/kidiff_linux.py index 2677fff..1b60264 100755 --- a/kidiff_linux.py +++ b/kidiff_linux.py @@ -1592,7 +1592,7 @@ if __name__ == "__main__": scm = getSCM(_escape_string(prjctPath)) gui.destroy() - if args.commit1 == "" or args.commit2 == "": + if args.commit1 == "" and args.commit2 == "": if scm == 'Git': artifacts = gitDiff(_escape_string(prjctPath), prjctName) @@ -1604,14 +1604,11 @@ if __name__ == "__main__": 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, d2 = tkUI.runGUI(artifacts, prjctName, prjctPath, 'Git') - - # How to get the hash when the branch was created - # git reflog show yardbird-0.3.2-ci2 | grep Created - d1 = args.commit1 d2 = args.commit2 From 2b2127d5c7bbdd81c132bbfda49960917eddd5bd Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 17:27:34 -0300 Subject: [PATCH 6/8] Update instructions --- README.md | 62 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c5cf543..f0f8462 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # KiCad-Diff + 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. @@ -10,26 +11,55 @@ 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. + +# 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 TestBoard.kicad_pcb testdir +``` + +# 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) +``` + +# 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. From 87f1512fc6a422f623b53cbdcf56240bb24e576c Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 17:29:29 -0300 Subject: [PATCH 7/8] Update formatting --- README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f0f8462..45ec7e5 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ The script should build a series of svg files and display the diff in a webpage. 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 TestBoard.kicad_pcb testdir +plotPCB.py boar.kicad_pcb output_folder ``` # Command Line Usage @@ -62,43 +62,41 @@ optional arguments: 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) From 22ef206c6b396fa0a8f9904116d0f1fa03507a5b Mon Sep 17 00:00:00 2001 From: Leandro Date: Sat, 30 May 2020 17:31:05 -0300 Subject: [PATCH 8/8] Update formatting --- README.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 45ec7e5..3db261f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # KiCad-Diff 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. @@ -12,10 +12,10 @@ There is an additional 'Text Diff' which is helpful for identifying specific are 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. -# Instructions +## 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 +- 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. @@ -24,15 +24,8 @@ This was originally written as a bash script, this newer GUI version has been re 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. -# 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 -``` - -# Command Line Usage +## Command Line Usage ``` ➜ ./kidiff_linux.py -h @@ -58,7 +51,15 @@ optional arguments: Does not execute webserver (just generate images) ``` -# Next Steps +## 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 1. Improvement in parsing and meaning of text diffs. 2. Place all template text/css text in external files.