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
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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
Example #6
0
    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
Example #7
0
    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
Example #8
0
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)
Example #9
0
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)
Example #10
0
    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))
Example #11
0
    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
Example #13
0
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
Example #15
0
    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
Example #16
0
    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)
Example #17
0
    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)
Example #18
0
    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)
Example #19
0
 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)
Example #20
0
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)
Example #21
0
    def _generate_path(self, ei):
        name = ei.name.replace(' ', '_')

        p, _ = unique_path2(self.root, name, extension=self.extension)
        return p
Example #22
0
 def _get_new_path(self):
     return unique_path2(paths.dvc_dir, 'index', extension='.sqlite3')[0]
Example #23
0
    def _generate_path(self, ei):
        name = ei.name.replace(' ', '_')

        p, _ = unique_path2(self.root, name, extension=self.extension)
        return p
Example #24
0
 def _get_new_path(self):
     return unique_path2(paths.dvc_dir, 'index', extension='.sqlite3')[0]