klippy: Avoid using '%' syntax when calling logging module

The logging module can build strings directly from printf syntax - no
need to build the string first.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-09-27 11:43:14 -04:00
parent 8f8951b4c1
commit 8d5a9143bb
8 changed files with 32 additions and 32 deletions

View File

@ -90,7 +90,7 @@ def check_build_code(srcdir, target, sources, cmd, other_files=[]):
src_times = get_mtimes(srcdir, sources + other_files) src_times = get_mtimes(srcdir, sources + other_files)
obj_times = get_mtimes(srcdir, [target]) obj_times = get_mtimes(srcdir, [target])
if not obj_times or max(src_times) > min(obj_times): if not obj_times or max(src_times) > min(obj_times):
logging.info("Building C code module %s" % (target,)) logging.info("Building C code module %s", target)
srcfiles = [os.path.join(srcdir, fname) for fname in sources] srcfiles = [os.path.join(srcdir, fname) for fname in sources]
destlib = os.path.join(srcdir, target) destlib = os.path.join(srcdir, target)
os.system(cmd % (destlib, ' '.join(srcfiles))) os.system(cmd % (destlib, ' '.join(srcfiles)))

View File

@ -148,9 +148,9 @@ class PrinterHeater:
pwm_time = read_time + REPORT_TIME + SAMPLE_TIME*SAMPLE_COUNT pwm_time = read_time + REPORT_TIME + SAMPLE_TIME*SAMPLE_COUNT
self.next_pwm_time = pwm_time + 0.75 * MAX_HEAT_TIME self.next_pwm_time = pwm_time + 0.75 * MAX_HEAT_TIME
self.last_pwm_value = value self.last_pwm_value = value
logging.debug("%s: pwm=%.3f@%.3f (from %.3f@%.3f [%.3f])" % ( logging.debug("%s: pwm=%.3f@%.3f (from %.3f@%.3f [%.3f])",
self.name, value, pwm_time, self.name, value, pwm_time,
self.last_temp, self.last_temp_time, self.target_temp)) self.last_temp, self.last_temp_time, self.target_temp)
self.mcu_pwm.set_pwm(pwm_time, value) self.mcu_pwm.set_pwm(pwm_time, value)
def adc_callback(self, read_time, read_value): def adc_callback(self, read_time, read_value):
temp = self.sensor.calc_temp(read_value) temp = self.sensor.calc_temp(read_value)
@ -159,7 +159,7 @@ class PrinterHeater:
self.last_temp_time = read_time self.last_temp_time = read_time
self.can_extrude = (temp >= self.min_extrude_temp) self.can_extrude = (temp >= self.min_extrude_temp)
self.control.adc_callback(read_time, temp) self.control.adc_callback(read_time, temp)
#logging.debug("temp: %.3f %f = %f" % (read_time, read_value, temp)) #logging.debug("temp: %.3f %f = %f", read_time, read_value, temp)
# External commands # External commands
def set_temp(self, print_time, degrees): def set_temp(self, print_time, degrees):
if degrees and (degrees < self.min_temp or degrees > self.max_temp): if degrees and (degrees < self.min_temp or degrees > self.max_temp):
@ -239,8 +239,8 @@ class ControlPID:
temp_integ = max(0., min(self.temp_integ_max, temp_integ)) temp_integ = max(0., min(self.temp_integ_max, temp_integ))
# Calculate output # Calculate output
co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv co = self.Kp*temp_err + self.Ki*temp_integ - self.Kd*temp_deriv
#logging.debug("pid: %f@%.3f -> diff=%f deriv=%f err=%f integ=%f co=%d" % ( #logging.debug("pid: %f@%.3f -> diff=%f deriv=%f err=%f integ=%f co=%d",
# temp, read_time, temp_diff, temp_deriv, temp_err, temp_integ, co)) # temp, read_time, temp_diff, temp_deriv, temp_err, temp_integ, co)
bounded_co = max(0., min(self.heater.max_power, co)) bounded_co = max(0., min(self.heater.max_power, co))
self.heater.set_pwm(read_time, bounded_co) self.heater.set_pwm(read_time, bounded_co)
# Store state for next measurement # Store state for next measurement
@ -305,9 +305,9 @@ class ControlAutoTune:
Td = 0.125 * Tu Td = 0.125 * Tu
Ki = Kp / Ti Ki = Kp / Ti
Kd = Kp * Td Kd = Kp * Td
logging.info("Autotune: raw=%f/%f Ku=%f Tu=%f Kp=%f Ki=%f Kd=%f" % ( logging.info("Autotune: raw=%f/%f Ku=%f Tu=%f Kp=%f Ki=%f Kd=%f",
temp_diff, max_power, Ku, Tu, temp_diff, max_power, Ku, Tu, Kp * PID_PARAM_BASE,
Kp * PID_PARAM_BASE, Ki * PID_PARAM_BASE, Kd * PID_PARAM_BASE)) Ki * PID_PARAM_BASE, Kd * PID_PARAM_BASE)
def check_busy(self, eventtime): def check_busy(self, eventtime):
if self.heating or len(self.peaks) < 12: if self.heating or len(self.peaks) < 12:
return True return True

