예제 #1
0
파일: test_parser.py 프로젝트: maebert/poyo
def test_parse_string(string_data):
    expected = {
        u"default_context": {
            u"greeting": u"こんにちは",
            u"email": u"*****@*****.**",
            u"docs": True,
            u"gui": False,
            u"lektor": "0.0.0.0:5000",
            u"relative-root": "/",
            123: 456.789,
            u"some:int": 1000000,
            u"foo": u"hallo #welt",
            u"trueish": u"Falseeeeeee",
            u"doc_tools": [u"mkdocs", u"sphinx", None],
        },
        u"zZz": True,
        u"NullValue": None,
        u"Hello World": {
            None: u"This is madness",
            u"gh": u"https://github.com/{0}.git",
        },
        u"Yay #python": u"Cool!",
    }

    assert parse_string(string_data) == expected
예제 #2
0
def test_parse_string(string_data):
    expected = {
        u'default_context': {
            u'greeting': u'こんにちは',
            u'email': u'*****@*****.**',
            u'docs': True,
            u'gui': False,
            u'lektor': '0.0.0.0:5000',
            u'relative-root': '/',
            123: 456.789,
            u'some:int': 1000000,
            u'foo': u'hallo #welt',
            u'trueish': u'Falseeeeeee',
            u'doc_tools': [u'mkdocs', u'sphinx', None],
        },
        u'zZz': True,
        u'NullValue': None,
        u'Hello World': {
            None: u'This is madness',
            u'gh': u'https://github.com/{0}.git',
        },
        u'Yay #python': u'Cool!'
    }

    assert parse_string(string_data) == expected
예제 #3
0
def get_config(config_path):
    """
    Retrieve the config from the specified path, returning it as a config dict.
    """

    if not os.path.exists(config_path):
        raise ConfigDoesNotExistException

    logger.debug('config_path is {0}'.format(config_path))
    with io.open(config_path, encoding='utf-8') as file_handle:
        try:
            yaml_dict = poyo.parse_string(file_handle.read())
        except poyo.exceptions.PoyoException as e:
            raise InvalidConfiguration(
                'Unable to parse YAML file {}. Error: {}'
                ''.format(config_path, e))

    config_dict = copy.copy(DEFAULT_CONFIG)
    config_dict.update(yaml_dict)

    raw_replay_dir = config_dict['replay_dir']
    config_dict['replay_dir'] = _expand_path(raw_replay_dir)

    raw_cookies_dir = config_dict['cookiecutters_dir']
    config_dict['cookiecutters_dir'] = _expand_path(raw_cookies_dir)

    return config_dict
예제 #4
0
def test_parse_string(string_data):
    expected = {
        u'default_context': {
            u'greeting': u'こんにちは',
            u'email': u'*****@*****.**',
            u'docs': True,
            u'gui': False,
            u'lektor': '0.0.0.0:5000',
            u'relative-root': '/',
            123: 456.789,
            u'some:int': 1000000,
            u'foo': u'hallo #welt',
            u'trueish': u'Falseeeeeee',
            u'doc_tools': [u'mkdocs', u'sphinx', None],
        },
        u'zZz': True,
        u'NullValue': None,
        u'Hello World': {
            None: u'This is madness',
            u'gh': u'https://github.com/{0}.git',
        },
        u'Yay #python': u'Cool!'
    }

    assert parse_string(string_data) == expected
예제 #5
0
def get_config(config_path):
    """
    Retrieve the config from the specified path, returning it as a config dict.
    """

    if not os.path.exists(config_path):
        raise ConfigDoesNotExistException

    logger.debug('config_path is {0}'.format(config_path))
    with io.open(config_path, encoding='utf-8') as file_handle:
        try:
            yaml_dict = poyo.parse_string(file_handle.read())
        except poyo.exceptions.PoyoException as e:
            raise InvalidConfiguration(
                'Unable to parse YAML file {}. Error: {}'
                ''.format(config_path, e)
            )

    config_dict = copy.copy(DEFAULT_CONFIG)
    config_dict.update(yaml_dict)

    raw_replay_dir = config_dict['replay_dir']
    config_dict['replay_dir'] = _expand_path(raw_replay_dir)

    raw_cookies_dir = config_dict['cookiecutters_dir']
    config_dict['cookiecutters_dir'] = _expand_path(raw_cookies_dir)

    return config_dict
예제 #6
0
def test_parse_string_no_newline(string_data):
    expected = {
        u'Hello World': {
            u'name': u'Toni Chu',
            u'gh': u'https://github.com/{0}.git',
        },
        u'Yay #python': 3.6,
    }
    assert parse_string(string_data) == expected
