Example #1
0
 def load_config(self, config_file):
     cfg = PyFileConfigLoader(config_file)
     cfg.load_config()
     self.config = cfg.config
     
     # special casing for SAMPLE_GENERATED
     if (self.config.trigger == 'SAMPLE_GENERATED'):
         self.config.trigger_msg = rc.MT_SAMPLE_GENERATED
         self.config.trigger_mdf = rc.MDF_SAMPLE_GENERATED
     else:
         self.config.trigger_msg = \
             eval('rc.MT_' + self.config.trigger)
         self.config.trigger_mdf = \
             eval('rc.MDF_' + self.config.trigger)
     print "Triggering with", self.config.trigger
     print "CoilPlotter: loading config"
     #Getting tool message number
     self.plate = self.config.tools.index('CB609')
     self.marker = self.config.tools.index('CT315')
     self.glasses = self.config.tools.index('ST568')
     self.pointer = self.config.tools.index('P717')
     #Get tool P717 calibration values for pointer calculation
     self.pointer_Ti = np.array(self.config.tool_list[self.pointer].Ti)
     self.pointer_Qi = qa.norm(np.array(self.config.tool_list[self.pointer].Qi))
     self.pointer_Ni = np.array(self.config.tool_list[self.pointer].Ni)
     self.pointer_tp = TP(self.pointer_Qi, self.pointer_Ni, self.pointer_Ti)
 def load_file_config(self):
     """Load the config file.
     
     This tries to load the config file from disk.  If successful, the
     ``CONFIG_FILE`` config variable is set to the resolved config file
     location.  If not successful, an empty config is used.
     """
     self.log.debug("Attempting to load config file: <%s>" %
                    self.config_file_name)
     loader = PyFileConfigLoader(self.config_file_name,
                                 path=self.config_file_paths)
     try:
         self.file_config = loader.load_config()
         self.file_config.Global.config_file = loader.full_filename
     except IOError:
         # Only warn if the default config file was NOT being used.
         if not self.config_file_name == self.default_config_file_name:
             self.log.warn("Config file not found, skipping: <%s>" % \
                            self.config_file_name, exc_info=True)
         self.file_config = Config()
     except:
         self.log.warn("Error loading config file: <%s>" % \
                        self.config_file_name, exc_info=True)
         self.file_config = Config()
     else:
         self.log.debug("Config file loaded: <%s>" % loader.full_filename)
         self.log.debug(repr(self.file_config))
     # We need to keeep self.log_level updated.  But we only use the value
     # of the file_config if a value was not specified at the command
     # line.
     if not hasattr(self.command_line_config.Global, 'log_level'):
         try:
             self.log_level = self.file_config.Global.log_level
         except AttributeError:
             pass  # Use existing value
Example #3
0
 def load_file_config(self, suppress_errors=True):
     """Load the config file.
     
     This tries to load the config file from disk.  If successful, the
     ``CONFIG_FILE`` config variable is set to the resolved config file
     location.  If not successful, an empty config is used.
     
     By default, errors in loading config are handled, and a warning
     printed on screen. For testing, the suppress_errors option is set
     to False, so errors will make tests fail.
     """
     self.log.debug("Attempting to load config file: %s" %
                    self.config_file_name)
     loader = PyFileConfigLoader(self.config_file_name,
                                 path=self.config_file_paths)
     try:
         self.file_config = loader.load_config()
         self.file_config.Global.config_file = loader.full_filename
     except IOError:
         # Only warn if the default config file was NOT being used.
         if not self.config_file_name==self.default_config_file_name:
             self.log.warn("Config file not found, skipping: %s" %
                            self.config_file_name, exc_info=True)
         self.file_config = Config()
     except:
         if not suppress_errors:     # For testing purposes
             raise
         self.log.warn("Error loading config file: %s" %
                       self.config_file_name, exc_info=True)
         self.file_config = Config()
