def load_additional_args(self, config):
        '''
        '''
        self.set_attribute(config, 'request_powermin', 'General',
                           'power min', cast='float')
        self.set_attribute(config, 'request_powermax', 'General',
                            'power max', cast='float')

        # read in the coefficients from file
        coeffs = self.config_get(config, 'PowerMeter', 'coefficients')
        if coeffs is not None:
            self.power_meter_calibration = MeterCalibration(coeffs)

        coeffs = self.config_get(config, 'PowerOutput', 'coefficients')
        if coeffs is not None:

            p = os.path.join(paths.hidden_dir,
                        '{}_power_calibration'.format(self.name.split('.')[0]))

            obj = MeterCalibration(coeffs)
            # dump to the hidden dir
            # the manager will use it directly
            try:
                self.info('loading power calibration from config file')
                with open(p, 'wb') as f:
                    pickle.dump(obj, f)
            except (OSError, pickle.PickleError):
                self.warning('failed loading power output calibration')

        return super(FusionsCO2LogicBoard, self).load_additional_args(config)
 def kill(self):
     super(PowerCalibrationManager, self).kill()
     if self.initialized:
         for n in ['parameters', 'check_parameters']:
             with open(self._get_parameters_path(n),
                       'wb') as f:
                 pickle.dump(getattr(self, n), f)
 def kill(self):
     super(PowerCalibrationManager, self).kill()
     if self.initialized:
         for n in ['parameters', 'check_parameters']:
             with open(self._get_parameters_path(n),
                       'wb') as f:
                 pickle.dump(getattr(self, n), f)
Example #4
0
    def dump(self):
        with open(self.path, 'wb') as f:
            d = dict(center=self.center,
                     rotation=self.rotation,
                     markup=self.canvas.markupcontainer)

            pickle.dump(d, f)
Example #5
0
    def dump(self):
        p = os.path.join(paths.hidden_dir, add_extension('config', '.p'))
        with open(p, 'wfile') as wfile:
            obj = {'name': self.active_name}
            pickle.dump(obj, wfile)

        self.dump_item(self.active_item)
Example #6
0
    def dump(self):
        p = os.path.join(paths.hidden_dir, add_extension('config', '.p'))
        with open(p, 'wfile') as wfile:
            obj = {'name': self.active_name}
            pickle.dump(obj, wfile)

        self.dump_item(self.active_item)
 def _save(self, path):
     if not path.endswith('.lp'):
         path += '.lp'
     self.pattern.path = path
     with open(path, 'wb') as f:
         pickle.dump(self.pattern, f)
     self.info('pattern saved as {}'.format(path))
Example #8
0
    def dump_browser_selection(self):
        # self.debug('$$$$$$$$$$$$$$$$$$$$$ Dumping browser selection')

        ps = []
        if self.selected_projects:
            ps = [p.name for p in self.selected_projects]

        ss = []
        if self.selected_samples:
            ss = [p.identifier for p in self.selected_samples]

        obj = dict(projects=ps,
                   samples=ss,
                   use_low_post=self.use_low_post,
                   use_high_post=self.use_high_post,
                   use_named_date_range=self.use_named_date_range,
                   named_date_range=self.named_date_range,
                   low_post=self.low_post,
                   high_post=self.high_post)

        # p = os.path.join(paths.hidden_dir, 'browser_selection')

        try:
            with open(self.selection_persistence_path, 'wb') as fp:
                pickle.dump(obj, fp)
        except (pickle.PickleError, EOFError, OSError), e:
            #self.debug('Failed dumping previous browser selection. {}'.format(e))
            return
Example #9
0
    def save(self, file_or_path):
        """ Pickle the data context out to a file

        Parameters
        ----------
        file_or_path : str or writable filelike object
        """

        # Check if there is a key called 'context' that references to its
        # bindings
        if self.has_key('context') and self['context'] == self._bindings:
            self.pop('context')

        if hasattr(file_or_path, 'write'):
            # File is already opened. Will not close.
            should_close = False
            file_object = file_or_path
        else:
            should_close = True
            file_object = open(file_or_path, 'wb')

        try:
            # Filter out nonpickleable data from the context dictionary
            for item in self.keys():
                if isinstance(self[item], tuple(NonPickleable)):
                    del self[item]
            sweet_pickle.dump(self, file_object, 1)
        finally:
            if should_close:
                file_object.close()
