Ejemplo n.º 1
0
 def export_csv(self, filename):
     "Export the bottle list to a CSV file"
     dialog = ExportCsvDialog(self.parent)
     if dialog.exec_():
         from oxitopped.export_csv import CsvExporter
         exporter = CsvExporter()
         exporter.delimiter = dialog.delimiter
         exporter.lineterminator = dialog.lineterminator
         exporter.quotechar = dialog.quotechar
         exporter.quoting = dialog.quoting
         exporter.header_row = dialog.header_row
         exporter.timestamp_format = dialog.timestamp_format
         exporter.export_bottles(filename, self.parent.data_logger.bottles)
 def export_csv(self, filename):
     "Export the bottle list to a CSV file"
     dialog = ExportCsvDialog(self.parent)
     if dialog.exec_():
         from oxitopped.export_csv import CsvExporter
         exporter = CsvExporter()
         exporter.delimiter = dialog.delimiter
         exporter.lineterminator = dialog.lineterminator
         exporter.quotechar = dialog.quotechar
         exporter.quoting = dialog.quoting
         exporter.header_row = dialog.header_row
         exporter.timestamp_format = dialog.timestamp_format
         exporter.export_bottles(filename, self.parent.data_logger.bottles)
Ejemplo n.º 3
0
 def export_csv(self, filename):
     "Export the bottle readings to a CSV file"
     dialog = ExportCsvDialog(self.parent)
     if dialog.exec_():
         from oxitopped.export_csv import CsvExporter
         exporter = CsvExporter()
         exporter.delimiter = dialog.delimiter
         exporter.lineterminator = dialog.lineterminator
         exporter.quotechar = dialog.quotechar
         exporter.quoting = dialog.quoting
         exporter.header_row = dialog.header_row
         exporter.timestamp_format = dialog.timestamp_format
         exporter.export_bottle(filename,
                                self.parent.model.analyzer.bottle,
                                delta=self.parent.model.delta,
                                points=self.parent.model.points)
Ejemplo n.º 4
0
 def export_csv(self, filename):
     "Export the bottle readings to a CSV file"
     dialog = ExportCsvDialog(self.parent)
     if dialog.exec_():
         from oxitopped.export_csv import CsvExporter
         exporter = CsvExporter()
         exporter.delimiter = dialog.delimiter
         exporter.lineterminator = dialog.lineterminator
         exporter.quotechar = dialog.quotechar
         exporter.quoting = dialog.quoting
         exporter.header_row = dialog.header_row
         exporter.timestamp_format = dialog.timestamp_format
         exporter.export_bottle(
             filename,
             self.parent.model.analyzer.bottle,
             delta=self.parent.model.delta,
             points=self.parent.model.points)
Ejemplo n.º 5
0
 def main(self, options, args):
     super(DumpApplication, self).main(options, args)
     if len(args) < 1:
         self.parser.error('you must specify an output filename')
     try:
         options.points = int(options.points)
     except ValueError:
         self.parser.error(
             '--moving-average value must be an integer number')
     if options.points % 2 == 0:
         self.parser.error(
             '--moving-average value must be an odd number')
     ext = os.path.splitext(args[-1])[-1].lower()
     try:
         if ext == '.csv':
             from oxitopped.export_csv import CsvExporter
             exporter = CsvExporter()
             exporter.delimiter = str(options.delimiter)
             exporter.quotechar = str(options.quotechar)
             try:
                 exporter.lineterminator = TERMINATORS[options.lineterminator]
             except KeyError:
                 self.parser.error(
                     '--line-terminator must be one of %s' % (
                         ', '.join(TERMINATORS.keys())))
             try:
                 exporter.quoting = QUOTING[options.quoting]
             except KeyError:
                 self.parser.error(
                     '--quoting must be one of %s' % (
                         ', '.join(QUOTING.keys())))
             try:
                 datetime.now().strftime(options.timestamp_format)
             except ValueError as exc:
                 self.parser.error(
                     'invalid value for --timestamp-format: %s' % str(exc))
             else:
                 exporter.timestamp_format = options.timestamp_format
         elif ext == '.xls':
             from oxitopped.export_xls import ExcelExporter
             exporter = ExcelExporter()
         else:
             self.parser.error('unknown file extension %s' % ext)
         exporter.header_row = options.header_row
     except ImportError:
         self.parser.error(
             'unable to load exporter for file extension %s' % ext)
     filename_or_obj = sys.stdout if args[-1] == '-' else args[-1]
     args = args[:-1]
     if len(args) > 0:
         # Construct a set of unique serial numbers (we use a set instead
         # of a list so that in the event of multiple patterns matching a
         # single bottle it doesn't get listed multiple times)
         serials = set()
         for arg in args:
             if set('*?[') & set(arg):
                 serials |= set(
                     fnmatch.filter((
                         bottle.serial
                         for bottle in self.data_logger.bottles), arg))
             else:
                 serials.add(arg)
         if len(serials) > 1:
             # Ensure output filename is a string with a format part
             if hasattr(filename_or_obj, 'write'):
                 self.parser.error(
                     'cannot use stdout for output with more than '
                     'one bottle')
             bottles = [
                 self.data_logger.bottle(serial)
                 for serial in serials
                 ]
             bottles = [
                 (bottle, filename_or_obj.format(bottle=bottle))
                 for bottle in bottles
                 ]
             all_filenames = [f for (_, f) in bottles]
             if len(set(all_filenames)) < len(bottles):
                 self.parser.error(
                     'filename must be unique for each bottle '
                     '(use {bottle.serial} in filename)')
             for bottle, filename in bottles:
                 exporter.export_bottle(
                     filename, bottle,
                     delta=options.delta, points=options.points)
         else:
             bottle = self.data_logger.bottle(serials.pop())
             if not hasattr(filename_or_obj, 'write'):
                 filename_or_obj = filename_or_obj.format(bottle=bottle)
             exporter.export_bottle(
                 filename_or_obj, bottle,
                 delta=options.delta, points=options.points)
     else:
         exporter.export_bottles(filename_or_obj, self.data_logger.bottles)