예제 #7
0
파일: test_parser.py 프로젝트: maebert/poyo
def test_parse_string_no_newline(string_data):
    expected = {
        u"Hello World": {
            u"name": u"Toni Chu",
            u"gh": u"https://github.com/{0}.git"
        },
        u"Yay #python": 3.6,
    }
    assert parse_string(string_data) == expected
예제 #8
0
파일: test_parser.py 프로젝트: maebert/poyo
def test_parse_string_no_newline_list(string_data):
    expected = {
        u"Hello World": {
            u"numbers": [1, 2],
            u"name": u"Toni Chu",
            u"gh": u"https://github.com/{0}.git",
            u"doc_tools": [u"mkdocs", u"sphinx", None],
        }
    }
    assert parse_string(string_data) == expected
def open_incident(component_id):
    template_path = f"{os.path.dirname(__file__)}/incident_templates/default.yml"
    template = poyo.parse_string(open(template_path, "r").read())
    name, body = _render_incident_text(component_id, template["name"], template["body"])

    print(
        f"Opening statuspage incident for component {component_id} and marking it {template['component_status']}"
    )
    _create_incident(
        name,
        body,
        template["incident_status"],
        component_id,
        template["component_status"],
    )
예제 #10
0
def test_parse_list_objects(string_data):
    expected = {
        u"complicated": {
            u"numbers": [
                {
                    u"name": u"Hello",
                    u"result": u"World"
                },
                {
                    u"name": u"Question",
                    u"result": u"Answer"
                },
            ]
        }
    }
    assert parse_string(string_data) == expected
예제 #11
0
def test_parse_string_no_newline_list(string_data):
    expected = {
        u'Hello World': {
            u'numbers': [
                1,
                2,
            ],
            u'name': u'Toni Chu',
            u'gh': u'https://github.com/{0}.git',
            u'doc_tools': [
                u'mkdocs',
                u'sphinx',
                None,
            ]
        },
    }
    assert parse_string(string_data) == expected
예제 #12
0
파일: test_parser.py 프로젝트: maebert/poyo
def test_parse_multiline_string(string_data):
    import logging

    logging.basicConfig(level=logging.DEBUG)
    expected = {
        u"Hello World": {
            u"multi":
            (u"This is a multiline string. It can contain all manners " +
             u"of characters.\nSingle line breaks are ignored, but blank " +
             u"lines cause line breaks.\n"),
            u"withbreaks":
            u"Here we will\nkeep our linebreaks\n",
            u"indent":
            (u"  This has 2 leading spaces and 2 trailing new lines.\n\n"),
            u"chomped":
            u"Now trailing new line here.",
        }
    }
    assert parse_string(string_data) == expected
예제 #13
0
def test_parse_string_lists(string_data):
    expected = {
        u'a': [
            1,
            2,
        ],
        u'b': [
            3,
            4,
        ],
        u'c': [
            5,
            6,
        ],
        u'd': [
            7,
            8,
        ],
    }
    assert parse_string(string_data) == expected
예제 #14
0
def nb_cell_yaml_options(lang, cell):

    # go through the lines until we've found all of the yaml
    yaml_lines = nb_cell_yaml_lines(lang, cell.source)

    # if we have yaml then parse it
    if len(yaml_lines) > 0:
        yaml_code = "\n".join(yaml_lines)
        yaml_options = parse_string(yaml_code)
        if (type(yaml_options) is dict):
            return yaml_options
        else:
            sys.stderr.write(
                "\nWARNING: Invalid YAML option format in cell:\n" +
                yaml_code + "\n")
            sys.stderr.flush()
            return dict()

    else:
        return dict()
예제 #15
0
def test_parse_string(string_data):
    expected = {
        u"default_context": {
            u"greeting":
            u"こんにちは",
            u"email":
            u"*****@*****.**",
            u"docs":
            True,
            u"gui":
            False,
            u"lektor":
            "0.0.0.0:5000",
            u"relative-root":
            "/",
            123:
            456.789,
            u"some:int":
            1000000,
            u"foo":
            u"hallo #welt",
            u"longtext": (u"This is a multiline string. It can contain all "
                          u"manners of characters.\nSingle line breaks are "
                          u"ignored, but blank linkes cause line breaks.\n"),
            u"trueish":
            u"Falseeeeeee",
            u"blog":
            u"raphael.codes",
            u"doc_tools": [u"mkdocs", u"sphinx", None],
        },
        u"zZz": True,
        u"NullValue": None,
        u"Hello World": {
            None: u"This is madness",
            u"gh": u"https://github.com/{0}.git",
        },
        u"Yay #python": u"Cool!",
    }

    assert parse_string(string_data) == expected