Example #10
0
    def save(self, file_or_path):
        """ Pickle the data context out to a file

        Parameters
        ----------
        file_or_path : str or writable filelike object
        """

        # Check if there is a key called 'context' that references to its
        # bindings
        if self.has_key('context') and self['context'] == self._bindings:
            self.pop('context')

        if hasattr(file_or_path, 'write'):
            # File is already opened. Will not close.
            should_close = False
            file_object = file_or_path
        else:
            should_close = True
            file_object = open(file_or_path, 'wb')

        try:
            # Filter out nonpickleable data from the context dictionary
            for item in self.keys():
                if isinstance(self[item], tuple(NonPickleable)):
                    del self[item]
            sweet_pickle.dump(self, file_object, 1)
        finally:
            if should_close:
                file_object.close()
Example #11
0
 def _save(self, path):
     if not path.endswith('.lp'):
         path += '.lp'
     self.pattern.path = path
     with open(path, 'wb') as f:
         pickle.dump(self.pattern, f)
     self.info('pattern saved as {}'.format(path))
Example #12
0
 def save_state(self, cmpconfigfile):
     """ Save CMP Configuration state directly.
     Useful if you do not want to invoke the GUI
     
     Parameters
     ----------
     cmpconfigfile : string
         Absolute path and filename to store the CMP configuration
         pickled object
     
     """
     # check if path available
     if not os.path.exists(os.path.dirname(cmpconfigfile)):
         os.makedirs(os.path.abspath(os.path.dirname(cmpconfigfile)))
         
     # support the new traits api
     try:
       import apptools.sweet_pickle as sp        
     except ImportError:
       import enthought.sweet_pickle as sp 
     output = open(cmpconfigfile, 'wb')
     # Pickle the list using the highest protocol available.
     # copy object first
     tmpconf = CMPGUI()
     tmpconf.copy_traits(self)
     sp.dump(tmpconf, output, -1)
     output.close()
 def closed(self, info, is_ok):
     if is_ok:
         p = os.path.join(paths.hidden_dir, 'find_associated_parameters_dialog')
         with open(p, 'w') as fp:
             try:
                 pickle.dump(self.model, fp)
             except pickle.PickleError:
                 pass
Example #14
0
    def dump(self):
        with open(self.path, 'wb') as f:
            d = dict(center=self.center,
                   rotation=self.rotation,
                   markup=self.canvas.markupcontainer
                   )

            pickle.dump(d, f)
 def closed(self, info, is_ok):
     if is_ok:
         p = os.path.join(paths.hidden_dir, 'table_selection_dialog')
         with open(p, 'w') as fp:
             try:
                 pickle.dump(self.model, fp)
             except pickle.PickleError:
                 pass
Example #16
0
 def _dump_items(self, path, items, use_pickle=True):
     with open(path, 'w') as f:
         self.dirty = False
         self.file_path = path
         if use_pickle:
             pickle.dump(items, f)
         else:
             f.write(items)
Example #17
0
    def dump_fits(self):

        p = os.path.join(paths.hidden_dir, 'fit_manager.fits')

        try:
            with open(p, 'wb') as fp:
                pickle.dump(self.fits, fp)
        except pickle.PickleError:
            pass
Example #18
0
    def save_selected_as(self):
        name = self.new_name

        with open(os.path.join(self.persistence_root, '{}.p'.format(name)), 'wb') as wfile:
            pickle.dump(self.selected_options, wfile)

        self.refresh()
        self.selected = name
        self.save_selected()
    def _dump_pid_object(self):

        try:
            p = os.path.join(paths.hidden_dir, 'brightness_pid_object')
            self.info('dumping pid object to {}'.format(p))
            with open(p, 'wb') as f:
                pickle.dump(self.pid_object, f)
        except pickle.PickleError:
            pass
