def _load(self, p=None):
        '''
            files ending with .txt loaded as text
            otherwise unpickled
        '''
        if p is None:
            p = self.path
        else:
            self.path = p

        self.steps = []
        if p.endswith('.txt'):
            # load a text file
            for args in parse_file(p, delimiter=','):
                if len(args) == 2:
                    self.steps.append(ExtractStep(extract_value=float(args[0]),
                                               duration=float(args[1])
                                               ))
                elif len(args) == 4:
                    for i in range(*map(int, args[:3])):
                        self.steps.append(ExtractStep(extract_value=float(i),
                                                   duration=float(args[3])
                                                   ))
        else:
            with open(p, 'rb') as f:
                try:
                    self.steps = pickle.load(f)
                except Exception:
                    pass
Exemple #2
0
    def _selected_changed(self, new):
        if new:
            obj = None
            p = os.path.join(self.persistence_root, '{}.p'.format(new.lower()))
            if os.path.isfile(p):
                try:
                    with open(p, 'r') as rfile:
                        obj = pickle.load(rfile)
                except BaseException:
                    pass

            if obj is None:
                obj = self.options_klass()

            obj.initialize()
            obj.name = new
            self.subview_names = obj.subview_names
            self.selected_options = obj

            o = self.selected_subview
            if not o:
                o = 'Main'

            self.selected_subview = ''
            self.selected_subview = o

        else:
            self.selected_options = None
Exemple #3
0
    def load(file_or_path):
        """ Unpickle the context from a file

        Parameters
        ----------
        file_or_path : str or readable filelike object

        Returns
        -------
        context : object
        """

        if hasattr(file_or_path, 'read'):
            # Already a readable file object.
            should_close = False
            file_object = file_or_path
        else:
            # Open the file.
            should_close = True
            file_object = file(file_or_path, 'rb')

        try:
            data_context = sweet_pickle.load(file_object)
        finally:
            if should_close:
                file_object.close()

        return data_context
Exemple #4
0
    def load(file_or_path):
        """ Unpickle the context from a file

        Parameters
        ----------
        file_or_path : str or readable filelike object

        Returns
        -------
        context : object
        """

        if hasattr(file_or_path, 'read'):
            # Already a readable file object.
            should_close = False
            file_object = file_or_path
        else:
            # Open the file.
            should_close = True
            file_object = file(file_or_path, 'rb')

        try:
            data_context = sweet_pickle.load(file_object)
        finally:
            if should_close:
                file_object.close()

        return data_context
Exemple #5
0
    def check(self):
        '''
        '''
        local_info = None
        major = None
        minor = None

        # get the local version info

        if os.path.isfile(self.local_path):
            with open(self.local_path, 'rb') as f:
                local_info = pickle.load(f)

        if os.path.isfile(self.src_path):

        # get the version_info associated with the src code

            with open(self.src_path, 'rb') as f:
                f.readline()
                line = f.readline()
                major = line.split('=')[1].strip()

                line = f.readline()
                minor = line.split('=')[1].strip()

                self.version_info = VersionInfo(major=major,
                        minor=minor)
                f.readline()
                p = []
                ps = []
                new_para = False
                for line in f:
                    line = line.strip()
                    if new_para:
                        ps.append(p)
                        p = []
                        new_para = False

                    if len(line) > 0:
                        if len(p) == 0 and line[0] == '#':
                            line = '<h5><u>{}</u></h5>'.format(line[1:])
                        p.append(line)
                    else:
                        new_para = True

                self.version_info.text = \
                    ''.join(['<p>{}</p>'.format(pj) for pj in
                            [' '.join(pi) for pi in ps if len(pi) > 0]])

        if minor is not None and major is not None:
            mismatch = True
            if local_info is not None:
                mismatch = local_info.version != '.'.join((major,
                        minor))

            if mismatch:
                if local_info is not None:
                    self.local_version = local_info.version
            elif local_info is None:
                do_later(self.edit_traits, kind='modal')
Exemple #6
0
    def _selected_changed(self, new):
        if new:
            obj = None
            p = os.path.join(self.persistence_root, '{}.p'.format(new.lower()))
            if os.path.isfile(p):
                try:
                    with open(p, 'r') as rfile:
                        obj = pickle.load(rfile)
                except BaseException:
                    pass

            if obj is None:
                obj = self.options_klass()

            obj.initialize()
            obj.name = new
            self.subview_names = obj.subview_names
            self.selected_options = obj

            o = self.selected_subview
            if not o:
                o = 'Main'

            self.selected_subview = ''
            self.selected_subview = o

        else:
            self.selected_options = None
