Skip to content

Commit

Permalink
Added script to init the repo. Changed version to 1.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Mar 3, 2020
1 parent 06eb19c commit b3a681f
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

3 changes: 0 additions & 3 deletions .gitconfig

This file was deleted.

7 changes: 0 additions & 7 deletions .kicad_pcb-git-diff

This file was deleted.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all:
install:
install -D kicad_pcb-diff.py $(DESTDIR)$(prefix)/bin/kicad_pcb-diff.py
install -D kicad_pcb-git-diff.py $(DESTDIR)$(prefix)/bin/kicad_pcb-git-diff.py
install -D kicad_pcb-diff-init.py $(DESTDIR)$(prefix)/bin/kicad_pcb-diff-init.py

clean:

Expand All @@ -14,6 +15,7 @@ distclean: clean
uninstall:
-rm -f $(DESTDIR)$(prefix)/bin/kicad_pcb-diff.py
-rm -f $(DESTDIR)$(prefix)/bin/kicad_pcb-git-diff.py
-rm -f $(DESTDIR)$(prefix)/bin/kicad_pcb-diff-init.py

.PHONY: all install clean distclean uninstall

34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,27 @@ In a Debian/Ubuntu system you'll get them running:

## Standalone use

1. Copy the python scripts to some executable directory in your path (i.e. to /usr/local/bin/)
2. Well ... that's all

## Git plug-in

1. Copy the python scripts to some executable directory in your path (i.e. to /usr/local/bin/)
2. To force git to look for a plug-in to show diffs between KiCad PCBs create a *.gitattributes* file at the root of your repo containing:
1. As root run:
```
*.kicad_pcb diff=kicad_pcb
# make install
```
3. Now we have to define the *kicad_pcb* plug-in. This is done in the *gitconfig* file. In order to make it local to this repo you have to configure git to include the local file *.gitconfig*:
```
$ git config --local include.path ../.gitconfig
```
4. Now we create a *.gitconfig* file at the root of the repo defining the plug-in action:

The scripts will be copied to */usr/local/bin*. If you want to install the scripts in */usr/bin* run

```
[diff "kicad_pcb"]
command=/usr/local/bin/kicad_pcb-git-diff.py -v
# make prefix=/usr install
```
5. If you want to exclude some layers from the diff create a file named *.kicad_pcb-git-diff* at the root of your repo containing the names of the layer to be excluded. You have to use line for each layer.

An example of *.gitconfig*, *gitconfig* and *.kicad_pcb-git-diff* can be found in this repo.
Once configured the tool will be used every time you do a git diff.
## Git plug-in

1. Install the scripts
2. To initialize a repo just run the *kicad_pcb-diff-init.py* script from the root of the repo.
This will configure the repo to read extra configuration from the *.gitconfig* file.
It will also associate the *kicad_pcb* file extension with the *kicad_pcb-git-diff.py* script.
3. The initialization script will create a list of layers to be excluded in the *.kicad_pcb-git-diff* file.
Review this file and adjust it to your needs. Lines starting with *#* will be ignored.

Once configured the tool will be used every time you do a diff using *git*.

# Usage

Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
kicad-pcb-diff (1.1.0-1) testing; urgency=medium

* Added script to init the repo.

-- Salvador Eduardo Tropea <[email protected]> Tue, 03 Mar 2020 09:17:18 -0300

kicad-pcb-diff (1.0.0-1) unstable; urgency=low

* Initial release.
Expand Down
142 changes: 142 additions & 0 deletions kicad_pcb-diff-init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env python3
"""KiCad PCB diff tool
This program initializes a repo to use the kicad_pcb-git-diff plug-in.
"""
__author__ ='Salvador E. Tropea'
__copyright__='Copyright 2020, INTI'
__credits__ =['Salvador E. Tropea']
__license__ ='GPL 2.0'
__version__ ='1.1.0'
__email__ ='[email protected]'
__status__ ='beta'

from os.path import (isfile,isdir,basename,sep,dirname,realpath)
from os import (getcwd)
from shutil import (which)
from sys import (exit)
from subprocess import (call)
import argparse
import logging
import re

# Exit error codes
NO_GIT_ROOT=1
MISSING_GIT=2
MISSING_SCRIPTS=3

git_attributes='.gitattributes'
git_config='.gitconfig'
layers_file='.kicad_pcb-git-diff'

