Skip to content

Commit

Permalink
get all the ConfigParser in one place, preparing for tomlkit
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Apr 5, 2024
1 parent 5f617f8 commit 8f5c123
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
11 changes: 11 additions & 0 deletions countess/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import os.path
import re
import sys
# import tomlkit
from typing import Any, Iterable, Mapping

from configparser import ConfigParser

from countess.core.logger import ConsoleLogger, Logger
Expand Down Expand Up @@ -85,6 +88,14 @@ def read_config(
return pipeline_graph


def config_string_to_dicts(string: str) -> Iterable[tuple[str,Mapping[str,Any]]]:

cp = ConfigParser()
cp.read_string(string)
for section_name in cp.sections():
yield section_name, dict(cp[section_name])


def write_config(pipeline_graph: PipelineGraph, filename: str):
"""Write `pipeline_graph`'s configuration out to `filename`"""

Expand Down
9 changes: 2 additions & 7 deletions countess/gui/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import random
import re
import tkinter as tk
from configparser import ConfigParser
from enum import Enum, IntFlag
from functools import partial

from countess.core.config import read_config_dict, write_config_node_string
from countess.core.config import config_string_to_dicts, read_config_dict, write_config_node_string
from countess.core.pipeline import PipelineNode
from countess.gui.widgets import copy_to_clipboard, get_icon

Expand Down Expand Up @@ -398,11 +397,7 @@ def on_paste(self, event):
# Try and interpret whatever is in the clipboard as a config
# file section and create it as a node! This lets users
# cut and paste between CountESS instances!
cp = ConfigParser()
cp.read_string(self.canvas.clipboard_get())

for section_name in cp.sections():
config_dict = cp[section_name]
for section_name, config_dict in config_string_to_dicts(self.canvas.clipboard_get()):
node = read_config_dict(section_name, "", config_dict)
node.position = self.new_node_position(event.x, event.y)
self.add_node(node)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
'psutil~=5.9.5',
'rapidfuzz~=2.15.1',
'tkinterweb~=3.23.5',
'tomlkit~=0.12.4',
'ttkthemes~=3.2.2',
'typing_extensions~=4.8.0',
]
Expand Down

0 comments on commit 8f5c123

Please sign in to comment.