pylint3 cleanup of (most) post processors
This commit is contained in:
@@ -116,6 +116,7 @@ if open.__module__ in ['__builtin__', 'io']:
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
@@ -147,6 +148,7 @@ def processArguments(argstring):
|
||||
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
# pylint: disable=global-statement
|
||||
processArguments(argstring)
|
||||
for i in objectslist:
|
||||
print(i.Name)
|
||||
@@ -221,6 +223,7 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
|
||||
def linenumber():
|
||||
# pylint: disable=global-statement
|
||||
global LINENR
|
||||
if OUTPUT_LINE_NUMBERS is True:
|
||||
LINENR += 10
|
||||
@@ -229,8 +232,6 @@ def linenumber():
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
global AXIS_PRECISION
|
||||
global FEED_PRECISION
|
||||
out = ""
|
||||
lastcommand = None
|
||||
axis_precision_string = '.' + str(AXIS_PRECISION) + 'f'
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
# ***************************************************************************
|
||||
import FreeCAD
|
||||
import Path
|
||||
import PathScripts
|
||||
import PathScripts.PostUtils as PostUtils
|
||||
|
||||
TOOLTIP = ''' Example Post, using Path.Commands instead of Path.toGCode strings for Path gcode output. '''
|
||||
@@ -81,6 +80,7 @@ def lineout(command, oldvals, modal):
|
||||
|
||||
|
||||
def export(obj, filename, argstring):
|
||||
# pylint: disable=unused-argument
|
||||
modal = True
|
||||
gcode = ''
|
||||
safetyblock1 = 'G90G40G49\n'
|
||||
|
||||
@@ -40,6 +40,9 @@ if open.__module__ in ['__builtin__','io']:
|
||||
|
||||
|
||||
def export(objectslist, filename,argstring):
|
||||
"called when freecad exports a list of objects"
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
output = '''(This output produced with the dump post processor)
|
||||
(Dump is useful for inspecting the raw commands in your paths)
|
||||
(but is not useful for driving machines.)
|
||||
@@ -48,7 +51,6 @@ def export(objectslist, filename,argstring):
|
||||
|
||||
'''
|
||||
|
||||
"called when freecad exports a list of objects"
|
||||
for obj in objectslist:
|
||||
|
||||
if not hasattr(obj, "Path"):
|
||||
|
||||
@@ -111,7 +111,8 @@ if open.__module__ in ['__builtin__','io']:
|
||||
|
||||
|
||||
def export(objectslist,filename,argstring):
|
||||
global UNITS
|
||||
# pylint: disable=unused-argument
|
||||
global UNITS # pylint: disable=global-statement
|
||||
for obj in objectslist:
|
||||
if not hasattr(obj,"Path"):
|
||||
print("the object " + obj.Name + " is not a path. Please select only path and Compounds.")
|
||||
@@ -128,9 +129,9 @@ def export(objectslist,filename,argstring):
|
||||
myMachine = pathobj.MachineName
|
||||
if hasattr(pathobj, "MachineUnits"):
|
||||
if pathobj.MachineUnits == "Metric":
|
||||
UNITS = "G21"
|
||||
UNITS = "G21"
|
||||
else:
|
||||
UNITS = "G20"
|
||||
UNITS = "G20"
|
||||
if myMachine is None:
|
||||
print("No machine found in this selection")
|
||||
|
||||
@@ -185,7 +186,7 @@ def export(objectslist,filename,argstring):
|
||||
|
||||
|
||||
def linenumber():
|
||||
global LINENR
|
||||
global LINENR # pylint: disable=global-statement
|
||||
if OUTPUT_LINE_NUMBERS == True:
|
||||
LINENR += 1
|
||||
return "N" + str(LINENR) + " "
|
||||
|
||||
@@ -41,6 +41,7 @@ if open.__module__ in ['__builtin__','io']:
|
||||
|
||||
def export(objectslist, filename,argstring):
|
||||
"called when freecad exports a list of objects"
|
||||
# pylint: disable=unused-argument
|
||||
if len(objectslist) > 1:
|
||||
print("This script is unable to write more than one Path object")
|
||||
return
|
||||
|
||||
@@ -50,8 +50,8 @@ if open.__module__ in ['__builtin__', 'io']:
|
||||
|
||||
|
||||
def open(filename):
|
||||
PathLog.track(filename)
|
||||
"called when freecad opens a file."
|
||||
PathLog.track(filename)
|
||||
docname = os.path.splitext(os.path.basename(filename))[0]
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
insert(filename, doc.Name)
|
||||
|
||||
@@ -94,6 +94,7 @@ if open.__module__ in ['__builtin__', 'io']:
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
@@ -124,6 +125,7 @@ def processArguments(argstring):
|
||||
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
# pylint: disable=global-statement
|
||||
processArguments(argstring)
|
||||
global UNITS
|
||||
for obj in objectslist:
|
||||
@@ -205,6 +207,7 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
|
||||
def linenumber():
|
||||
# pylint: disable=global-statement
|
||||
global LINENR
|
||||
if OUTPUT_LINE_NUMBERS is True:
|
||||
LINENR += 10
|
||||
|
||||
@@ -110,6 +110,7 @@ if open.__module__ == '__builtin__':
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
@@ -151,7 +152,7 @@ def processArguments(argstring):
|
||||
OUTPUT_DOUBLES = False
|
||||
POWER_ON_DELAY = float(args.power_on_delay) / 1000 # milliseconds
|
||||
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -160,9 +161,6 @@ def processArguments(argstring):
|
||||
def export(objectslist, filename, argstring):
|
||||
if not processArguments(argstring):
|
||||
return None
|
||||
global UNITS
|
||||
global UNIT_FORMAT
|
||||
global UNIT_SPEED_FORMAT
|
||||
|
||||
for obj in objectslist:
|
||||
if not hasattr(obj, "Path"):
|
||||
@@ -229,7 +227,7 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
|
||||
def linenumber():
|
||||
global LINENR
|
||||
global LINENR # pylint: disable=global-statement
|
||||
if OUTPUT_LINE_NUMBERS is True:
|
||||
LINENR += 10
|
||||
return "N" + str(LINENR) + " "
|
||||
@@ -237,15 +235,6 @@ def linenumber():
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
global PRECISION
|
||||
global MODAL
|
||||
global OUTPUT_DOUBLES
|
||||
global UNIT_FORMAT
|
||||
global UNIT_SPEED_FORMAT
|
||||
global POWER_ON_DELAY
|
||||
global PRE_FEED
|
||||
global POST_FEED
|
||||
|
||||
out = ""
|
||||
lastcommand = None
|
||||
precision_string = '.' + str(PRECISION) + 'f'
|
||||
|
||||
@@ -102,6 +102,7 @@ if open.__module__ in ['__builtin__','io']:
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
@@ -142,13 +143,14 @@ def processArguments(argstring):
|
||||
print ('here')
|
||||
OUTPUT_DOUBLES = False
|
||||
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
# pylint: disable=global-statement
|
||||
if not processArguments(argstring):
|
||||
return None
|
||||
global UNITS
|
||||
@@ -239,6 +241,7 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
|
||||
def linenumber():
|
||||
# pylint: disable=global-statement
|
||||
global LINENR
|
||||
if OUTPUT_LINE_NUMBERS is True:
|
||||
LINENR += 10
|
||||
@@ -247,6 +250,7 @@ def linenumber():
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
# pylint: disable=global-statement
|
||||
global PRECISION
|
||||
global MODAL
|
||||
global OUTPUT_DOUBLES
|
||||
|
||||
@@ -98,6 +98,7 @@ GetValue = getMetricValue
|
||||
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_HEADER
|
||||
global SHOW_EDITOR
|
||||
@@ -182,8 +183,6 @@ def export(objectslist, filename, argstring):
|
||||
|
||||
|
||||
def move(command):
|
||||
global CurrentState
|
||||
|
||||
txt = ""
|
||||
|
||||
# if 'F' in command.Parameters:
|
||||
@@ -298,7 +297,7 @@ def tool_change(command):
|
||||
|
||||
|
||||
def comment(command):
|
||||
print("a comment")
|
||||
print("a comment", command)
|
||||
return
|
||||
|
||||
|
||||
@@ -333,8 +332,6 @@ scommands = {
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
global CurrentState
|
||||
|
||||
output = ""
|
||||
# Above list controls the order of parameters
|
||||
|
||||
|
||||
@@ -68,9 +68,9 @@ def open(filename):
|
||||
|
||||
|
||||
def insert(filename, docname):
|
||||
"called when freecad imports a file"
|
||||
"This insert expects parse to return a list of strings"
|
||||
"each string will become a separate path"
|
||||
'''called when freecad imports a file
|
||||
This insert expects parse to return a list of strings
|
||||
each string will become a separate path'''
|
||||
gfile = pythonopen(filename)
|
||||
gcode = gfile.read()
|
||||
gfile.close()
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
# reload(generic_post)
|
||||
|
||||
import FreeCAD
|
||||
from FreeCAD import Units
|
||||
import argparse
|
||||
import time
|
||||
from PathScripts import PostUtils
|
||||
@@ -220,31 +219,19 @@ parser.add_argument('--no-show-editor', action='store_true', help='don\'t pop up
|
||||
TOOLTIP_ARGS = parser.format_help()
|
||||
|
||||
def processArguments(argstring):
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
# pylint: disable=global-statement
|
||||
global LINENUMBERS
|
||||
global SHOW_EDITOR
|
||||
global PRECISION
|
||||
|
||||
for arg in argstring.split():
|
||||
if arg == '--header':
|
||||
OUTPUT_HEADER = True
|
||||
elif arg == '--no-header':
|
||||
OUTPUT_HEADER = False
|
||||
elif arg == '--comments':
|
||||
OUTPUT_COMMENTS = True
|
||||
elif arg == '--no-comments':
|
||||
OUTPUT_COMMENTS = False
|
||||
elif arg == '--line-numbers':
|
||||
OUTPUT_LINE_NUMBERS = True
|
||||
if arg == '--line-numbers':
|
||||
LINENUMBERS = True
|
||||
elif arg == '--no-line-numbers':
|
||||
OUTPUT_LINE_NUMBERS = False
|
||||
LINENUMBERS = False
|
||||
elif arg == '--show-editor':
|
||||
SHOW_EDITOR = True
|
||||
elif arg == '--no-show-editor':
|
||||
SHOW_EDITOR = False
|
||||
elif arg.split('=')[0] == '--output-precision':
|
||||
PRECISION = arg.split('=')[1]
|
||||
|
||||
def mkHeader(selection):
|
||||
job = PathUtils.findParentJob(selection[0])
|
||||
@@ -324,7 +311,7 @@ def mapGCode(command):
|
||||
|
||||
def linenumberify(GCodeString):
|
||||
# add a linenumber at every beginning of line
|
||||
global linenr
|
||||
global linenr # pylint: disable=global-statement
|
||||
if not LINENUMBERS:
|
||||
result = GCodeString + "\n"
|
||||
else:
|
||||
@@ -342,11 +329,9 @@ def linenumberify(GCodeString):
|
||||
return result
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
# pylint: disable=unused-argument,global-statement
|
||||
global UNITS
|
||||
global linenr
|
||||
global ABSOLUTE_CIRCLE_CENTER
|
||||
global USE_RADIUS_IF_POSSIBLE
|
||||
global RADIUS_COMMENT
|
||||
|
||||
linenr = STARTLINENR
|
||||
lastX = 0
|
||||
@@ -474,7 +459,7 @@ def export(objectslist, filename, argstring):
|
||||
# absolute center
|
||||
outstring.append(
|
||||
'(' + param + PostUtils.fmt(c.Parameters[param], AXIS_DECIMALS, UNITS) + ')')
|
||||
z = c.Parameters['Z']
|
||||
z = c.Parameters['Z'] # pylint: disable=unused-variable
|
||||
k = c.Parameters['K']
|
||||
if USE_RADIUS_IF_POSSIBLE and angleUnder180(command, lastX, lastY, c.Parameters['X'], c.Parameters['Y'], i, j):
|
||||
# R is handled with the I parameter, here:
|
||||
|
||||
@@ -46,6 +46,7 @@ if open.__module__ in ['__builtin__','io']:
|
||||
# Entrypoint used by FreeCAD
|
||||
def export(objectslist, filename, argstring):
|
||||
"Export objects as Roland Modela code."
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
code = ""
|
||||
for obj in objectslist:
|
||||
@@ -68,8 +69,8 @@ def home():
|
||||
return [ "H;" ]
|
||||
|
||||
def setjog():
|
||||
# "!PZ%d,%d;",iz_down,iz_up); // set z down, jog
|
||||
return ""
|
||||
# "!PZ%d,%d;",iz_down,iz_up); // set z down, jog
|
||||
return ""
|
||||
|
||||
def addheader():
|
||||
return [ "PA;PA;" ] # absolute positioning
|
||||
@@ -80,8 +81,10 @@ def mm2cord(mm):
|
||||
mm = float(mm)
|
||||
return int(40.0*mm)
|
||||
|
||||
def feed(x=None, y=None, z=None, state={}):
|
||||
def feed(x=None, y=None, z=None, state=None):
|
||||
c = []
|
||||
if state is None:
|
||||
state = {}
|
||||
|
||||
if x is not None:
|
||||
x = float(x)
|
||||
@@ -100,21 +103,22 @@ def feed(x=None, y=None, z=None, state={}):
|
||||
# 2d in XY plane
|
||||
c.append("PD%d,%d;" % (mm2cord(x), mm2cord(y)))
|
||||
elif z is not None:
|
||||
pass # XXX: is this used?
|
||||
pass
|
||||
return c
|
||||
|
||||
def jog(x=None, y=None, z=None, state={}):
|
||||
def jog(x=None, y=None, z=None, state=None):
|
||||
c = []
|
||||
if state is None:
|
||||
state = {}
|
||||
if x is not None and y is not None:
|
||||
x, y = float(x), float(y)
|
||||
c.append("PU%d,%d;" % (mm2cord(x), mm2cord(y)))
|
||||
state['X'] = x
|
||||
state['Y'] = y
|
||||
x, y = float(x), float(y)
|
||||
c.append("PU%d,%d;" % (mm2cord(x), mm2cord(y)))
|
||||
state['X'] = x
|
||||
state['Y'] = y
|
||||
if z is not None:
|
||||
z = float(z)
|
||||
c.append("PU;")
|
||||
# TODO: use !ZZ command
|
||||
state['Z'] = z
|
||||
z = float(z)
|
||||
c.append("PU;")
|
||||
state['Z'] = z
|
||||
|
||||
return c
|
||||
|
||||
@@ -132,16 +136,18 @@ def xyarc(args, state):
|
||||
p0 = circle.parameter(lastPoint)
|
||||
p1 = circle.parameter(newPoint)
|
||||
arc = Part.ArcOfCircle(circle, p0, p1)
|
||||
steps = 64 # TODO: specify max error instead
|
||||
steps = 64 # specify max error instead?
|
||||
points = arc.discretize(steps)
|
||||
# TODO: consider direction
|
||||
# consider direction?
|
||||
#print('p = Part.ArcOfCircle(Part.Circle(FreeCAD.Vector(%f, %f), FreeCAD.Vector(0, 0, 1), %f), %f, %f)' % (center.x, center.y, radius, p0, p1))
|
||||
for p in points:
|
||||
c += feed(p.x, p.y, state['Z'], state)
|
||||
return c
|
||||
|
||||
def speed(xy=None, z=None, state={}):
|
||||
def speed(xy=None, z=None, state=None):
|
||||
c = []
|
||||
if state is None:
|
||||
state = {}
|
||||
print(xy, z, state)
|
||||
if xy is not None:
|
||||
xy = float(xy)
|
||||
@@ -223,7 +229,7 @@ def parse(inputstring):
|
||||
|
||||
output += speed(2.0, 1.0, state) # defaults
|
||||
|
||||
# TODO: respect clearance height
|
||||
# respect clearance height?
|
||||
|
||||
# treat the input line by line
|
||||
lines = inputstring.split("\n")
|
||||
|
||||
@@ -106,6 +106,8 @@ POST_OPERATION = ''''''
|
||||
# Tool Change commands will be inserted before a tool change
|
||||
TOOL_CHANGE = ''''''
|
||||
|
||||
# Number of digits after the decimal point
|
||||
PRECISION = 5
|
||||
|
||||
# to distinguish python built-in open function from the one declared below
|
||||
if open.__module__ in ['__builtin__', 'io']:
|
||||
@@ -113,6 +115,7 @@ if open.__module__ in ['__builtin__', 'io']:
|
||||
|
||||
|
||||
def processArguments(argstring):
|
||||
# pylint: disable=global-statement
|
||||
global OUTPUT_HEADER
|
||||
global OUTPUT_COMMENTS
|
||||
global OUTPUT_LINE_NUMBERS
|
||||
@@ -159,7 +162,7 @@ def processArguments(argstring):
|
||||
IP_ADDR = args.IP_ADDR
|
||||
VERBOSE = args.verbose
|
||||
|
||||
except Exception:
|
||||
except Exception: # pylint: disable=broad-except
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -167,8 +170,7 @@ def processArguments(argstring):
|
||||
|
||||
def export(objectslist, filename, argstring):
|
||||
processArguments(argstring)
|
||||
global UNITS
|
||||
global IP_ADDR
|
||||
global UNITS # pylint: disable=global-statement
|
||||
for obj in objectslist:
|
||||
if not hasattr(obj, "Path"):
|
||||
FreeCAD.Console.PrintError("the object " + obj.Name + " is not a path. Please select only path and Compounds.\n")
|
||||
@@ -252,11 +254,10 @@ def export(objectslist, filename, argstring):
|
||||
return final
|
||||
|
||||
|
||||
def sendToSmoothie(IP_ADDR, GCODE, fname):
|
||||
def sendToSmoothie(ip, GCODE, fname):
|
||||
import sys
|
||||
import socket
|
||||
import os
|
||||
global VERBOSE
|
||||
|
||||
fname = os.path.basename(fname)
|
||||
FreeCAD.Console.PrintMessage('sending to smoothie: {}\n'.format(fname))
|
||||
@@ -266,7 +267,7 @@ def sendToSmoothie(IP_ADDR, GCODE, fname):
|
||||
# make connection to sftp server
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(4.0)
|
||||
s.connect((IP_ADDR, 115))
|
||||
s.connect((ip, 115))
|
||||
tn = s.makefile(mode='rw')
|
||||
|
||||
# read startup prompt
|
||||
@@ -330,7 +331,7 @@ def sendToSmoothie(IP_ADDR, GCODE, fname):
|
||||
|
||||
|
||||
def linenumber():
|
||||
global LINENR
|
||||
global LINENR # pylint: disable=global-statement
|
||||
if OUTPUT_LINE_NUMBERS is True:
|
||||
LINENR += 10
|
||||
return "N" + str(LINENR) + " "
|
||||
@@ -338,10 +339,10 @@ def linenumber():
|
||||
|
||||
|
||||
def parse(pathobj):
|
||||
global PRECISION
|
||||
global SPINDLE_SPEED # pylint: disable=global-statement
|
||||
|
||||
out = ""
|
||||
lastcommand = None
|
||||
global SPINDLE_SPEED
|
||||
precision_string = '.' + str(PRECISION) + 'f'
|
||||
|
||||
# params = ['X','Y','Z','A','B','I','J','K','F','S'] #This list control
|
||||
|
||||
@@ -62,15 +62,17 @@ EXTERNAL_MODULES+=' importlib'
|
||||
EXTERNAL_MODULES+=' ocl'
|
||||
EXTERNAL_MODULES+=' pivy'
|
||||
|
||||
IGNORE_MODULES+=' post'
|
||||
IGNORE_MODULES+=' grbl_post.py'
|
||||
IGNORE_MODULES+=' PathSimulatorGui.py'
|
||||
IGNORE_MODULES+=' PathSurface.py'
|
||||
|
||||
#ARGS+=" --errors-only"
|
||||
ARGS+=" --disable=C,R"
|
||||
ARGS+=" --ignored-modules=$(echo ${EXTERNAL_MODULES} | tr ' ' ',')"
|
||||
ARGS+=" --ignore=$(echo ${IGNORE_MODULES} | tr ' ' ',')"
|
||||
ARGS+=" --jobs=4"
|
||||
if [ -n "${IGNORE_MODULES}" ]; then
|
||||
ARGS+=" --ignore=$(echo ${IGNORE_MODULES} | tr ' ' ',')"
|
||||
fi
|
||||
ARGS+=" --jobs=0"
|
||||
|
||||
if [ -z "$(which pylint3)" ]; then
|
||||
echo "Cannot find pylint, please install and try again!"
|
||||
|
||||
Reference in New Issue
Block a user