def CheckAttributes():
if not isfile(git_attributes):
logger.debug('No '+git_attributes)
return False
attr_file=open(git_attributes,"r")
for line in attr_file:
if re.match('^\*.kicad_pcb\s+diff',line):
attr_file.close()
return True
attr_file.close()
return False

def CheckCommand():
if not isfile(git_config):
logger.debug('No '+git_config)
return False
cfg_file=open(git_config,"r")
for line in cfg_file:
if re.match('^\[diff\s+\"kicad_pcb_diff\"',line):
cfg_file.close()
return True
cfg_file.close()
return False

if __name__=='__main__':
parser=argparse.ArgumentParser(description='KiCad PCB diff GIT repo initialization')

parser.add_argument('--verbose','-v',action='count',default=0)
parser.add_argument('--version','-V',action='version', version='%(prog)s '+__version__+' - '+
__copyright__+' - License: '+__license__)

args=parser.parse_args()

# Create a logger with the specified verbosity
if args.verbose>=2:
log_level=logging.DEBUG
verb='-vv'
elif args.verbose==1:
log_level=logging.INFO
verb='-v'
else:
verb=None
log_level=logging.WARNING
logging.basicConfig(level=log_level)
logger=logging.getLogger(basename(__file__))

# Check the environment
if which('git')==None:
logger.error('No git command, install it')
exit(MISSING_GIT)
if which('kicad_pcb-git-diff.py')==None:
logger.error('Please install the diff scripts first')
exit(MISSING_SCRIPTS)

# The script must be invoked from the root of the repo
dir_git=getcwd()+sep+'.git'
if not isdir(dir_git):
logger.error('Run this script from the root of your repo (no .git/ here)')
exit(NO_GIT_ROOT)

# Configure the repo to use a local .gitconfig file
logger.info('Configuring git to use ".gitconfig" as a configuration file')
command=['git','config','--local','include.path','../'+git_config]
logger.debug(command)
call(command)

# Add an attribute for *.kicad_pcb files
if CheckAttributes():
logger.info('KiCad PCB files already has a diff tool associated')
else:
logger.info('Associating the KiCad PCB extension to a diff plug-in')
attr_file=open(git_attributes,"a+")
attr_file.write("*.kicad_pcb diff=kicad_pcb_diff\n")
attr_file.close()

# Add a command to the new attribute
if CheckCommand():
logger.info('Command already configured')
else:
logger.info('Defining a command to compute a diff between KiCad PCB files')
cfg_file=open(git_config,"a+")
cfg_file.write("[diff \"kicad_pcb_diff\"]\n")
cfg_file.write("\tcommand="+which('kicad_pcb-git-diff.py')+" -v\n")
cfg_file.close()

# Add a list of layers to be excluded
if isfile(layers_file):
logger.info('Layer exclusion file already present')
else:
logger.info('Generating a list of layers to be excluded')
layer_file=open(layers_file,"w+")
layer_file.write("B.Adhes\n")
layer_file.write("F.Adhes\n")
layer_file.write("#B.Paste\n")
layer_file.write("#F.Paste\n")
layer_file.write("#B.SilkS\n")
layer_file.write("#F.SilkS\n")
layer_file.write("#B.Mask\n")
layer_file.write("#F.Mask\n")
layer_file.write("#Dwgs.User\n")
layer_file.write("Cmts.User\n")
layer_file.write("Eco1.User\n")
layer_file.write("Eco2.User\n")
layer_file.write("Edge.Cuts\n")
layer_file.write("Margin\n")
layer_file.write("#B.CrtYd\n")
layer_file.write("#F.CrtYd\n")
layer_file.write("#B.Fab\n")
layer_file.write("#F.Fab\n")
layer_file.close()

2 changes: 1 addition & 1 deletion kicad_pcb-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
__copyright__='Copyright 2020, INTI/'+__author__
__credits__ =['Salvador E. Tropea','Jesse Vincent']
__license__ ='GPL 2.0'
__version__ ='1.0.0'
__version__ ='1.1.0'
__email__ ='[email protected]'
__status__ ='beta'

Expand Down
2 changes: 1 addition & 1 deletion kicad_pcb-git-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__copyright__='Copyright 2020, INTI'
__credits__ =['Salvador E. Tropea','Jesse Vincent']
__license__ ='GPL 2.0'
__version__ ='1.0.0'
__version__ ='1.1.0'
__email__ ='[email protected]'
__status__ ='beta'
# PCB diff tool
Expand Down

0 comments on commit b3a681f

Please sign in to comment.