Skip to content

Commit

Permalink
fix logic for args
Browse files Browse the repository at this point in the history
previously the script args were not being respected - this fixes that

the issue was that I was not properly updating the "global" args variable. I had switched to a method of passing it to "generate" but args was used in many more places

this change also gets closer to the original implementation of "generate"
  • Loading branch information
oclyke committed Jun 5, 2020
1 parent d7cc346 commit 10f1d53
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions buzzard.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,14 @@ def drawSVG(svg_attributes, attributes, paths):
return out


def generate(args):
def generate(labelString):

print(args)

path_to_script = os.path.dirname(os.path.abspath(__file__))

if args.outMode != 'lib':
paths, attributes, svg_attributes = string2paths(renderLabel(args.labelText).tostring())
paths, attributes, svg_attributes = string2paths(renderLabel(labelString).tostring())

try:
f = open(path_to_script + "/" + args.destination + ".scr", 'w')
Expand All @@ -719,7 +721,7 @@ def generate(args):
sys.exit(0) # quit Python

else:
labelStrings = args.labelText.split(",")
labelStrings = labelString.split(",")
scripts = []

for string in labelStrings:
Expand Down Expand Up @@ -884,26 +886,37 @@ def cleanName(name):
return name

def generateCollection(script):
cli_args = args # store arguments as given on the command line

# the file 'script' contains label-specific options. certain options are not processed per-label such as:
# -o: outMode (the entire collection will be output using one mode)
def mergeGlobalArgs(args):
merged = args
merged.outMode = cli_args.outMode
merged.verbose = cli_args.verbose
merged.destination = cli_args.destination
merged.writeMode = 'a'
return merged
def mergeLocalArgs(local_args):
# global options for collection:
# args.outMode
# args.verbose
# args.destination
# args.useCollection

args.writeMode = 'a'

args.eagleLayerNumber = local_args.eagleLayerNumber
args.fontName = local_args.fontName
args.labelText = local_args.labelText
args.originPos = local_args.originPos
args.scaleFactor = local_args.scaleFactor
args.signalName = local_args.signalName
args.subSampling = local_args.subSampling
args.traceWidth = local_args.traceWidth

with open(script, 'r') as f_in:
collection = f_in.read().split('\n')

for index, element in enumerate(collection):

args = mergeGlobalArgs(parser.parse_args(shlex.split(element)))
mergeLocalArgs(parser.parse_args(shlex.split(element)))
if index == 0:
args.writeMode = 'w' # overwrite on first call for blank slate

generate(args)
generate(args.labelText)

#
#
Expand Down Expand Up @@ -1068,13 +1081,12 @@ def simplify(points, tolerance, highestQuality):
parser.add_argument('-c', dest='useCollection', default=False, action='store_true',
help='If specified labelText is used as a path to collection script (a text list of labels and options to create)')

cli_args = parser.parse_args()
args = cli_args # forward cli_args -> args for normal operation
args = parser.parse_args()

if cli_args.useCollection:
generateCollection(cli_args.labelText) # labelText should be path to collection
if args.useCollection:
generateCollection(args.labelText) # labelText should be path to collection
else:
generate(cli_args)
generate(args.labelText)

#
# ******************************************************************************

0 comments on commit 10f1d53

Please sign in to comment.