View File

@ -159,7 +159,7 @@ class Printer:
out.append(toolhead.stats(eventtime)) out.append(toolhead.stats(eventtime))
for m in self.mcus: for m in self.mcus:
out.append(m.stats(eventtime)) out.append(m.stats(eventtime))
logging.info("Stats %.1f: %s" % (eventtime, ' '.join(out))) logging.info("Stats %.1f: %s", eventtime, ' '.join(out))
return eventtime + 1. return eventtime + 1.
def add_object(self, name, obj): def add_object(self, name, obj):
self.objects[name] = obj self.objects[name] = obj
@ -217,8 +217,8 @@ class Printer:
def run(self): def run(self):
systime = time.time() systime = time.time()
monotime = self.reactor.monotonic() monotime = self.reactor.monotonic()
logging.info("Start printer at %s (%.1f %.1f)" % ( logging.info("Start printer at %s (%.1f %.1f)",
time.asctime(time.localtime(systime)), systime, monotime)) time.asctime(time.localtime(systime)), systime, monotime)
# Enter main reactor loop # Enter main reactor loop
try: try:
self.reactor.run() self.reactor.run()

View File

@ -208,7 +208,7 @@ class MessageParser:
msgcrc = s[msglen-MESSAGE_TRAILER_CRC:msglen-MESSAGE_TRAILER_CRC+2] msgcrc = s[msglen-MESSAGE_TRAILER_CRC:msglen-MESSAGE_TRAILER_CRC+2]
crc = crc16_ccitt(s[:msglen-MESSAGE_TRAILER_SIZE]) crc = crc16_ccitt(s[:msglen-MESSAGE_TRAILER_SIZE])
if crc != msgcrc: if crc != msgcrc:
#logging.debug("got crc %s vs %s" % (repr(crc), repr(msgcrc))) #logging.debug("got crc %s vs %s", repr(crc), repr(msgcrc))
return -1 return -1
return msglen return msglen
def dump(self, s): def dump(self, s):

View File

@ -63,7 +63,7 @@ class SerialReader:
else: else:
self.ser = open(self.serialport, 'rb+') self.ser = open(self.serialport, 'rb+')
except (OSError, IOError, serial.SerialException) as e: except (OSError, IOError, serial.SerialException) as e:
logging.warn("Unable to open port: %s" % (e,)) logging.warn("Unable to open port: %s", e)
self.reactor.pause(starttime + 5.) self.reactor.pause(starttime + 5.)
continue continue
if self.baud: if self.baud:
@ -84,10 +84,10 @@ class SerialReader:
msgparser.process_identify(identify_data) msgparser.process_identify(identify_data)
self.msgparser = msgparser self.msgparser = msgparser
self.register_callback(self.handle_unknown, '#unknown') self.register_callback(self.handle_unknown, '#unknown')
logging.info("Loaded %d commands (%s)" % ( logging.info("Loaded %d commands (%s)",
len(msgparser.messages_by_id), msgparser.version)) len(msgparser.messages_by_id), msgparser.version)
logging.info("MCU config: %s" % (" ".join( logging.info("MCU config: %s", " ".join(
["%s=%s" % (k, v) for k, v in msgparser.config.items()]))) ["%s=%s" % (k, v) for k, v in msgparser.config.items()]))
# Setup baud adjust # Setup baud adjust
mcu_baud = float(msgparser.config.get('SERIAL_BAUD', 0.)) mcu_baud = float(msgparser.config.get('SERIAL_BAUD', 0.))
if mcu_baud: if mcu_baud:
@ -165,12 +165,12 @@ class SerialReader:
return '\n'.join(out) return '\n'.join(out)
# Default message handlers # Default message handlers
def handle_unknown(self, params): def handle_unknown(self, params):
logging.warn("Unknown message type %d: %s" % ( logging.warn("Unknown message type %d: %s",
params['#msgid'], repr(params['#msg']))) params['#msgid'], repr(params['#msg']))
def handle_output(self, params): def handle_output(self, params):
logging.info("%s: %s" % (params['#name'], params['#msg'])) logging.info("%s: %s", params['#name'], params['#msg'])
def handle_default(self, params): def handle_default(self, params):
logging.warn("got %s" % (params,)) logging.warn("got %s", params)
def __del__(self): def __del__(self):
self.disconnect() self.disconnect()
@ -249,8 +249,8 @@ class SerialBootStrap:
self.serial.send(imsg) self.serial.send(imsg)
return eventtime + self.RETRY_TIME return eventtime + self.RETRY_TIME
def handle_unknown(self, params): def handle_unknown(self, params):
logging.debug("Unknown message %d (len %d) while identifying" % ( logging.debug("Unknown message %d (len %d) while identifying",
params['#msgid'], len(params['#msg']))) params['#msgid'], len(params['#msg']))
# Attempt to place an AVR stk500v2 style programmer into normal mode # Attempt to place an AVR stk500v2 style programmer into normal mode
def stk500v2_leave(ser, reactor): def stk500v2_leave(ser, reactor):
@ -267,7 +267,7 @@ def stk500v2_leave(ser, reactor):
ser.write('\x1b\x01\x00\x01\x0e\x11\x04') ser.write('\x1b\x01\x00\x01\x0e\x11\x04')
reactor.pause(reactor.monotonic() + 0.050) reactor.pause(reactor.monotonic() + 0.050)
res = ser.read(4096) res = ser.read(4096)
logging.debug("Got %s from stk500v2" % (repr(res),)) logging.debug("Got %s from stk500v2", repr(res))
ser.baudrate = origbaud ser.baudrate = origbaud
# Attempt an arduino style reset on a serial port # Attempt an arduino style reset on a serial port

