mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-28 02:03:36 +05:00
Compare commits
3 Commits
e68979967d
...
v5.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec3f93eeda | ||
|
|
4cf523a758 | ||
|
|
1d06bf76f3 |
@@ -192,10 +192,10 @@ class SimpleConfigParser:
|
|||||||
self.config[section] = {"_raw": f"[{section}]\n"}
|
self.config[section] = {"_raw": f"[{section}]\n"}
|
||||||
|
|
||||||
def _check_set_section_spacing(self):
|
def _check_set_section_spacing(self):
|
||||||
prev_section: str = self.get_sections()[-1]
|
prev_section = self.get_sections()[-1]
|
||||||
prev_section_content: Dict = self.config[prev_section]
|
prev_section_content = self.config[prev_section]
|
||||||
last_item: str = list(prev_section_content.keys())[-1]
|
last_item = list(prev_section_content.keys())[-1]
|
||||||
if last_item.startswith("#_") and prev_section_content[last_item][-1] != "\n":
|
if last_item.startswith("#_") and last_item.keys()[-1] != "\n":
|
||||||
prev_section_content[last_item].append("\n")
|
prev_section_content[last_item].append("\n")
|
||||||
else:
|
else:
|
||||||
prev_section_content[self._generate_rand_id()] = ["\n"]
|
prev_section_content[self._generate_rand_id()] = ["\n"]
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
# a comment at the very top
|
|
||||||
# should be treated as the file header
|
|
||||||
|
|
||||||
# up to the first section, including all blank lines
|
|
||||||
|
|
||||||
[section_1]
|
|
||||||
option_1: value_1
|
|
||||||
option_1_1: True # this is a boolean
|
|
||||||
option_1_2: 5 ; this is an integer
|
|
||||||
option_1_3: 1.123 #;this is a float
|
|
||||||
|
|
||||||
[section_2] ; comment
|
|
||||||
option_2: value_2
|
|
||||||
|
|
||||||
; comment
|
|
||||||
|
|
||||||
[section_3]
|
|
||||||
option_3: value_3 # comment
|
|
||||||
|
|
||||||
[section_4]
|
|
||||||
# comment
|
|
||||||
option_4: value_4
|
|
||||||
|
|
||||||
[section number 5]
|
|
||||||
#option_5: value_5
|
|
||||||
option_5 = this.is.value-5
|
|
||||||
multi_option:
|
|
||||||
# these are multi-line values
|
|
||||||
value_5_1
|
|
||||||
value_5_2 ; here is a comment
|
|
||||||
value_5_3
|
|
||||||
option_5_1: value_5_1
|
|
||||||
# config ending with a comment
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
# a comment at the very top
|
|
||||||
# should be treated as the file header
|
|
||||||
|
|
||||||
# up to the first section, including all blank lines
|
|
||||||
|
|
||||||
[section_1]
|
|
||||||
option_1: value_1
|
|
||||||
option_1_1: True # this is a boolean
|
|
||||||
option_1_2: 5 ; this is an integer
|
|
||||||
option_1_3: 1.123 #;this is a float
|
|
||||||
|
|
||||||
[section_2] ; comment
|
|
||||||
option_2: value_2
|
|
||||||
|
|
||||||
; comment
|
|
||||||
|
|
||||||
[section_3]
|
|
||||||
option_3: value_3 # comment
|
|
||||||
|
|
||||||
[section_4]
|
|
||||||
# comment
|
|
||||||
option_4: value_4
|
|
||||||
|
|
||||||
[section number 5]
|
|
||||||
#option_5: value_5
|
|
||||||
option_5 = this.is.value-5
|
|
||||||
multi_option:
|
|
||||||
# these are multi-line values
|
|
||||||
value_5_1
|
|
||||||
value_5_2 ; here is a comment
|
|
||||||
value_5_3
|
|
||||||
option_5_1: value_5_1
|
|
||||||
|
|
||||||
[gcode_macro M117]
|
|
||||||
rename_existing: M117.1
|
|
||||||
gcode:
|
|
||||||
{% if rawparams %}
|
|
||||||
{% set escaped_msg = rawparams.split(';', 1)[0].split('\x23', 1)[0]|replace('"', '\\"') %}
|
|
||||||
SET_DISPLAY_TEXT MSG="{escaped_msg}"
|
|
||||||
RESPOND TYPE=command MSG="{escaped_msg}"
|
|
||||||
{% else %}
|
|
||||||
SET_DISPLAY_TEXT
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
# SDCard 'looping' (aka Marlin M808 commands) support
|
|
||||||
#
|
|
||||||
# Support SDCard looping
|
|
||||||
[sdcard_loop]
|
|
||||||
[gcode_macro M486]
|
|
||||||
gcode:
|
|
||||||
# Parameters known to M486 are as follows:
|
|
||||||
# [C<flag>] Cancel the current object
|
|
||||||
# [P<index>] Cancel the object with the given index
|
|
||||||
# [S<index>] Set the index of the current object.
|
|
||||||
# If the object with the given index has been canceled, this will cause
|
|
||||||
# the firmware to skip to the next object. The value -1 is used to
|
|
||||||
# indicate something that isn’t an object and shouldn’t be skipped.
|
|
||||||
# [T<count>] Reset the state and set the number of objects
|
|
||||||
# [U<index>] Un-cancel the object with the given index. This command will be
|
|
||||||
# ignored if the object has already been skipped
|
|
||||||
|
|
||||||
{% if 'exclude_object' not in printer %}
|
|
||||||
{action_raise_error("[exclude_object] is not enabled")}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'T' in params %}
|
|
||||||
EXCLUDE_OBJECT RESET=1
|
|
||||||
|
|
||||||
{% for i in range(params.T | int) %}
|
|
||||||
EXCLUDE_OBJECT_DEFINE NAME={i}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'C' in params %}
|
|
||||||
EXCLUDE_OBJECT CURRENT=1
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'P' in params %}
|
|
||||||
EXCLUDE_OBJECT NAME={params.P}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'S' in params %}
|
|
||||||
{% if params.S == '-1' %}
|
|
||||||
{% if printer.exclude_object.current_object %}
|
|
||||||
EXCLUDE_OBJECT_END NAME={printer.exclude_object.current_object}
|
|
||||||
{% endif %}
|
|
||||||
{% else %}
|
|
||||||
EXCLUDE_OBJECT_START NAME={params.S}
|
|
||||||
{% endif %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if 'U' in params %}
|
|
||||||
EXCLUDE_OBJECT RESET=1 NAME={params.U}
|
|
||||||
{% endif %}
|
|
||||||
@@ -32,7 +32,7 @@ def test_section_parsing(parser):
|
|||||||
parser.config.keys()
|
parser.config.keys()
|
||||||
), f"Expected keys: {expected_keys}, got: {parser.config.keys()}"
|
), f"Expected keys: {expected_keys}, got: {parser.config.keys()}"
|
||||||
assert parser.in_option_block is False
|
assert parser.in_option_block is False
|
||||||
assert parser.current_section == parser.get_sections()[-1]
|
assert parser.current_section == "section number 5"
|
||||||
assert parser.config["section_2"]["_raw"] == "[section_2] ; comment"
|
assert parser.config["section_2"]["_raw"] == "[section_2] ; comment"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
# ======================================================================= #
|
|
||||||
# Copyright (C) 2024 Dominik Willner <th33xitus@gmail.com> #
|
|
||||||
# #
|
|
||||||
# https://github.com/dw-0/simple-config-parser #
|
|
||||||
# #
|
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
|
||||||
# ======================================================================= #
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from src.simple_config_parser.simple_config_parser import SimpleConfigParser
|
|
||||||
from tests.utils import load_testdata_from_file
|
|
||||||
|
|
||||||
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
|
||||||
CONFIG_FILES = ["test_config_1.cfg", "test_config_2.cfg", "test_config_3.cfg"]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=CONFIG_FILES)
|
|
||||||
def parser(request):
|
|
||||||
parser = SimpleConfigParser()
|
|
||||||
file_path = BASE_DIR.joinpath(request.param)
|
|
||||||
for line in load_testdata_from_file(file_path):
|
|
||||||
parser._parse_line(line) # noqa
|
|
||||||
|
|
||||||
return parser
|
|
||||||
@@ -5,13 +5,28 @@
|
|||||||
# #
|
# #
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from src.simple_config_parser.simple_config_parser import (
|
from src.simple_config_parser.simple_config_parser import (
|
||||||
NoOptionError,
|
NoOptionError,
|
||||||
NoSectionError,
|
NoSectionError,
|
||||||
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
|
from tests.utils import load_testdata_from_file
|
||||||
|
|
||||||
|
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||||
|
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def parser():
|
||||||
|
parser = SimpleConfigParser()
|
||||||
|
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||||
|
parser._parse_line(line) # noqa
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def test_get_options(parser):
|
def test_get_options(parser):
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from src.simple_config_parser.simple_config_parser import (
|
from src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -15,8 +17,12 @@ BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
|||||||
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||||
|
|
||||||
|
|
||||||
def test_read_file():
|
@pytest.fixture
|
||||||
parser = SimpleConfigParser()
|
def parser():
|
||||||
|
return SimpleConfigParser()
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_file(parser):
|
||||||
parser.read_file(TEST_DATA_PATH)
|
parser.read_file(TEST_DATA_PATH)
|
||||||
assert parser.config is not None
|
assert parser.config is not None
|
||||||
assert parser.config.keys() is not None
|
assert parser.config.keys() is not None
|
||||||
|
|||||||
@@ -5,12 +5,27 @@
|
|||||||
# #
|
# #
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license #
|
# This file may be distributed under the terms of the GNU GPLv3 license #
|
||||||
# ======================================================================= #
|
# ======================================================================= #
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from src.simple_config_parser.simple_config_parser import (
|
from src.simple_config_parser.simple_config_parser import (
|
||||||
DuplicateSectionError,
|
DuplicateSectionError,
|
||||||
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
|
from tests.utils import load_testdata_from_file
|
||||||
|
|
||||||
|
BASE_DIR = Path(__file__).parent.parent.joinpath("assets")
|
||||||
|
TEST_DATA_PATH = BASE_DIR.joinpath("test_config_1.cfg")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def parser():
|
||||||
|
parser = SimpleConfigParser()
|
||||||
|
for line in load_testdata_from_file(TEST_DATA_PATH):
|
||||||
|
parser._parse_line(line) # noqa
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def test_get_sections(parser):
|
def test_get_sections(parser):
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ def add_config_section(
|
|||||||
|
|
||||||
scp.write_file(cfg_file)
|
scp.write_file(cfg_file)
|
||||||
|
|
||||||
Logger.print_ok("OK!")
|
|
||||||
|
|
||||||
|
|
||||||
def add_config_section_at_top(section: str, instances: List[InstanceType]) -> None:
|
def add_config_section_at_top(section: str, instances: List[InstanceType]) -> None:
|
||||||
# TODO: this could be implemented natively in SimpleConfigParser
|
# TODO: this could be implemented natively in SimpleConfigParser
|
||||||
@@ -71,8 +69,6 @@ def add_config_section_at_top(section: str, instances: List[InstanceType]) -> No
|
|||||||
cfg_file.unlink()
|
cfg_file.unlink()
|
||||||
tmp_cfg_path.rename(cfg_file)
|
tmp_cfg_path.rename(cfg_file)
|
||||||
|
|
||||||
Logger.print_ok("OK!")
|
|
||||||
|
|
||||||
|
|
||||||
def remove_config_section(section: str, instances: List[InstanceType]) -> None:
|
def remove_config_section(section: str, instances: List[InstanceType]) -> None:
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
@@ -91,5 +87,3 @@ def remove_config_section(section: str, instances: List[InstanceType]) -> None:
|
|||||||
|
|
||||||
scp.remove_section(section)
|
scp.remove_section(section)
|
||||||
scp.write_file(cfg_file)
|
scp.write_file(cfg_file)
|
||||||
|
|
||||||
Logger.print_ok("OK!")
|
|
||||||
|
|||||||
Reference in New Issue
Block a user