Exemple #7
0
 def _load_pulse(self, p):
     with open(p, 'rb') as f:
         try:
             pul = pickle.load(f)
             pul.manager = self
             return pul
         except Exception, e:
             self.debug('load pulse problem {} {}'.format(p, e))
Exemple #8
0
    def check(self):
        '''
        '''
        local_info = None
        major = None
        minor = None

        # get the local version info

        if os.path.isfile(self.local_path):
            with open(self.local_path, 'rb') as f:
                local_info = pickle.load(f)

        if os.path.isfile(self.src_path):

            # get the version_info associated with the pychron code

            with open(self.src_path, 'rb') as f:
                f.readline()
                line = f.readline()
                major = line.split('=')[1].strip()

                line = f.readline()
                minor = line.split('=')[1].strip()

                self.version_info = VersionInfo(major=major, minor=minor)
                f.readline()
                p = []
                ps = []
                new_para = False
                for line in f:
                    line = line.strip()
                    if new_para:
                        ps.append(p)
                        p = []
                        new_para = False

                    if len(line) > 0:
                        if len(p) == 0 and line[0] == '#':
                            line = '<h5><u>{}</u></h5>'.format(line[1:])
                        p.append(line)
                    else:
                        new_para = True

                self.version_info.text = \
                    ''.join(['<p>{}</p>'.format(pj) for pj in
                            [' '.join(pi) for pi in ps if len(pi) > 0]])

        if minor is not None and major is not None:
            mismatch = True
            if local_info is not None:
                mismatch = local_info.version != '.'.join((major, minor))

            if mismatch:
                if local_info is not None:
                    self.local_version = local_info.version
            elif local_info is None:
                do_later(self.edit_traits, kind='modal')
    def get(self, name):
        p = os.path.join(paths.peak_center_config_dir, add_extension(name, '.p'))
        if os.path.isfile(p):
            with open(p, 'rb') as rfile:
                obj = pickle.load(rfile)
        else:
            obj = self.item_klass()

        return obj
Exemple #10
0
 def _load(self, attr, func):
     p = os.path.join(paths.hidden_dir, 'series_manager.{}'.format(attr))
     if os.path.isfile(p):
         try:
             with open(p, 'r') as fp:
                 pobj = pickle.load(fp)
                 func(pobj, attr)
         except pickle.PickleError:
             pass
Exemple #11
0
 def _load(self, root):
     p = os.path.join(root, self.name)
     if os.path.isfile(p):
         with open(p, 'r') as fp:
             try:
                 obj = pickle.load(fp)
                 self.trait_set(**obj)
             except (pickle.PickleError, TypeError, EOFError, TraitError), e:
                 print 'error loading {}'.format(self.name), e
Exemple #12
0
    def get(self, name):
        p = os.path.join(paths.peak_center_config_dir,
                         add_extension(name, '.p'))
        if os.path.isfile(p):
            with open(p, 'rb') as rfile:
                obj = pickle.load(rfile)
        else:
            obj = self.item_klass()

        return obj
Exemple #13
0
 def load(cls, name):
     path = cls._get_path(name)
     #        print os.path.isfile(path), path
     if os.path.isfile(path):
         with open(path, 'rb') as f:
             try:
                 obj = pickle.load(f)
                 return obj
             except pickle.PickleError, e:
                 pass
 def _load_pid_object(self):
     p = os.path.join(paths.hidden_dir, 'brightness_pid_object')
     if os.path.isfile(p):
         self.info('loading pid object from {}'.format(p))
         try:
             with open(p, 'rb') as f:
                 po = pickle.load(f)
         except pickle.PickleError, e:
             self.info('error loading pid object from {}, {}'.format(p, e))
             po = PIDObject()
Exemple #15
0
    def _load(self, root):
        p = os.path.join(root, self.name)
        if os.path.isfile(p):
            with open(p, 'r') as fp:
                try:
                    obj = pickle.load(fp)
                    self.trait_set(**obj)

                except (pickle.PickleError, TypeError, EOFError):
                    pass
Exemple #16
0
 def _get_browser_persistence(self):
     p = self.selection_persistence_path
     # p = os.path.join(paths.hidden_dir, 'browser_selection')
     if os.path.isfile(p):
         try:
             with open(p, 'rb') as fp:
                 return pickle.load(fp)
         except (pickle.PickleError, EOFError, OSError), e:
             # self.debug('Failed loaded previous browser selection. {}'.format(e))
             pass