Example #20
0
    def save_selected_as(self):
        name = self.new_name

        with open(os.path.join(self.persistence_root, '{}.p'.format(name)),
                  'wb') as wfile:
            pickle.dump(self.selected_options, wfile)

        self.refresh()
        self.selected = name
        self.save_selected()
Example #21
0
    def dump(self):
        for ai in ['calculated_values', 'measured_values',
                    'baseline_values', 'blank_values', 'background_values',
                    'peak_center_option'
                    ]:
            self._dump(ai)

        p = os.path.join(paths.hidden_dir, 'series_manager.traits')
        with open(p, 'w') as fp:
            dd = dict([(ai, getattr(self, ai)) for ai in ['use_single_window']])
            pickle.dump(dd, fp)
Example #22
0
    def save_selection(self):
        if not os.path.isdir(self.persistence_root):
            try:
                os.mkdir(self.persistence_root)
            except OSError:
                os.mkdir(os.path.dirname(self.persistence_root))
                os.mkdir(self.persistence_root)

        if self.selected:
            with open(self.selected_options_path, 'w') as wfile:
                pickle.dump(self.selected, wfile)
Example #23
0
    def save_selection(self):
        if not os.path.isdir(self.persistence_root):
            try:
                os.mkdir(self.persistence_root)
            except OSError:
                os.mkdir(os.path.dirname(self.persistence_root))
                os.mkdir(self.persistence_root)

        if self.selected:
            with open(self.selected_options_path, 'w') as wfile:
                pickle.dump(self.selected, wfile)
Example #24
0
    def save(self, name=None, obj=None):
        # dump the default plotter options
        self.save_selection()

        if name is None:
            if self.selected:
                obj = self.selected_options
                name = self.selected

        with open(os.path.join(self.persistence_root, '{}.p'.format(name)), 'w') as wfile:
            pickle.dump(obj, wfile)
Example #25
0
    def _dump(self, root):
        if not self.name:
            return
        p = os.path.join(root, self.name)
        with open(p, 'w') as fp:
            d = dict()
            attrs = self._get_dump_attrs()
            for t in attrs:
                d[t] = getattr(self, t)

            pickle.dump(d, fp)
Example #26
0
    def save(self, name=None, obj=None):
        # dump the default plotter options
        self.save_selection()

        if name is None:
            if self.selected:
                obj = self.selected_options
                name = self.selected

        with open(os.path.join(self.persistence_root, '{}.p'.format(name)),
                  'w') as wfile:
            pickle.dump(obj, wfile)
    def save_calibration(self, name=None):
        PICKLE_PATH = p = os.path.join(paths.hidden_dir, '{}_stage_calibration')
        if name is None:
        # delete the corrections file
            name = self.parent.stage_map

        ca = self.canvas.calibration_item
        if  ca is not None:
            self.parent._stage_map.clear_correction_file()
            ca.style = self.style
            p = PICKLE_PATH.format(name)
            self.info('saving calibration {}'.format(p))
            with open(p, 'wb') as f:
                pickle.dump(ca, f)
    def save_calibration(self, name=None):
        PICKLE_PATH = p = os.path.join(paths.hidden_dir,
                                       '{}_stage_calibration')
        if name is None:
            # delete the corrections file
            name = self.parent.stage_map

        ca = self.canvas.calibration_item
        if ca is not None:
            self.parent._stage_map.clear_correction_file()
            ca.style = self.style
            p = PICKLE_PATH.format(name)
            self.info('saving calibration {}'.format(p))
            with open(p, 'wb') as f:
                pickle.dump(ca, f)
Example #29
0
    def save_pattern(self):
#        if not self.pattern_name:
#            path, _cnt = unique_path(pattern_dir, 'pattern', filetype='lp')
#        else:
#            path = os.path.join(pattern_dir, '{}.lp'.format(self.pattern_name))

        path = self.save_file_dialog(default_directory=paths.pattern_dir)

        if path:
            if not path.endswith('.lp'):
                path += '.lp'
            self.pattern.path = path
            with open(path, 'wb') as f:
                pickle.dump(self.pattern, f)
            self.info('saved {} pattern to {}'.format(self.pattern_name, path))