View File

@ -91,7 +91,7 @@ class PrinterHomingStepper(PrinterStepper):
endstop_accuracy * self.inv_step_dist)) endstop_accuracy * self.inv_step_dist))
if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2: if self.homing_endstop_accuracy >= self.homing_stepper_phases // 2:
logging.info("Endstop for %s is not accurate enough for stepper" logging.info("Endstop for %s is not accurate enough for stepper"
" phase adjustment" % (name,)) " phase adjustment", name)
self.homing_stepper_phases = None self.homing_stepper_phases = None
if self.mcu_endstop.get_mcu().is_fileoutput(): if self.mcu_endstop.get_mcu().is_fileoutput():
self.homing_endstop_accuracy = self.homing_stepper_phases self.homing_endstop_accuracy = self.homing_stepper_phases
@ -108,7 +108,7 @@ class PrinterHomingStepper(PrinterStepper):
pos = self.mcu_stepper.get_mcu_position() pos = self.mcu_stepper.get_mcu_position()
pos %= self.homing_stepper_phases pos %= self.homing_stepper_phases
if self.homing_endstop_phase is None: if self.homing_endstop_phase is None:
logging.info("Setting %s endstop phase to %d" % (self.name, pos)) logging.info("Setting %s endstop phase to %d", self.name, pos)
self.homing_endstop_phase = pos self.homing_endstop_phase = pos
return 0 return 0
delta = (pos - self.homing_endstop_phase) % self.homing_stepper_phases delta = (pos - self.homing_endstop_phase) % self.homing_stepper_phases

View File

@ -339,7 +339,7 @@ class ToolHead:
self.extruder.motor_off(last_move_time) self.extruder.motor_off(last_move_time)
self.dwell(STALL_TIME) self.dwell(STALL_TIME)
self.need_motor_off = False self.need_motor_off = False
logging.debug('; Max time of %f' % (last_move_time,)) logging.debug('; Max time of %f', last_move_time)
def wait_moves(self): def wait_moves(self):
self._flush_lookahead() self._flush_lookahead()
if self.mcu.is_fileoutput(): if self.mcu.is_fileoutput():

View File

@ -43,8 +43,8 @@ def get_cpu_info():
data = f.read() data = f.read()
f.close() f.close()
except OSError: except OSError:
logging.debug("Exception on read /proc/cpuinfo: %s" % ( logging.debug("Exception on read /proc/cpuinfo: %s",
traceback.format_exc(),)) traceback.format_exc())
return "?" return "?"
lines = [l.split(':', 1) for l in data.split('\n')] lines = [l.split(':', 1) for l in data.split('\n')]
lines = [(l[0].strip(), l[1].strip()) for l in lines if len(l) == 2] lines = [(l[0].strip(), l[1].strip()) for l in lines if len(l) == 2]
@ -64,6 +64,6 @@ def get_git_version():
output = process.communicate()[0] output = process.communicate()[0]
retcode = process.poll() retcode = process.poll()
except OSError: except OSError:
logging.debug("Exception on run: %s" % (traceback.format_exc(),)) logging.debug("Exception on run: %s", traceback.format_exc())
return "?" return "?"
return output.strip() return output.strip()