File: canon.py

package info (click to toggle)
linuxcnc 1%3A2.9.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 285,604 kB
  • sloc: python: 202,568; ansic: 109,036; cpp: 99,239; tcl: 16,054; xml: 10,631; sh: 10,303; makefile: 1,255; javascript: 138; sql: 72; asm: 15
file content (35 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
import tempfile
import gcode
import sys

def float_fmt(f):
    if isinstance(f, float): return "% 5.1g" % f
    return "%5s" % f

class Canon:
    def __getattr__(self, attr):
        """Assume that any unknown attribute is a canon call; just print
        its args and return None"""

        def inner(*args):
            args = list(map(float_fmt, args))
            print("%-17s %s" % (attr, " ".join(args)))
        return inner

    # this is just noisy
    def next_line(self, linecode): pass

    # These can't just return None...
    def get_external_length_units(self): return 1.0
    def get_external_angular_units(self): return 1.0
    def get_axis_mask(self): return 7 # (x y z)
    def get_block_delete(self): return False
    def get_tool(self, pocket):
        return -1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0

parameter = tempfile.NamedTemporaryFile()
canon = Canon()
canon.parameter_file = parameter.name
result, seq = gcode.parse(sys.argv[1], canon, '', '', '')
if result > gcode.MIN_ERROR: raise SystemExit(gcode.strerror(result))