Parcourir la source

add header to generated TOML file warning its been converted from INI

Nick Sweeting il y a 1 an
Parent
commit
c8ff8f2b86
1 fichiers modifiés avec 6 ajouts et 4 suppressions
  1. 6 4
      archivebox/plugantic/ini_to_toml.py

+ 6 - 4
archivebox/plugantic/ini_to_toml.py

@@ -6,6 +6,8 @@ import ast
 
 
 JSONValue = str | bool | int | None | List['JSONValue']
 JSONValue = str | bool | int | None | List['JSONValue']
 
 
+TOML_HEADER = "# Converted from INI to TOML format: https://toml.io/en/\n\n"
+
 def load_ini_value(val: str) -> JSONValue:
 def load_ini_value(val: str) -> JSONValue:
     """Convert lax INI values into strict TOML-compliant (JSON) values"""
     """Convert lax INI values into strict TOML-compliant (JSON) values"""
     if val.lower() in ('true', 'yes', '1'):
     if val.lower() in ('true', 'yes', '1'):
@@ -22,7 +24,7 @@ def load_ini_value(val: str) -> JSONValue:
 
 
     try:
     try:
         return json.loads(val)
         return json.loads(val)
-    except Exception as err:
+    except Exception:
         pass
         pass
     
     
     return val
     return val
@@ -50,7 +52,7 @@ def convert(ini_str: str) -> str:
             toml_dict[section.upper()][key.upper()] = json.dumps(parsed_value)
             toml_dict[section.upper()][key.upper()] = json.dumps(parsed_value)
 
 
     # Build the TOML string
     # Build the TOML string
-    toml_str = ""
+    toml_str = TOML_HEADER
     for section, items in toml_dict.items():
     for section, items in toml_dict.items():
         toml_str += f"[{section}]\n"
         toml_str += f"[{section}]\n"
         for key, value in items.items():
         for key, value in items.items():
@@ -63,7 +65,7 @@ def convert(ini_str: str) -> str:
 
 
 ### Basic Assertions
 ### Basic Assertions
 
 
-test_input = r"""
+test_input = """
 [SERVER_CONFIG]
 [SERVER_CONFIG]
 IS_TTY=False
 IS_TTY=False
 USE_COLOR=False
 USE_COLOR=False
@@ -225,7 +227,7 @@ NODE_VERSION=v21.7.3
 """
 """
 
 
 
 
-expected_output = r'''[SERVER_CONFIG]
+expected_output = TOML_HEADER + '''[SERVER_CONFIG]
 IS_TTY = false
 IS_TTY = false
 USE_COLOR = false
 USE_COLOR = false
 SHOW_PROGRESS = false
 SHOW_PROGRESS = false