22cfgwriter.py
33------------
44
5- Inputs the configuration files while checking it is valid.
5+ Inputs the configuration files while checking it is valid. Can be executed by `manim-cfg` command.
66
77"""
8- from os import path
8+ import os
99import configparser
1010
11- from .config_utils import successfully_read_files
11+ from .config_utils import _run_config , _paths_config_file
1212
1313from rich .console import Console
1414from rich .progress import track
15- from rich .color import Color
15+ from rich .style import Style
16+ from rich .errors import StyleSyntaxError
1617
1718
18- def check_valid_colour ( color ):
19+ def check_valid_style ( style ):
1920 """Checks whether the entered color is a valid color according to rich
2021 Parameters
2122 ----------
22- color : :class:`str`
23- The color to check whether it is valid.
23+ style : :class:`str`
24+ The style to check whether it is valid.
2425 Returns
2526 -------
2627 Boolean
27- Returns whether it is valid color or not.
28+ Returns whether it is valid style or not according to rich .
2829 """
2930 try :
30- Color .parse (color )
31+ Style .parse (style )
3132 return True
32- except :
33+ except StyleSyntaxError :
3334 return False
3435
3536
3637def main ():
38+ successfully_read_files = _run_config ()[- 1 ]
3739 console = Console ()
3840 config = configparser .ConfigParser ()
39- config .read ( successfully_read_files )
40- default = {
41- "logging.keyword" : "bold yellow" ,
42- "logging.level.notset" : "dim" ,
43- "logging.level.debug" : "green" ,
44- "logging.level.info" : "blue" ,
45- "logging.level.warning" : "red" ,
46- "logging.level.error" : "red bold" ,
47- "logging.level.critical" : "red bold reverse" ,
48- "log.level" : "" ,
49- "log.time" : "cyan dim" ,
50- "log.message" : "" ,
51- "log.path" : "dim" ,
52- }
41+ config .read (successfully_read_files )
42+ default = config ["logger" ]
5343 console .print (
5444 "[yellow bold]Manim Logger Configuration Editor[/yellow bold]" , justify = "center"
5545 )
@@ -59,27 +49,58 @@ def main():
5949 console .print (
6050 "[magenta]Please follow the link for available styles.[/magenta][link=https://rich.readthedocs.io/en/latest/style.html]docs[/link]"
6151 )
52+ for key in default :
53+ temp = default [key ]
54+ del default [key ]
55+ key = key .replace ("_" , "." )
56+ default [key ] = temp
6257 for key in default :
6358 console .print ("Enter the Style for %s" % key + ":" , style = key , end = "" )
6459 temp = input ()
6560 if temp :
66- while not check_valid_colour (temp ):
61+ while not check_valid_style (temp ):
6762 console .print (
6863 "[red bold]Your Style is not valid. Try again.[/red bold]"
6964 )
7065 console .print ("Enter the Style for %s" % key + ":" , style = key , end = "" )
7166 temp = input ()
7267 else :
7368 default [key ] = temp
74- config ["log.color" ] = default
75- for n in track (range (100 ), description = "Converting to Manim.cfg" ):
76- with open ("manim.cfg" , "w" ) as fp :
77- config .write (fp )
69+ for key in default :
70+ temp = default [key ]
71+ del default [key ]
72+ key = key .replace ("." , "_" )
73+ default [key ] = temp
74+ config ["logger" ] = default
7875 console .print (
79- """A configuration file called [yellow]manim.cfg[/yellow] has been created.
80- To save your theme please save that file and each time place it in your current working directory ,
81- (the directory where you executed the command manim)"""
76+ "Do you want it as a default for the User?(y/n)[[n]]" ,
77+ style = "dim purple" ,
78+ end = "" ,
8279 )
80+ save_to_userpath = input ()
81+ config_paths = _paths_config_file ()
82+ if save_to_userpath .lower () == "y" :
83+ if not os .path .exists (os .path .abspath (os .path .join (config_paths [1 ], ".." ))):
84+ os .makedirs (os .path .abspath (os .path .join (config_paths [1 ], ".." )))
85+ with open (config_paths [1 ], "w" ) as fp :
86+ config .write (fp )
87+ console .print (
88+ """A configuration file called [yellow]{}[/yellow] has been created with your required changes.
89+ which would be used while running manim command. If you want to overide that
90+ you would have to create a manim.cfg in local directory.""" .format (
91+ config_paths [1 ]
92+ )
93+ )
94+ else :
95+ with open (config_paths [2 ], "w" ) as fp :
96+ config .write (fp )
97+ console .print (
98+ """A configuration file called [yellow]{}[/yellow] has been created.
99+ To save your theme please save that file and each time place it in your current working directory,
100+ (the directory where you executed the command manim)""" .format (
101+ config_paths [2 ]
102+ )
103+ )
83104
84105
85106if __name__ == "__main__" :
0 commit comments