Merge pull request #15 from sunwukonga/hotfix-cmdline

Remove --gui option in favor of checking need
This commit is contained in:
John 2020-06-13 09:20:25 +01:00 committed by GitHub
commit 7a3b9218eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 47 deletions

View File

@ -14,18 +14,25 @@ This was originally written as a bash script, this newer GUI version has been re
## 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=''.
### General
- 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.
### Linux and MacOS
- Run the main script `kidiff_linux.py`. Use `--help` option for usage.
- [Optional] Temporarily add `kidiff_linux.py` to your PATH with `. env.sh`
- [MacOS only] 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
### Windows
- Run `kidiff_gui.py` script
- 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=''.
- Check that the path to `plotPCB.py` is correct in `kidiff_gui.py`
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
## Command Line Usage [Linux and MacOS]
```
➜ ./kidiff_linux.py -h
@ -38,15 +45,14 @@ positional arguments:
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
-d DISPLAY, --display DISPLAY
Set DISPLAY value, default :1.0
-p PORT, --port PORT Set webserver port
-s SCM, --scm SCM Select SCM (Git, SVN, Fossil)
-w, --webserver-disable
Does not execute webserver (just generate images)
```

View File

@ -55,7 +55,7 @@ fossilProg = 'fossil'
svnProg = 'svn'
diffProg = 'diff'
grepProg = 'grep'
plotProg = 'plotPCB.py'
plotProg = executablePath + '/plotPCB.py'
plotDir = '/plots'
webDir = '/web'
@ -988,10 +988,16 @@ def getFossilDiff(diff1, diff2, prjctName, prjctPath):
return dateTime
def getProject():
def getProject(display, SCMS):
'''File select dialogue. Opens Tk File browser and
selector set for .kicad_pcb files. Returns path and file name
'''
gui = tk.Tk(display, SCMS)
gui.withdraw()
gui.update()
select = Select(gui)
select.destroy()
selected = tk.filedialog.askopenfile(
initialdir="~/",
title="Select kicad_pcb file in a VC directory",
@ -999,6 +1005,7 @@ def getProject():
if selected:
path, prjct = os.path.split(selected.name)
gui.destroy()
return (path, prjct)
@ -1535,7 +1542,6 @@ class Select(tk.Toplevel):
if action == "cancel":
self.quit()
def startWebServer(port):
with socketserver.TCPServer(("", port), Handler) as httpd:
print("serving at port", port)
@ -1545,14 +1551,13 @@ def startWebServer(port):
def parse_cli_args():
parser = argparse.ArgumentParser(description='Kicad PCB visual diffs.')
parser.add_argument('-a', "--commit1", type=str, help="Commit1")
parser.add_argument('-b', "--commit2", type=str, help="Commit2")
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('-s', "--scm", type=str, help="Select SCM (Git, SVN, Fossil)")
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")
parser.add_argument("kicad_pcb", nargs='?', help="Kicad PCB")
args = parser.parse_args()
print(args)
return args
@ -1568,49 +1573,41 @@ if __name__ == "__main__":
print("You need to have at least one SCM program path identified in lines 32 - 40")
exit()
prjctPath = os.path.dirname(os.path.realpath(args.kicad_pcb))
prjctName = os.path.basename(os.path.realpath(args.kicad_pcb))
if args.kicad_pcb is None:
prjctPath, prjctName = getProject(args.display, SCMS)
else:
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 args.scm:
scm = args.scm
if args.gui:
gui = tk.Tk(args.display, SCMS)
gui.withdraw()
gui.update()
Select = Select(gui)
Select.destroy()
gui.update()
gui.deiconify()
else:
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)
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.commit1 is None and args.commit2 is None:
d1, d2 = tkUI.runGUI(artifacts, prjctName, prjctPath, scm)
else:
artifacts = []
d1 = args.commit1
d2 = args.commit2
d1 = args.commit1
d2 = args.commit2
if args.commit1 is None:
d1 = artifacts[0]
if args.commit2 is None:
d2 = artifacts[0]
print("Commit1", d1)
print("Commit2", d2)