Example #1
0
def write_config_file(config, username=None):
	config_path = CONFIG_BASE_PATH / (username or '') / 'google-music-scripts.toml'
	config_path.parent.mkdir(parents=True, exist_ok=True)
	config_path.touch()

	config_file = TOMLFile(config_path)
	config_file.write(config)
Example #2
0
def test_mixed_eol(tmpdir):
    toml_path = str(tmpdir / "pyproject.toml")
    with open(toml_path, "wb+") as f:
        f.write(b"a = 1\r\nrb = 2\n")

    f = TOMLFile(toml_path)
    f.write(f.read())

    with open(toml_path, "rb") as f:
        assert f.read() == b"a = 1\r\nrb = 2\n"
Example #3
0
def test_keep_old_eol_2(tmpdir):
    toml_path = str(tmpdir / "pyproject.toml")
    with open(toml_path, "wb+") as f:
        f.write(b"a = 1\nb = 2\n")

    f = TOMLFile(toml_path)
    content = f.read()
    content["b"] = 3
    f.write(content)

    with open(toml_path, "rb") as f:
        assert f.read() == b"a = 1\nb = 3\n"
Example #4
0
class PyProject:
    def __init__(self):
        self._file = TOMLFile('pyproject.toml')

    def get_version(self):
        pyproject_data = self._file.read()
        version = pyproject_data['tool']['poetry']['version']
        return version

    def set_version(self, version):
        pyproject_data = self._file.read()
        pyproject_data['tool']['poetry']['version'] = version
        self._file.write(pyproject_data)
Example #5
0
def test_toml_file(example):
    original_content = example("example")

    toml_file = os.path.join(os.path.dirname(__file__), "examples",
                             "example.toml")
    toml = TOMLFile(toml_file)

    content = toml.read()
    assert isinstance(content, TOMLDocument)
    assert content["owner"]["organization"] == "GitHub"

    toml.write(content)

    with io.open(toml_file, encoding="utf-8") as f:
        assert original_content == f.read()
Example #6
0
def cargo_release(project, internal_dependencies=[None]):
    project_path = path.join(project, "Cargo.toml")
    file = TOMLFile(project_path)
    content = file.read()
    dependencies = content.get('dependencies') or {}
    build_dependencies = content.get('build-dependencies') or {}
    new_version = change_version(content['package']['version'])

    content['package']['version'] = new_version
    for local in internal_dependencies:
        if dependencies.get(local) is not None:
            dependencies[local]['version'] = new_version
        if build_dependencies.get(local) is not None:
            build_dependencies[local]['version'] = new_version

    file.write(content)
def generateDefaultConfigurationTomlFile(configurationFilename):
    """Generate default configuration file.
    Print once a warning to inform the user that the default needs to be adopted.
    """

    print(
        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    )
    print("!!  Default configuration was written to file '",
          configurationFilename,
          "'  !!",
          sep="")
    print(
        "!!  It is assumed, that you need to adopt the defaults to your needs.                         !!"
    )
    print(
        "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    )
    tomlfile = TOMLFile(configurationFilename)
    config = tomlkit.parse(defaultConfiguration)
    tomlfile.write(config)
Example #8
0
def write_config_file(config):
    CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
    CONFIG_PATH.touch()

    config_file = TOMLFile(CONFIG_PATH)
    config_file.write(config)
Example #9
0
    doc = document()

    toml_file_header(doc)

    doc.add(nl())

    doc.add("name", xml_root.get("RefName"))
    doc.add("object_type", "mcu")
    if xml_root.get("Package"):
        doc.add("package", xml_root.get("Package"))
    if xml_root.get("Family"):
        doc.add("family", xml_root.get("Family"))
    if xml_root.get("Line"):
        doc.add("line", xml_root.get("Line"))
    if xml_root.get("HasPowerPad"):
        doc.add("has_power_pad", toml_boolean(xml_root.get("HasPowerPad")))
    if xml_root.findtext("Core", None, xml_root.nsmap):
        doc.add("core", xml_root.findtext("./Core", None, xml_root.nsmap))
    if xml_root.findtext("Frequency", None, xml_root.nsmap):
        doc.add(
            "max_frequency",
            toml_int(xml_root.findtext("Frequency", None, xml_root.nsmap)),
        )
    if xml_root.findtext("Ram", None, xml_root.nsmap):
        doc.add("ram", toml_int(xml_root.findtext("Ram", None, xml_root.nsmap)))
    if xml_root.findtext("IONb", None, xml_root.nsmap):
        doc.add("io_count", toml_int(xml_root.findtext("IONb", None, xml_root.nsmap)))
    if xml_root.findtext("Flash", None, xml_root.nsmap):
        doc.add("flash", toml_int(xml_root.findtext("Flash", None, xml_root.nsmap)))
    toml.write(doc)