예제 #16
0
    def deploy(self, bundle):
        """ Deploy a service
        Args:
            bundle: Service Package
        """
        logging.info("DownloadBundle...")
        self.download_bundle(bundle)
        zf = zipfile.ZipFile(self._bundle, "r")
        #appspec = yaml.load(zf.read("appspec.yml"))
        appspec = parse_string(zf.read("appspec.yml"))
        zf.close()
        self.unzip_bundle()

        workdir = appspec.get("workdir")
        if workdir is not None:
            self._workdir = workdir
        if not os.path.isdir(self._program_dir):
            os.makedirs(self._program_dir)

        logging.info("RUN ApplicationStop...")
        self._exec_hooks(appspec.get("hooks").get("ApplicationStop"))

        logging.info("RUN BeforeInstall...")
        self._exec_hooks(appspec.get("hooks").get("BeforeInstall"))

        logging.info("RUN Install...")
        self.install(appspec.get("files"))

        logging.info("RUN AfterInstall...")
        self._exec_hooks(appspec.get("hooks").get("AfterInstall"))

        logging.info("RUN ApplicationStart...")
        self._exec_hooks(appspec.get("hooks").get("ApplicationStart"))

        logging.info("RUN ValidateService...")
        self._exec_hooks(appspec.get("hooks").get("ValidateService"))

        logging.info("Deploy OK.")
예제 #17
0
def get_config(config_path):
    """Retrieve the config from the specified path, returning a config dict."""
    if not os.path.exists(config_path):
        raise ConfigDoesNotExistException

    logger.debug("config_path is {0}".format(config_path))
    with io.open(config_path, encoding="utf-8") as file_handle:
        try:
            yaml_dict = poyo.parse_string(file_handle.read())
        except poyo.exceptions.PoyoException as e:
            raise InvalidConfiguration(
                "Unable to parse YAML file {}. Error: {}"
                "".format(config_path, e))

    config_dict = merge_configs(DEFAULT_CONFIG, yaml_dict)

    raw_replay_dir = config_dict["replay_dir"]
    config_dict["replay_dir"] = _expand_path(raw_replay_dir)

    raw_cookies_dir = config_dict["cookiecutters_dir"]
    config_dict["cookiecutters_dir"] = _expand_path(raw_cookies_dir)

    return config_dict
예제 #18
0
def parse_config(config_path):
    config_file = open(config_path, 'r')
    content = config_file.read().strip()
    config = parse_string(content)
    return config
예제 #19
0
logger = logging.getLogger(__name__)
# I changed this to debug
logger.setLevel(logging.DEBUG)


# ## the yml file must end with a blank line!!

# In[56]:

if __name__ == "__main__":
    import codecs
    import pprint
    from poyo import parse_string, PoyoException

    with codecs.open('./sample.yml', encoding='utf-8') as ymlfile:
        ymlstring = ymlfile.read()

    try:
        config = parse_string(ymlstring)
    except PoyoException as exc:
        logger.error(exc)
    else:
        logger.debug(config)
pprint.pprint(config)


# In[ ]:



예제 #20
0
def parse_yaml(yaml):
    return poyo.parse_string(yaml)
예제 #21
0
파일: test_parser.py 프로젝트: maebert/poyo
def test_parse_string_lists(string_data):
    expected = {u"a": [1, 2], u"b": [3, 4], u"c": [5, 6], u"d": [7, 8]}
    assert parse_string(string_data) == expected
예제 #22
0
파일: config.py 프로젝트: haipdev/config
def _load_file(config, file):
    """ load config from file and merge it into config """
    with open(file, 'r', encoding='utf-8') as ymlfile:
        ymlstring = ymlfile.read()
    file_config = poyo.parse_string(ymlstring)
    _merge(config, file_config, overwrite=False)
예제 #23
0
import os
from functools import reduce
from pathlib import Path

from poyo import PoyoException, parse_string

logging.basicConfig(level=logging.DEBUG)

ROOT = Path(__file__).parent
CONFIG_PATH = os.path.join(ROOT, "settings.yml")

with codecs.open(CONFIG_PATH, encoding="utf-8") as ymlfile:
    ymlstring = ymlfile.read()

try:
    config = parse_string(ymlstring)
except PoyoException as exc:
    logging.error(exc)
else:
    logging.debug(config)


def fetch(*argv):
    return os.path.join(ROOT, *argv)


def fetch_from_home(what, *argv):
    return fetch(config[what]["dir"], *argv)


def get_from_config(*argv):
예제 #24
0
파일: cli.py 프로젝트: pnlng/crisscross
 def process_yaml(f):
     identifier = FilePath.get_filename(f)
     with open(f) as yamlfile:
         yaml_vars = poyo.parse_string(yamlfile.read())
         id_vars = add_default_kv(yaml_vars, identifier)
     return id_vars
예제 #25
0
 def _deserialized_from_string(self, source):
     return [poyo.parse_string(source)]