Beispiel #1
0
def files_to_settings(settings, setting_files, cancel_mode=False):
    """Parse setting files, and append to settings."""
    cfg = ParsecConfig(
        SPEC['runtime']['__MANY__'], validator=cylc_config_validate)
    for setting_file in setting_files:
        if setting_file == '-':
            with NamedTemporaryFile() as handle:
                handle.write(sys.stdin.read().encode())
                handle.seek(0, 0)
                cfg.loadcfg(handle.name)
        else:
            cfg.loadcfg(setting_file)
    stack = [([], cfg.get(sparse=True))]
    while stack:
        keys, item = stack.pop()
        if isinstance(item, dict):
            for key, value in item.items():
                stack.append((keys + [key], value))
        else:
            settings.append({})
            cur_setting = settings[-1]
            while keys:
                key = keys.pop(0)
                if keys:
                    cur_setting[key] = {}
                    cur_setting = cur_setting[key]
                elif cancel_mode:
                    cur_setting[key] = None
                else:
                    cur_setting[key] = item
Beispiel #2
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
An empty config file should successfully yield an empty sparse config dict.
"""


import os
import sys

from cylc.flow.parsec.config import ParsecConfig
from cylc.flow.parsec.validate import ParsecValidator as VDR
from cylc.flow.parsec.OrderedDict import OrderedDict

fpath = os.path.dirname(os.path.abspath(__file__))
# parsec
sys.path.append(fpath + '/../../..')

SPEC = {'meta': {'title': [VDR.V_STRING]}}
cfg = ParsecConfig(SPEC)
cfg.loadcfg("empty.rc")

if cfg.get(sparse=True) != OrderedDict():
    sys.exit(1)
Beispiel #3
0
    },
    'integer_list': {
        '__MANY__': {
            '__MANY__': [VDR.V_INTEGER_LIST]
        }
    },
}

rcname = sys.argv[1]
rcfile = rcname + '.rc'

cfg = ParsecConfig(SPEC)

cfg.loadcfg(rcfile)

res = cfg.get(sparse=True)

for expected in res[rcname]:

    vals = list(cfg.get([rcname, expected], sparse=True).values())
    expected = expected.replace('COMMA', ',').replace('NULL', '')

    if rcname == 'boolean':
        expected = (expected == 'True') or False

    elif rcname == 'integer':
        expected = int(expected)

    elif rcname == 'float':
        expected = float(expected)
Beispiel #4
0
    'string_list': {'__MANY__': {'__MANY__': [VDR.V_STRING_LIST]}},
    'spaceless_string_list': {'__MANY__': {'__MANY__': [
        VDR.V_SPACELESS_STRING_LIST]}},
    'float_list': {'__MANY__': {'__MANY__': [VDR.V_FLOAT_LIST]}},
    'integer_list': {'__MANY__': {'__MANY__': [VDR.V_INTEGER_LIST]}},
}


rcname = sys.argv[1]
rcfile = rcname + '.rc'

cfg = ParsecConfig(SPEC)

cfg.loadcfg(rcfile)

res = cfg.get(sparse=True)

for expected in res[rcname]:

    vals = list(cfg.get([rcname, expected], sparse=True).values())
    expected = expected.replace('COMMA', ',').replace('NULL', '')

    if rcname == 'boolean':
        expected = (expected == 'True') or False

    elif rcname == 'integer':
        expected = int(expected)

    elif rcname == 'float':
        expected = float(expected)