Example #30
0
    def _dump(self, root):
        if not self.name:
            return
        p = os.path.join(root, self.name)
        #         print root, self.name
        self._make_dir(root)
        with open(p, 'w') as fp:
            d = dict()
            attrs = self._get_dump_attrs()
            for t in attrs:
                d[t] = getattr(self, t)

            try:
                pickle.dump(d, fp)
            except (pickle.PickleError, TypeError, EOFError, TraitError):
                pass
Example #31
0
    def _dump(self, root):
        if not self.name:
            return
        p = os.path.join(root, self.name)
        #         print root, self.name
        self._make_dir(root)
        with open(p, 'w') as fp:
            d = dict()
            attrs = self._get_dump_attrs()
            for t in attrs:
                d[t] = v = getattr(self, t)

            try:
                pickle.dump(d, fp)
            except (pickle.PickleError, TypeError, EOFError, TraitError), e:
                print 'error dumping {}'.format(self.name), e
Example #32
0
    def closed(self, info, is_ok):
        '''

        '''

        # delete any previous view
        # if they exist they will be rewritten below

        for uvi in get_user_views():
            os.remove(uvi)

        obj = info.object.views
        for i, v in enumerate(obj):

            name = 'userview{}'.format(i)
            with open(os.path.join(paths.hidden_dir, name), 'w') as f:
                pickle.dump(v, f)

        super(ViewControllerHandler, self).closed(info, is_ok)
    def save(self, path, obj):
        """ Saves an object to a file. """

        if not path.endswith(self.ext):
            actual_path = path + self.ext

        else:
            actual_path = path

        # Pickle the object.
        f = open(actual_path, 'wb')
        try:
            sweet_pickle.dump(obj, f, 1)
#            cPickle.dump(obj, f, 1)
#            pickle.dump(obj, f, 1)
        except Exception, ex:
            logger.exception("Failed to pickle into file: %s, %s, object:%s" %
                             (path, ex, obj))
            print_exc()
Example #34
0
    def save(self, path, obj):
        """ Saves an object to a file. """

        if not path.endswith(self.ext):
            actual_path = path + self.ext

        else:
            actual_path = path

        # Pickle the object.
        f = open(actual_path, 'wb')
        try:
            sweet_pickle.dump(obj, f, 1)
#            cPickle.dump(obj, f, 1)
#            pickle.dump(obj, f, 1)
        except Exception, ex:
            logger.exception( "Failed to pickle into file: %s, %s, object:%s"
                % (path, ex, obj))
            print_exc()
Example #35
0
    def closed(self, info, is_ok):
        '''

        '''

        # delete any previous view
        # if they exist they will be rewritten below

        for uvi in get_user_views():
            os.remove(uvi)

        obj = info.object.views
        for i, v in enumerate(obj):

            name = 'userview{}'.format(i)
            with open(os.path.join(paths.hidden_dir, name), 'w') as f:
                pickle.dump(v, f)

        super(ViewControllerHandler, self).closed(info, is_ok)
    def save(self):
        # dump the default plotter options
        if not os.path.isdir(self.persistence_root):
            try:
                os.mkdir(self.persistence_root)
            except OSError:
                os.mkdir(os.path.dirname(self.persistence_root))
                os.mkdir(self.persistence_root)

        p = os.path.join(self.persistence_root,
                         '{}.default'.format(self.plotter_options_name))
        name = self.plotter_options.name
        with open(p, 'w') as fp:
            pickle.dump(name, fp)

        self.plotter_options.dump(self.persistence_root)
        self._plotter_options_list_dirty = True

        self.plotter_options=next((pp for pp in self.plotter_options_list if pp.name==name), None)
    def save(self):
        # dump the default plotter options
        if not os.path.isdir(self.persistence_root):
            try:
                os.mkdir(self.persistence_root)
            except OSError:
                os.mkdir(os.path.dirname(self.persistence_root))
                os.mkdir(self.persistence_root)

        p = os.path.join(self.persistence_root,
                         '{}.default'.format(self.plotter_options_name))
        name = self.plotter_options.name
        with open(p, 'w') as fp:
            pickle.dump(name, fp)

        self.plotter_options.dump(self.persistence_root)
        self._plotter_options_list_dirty = True

        self.plotter_options = next(
            (pp for pp in self.plotter_options_list if pp.name == name), None)
