def snapshot(self, path=None, name=None, auto=False, inform=True, return_blob=False, pic_format='.jpg'): """ path: abs path to use name: base name to use if auto saving in default dir auto: force auto save returns: path: local abs path upath: remote abs path """ if path is None: if self.auto_save_snapshot or auto: if name is None: name = 'snapshot' path, _cnt = unique_path2(root=paths.snapshot_dir, base=name, extension=pic_format) elif name is not None: if not os.path.isdir(os.path.dirname(name)): path, _ = unique_path2(root=paths.snapshot_dir, base=name, extension=pic_format) else: path = name else: path = self.save_file_dialog() if path: self.info('saving snapshot {}'.format(path)) # play camera shutter sound # play_sound('shutter') self._render_snapshot(path) upath = self._upload(path) if upath is None: upath = '' if inform: self.information_dialog('Snapshot save to {}. ' 'Uploaded to'.format(path, upath)) # return path, upath if return_blob: with open(path, 'rb') as rfile: im = rfile.read() return path, upath, im else: return path, upath
def save_file_snapshot(self): from pychron.core.helpers.filetools import unique_path2 p, _ = unique_path2(paths.sample_image_dir, 'nosample', extension='.jpg') p, _ = unique_path2(paths.sample_image_dir, 'nosample', extension='.tiff') self.camera.save(p)
def capture(self, path=None, name=None, **options): with picamera.PiCamera() as camera: self._setup_camera(camera) if path is None: if name is None: path, _ = unique_path2(paths.snapshot_dir, name, extension='.jpg') else: path, _ = unique_path2(paths.snapshot_dir, 'rpi', extension='.jpg') camera.capture(path, **options)
def _prepare_path(self, make=False): root = os.path.join(self.default_root, self.root_directory) if make and not os.path.isdir(root): os.mkdir(root) path, cnt = unique_path2(root, self.name, extension=self.extension) return path
def reset_system_health_series(): src = os.path.join(paths.hidden_dir, 'health_series.yaml') if os.path.isfile(src): dest, _ = unique_path2(paths.hidden_dir, 'health_series', extension='.yaml') shutil.copyfile(src, dest) os.remove(src)
def logging_setup(name, use_archiver=True, root=None, use_file=True, **kw): """ """ # set up deprecation warnings # import warnings # warnings.simplefilter('default') bdir = paths.log_dir if root is None else root # make sure we have a log directory # if not os.path.isdir(bdir): # os.mkdir(bdir) if use_archiver: # archive logs older than 1 month # lazy load Archive because of circular dependency from pychron.core.helpers.archiver import Archiver a = Archiver(archive_days=14, archive_months=1, root=bdir) a.clean() if use_file: # create a new logging file logname = '{}.current.log'.format(name) logpath = os.path.join(bdir, logname) if os.path.isfile(logpath): backup_logpath, _cnt = unique_path2(bdir, name, delimiter='-', extension='.log', width=5) shutil.copyfile(logpath, backup_logpath) os.remove(logpath) ps = list_directory(bdir, filtername=logname, remove_extension=False) for pi in ps: _h, t = os.path.splitext(pi) v = os.path.join(bdir, pi) shutil.copyfile(v, '{}{}'.format(backup_logpath, t)) os.remove(v) root = logging.getLogger() root.setLevel(gLEVEL) shandler = logging.StreamHandler() handlers = [shandler] if use_file: rhandler = RotatingFileHandler(logpath, maxBytes=1e7, backupCount=50) handlers.append(rhandler) fmt = logging.Formatter(gFORMAT) for hi in handlers: hi.setLevel(gLEVEL) hi.setFormatter(fmt) root.addHandler(hi)
def _record(self, pv, v): path = pv.path if not path: path, _ = unique_path2(paths.device_scan_dir, pv.name) pv.path = path self.info("Saving {} to {}".format(pv.name, path)) with open(path, "a") as wfile: wfile.write("{},{}\n".format(time.time(), v))
def _record(self, pv, v): path = pv.path if not path: path, _ = unique_path2(paths.device_scan_dir, pv.name) pv.path = path self.info('Saving {} to {}'.format(pv.name, path)) with open(path, 'a') as wfile: wfile.write('{},{}\n'.format(time.time(), v))
def path(self): name = self.name if not name or name == 'Untitled': path, _ = unique_path2(paths.table_dir, 'Untitled', extension='.xlsx') else: path = os.path.join(paths.table_dir, add_extension(name, ext='.xlsx')) return path
def logging_setup(name, use_archiver=True, root=None, use_file=True, **kw): """ """ # set up deprecation warnings # import warnings # warnings.simplefilter('default') bdir = paths.log_dir if root is None else root # make sure we have a log directory # if not os.path.isdir(bdir): # os.mkdir(bdir) if use_archiver: # archive logs older than 1 month # lazy load Archive because of circular dependency from pychron.core.helpers.archiver import Archiver a = Archiver(archive_days=14, archive_months=1, root=bdir) a.clean() if use_file: # create a new logging file logname = '{}.current.log'.format(name) logpath = os.path.join(bdir, logname) if os.path.isfile(logpath): backup_logpath, _cnt = unique_path2(bdir, name, delimiter='-', extension='.log', width=5) shutil.copyfile(logpath, backup_logpath) os.remove(logpath) ps = list_directory(bdir, filtername=logname, remove_extension=False) for pi in ps: _h, t = os.path.splitext(pi) v = os.path.join(bdir, pi) shutil.copyfile(v, '{}{}'.format(backup_logpath, t)) os.remove(v) root = logging.getLogger() root.setLevel(gLEVEL) shandler = logging.StreamHandler() handlers = [shandler] if use_file: rhandler = RotatingFileHandler( logpath, maxBytes=1e7, backupCount=50) handlers.append(rhandler) fmt = logging.Formatter(gFORMAT) for hi in handlers: hi.setLevel(gLEVEL) hi.setFormatter(fmt) root.addHandler(hi)
def path(self): name = self.name root = paths.table_dir if self.root_directory: root = self.root_directory elif self.root_name: root = os.path.join(root, self.root_name) if not name or name == 'Untitled': path, _ = unique_path2(root, 'Untitled', extension='.xlsx') else: path = os.path.join(root, add_extension(name, ext='.xlsx')) return path
def _backup_deflection(self, reset=False): src = paths.deflection if src: dst = unique_path2(paths.backup_deflection_dir) self.debug('backing up {} to {}'.format(src, dst)) shutil.copyfile(src, dst) if reset: with open(src, 'r') as rfile: yd = yaml.load(rfile) nd = {} for k in yd: nd[k] = {'deflections': '', 'dacs': ''} with open(src, 'w') as wfile: yaml.dump(nd, wfile, default_flow_style=False)
def _save_button_fired(self): # p = '/Users/ross/Desktop/output_uint8.jpg' p, _ = unique_path2(paths.sample_image_dir, 'nosample', extension='.tiff') self.camera.save(p)
def _generate_path(self, ei): name = ei.name.replace(' ', '_') p, _ = unique_path2(self.root, name, extension=self.extension) return p
def _get_new_path(self): return unique_path2(paths.dvc_dir, 'index', extension='.sqlite3')[0]