Exemple #17
0
 def _load_selected_po(self):
     p = self.selected_options_path
     n = 'Default'
     if os.path.isfile(p):
         with open(p, 'r') as rfile:
             try:
                 n = pickle.load(rfile)
             except (pickle.PickleError, EOFError):
                 n = 'Default'
     return n
Exemple #18
0
    def load(cls, name):
        path = cls._get_path(name)
#        print os.path.isfile(path), path
        if os.path.isfile(path):
            with open(path, 'rb') as f:
                try:
                    obj = pickle.load(f)
                    return obj
                except pickle.PickleError, e:
                    pass
Exemple #19
0
 def _load_selected_po(self):
     p = self.selected_options_path
     n = 'Default'
     if os.path.isfile(p):
         with open(p, 'r') as rfile:
             try:
                 n = pickle.load(rfile)
             except (pickle.PickleError, EOFError):
                 n = 'Default'
     return n
 def __init__(self, *args, **kw):
     super(FindAssociatedParametersDialog, self).__init__(*args, **kw)
     p = os.path.join(paths.hidden_dir, 'find_associated_parameters_dialog')
     if os.path.isfile(p):
         with open(p, 'r') as fp:
             try:
                 self.model = pickle.load(fp)
             except (pickle.PickleError, AttributeError, OSError, EOFError):
                 pass
     if not self.model:
         self.model = FindAssociatedParametersModel()
Exemple #21
0
 def _load_pattern(self, fileobj, path):
     '''
         unpickle fileobj as a pattern
     '''
     try:
         obj = pickle.load(fileobj)
         self.pattern = obj
         self.pattern.path = path
         return obj
     except (pickle.PickleError, Exception), e:
         self.debug('load pattern:{}'.format(e))
    def _load_detector(self, name, klass):
        p = path.join(paths.hidden_dir, name)
        if path.isfile(p):
            with open(p, 'rb') as f:
                try:
                    hd = pickle.load(f)
                    if not isinstance(hd, klass):
                        hd = klass()

                except Exception, e:
                    print e
Exemple #23
0
    def load_browser_selection(self):
        #self.debug('$$$$$$$$$$$$$$$$$$$$$ Loading browser selection')
        p = os.path.join(paths.hidden_dir, 'browser_selection')
        if os.path.isfile(p):
            try:
                with open(p, 'rb') as fp:
                    sel = pickle.load(fp)
            except (pickle.PickleError, EOFError, OSError), e:
                #self.debug('Failed loaded previous browser selection. {}'.format(e))
                return

            self._load_browser_selection(sel)
    def __init__(self, *args, **kw):
        super(TableSelectionDialog, self).__init__(*args, **kw)

        p = os.path.join(paths.hidden_dir, 'table_selection_dialog')
        if os.path.isfile(p):
            with open(p, 'r') as fp:
                try:
                    self.model = pickle.load(fp)
                except (pickle.PickleError, AttributeError, OSError, EOFError):
                    pass
        if not self.model:
            self.model=TableSelectionModel()
    def _peak_center_config_default(self):
        config = None
        p = os.path.join(paths.hidden_dir, 'peak_center_config')
        if os.path.isfile(p):
            try:
                with open(p) as fp:
                    config = pickle.load(fp)
                    config.detectors = dets = self.spectrometer.detectors
                    config.detector = next((di for di in dets if di.name == config.detector_name), None)

            except Exception, e:
                print 'peak center config', e
Exemple #26
0
    def _pulse_default(self):
        p = os.path.join(paths.hidden_dir, 'pulse')
        if os.path.isfile(p):
            with open(p, 'rb') as f:
                try:
                    pul = pickle.load(f)
                    pul.manager = self
                except pickle.PickleError:
                    pul = Pulse(manager=self)
        else:
            pul = Pulse(manager=self)

        return pul
Exemple #27
0
 def _load_pattern(self, fileobj, path):
     '''
         unpickle fileobj as a pattern
     '''
     try:
         obj = pickle.load(fileobj)
         self.pattern = obj
         self.pattern.path = path
         return obj
     except (pickle.PickleError, Exception), e:
         import traceback
         traceback.print_exc()
         self.debug('load pattern:{}'.format(e))