Example #4
0
def check_null_profile(profile):
    loader = PyFileConfigLoader(
        profile, path=[os.path.join(os.getcwdu(), 'profile/test')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    result, _ = C.from_filename('tests/ipynbref/IntroNumPy.orig.ipynb')
    nt.assert_equal(result.strip('\n'), '')
Example #5
0
def test_profile(profile_name,infile, reference_file):
    loader = PyFileConfigLoader(profile_name+'.nbcv',path=[os.path.join(os.getcwdu(),'profile/')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    output,resources = C.from_filename(infile)
    with io.open(reference_file,'r') as f:
        compfiles(output,f.read())
Example #6
0
def test_profile(profile_name,infile, reference_file):
    loader = PyFileConfigLoader(profile_name+'.py',path=[os.path.join(os.getcwdu(),'profile/')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    output,resources = C.from_filename(infile)
    with io.open(reference_file,'r') as f:
        compfiles(output,f.read())
Example #7
0
 def load_file_config(self, suppress_errors=True):
     """Load the config file.
     
     This tries to load the config file from disk.  If successful, the
     ``CONFIG_FILE`` config variable is set to the resolved config file
     location.  If not successful, an empty config is used.
     
     By default, errors in loading config are handled, and a warning
     printed on screen. For testing, the suppress_errors option is set
     to False, so errors will make tests fail.
     """
     self.log.debug("Attempting to load config file: %s" %
                    self.config_file_name)
     loader = PyFileConfigLoader(self.config_file_name,
                                 path=self.config_file_paths)
     try:
         self.file_config = loader.load_config()
         self.file_config.Global.config_file = loader.full_filename
     except IOError:
         # Only warn if the default config file was NOT being used.
         if not self.config_file_name == self.default_config_file_name:
             self.log.warn("Config file not found, skipping: %s" %
                           self.config_file_name,
                           exc_info=True)
         self.file_config = Config()
     except:
         if not suppress_errors:  # For testing purposes
             raise
         self.log.warn("Error loading config file: %s" %
                       self.config_file_name,
                       exc_info=True)
         self.file_config = Config()
Example #8
0
def get_config(profile_name='default'):
    basefilename = 'nbx_config'

    ipython_dir = get_ipython_dir()
    profiledir = ProfileDir.find_profile_dir_by_name(ipython_dir, profile_name)
    pyloader = PyFileConfigLoader(basefilename+'.py', path=profiledir.location)
    config = pyloader.load_config()
    return config
Example #9
0
 def test_python(self):
     fd, fname = mkstemp('.py')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname, log=log)
     config = cl.load_config()
     self._check_conf(config)
Example #10
0
def get_config(profile_name='default'):
    basefilename = 'nbx_config'

    ipython_dir = get_ipython_dir()
    profiledir = ProfileDir.find_profile_dir_by_name(ipython_dir, profile_name)
    pyloader = PyFileConfigLoader(basefilename + '.py',
                                  path=profiledir.location)
    config = pyloader.load_config()
    return config
Example #11
0
 def test_python(self):
     fd, fname = mkstemp('.py')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname, log=log)
     config = cl.load_config()
     self._check_conf(config)
Example #12
0
def load_default_config(ipython_dir=None):
    """Load the default config file from the default ipython_dir.

    This is useful for embedded shells.
    """
    if ipython_dir is None:
        ipython_dir = get_ipython_dir()
    cl = PyFileConfigLoader(default_config_file_name, ipython_dir)
    config = cl.load_config()
    return config
Example #13
0
def load_default_config(ipython_dir=None):
    """Load the default config file from the default ipython_dir.

    This is useful for embedded shells.
    """
    if ipython_dir is None:
        ipython_dir = get_ipython_dir()
    cl = PyFileConfigLoader(default_config_file_name, ipython_dir)
    config = cl.load_config()
    return config
Example #14
0
    def load_config_file(self, filename):
        """Load a config file from the top level of the cluster dir.

        Parameters
        ----------
        filename : unicode or str
            The filename only of the config file that must be located in
            the top-level of the cluster directory.
        """
        loader = PyFileConfigLoader(filename, self.location)
        return loader.load_config()
Example #15
0
    def load_config_file(self, filename):
        """Load a config file from the top level of the cluster dir.

        Parameters
        ----------
        filename : unicode or str
            The filename only of the config file that must be located in
            the top-level of the cluster directory.
        """
        loader = PyFileConfigLoader(filename, self.location)
        return loader.load_config()
Example #16
0
def config_ipw(ipw):
    """Apply and then modify default settings of IPython Qt widget"""
    ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader('ipython_qtconsole_config.py', profile_dir)
    config = cl.load_config()
    ipw.config = config

    ipw.set_default_style(colors='Linux')
    ipw.font = QFont('Lucida Console', 11) # 3rd arg can be e.g. QFont.Bold
    ipw.font.setFixedPitch(True)
Example #17
0
 def test_basic(self):
     fd, fname = mkstemp('.py')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname)
     config = cl.load_config()
     self.assertEquals(config.a, 10)
     self.assertEquals(config.b, 20)
     self.assertEquals(config.Foo.Bar.value, 10)
     self.assertEquals(config.Foo.Bam.value, range(10))
     self.assertEquals(config.D.C.value, 'hi there')
Example #18
0
 def test_basic(self):
     fd, fname = mkstemp('.py')
     f = os.fdopen(fd, 'w')
     f.write(pyfile)
     f.close()
     # Unlink the file
     cl = PyFileConfigLoader(fname)
     config = cl.load_config()
     self.assertEqual(config.a, 10)
     self.assertEqual(config.b, 20)
     self.assertEqual(config.Foo.Bar.value, 10)
     self.assertEqual(config.Foo.Bam.value, range(10))
     self.assertEqual(config.D.C.value, 'hi there')
Example #19
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     loader = PyFileConfigLoader(filename, path=path)
     try:
         config = loader.load_config()
     except IOError:
         # problem with the file (probably doesn't exist), raise
         raise
     except Exception:
         # problem while running the file
         self.log.error("Exception while loading config file %s [path=%s]"%
                         (filename, path), exc_info=True)
     else:
         self.update_config(config)
Example #20
0
 def load_config(self, config_file):
     cfg = PyFileConfigLoader(config_file)
     cfg.load_config()
     self.config = cfg.config
     print "HotspotLocator: loading config"
     #self.ntools = len(self.config.tool_list)
     self.plate = self.config.tools.index('CB609')
     self.marker = self.config.tools.index('CT315')
     self.glasses = self.config.tools.index('ST568')
     self.pointer = self.config.tools.index('P717')
     self.pointer_Ti = np.array(self.config.tool_list[self.pointer].Ti)
     self.pointer_Qi = qa.norm(
         np.array(self.config.tool_list[self.pointer].Qi))
     self.pointer_Ni = np.array(self.config.tool_list[self.pointer].Ni)
     self.pointer_tp = TP(self.pointer_Qi, self.pointer_Ni, self.pointer_Ti)
Example #21
0
 def load_config(self, config_file):
     cfg = PyFileConfigLoader(config_file)
     cfg.load_config()
     self.config = cfg.config
     self.filename = self.config.head_model
     self.plate = self.config.tools.index('CB609')
     self.marker = self.config.tools.index('CT315')
     self.glasses = self.config.tools.index('ST568')
     self.pointer = self.config.tools.index('P717')
     self.pointer_Ti = np.array(self.config.tool_list[self.pointer].Ti)
     self.pointer_Qi = qa.norm(
         np.array(self.config.tool_list[self.pointer].Qi))
     self.pointer_Ni = np.array(self.config.tool_list[self.pointer].Ni)
     self.pointer_Xi = self.pointer_Ni - self.pointer_Ti
     self.tp = TP(self.pointer_Qi, self.pointer_Ni, self.pointer_Ti)
Example #22
0
def load_default_config(ipython_dir=None):
    """Load the default config file from the default ipython_dir.

    This is useful for embedded shells.
    """
    if ipython_dir is None:
        ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader(default_config_file_name, profile_dir)
    try:
        config = cl.load_config()
    except ConfigFileNotFound:
        # no config found
        config = Config()
    return config
Example #23
0
def load_default_config(ipython_dir=None):
    """Load the default config file from the default ipython_dir.

    This is useful for embedded shells.
    """
    if ipython_dir is None:
        ipython_dir = get_ipython_dir()
    profile_dir = os.path.join(ipython_dir, 'profile_default')
    cl = PyFileConfigLoader("ipython_config.py", profile_dir)
    try:
        config = cl.load_config()
    except ConfigFileNotFound:
        # no config found
        config = Config()
    return config
Example #24
0
    def _load_config_files(cls, basefilename, path=None, log=None):
        """Load config files (py,json) by filename and path.

        yield each config object in turn.
        """
        pyloader = PyFileConfigLoader(basefilename + '.py', path=path, log=log)
        jsonloader = JSONFileConfigLoader(basefilename + '.json',
                                          path=path,
                                          log=log)
        config = None
        for loader in [pyloader, jsonloader]:
            try:
                config = loader.load_config()
            except ConfigFileNotFound:
                pass
            except Exception:
                # try to get the full filename, but it will be empty in the
                # unlikely event that the error raised before filefind finished
                filename = loader.full_filename or basefilename
                # problem while running the file
                if log:
                    log.error("Exception while loading config file %s",
                              filename,
                              exc_info=True)
            else:
                if log:
                    log.debug("Loaded config file: %s", loader.full_filename)
            if config:
                yield config

        raise StopIteration
Example #25
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     loader = PyFileConfigLoader(filename, path=path)
     try:
         config = loader.load_config()
     except ConfigFileNotFound:
         # problem finding the file, raise
         raise
     except Exception:
         # try to get the full filename, but it will be empty in the
         # unlikely event that the error raised before filefind finished
         filename = loader.full_filename or filename
         # problem while running the file
         self.log.error("Exception while loading config file %s", filename, exc_info=True)
     else:
         self.log.debug("Loaded config file: %s", loader.full_filename)
         self.update_config(config)
Example #26
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     loader = PyFileConfigLoader(filename, path=path)
     try:
         config = loader.load_config()
     except ConfigFileNotFound:
         # problem finding the file, raise
         raise
     except Exception:
         # try to get the full filename, but it will be empty in the
         # unlikely event that the error raised before filefind finished
         filename = loader.full_filename or filename
         # problem while running the file
         self.log.error("Exception while loading config file %s",
                         filename, exc_info=True)
     else:
         self.log.debug("Loaded config file: %s", loader.full_filename)
         self.update_config(config)
Example #27
0
    def load_config(self, config_file):
        cfg = PyFileConfigLoader(config_file)
        cfg.load_config()
        self.config = cfg.config

        # special casing for SAMPLE_GENERATED
        if self.config.trigger == "SAMPLE_GENERATED":
            self.config.trigger_msg = rc.MT_SAMPLE_GENERATED
            self.config.trigger_mdf = rc.MDF_SAMPLE_GENERATED
        else:
            self.config.trigger_msg = eval("rc.MT_" + self.config.trigger)
            self.config.trigger_mdf = eval("rc.MDF_" + self.config.trigger)
        print "Triggering with", self.config.trigger
        print "PolarisDragonfly: loading config"

        # self.ntools = len(self.config.tool_list)
        self.plate = self.config.tools.index("CB609")
        self.marker = self.config.tools.index("CT315")
Example #28
0
    def load_config_file(self, *args, **kwds):
        from IPython.config.loader import PyFileConfigLoader, ConfigFileNotFound
        from IPython.core.profiledir import ProfileDir
        from IPython.utils.path import get_ipython_dir

        conf = Config()
        conf._merge(DEFAULT_SAGE_CONFIG)
        conf._merge(self.command_line_config)

        # Get user config.
        sage_profile_dir = ProfileDir.find_profile_dir_by_name(
            get_ipython_dir(), 'sage').location
        try:
            cl = PyFileConfigLoader('ipython_config.py', sage_profile_dir)
            conf._merge(cl.load_config())
        except ConfigFileNotFound:
            pass
        self.update_config(conf)
Example #29
0
    def load_config_file(self, *args, **kwds):
        from IPython.config.loader import PyFileConfigLoader, ConfigFileNotFound
        from IPython.core.profiledir import ProfileDir
        from IPython.utils.path import get_ipython_dir

        conf = Config()
        conf._merge(DEFAULT_SAGE_CONFIG)
        conf._merge(self.command_line_config)

        # Get user config.
        sage_profile_dir = ProfileDir.find_profile_dir_by_name(
            get_ipython_dir(), 'sage').location
        try:
            cl = PyFileConfigLoader('ipython_config.py', sage_profile_dir)
            conf._merge(cl.load_config())
        except ConfigFileNotFound:
            pass
        self.update_config(conf)
Example #30
0
    def load_config(self, config_file):
        cfg = PyFileConfigLoader(config_file)
        cfg.load_config()
        self.config = cfg.config

        # special casing for SAMPLE_GENERATED
        if (self.config.trigger == 'SAMPLE_GENERATED'):
            self.config.trigger_msg = rc.MT_SAMPLE_GENERATED
            self.config.trigger_mdf = rc.MDF_SAMPLE_GENERATED
        else:
            self.config.trigger_msg = \
                eval('rc.MT_' + self.config.trigger)
            self.config.trigger_mdf = \
                eval('rc.MDF_' + self.config.trigger)
        print "Triggering with", self.config.trigger
        print "TMS Mapping Collection: loading config"

        #self.ntools = len(self.config.tool_list)
        self.plate = self.config.tools.index('CB609')
        self.marker = self.config.tools.index('CT315')
        self.glasses = self.config.tools.index('ST568')
        self.pointer = self.config.tools.index('P717')
Example #31
0
 def load_file_config(self):
     """Load the config file.
     
     This tries to load the config file from disk.  If successful, the
     ``CONFIG_FILE`` config variable is set to the resolved config file
     location.  If not successful, an empty config is used.
     """
     self.log.debug("Attempting to load config file: %s" %
                    self.config_file_name)
     loader = PyFileConfigLoader(self.config_file_name,
                                 path=self.config_file_paths)
     try:
         self.file_config = loader.load_config()
         self.file_config.Global.config_file = loader.full_filename
     except IOError:
         # Only warn if the default config file was NOT being used.
         if not self.config_file_name==self.default_config_file_name:
             self.log.warn("Config file not found, skipping: %s" %
                            self.config_file_name, exc_info=True)
         self.file_config = Config()
     except:
         self.log.warn("Error loading config file: %s" %
                       self.config_file_name, exc_info=True)
         self.file_config = Config()
Example #32
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     loader = PyFileConfigLoader(filename, path=path)
     config = loader.load_config()
     self.update_config(config)
Example #33
0
def check_null_profile(profile):
    loader = PyFileConfigLoader(profile, path=[os.path.join(os.getcwdu(),'profile/test')])
    config = loader.load_config()
    C = ConverterTemplate(config=config)
    result,_ = C.from_filename('tests/ipynbref/IntroNumPy.orig.ipynb')
    nt.assert_equal(result.strip('\n'),'')
Example #34
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     loader = PyFileConfigLoader(filename, path=path)
     config = loader.load_config()
     self.update_config(config)
Example #35
0
 def load_config_file(self, filename, path=None):
     """Load a .py based config file by filename and path."""
     # TODO: this raises IOError if filename does not exist.
     loader = PyFileConfigLoader(filename, path=path)
     config = loader.load_config()
     self.update_config(config)
Example #36
0
 def load_config(self, config_file):
     cfg = PyFileConfigLoader(config_file)
     cfg.load_config()
     self.config = cfg.config
     self.filename = self.config.head_model