Mercurial > hg > zebra
comparison zebra.py @ 17:a9dacd180597
Does not work in python 2.6 after all
Tidy up
author | Ben Croston <ben@croston.org> |
---|---|
date | Mon, 15 Aug 2011 20:18:38 +0100 |
parents | e6ea86e3d0e1 |
children | 117c2aac83e5 |
comparison
equal
deleted
inserted
replaced
16:3cad40fda053 | 17:a9dacd180597 |
---|---|
20 def _output_unix(self, commands): | 20 def _output_unix(self, commands): |
21 if self.queue == 'zebra_python_unittest': | 21 if self.queue == 'zebra_python_unittest': |
22 p = subprocess.Popen(['cat','-'], stdin=subprocess.PIPE) | 22 p = subprocess.Popen(['cat','-'], stdin=subprocess.PIPE) |
23 else: | 23 else: |
24 p = subprocess.Popen(['lpr','-P%s'%self.queue], stdin=subprocess.PIPE) | 24 p = subprocess.Popen(['lpr','-P%s'%self.queue], stdin=subprocess.PIPE) |
25 if type(commands) == bytes: | 25 p.communicate(commands) |
26 p.communicate(commands) | |
27 else: | |
28 p.communicate(str(commands).encode()) | |
29 p.stdin.close() | 26 p.stdin.close() |
30 | 27 |
31 def _output_win(self, commands): | 28 def _output_win(self, commands): |
32 if self.queue == 'zebra_python_unittest': | 29 if self.queue == 'zebra_python_unittest': |
33 print commands | 30 print commands |
34 return | 31 return |
35 if type(commands) != bytes: | |
36 commands = str(commands).encode() | |
37 hPrinter = win32print.OpenPrinter(self.queue) | 32 hPrinter = win32print.OpenPrinter(self.queue) |
38 try: | 33 try: |
39 hJob = win32print.StartDocPrinter(hPrinter, 1, ('Label',None,'RAW')) | 34 hJob = win32print.StartDocPrinter(hPrinter, 1, ('Label',None,'RAW')) |
40 try: | 35 try: |
41 win32print.StartPagePrinter(hPrinter) | 36 win32print.StartPagePrinter(hPrinter) |
50 """Output EPL2 commands to the label printer | 45 """Output EPL2 commands to the label printer |
51 | 46 |
52 commands - EPL2 commands to send to the printer | 47 commands - EPL2 commands to send to the printer |
53 """ | 48 """ |
54 assert self.queue is not None | 49 assert self.queue is not None |
50 if sys.version_info[0] == 3: | |
51 if type(commands) != bytes: | |
52 commands = str(commands).encode() | |
53 else: | |
54 commands = str(commands).encode() | |
55 if IS_WINDOWS: | 55 if IS_WINDOWS: |
56 self._output_win(commands) | 56 self._output_win(commands) |
57 else: | 57 else: |
58 self._output_unix(commands) | 58 self._output_unix(commands) |
59 | 59 |