Exemplo n.º 1
0
    def save(self):
        """Save the config to a file"""
        dbg('ConfigBase::save: saving config')
        parser = ConfigObj()
        parser.indent_type = '  '

        for section_name in ['global_config', 'keybindings']:
            dbg('ConfigBase::save: Processing section: %s' % section_name)
            section = getattr(self, section_name)
            parser[section_name] = dict_diff(DEFAULTS[section_name], section)

        parser['profiles'] = {}
        for profile in self.profiles:
            dbg('ConfigBase::save: Processing profile: %s' % profile)
            parser['profiles'][profile] = dict_diff(
                DEFAULTS['profiles']['default'], self.profiles[profile])

        parser['layouts'] = {}
        for layout in self.layouts:
            dbg('ConfigBase::save: Processing layout: %s' % layout)
            parser['layouts'][layout] = self.layouts[layout]

        parser['plugins'] = {}
        for plugin in self.plugins:
            dbg('ConfigBase::save: Processing plugin: %s' % plugin)
            parser['plugins'][plugin] = self.plugins[plugin]

        config_dir = get_config_dir()
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)
        try:
            parser.write(open(os.path.join(config_dir, 'config'), 'w'))
        except Exception, ex:
            err('ConfigBase::save: Unable to save config: %s' % ex)
Exemplo n.º 2
0
    def save(self):
        """Save the config to a file"""
        dbg('ConfigBase::save: saving config')
        parser = ConfigObj()
        parser.indent_type = '  '

        for section_name in ['global_config', 'keybindings']:
            dbg('ConfigBase::save: Processing section: %s' % section_name)
            section = getattr(self, section_name)
            parser[section_name] = dict_diff(DEFAULTS[section_name], section)

        parser['profiles'] = {}
        for profile in self.profiles:
            dbg('ConfigBase::save: Processing profile: %s' % profile)
            parser['profiles'][profile] = dict_diff(
                    DEFAULTS['profiles']['default'], self.profiles[profile])

        parser['layouts'] = {}
        for layout in self.layouts:
            dbg('ConfigBase::save: Processing layout: %s' % layout)
            parser['layouts'][layout] = self.layouts[layout]

        parser['plugins'] = {}
        for plugin in self.plugins:
            dbg('ConfigBase::save: Processing plugin: %s' % plugin)
            parser['plugins'][plugin] = self.plugins[plugin]

        config_dir = get_config_dir()
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)
        try:
            parser.write(open(self.command_line_options.config, 'w'))
        except Exception, ex:
            err('ConfigBase::save: Unable to save config: %s' % ex)
Exemplo n.º 3
0
    def save(self):
        """Save the config to a file"""
        dbg("ConfigBase::save: saving config")
        parser = ConfigObj()
        parser.indent_type = "  "

        for section_name in ["global_config", "keybindings"]:
            dbg("ConfigBase::save: Processing section: %s" % section_name)
            section = getattr(self, section_name)
            parser[section_name] = dict_diff(DEFAULTS[section_name], section)

        parser["profiles"] = {}
        for profile in self.profiles:
            dbg("ConfigBase::save: Processing profile: %s" % profile)
            parser["profiles"][profile] = dict_diff(DEFAULTS["profiles"]["default"], self.profiles[profile])

        parser["layouts"] = {}
        for layout in self.layouts:
            dbg("ConfigBase::save: Processing layout: %s" % layout)
            parser["layouts"][layout] = self.layouts[layout]

        parser["plugins"] = {}
        for plugin in self.plugins:
            dbg("ConfigBase::save: Processing plugin: %s" % plugin)
            parser["plugins"][plugin] = self.plugins[plugin]

        config_dir = get_config_dir()
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)
        try:
            parser.write(open(self.command_line_options.config, "w"))
        except Exception, ex:
            err("ConfigBase::save: Unable to save config: %s" % ex)