Exemple #28
0
    def _peak_center_config_default(self):
        config = None
        p = os.path.join(paths.hidden_dir, 'peak_center_config')
        if os.path.isfile(p):
            try:
                with open(p) as fp:
                    config = pickle.load(fp)
                    config.detectors = dets = self.spectrometer.detectors
                    config.detector = next(
                        (di for di in dets if di.name == config.detector_name),
                        None)

            except Exception, e:
                print 'peak center config', e
    def _load_parameters(self, p):
        pa = None
        if os.path.isfile(p):
            with open(p, 'rb') as f:
                try:
                    pa = pickle.load(f)
                except (pickle.PickleError, EOFError):
                    pass

        klass = self.parameters_klass
        if pa is None or not isinstance(pa, klass):
            pa = klass()

        return pa
    def _load_parameters(self, p):
        pa = None
        if os.path.isfile(p):
            with open(p, 'rb') as f:
                try:
                    pa = pickle.load(f)
                except (pickle.PickleError, EOFError):
                    pass

        klass = self.parameters_klass
        if pa is None or not isinstance(pa, klass):
            pa = klass()

        return pa
Exemple #31
0
    def _axis_factory(self, path, **kw):
        '''
        '''
        na = NewportAxis(parent=self,
                       **kw
                         )

        p = na.load(path)
        if p:
            with open(p, 'r') as f:
                na = pickle.load(f)
                na.parent = self
                na.loaded = True

        return na
Exemple #32
0
    def load(self):
        for ai in ['calculated_values', 'measured_values',
                    'baseline_values', 'blank_values', 'background_values']:
            self._load(ai, self._load_values)

        self._load('peak_center_option', self._load_peak_center)

        p = os.path.join(paths.hidden_dir, 'series_manager.traits')
        if os.path.isfile(p):
            try:
                with open(p, 'r') as fp:
                    dd = pickle.load(fp)
                    self.trait_set(**dd)
            except pickle.PickleError:
                pass
Exemple #33
0
    def load_visualization(self):
        p = self.open_file_dialog()

        if p is not None:
            with open(p, 'rb') as f:
                #                try:
                d = pickle.load(f)

                self.center = d['center']
                self.rotation = d['rotation']

                for k, v in d['markup'].iteritems():
                    v.set_canvas(self.canvas)

                self.canvas.markupcontainer = d['markup']
Exemple #34
0
    def load_visualization(self):
        p = self.open_file_dialog()

        if p is not None:
            with open(p, 'rb') as f:
#                try:
                    d = pickle.load(f)

                    self.center = d['center']
                    self.rotation = d['rotation']

                    for k, v in d['markup'].iteritems():
                        v.set_canvas(self.canvas)

                    self.canvas.markupcontainer = d['markup']
    def _plotter_options_default(self):
        p = os.path.join(self.persistence_root, '{}.default'.format(self.plotter_options_name))

        n = 'Default'
        if os.path.isfile(p):
            with open(p, 'r') as fp:
                try:
                    n = pickle.load(fp)
                except (pickle.PickleError, EOFError):
                    n = 'Default'

        po = next((pi for pi in self.plotter_options_list if pi.name == n), None)
        if not po:
            po = self.plotter_options_list[0]

        return po
Exemple #36
0
    def load_fits(self):
        p = os.path.join(paths.hidden_dir, 'fit_manager.fits')
        if os.path.isfile(p):
            try:
                with open(p, 'rb') as fp:
                    self.fits = pickle.load(fp)
            except (pickle.PickleError, EOFError):
                pass

        if not self.fits:
            self.fits = [Fit(deletable=False,
                             names=['Ar40', 'Ar39', 'Ar38', 'Ar37', 'Ar36'])]


        for fi in self.fits:
            fi.do_binding = self.do_fit_binding
Exemple #37
0
 def load_state(self, cmpconfigfile):
     """ Load CMP Configuration state directly.
     Useful if you do not want to invoke the GUI"""
     # support the new traits api
     try:
       import apptools.sweet_pickle as sp        
     except ImportError:
       import enthought.sweet_pickle as sp 
     output = open(cmpconfigfile, 'rb')
     data = sp.load(output)
     self.__setstate__(data.__getstate__())
     # make sure that dtk_matrices is set
     self.dtk_matrices = os.path.join(self.dtk_home, 'matrices')
     # update the subject directory
     if os.path.exists(self.project_dir):
         self.subject_workingdir = os.path.join(self.project_dir, self.subject_name, self.subject_timepoint)
     output.close()
    def _load_power_maps(self):
        p = os.path.join(paths.hidden_dir, 'power_maps')
        if os.path.isfile(p):
            with open(p, 'rb') as f:
                try:
                    pmc = pickle.load(f)
                except Exception:
                    pmc = [PowerMapping()]
        else:
            pmc = [PowerMapping()]

        for pmi in pmc:
            pmi.name = 'PowerMap'
