From e88fc272862c7b7a62cc9a00756f8ecf0853229c 2012-08-20 11:28:43 From: Lance Edgar Date: 2012-08-20 11:28:43 Subject: [PATCH] add (basic) "one-up" label printing support --- diff --git a/rattail/labels.py b/rattail/labels.py index 7998476bb75cefe47a0ffd78b5d10bd64df49adb..b536b01e94b740b9ce6f06d3792b1fb76da37d43 100644 --- a/rattail/labels.py +++ b/rattail/labels.py @@ -115,13 +115,13 @@ class CommandFilePrinter(LabelPrinter): header = self.batch_header_commands() if header: - print >> labels_file, '\n'.join(header) + labels_file.write('%s\n' % '\n'.join(header)) - print >> labels_file, self.formatter.format_labels(labels) + labels_file.write(self.formatter.format_labels(labels)) footer = self.batch_footer_commands() if footer: - print >> labels_file, '\n'.join(footer) + labels_file.write('%s\n' % '\n'.join(footer)) labels_file.close() return labels_path @@ -149,6 +149,23 @@ class CommandFormatter(LabelFormatter): (textual) commands. """ + def format_labels(self, labels): + fmt = StringIO() + + for product, quantity in labels: + for i in range(quantity): + header = self.label_header_commands() + if header: + fmt.write('%s\n' % '\n'.join(header)) + fmt.write('%s\n' % '\n'.join(self.label_body_commands(product))) + footer = self.label_footer_commands() + if footer: + fmt.write('%s\n' % '\n'.join(footer)) + + val = fmt.getvalue() + fmt.close() + return val + def label_header_commands(self): """ This method, if implemented, must return a sequence of string commands @@ -199,22 +216,24 @@ class TwoUpCommandFormatter(CommandFormatter): for product, quantity in labels: for i in range(quantity): if half_started: - print >> fmt, '\n'.join(self.label_body_commands(product, x=self.half_offset)) + fmt.write('%s\n' % '\n'.join( + self.label_body_commands(product, x=self.half_offset))) footer = self.label_footer_commands() if footer: - print >> fmt, '\n'.join(footer) + fmt.write('%s\n' % '\n'.join(footer)) half_started = False else: header = self.label_header_commands() if header: - print >> fmt, '\n'.join(header) - print >> fmt, '\n'.join(self.label_body_commands(product, x=0)) + fmt.write('%s\n' % '\n'.join(header)) + fmt.write('%s\n' % '\n'.join( + self.label_body_commands(product, x=0))) half_started = True if half_started: footer = self.label_footer_commands() if footer: - print >> fmt, '\n'.join(footer) + fmt.write('%s\n' % '\n'.join(footer)) val = fmt.getvalue() fmt.close()