Exemplo n.º 4
0
    def save(self, force=False):
        """Save the config to a file"""
        if self._nosave:
            dbg('~ConfigBase::save: WRITE SUPRESSED')
            return (True)
        elif force:
            dbg('~ConfigBase::save: WRITE FORCED')
            pass
        elif not self._dirty:
            dbg('~ConfigBase::save: CONFIG CLEAN')
            return (True)

        dbg('~ConfigBase::save: WRITE CONFIG')
        self._dirty = False

        # FIXME this craziness must be purged asap.
        parser = ConfigObj()
        parser.indent_type = '  '

        for section_name in ['global_config', 'keybindings']:
            dbg('ConfigBase::save: Processing section: %s' % section_name)
            section = getattr(self, section_name)
            parser[section_name] = dict_diff(DEFAULTS[section_name], section)

        parser['profiles'] = {}
        for profile in self.profiles:
            dbg('ConfigBase::save: Processing profile: %s' % profile)
            parser['profiles'][profile] = dict_diff(
                DEFAULTS['profiles']['default'], self.profiles[profile])

        parser['layouts'] = {}
        for layout in self.layouts:
            dbg('ConfigBase::save: Processing layout: %s' % layout)
            parser['layouts'][layout] = self.cleancfg(self.layouts[layout])

        parser['plugins'] = {}
        for plugin in self.plugins:
            dbg('ConfigBase::save: Processing plugin: %s' % plugin)
            parser['plugins'][plugin] = self.plugins[plugin]

        config_dir = get_config_dir()
        if not os.path.isdir(config_dir):
            os.makedirs(config_dir)
        try:
            parser.write(open(self.command_line_options.config, 'w'))
        except Exception, ex:
            err('ConfigBase::save: Unable to save config: %s' % ex)