#            pmi.laser_manager = self.laser_manager
            pmi.parent = self

        return pmc
    def _plotter_options_default(self):
        p = os.path.join(self.persistence_root,
                         '{}.default'.format(self.plotter_options_name))

        n = 'Default'
        if os.path.isfile(p):
            with open(p, 'r') as fp:
                try:
                    n = pickle.load(fp)
                except (pickle.PickleError, EOFError):
                    n = 'Default'

        po = next((pi for pi in self.plotter_options_list if pi.name == n),
                  None)
        if not po:
            po = self.plotter_options_list[0]

        return po
Exemple #40
0
    def load_pattern(self, path=None):
        if path is None:
            path = self.open_file_dialog(default_directory=paths.pattern_dir)

        if path is not None and os.path.isfile(path):
#            self.pattern = None
            with open(path, 'rb') as f:
                try:
                    p = pickle.load(f)
                    p.path = path
                    self.pattern = p
                    self._kind = self.pattern.__class__.__name__.partition('Pattern')[0]
                    self.info('loaded {} from {}'.format(self.pattern_name, path))
                    self.pattern.replot()
                except:
                    if self.confirmation_dialog('Invalid Pattern File {}'.format(path)):
                        os.remove(path)
        else:
            self.pattern = None
    def load(self, **kw):
        names = list_directory2(paths.peak_center_config_dir, remove_extension=True, extension='.p')
        if 'Default' not in names:
            item = self.item_klass()
            item.name = 'Default'
            self.dump_item(item)
            names = list_directory2(paths.peak_center_config_dir, remove_extension=True, extension='.p')

        name = 'Default'
        p = os.path.join(paths.hidden_dir, add_extension('config', '.p'))
        if os.path.isfile(p):
            with open(p, 'rb') as rfile:
                obj = pickle.load(rfile)
                name = obj.get('name', 'Default')

        self.names = names
        self.active_name = name

        self.active_item.trait_set(**kw)
    def load(self, path):
        """ Loads an object from a file. """

        # Unpickle the object.
        f = open(path, 'rb')
        try:
            try:
                obj = sweet_pickle.load(f)
#                obj = cPickle.load(f)
#                obj = pickle.load(f)
            except Exception as ex:
                print_exc()
                logger.exception("Failed to load pickle file: %s, %s" %
                                 (path, ex))

                raise
        finally:
            f.close()

        return obj
Exemple #43
0
    def _load(self, root):
        p = os.path.join(root, self.name)
        if os.path.isfile(p):
            with open(p, 'r') as fp:
                try:
                    obj = pickle.load(fp)
                    self.trait_set(**obj)
                except (pickle.PickleError, TypeError, EOFError, TraitError):
                    pass

        klass = self.plot_option_klass
        name = self.plot_option_name
        if name:
            pp = next((p for p in self.aux_plots if p.name == name), None)
            if not pp:
                po = klass(height=0)
                po.trait_set(name=name, trait_change_notfiy=False)
                self.aux_plots.append(po)

        self.initialize()
Exemple #44
0
    def views_factory(self):
        '''
        '''
        # if os.path.exists(picklepath):

        uvfs = get_user_views()
        if uvfs:
            px = []
            for pa in uvfs:
                with open(pa, 'r') as f:
                    try:
                        pi = pickle.load(f)
                        pi.scene_graph = self.scene_graph
                        px.append(pi)
                    except ImportError:
                        pass
            return px
        else:
            return [
            ]  # UserView(name = 'home', key = 'h', scene_graph = self.scene_graph)]
Exemple #45
0
    def load(self, **kw):
        names = list_directory2(paths.peak_center_config_dir,
                                remove_extension=True,
                                extension='.p')
        if 'Default' not in names:
            item = self.item_klass()
            item.name = 'Default'
            self.dump_item(item)
            names = list_directory2(paths.peak_center_config_dir,
                                    remove_extension=True,
                                    extension='.p')

        name = 'Default'
        p = os.path.join(paths.hidden_dir, add_extension('config', '.p'))
        if os.path.isfile(p):
            with open(p, 'rb') as rfile:
                obj = pickle.load(rfile)
                name = obj.get('name', 'Default')

        self.names = names
        self.active_name = name

        self.active_item.trait_set(**kw)
Exemple #46
0
 def load(self):
     '''
     '''
     if os.path.isfile(self.pickle_path):
         with open(self.pickle_path, 'r') as f:
             self.history = pickle.load(f)