def save(self): root = paths.corrections_dir base = self.stage_map_name p = unique_date_path(root, base, extension='') gp = '{}.{}'.format(p, 'pdf') gc = PdfPlotGraphicsContext(filename=gp, pagesize='letter') from reportlab.lib.pagesizes import letter bounds = self.canvas.bounds self.canvas.do_layout(size=letter, force=True) gc.render_component(self.canvas, valign='center') gc.save(p) self.canvas.do_layout(size=bounds, force=True) self.canvas.invalidate_and_redraw() tp = '{}.{}'.format(p, 'txt') with open(tp, 'w') as wfile: for r in self.results: args = r.nx, r.ny, r.dx, r.dy args = map(lambda x: '{:0.5f}'.format(x), args) args = [r.hole_id, str(r.corrected)] + args line = ','.join(args) wfile.write('{}\n'.format(line))
def _test(self, base): # make existing backup file p = os.path.join(self.root, '{}_{}-001.txt'.format(base, self.dt)) with open(p, 'w'): pass p = unique_date_path(self.root, base) self.assertEqual(os.path.basename(p), '{}_{}-002.txt'.format(base, self.dt))
def _backup_editor(self, editor): p = editor.path p = add_extension(p, '.txt') if os.path.isfile(p): # make a backup copy of the original experiment file bp, _ = os.path.splitext(os.path.basename(p)) pp = unique_date_path(paths.backup_experiment_dir, bp) self.info('{} - saving a backup copy to {}'.format(bp, pp)) shutil.copyfile(p, pp)