Example #38
0
    def dump_browser_selection(self):
        #self.debug('$$$$$$$$$$$$$$$$$$$$$ Dumping browser selection')

        ps = []
        if self.selected_projects:
            ps = [p.name for p in self.selected_projects]

        ss = []
        if self.selected_samples:
            ss = [p.name for p in self.selected_samples]

        obj = dict(projects=ps,
                   samples=ss)

        p = os.path.join(paths.hidden_dir, 'browser_selection')
        try:
            with open(p, 'wb') as fp:
                pickle.dump(obj, fp)
        except (pickle.PickleError, EOFError, OSError), e:
            #self.debug('Failed dumping previous browser selection. {}'.format(e))
            return
    def load_additional_args(self, config):
        '''
        '''
        self.set_attribute(config,
                           'request_powermin',
                           'General',
                           'power min',
                           cast='float')
        self.set_attribute(config,
                           'request_powermax',
                           'General',
                           'power max',
                           cast='float')

        # read in the coefficients from file
        coeffs = self.config_get(config, 'PowerMeter', 'coefficients')
        if coeffs is not None:
            self.power_meter_calibration = MeterCalibration(coeffs)

        coeffs = self.config_get(config, 'PowerOutput', 'coefficients')
        if coeffs is not None:

            p = os.path.join(
                paths.hidden_dir,
                '{}_power_calibration'.format(self.name.split('.')[0]))

            obj = MeterCalibration(coeffs)
            # dump to the hidden dir
            # the manager will use it directly
            try:
                self.info('loading power calibration from config file')
                with open(p, 'wb') as f:
                    pickle.dump(obj, f)
            except (OSError, pickle.PickleError):
                self.warning('failed loading power output calibration')

        return super(FusionsCO2LogicBoard, self).load_additional_args(config)
    def close(self, ok):
        if ok:

            # dump the default plotter options
            if not os.path.isdir(self.persistence_root):
                try:
                    os.mkdir(self.persistence_root)
                except OSError:
                    os.mkdir(os.path.dirname(self.persistence_root))
                    os.mkdir(self.persistence_root)

            p = os.path.join(self.persistence_root,
                             '{}.default'.format(self.plotter_options_name))
            with open(p, 'w') as fp:
                obj = self.plotter_options.name
                pickle.dump(obj, fp)

            self.plotter_options.dump(self.persistence_root)
            self._plotter_options_list_dirty = True

#            self.plotter_options = next((pi for pi in self.plotter_options_list
#                                         if pi.name == self.plotter_options.name), None)

        return True
Example #41
0
 def dump(self):
     '''
     '''
     with open(self.local_path, 'wb') as f:
         pickle.dump(self.version_info, f)
Example #42
0
 def save(self, obj):
     p = self._get_path(self.name)
     with open(p, 'wb') as f:
         pickle.dump(obj, f)
Example #43
0
 def dump_item(self, item):
     name = item.name
     p = os.path.join(paths.peak_center_config_dir,
                      add_extension(name, '.p'))
     with open(p, 'wb') as wfile:
         pickle.dump(item, wfile)
Example #44
0
 def save(self, obj):
     p = self._get_path(self.name)
     with open(p, 'wb') as f:
         pickle.dump(obj, f)
Example #45
0
 def __dump(self):
     '''
     '''
     with open(self.pickle_path, 'w') as f:
         pickle.dump(self.history, f)
Example #46
0
 def _dump_power_maps(self):
     p = os.path.join(paths.hidden_dir, 'power_maps')
     with open(p, 'wb') as f:
         pickle.dump(self.mappings, f)
Example #47
0
 def dump(self):
     with open(self.path, 'wb') as f:
         pickle.dump(self, f)
Example #48
0
 def _dump_pulse(self):
     p = os.path.join(paths.hidden_dir, 'pulse')
     with open(p, 'wb') as f:
         pickle.dump(self.pulse, f)
Example #49
0
 def dump(self):
     p = os.path.join(paths.hidden_dir, 'peak_center_config')
     with open(p, 'wb') as fp:
         pickle.dump(self, fp)