Exemplo n.º 5
0
    def defaults_to_configspec(self):
        """Convert our tree of default values into a ConfigObj validation
        specification"""
        configspecdata = {}

        keymap = {
            'int': 'integer',
            'str': 'string',
            'bool': 'boolean',
        }

        section = {}
        for key in DEFAULTS['global_config']:
            keytype = DEFAULTS['global_config'][key].__class__.__name__
            value = DEFAULTS['global_config'][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == 'list':
                value = 'list(%s)' % ','.join(value)

            keytype = '%s(default=%s)' % (keytype, value)

            section[key] = keytype
        configspecdata['global_config'] = section

        section = {}
        for key in DEFAULTS['keybindings']:
            value = DEFAULTS['keybindings'][key]
            if value is None or value == '':
                continue
            section[key] = 'string(default=%s)' % value
        configspecdata['keybindings'] = section

        section = {}
        for key in DEFAULTS['profiles']['default']:
            keytype = DEFAULTS['profiles']['default'][key].__class__.__name__
            value = DEFAULTS['profiles']['default'][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == 'list':
                value = 'list(%s)' % ','.join(value)
            if keytype == 'string':
                value = '"%s"' % value

            keytype = '%s(default=%s)' % (keytype, value)

            section[key] = keytype
        configspecdata['profiles'] = {}
        configspecdata['profiles']['__many__'] = section

        section = {}
        section['type'] = 'string'
        section['parent'] = 'string'
        section['profile'] = 'string(default=default)'
        section['command'] = 'string(default="")'
        section['position'] = 'string(default="")'
        section['size'] = 'list(default=list(-1,-1))'
        configspecdata['layouts'] = {}
        configspecdata['layouts']['__many__'] = {}
        configspecdata['layouts']['__many__']['__many__'] = section

        configspecdata['plugins'] = {}

        configspec = ConfigObj(configspecdata)
        if DEBUG == True:
            configspec.write(open('/tmp/terminator_configspec_debug.txt', 'w'))
        return (configspec)
Exemplo n.º 6
0
    def defaults_to_configspec(self):
        """Convert our tree of default values into a ConfigObj validation
        specification"""
        configspecdata = {}

        keymap = {
                'int': 'integer',
                'str': 'string',
                'bool': 'boolean',
                }

        section = {}
        for key in DEFAULTS['global_config']:
            keytype = DEFAULTS['global_config'][key].__class__.__name__
            value = DEFAULTS['global_config'][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == 'list':
                value = 'list(%s)' % ','.join(value)

            keytype = '%s(default=%s)' % (keytype, value)

            if key == 'custom_url_handler':
                keytype = 'string(default="")'

            section[key] = keytype
        configspecdata['global_config'] = section

        section = {}
        for key in DEFAULTS['keybindings']:
            value = DEFAULTS['keybindings'][key]
            if value is None or value == '':
                continue
            section[key] = 'string(default=%s)' % value
        configspecdata['keybindings'] = section

        section = {}
        for key in DEFAULTS['profiles']['default']:
            keytype = DEFAULTS['profiles']['default'][key].__class__.__name__
            value = DEFAULTS['profiles']['default'][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == 'list':
                value = 'list(%s)' % ','.join(value)
            if key == 'background_image':
                keytype = 'string'
            if keytype == 'string':
                value = '"%s"' % value

            keytype = '%s(default=%s)' % (keytype, value)

            section[key] = keytype
        configspecdata['profiles'] = {}
        configspecdata['profiles']['__many__'] = section

        section = {}
        section['type'] = 'string'
        section['parent'] = 'string'
        section['profile'] = 'string(default=default)'
        section['command'] = 'string(default="")'
        section['position'] = 'string(default="")'
        section['size'] = 'list(default=list(-1,-1))'
        configspecdata['layouts'] = {}
        configspecdata['layouts']['__many__'] = {}
        configspecdata['layouts']['__many__']['__many__'] = section

        configspecdata['plugins'] = {}

        configspec = ConfigObj(configspecdata)
        if DEBUG == True:
            configspec.write(open('/tmp/terminator_configspec_debug.txt', 'w'))
        return(configspec)
Exemplo n.º 7
0
    def defaults_to_configspec(self):
        """Convert our tree of default values into a ConfigObj validation
        specification"""
        configspecdata = {}

        keymap = {"int": "integer", "str": "string", "bool": "boolean"}

        section = {}
        for key in DEFAULTS["global_config"]:
            keytype = DEFAULTS["global_config"][key].__class__.__name__
            value = DEFAULTS["global_config"][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == "list":
                value = "list(%s)" % ",".join(value)

            keytype = "%s(default=%s)" % (keytype, value)

            if key == "custom_url_handler":
                keytype = 'string(default="")'

            section[key] = keytype
        configspecdata["global_config"] = section

        section = {}
        for key in DEFAULTS["keybindings"]:
            value = DEFAULTS["keybindings"][key]
            if value is None or value == "":
                continue
            section[key] = "string(default=%s)" % value
        configspecdata["keybindings"] = section

        section = {}
        for key in DEFAULTS["profiles"]["default"]:
            keytype = DEFAULTS["profiles"]["default"][key].__class__.__name__
            value = DEFAULTS["profiles"]["default"][key]
            if keytype in keymap:
                keytype = keymap[keytype]
            elif keytype == "list":
                value = "list(%s)" % ",".join(value)
            if key == "background_image":
                keytype = "string"
            if keytype == "string":
                value = '"%s"' % value

            keytype = "%s(default=%s)" % (keytype, value)

            section[key] = keytype
        configspecdata["profiles"] = {}
        configspecdata["profiles"]["__many__"] = section

        section = {}
        section["type"] = "string"
        section["parent"] = "string"
        section["profile"] = "string(default=default)"
        section["command"] = 'string(default="")'
        section["position"] = 'string(default="")'
        section["size"] = "list(default=list(-1,-1))"
        configspecdata["layouts"] = {}
        configspecdata["layouts"]["__many__"] = {}
        configspecdata["layouts"]["__many__"]["__many__"] = section

        configspecdata["plugins"] = {}

        configspec = ConfigObj(configspecdata)
        if DEBUG == True:
            configspec.write(open("/tmp/terminator_configspec_debug.txt", "w"))
        return configspec
Exemplo n.º 8
0
def getUserInput():
    """
    Interactive input session based on Sphinx's interactive setup.

    """

    logging.info("\nGood day! Press enter to accept default reduction options.")

    fullReduction = getParam(
                "Do a full data reduction with default parameters loaded from recipes/default_input.cfg? [no]: ",
                False,
                "Type yes to start Nifty with data reduction input parameters loaded from recipes/default_input.cfg file."
    )
    if fullReduction == False:
        # "Select in". User has to turn individual steps on.
        # TODO(nat): Implement these steps.
        date = ""
        program = ""
        copy = ""

        sort = getParam(
        "Sort data? [no]: ",
        False
        )
        rawPath = getParam(
        "Path to raw files directory? [~/data]: ",
        "~/data"
        )
        tel = getParam(
        "Apply a telluric correction? [no]: ",
        False
        )
        # See if we want to reduce the baseline calibrations. And if so, which substeps
        # to perform.
        calibrationReduction = getParam(
        "Reduce baseline calibrations? [no]: ",
        False
        )
        # By default do all of them.
        rstart = getParam(
        "Starting point of baseline calibration reductions? [1]: ",
        1
        )
        rstop = getParam(
        "Stopping point of baseline calibration reductions? [4]: ",
        4
        )

        # Check for tellurics as well; by default do all reduction steps.
        telluricReduction = getParam(
        "Reduce telluric data? [no]: ",
        False
        )
        telStart = getParam(
        "Starting point of science and telluric reductions? [1]: ",
        1
        )
        telStop = getParam(
        "Stopping point of science and telluric reductions? [6]: ",
        6
        )
        # Set the telluric application correction method. Choices are iraf.telluric and a python variant.
        # Set the h-line removal method with the vega() function in nifsReduce as default.
        hline_method = getParam(
        "H-line removal method? [vega]: ",
        "vega"
        )
        # Set yes or no for interactive the h line removal, telluric correction, and continuum fitting
        hlineinter = getParam(
        "Interative H-line removal? [no]: ",
        False
        )
        continuuminter = getParam(
        "Interative telluric continuum fitting? [no]: ",
        False
        )
        telluric_correction_method = getParam(
        "Telluric correction method? [python]: ",
        "python"
        )
        telinter = getParam(
        "Interactive telluric correction? [no]: ",
        False
        )
        # Check for science as well.
        scienceReduction = getParam(
        "Reduce science data? [no]: ",
        False
        )
        sciStart = getParam(
        "Starting point of science and telluric reductions? [1]: ",
        1
        )
        sciStop = getParam(
        "Stopping point of science and telluric reductions? [6]: ",
        6
        )
        efficiencySpectrumCorrection = getParam(
        "Do a flux calibration? [no]: ",
        False
        )
        spectemp = getParam(
        "Effective temperature in kelvin of telluric standard star? [""]: ",
        ""
        )
        mag = getParam(
        "Magnitude of standard star? [""]: ",
        ""
        )
        merge = getParam(
        "Produce one final 3D cube? [no]: ",
        False
        )
        use_pq_offsets = getParam(
        "Use pq offsets to merge data cubes? [yes]: ",
        "yes"
        )
        im3dtran = getParam(
        "Transpose cubes for faster merging? [no]: ",
        False
        )
        over = getParam(
        "Overwrite old files? [no]: ",
        False
        )
        debug = getParam(
        "Pause after each data reduction step? [yes]: ",
        "yes"
        )

        # Serialize and save the options as a .cfg file.
        options = ConfigObj(unrepr=True)
        options['date'] = date
        options['program'] = program
        options['rawPath'] = rawPath
        options['over'] = over
        options['copy'] = copy
        options['sort'] = sort
        options['calibrationReduction'] = calibrationReduction
        options['scienceReduction'] = scienceReduction
        options['merge'] = merge
        options['tel'] = tel
        options['telluricReduction'] = telluricReduction
        options['spectemp'] = spectemp
        options['mag'] = mag
        options['efficiencySpectrumCorrection'] = efficiencySpectrumCorrection
        options['rstart']= rstart
        options['rstop'] = rstop
        options['telStart'] = telStart
        options['telStop'] = telStop
        options['sciStart'] = sciStart
        options['sciStop'] = sciStop
        options['hline_method'] = hline_method
        options['hlineinter'] = hlineinter
        options['continuuminter'] = continuuminter
        options['telluric_correction_method'] = telluric_correction_method
        options['telinter'] = telinter
        options['use_pq_offsets'] = use_pq_offsets
        options['im3dtran'] = im3dtran
        options['debug'] = debug
        with open(RUNTIME_DATA_PATH+'/config.cfg', 'w') as outfile:
            options.write(outfile)

    return fullReduction