@@ -49,53 +49,84 @@ def generate_default_project_details() -> dict[str, str | int | tuple]:
4949 "email" : "brianobot9@gmail.com" ,
5050 "repository_link" : "" ,
5151 "open_source_license" : (1 , [
52- ( 1 , "MIT" ) ,
53- ( 2 , "BSD" ) ,
54- ( 3 , "GPLv3" ) ,
55- ( 4 , "Apache Software License 2.0" ) ,
56- ( 5 , "Not open source" ) ,
52+ "MIT" ,
53+ "BSD" ,
54+ "GPLv3" ,
55+ "Apache Software License 2.0" ,
56+ "Not open source" ,
5757 ]),
5858 }
5959
60+
61+ class ProjectOptionConfig :
62+ """
63+ Utility Functions for working with Project Detail Options.
64+ """
65+
66+ @classmethod
67+ def get_option_at (cls , option : list [str ], position : int ) -> str :
68+ """
69+ Since indexes are zero based and position are 1 based
70+ substracting 1 from each get the option at the current index
71+ """
72+ return option [position - 1 ]
73+
74+ @classmethod
75+ def get_default_option (cls , default : tuple [int , list [str ]]) -> str :
76+ """
77+ Takes the whole default value, extracts the default index and extract the default value
78+ based on the default index
79+ """
80+ default_index = default [0 ]
81+ return cls .get_option_at (default [1 ], default_index )
82+
6083
6184def get_project_detail (
6285 attr : str ,
63- default : str | int | tuple [str , ... ],
86+ default : str | tuple [int , list [ str ] ],
6487 project_detail : dict [str , str | int | tuple ]
65- ) -> str | int | tuple [ str , ...] :
88+ ) -> str | int :
6689 """
6790 Get a project detail (attr) from the user via the command line interface, if nothing is provided
6891 the default value is used for the project detail value.
6992 """
93+
94+ if "_" in attr :
95+ attr = attr .lower ()
96+
97+ if attr == "slug_name" :
98+ default = slugify (str (project_detail ["name" ]))
7099
71100 # Tuples Attrs means the detail have options, so process them differently
72- if not isinstance (attr , tuple ):
101+ if not isinstance (default , tuple ):
73102 detail = input (f"Enter Project { attr } ['{ default } ']: " )
74103 else :
75104 count = 0
76105 detail = ""
77106 is_not_valid = True
78- default_index = int ( cast ( tuple , project_detail [ attr ])[ 0 ]) - 1
79- default = cast ( tuple , project_detail [ attr ])[ 1 ][ default_index ][ 1 ]
107+
108+ default_value = ProjectOptionConfig . get_default_option ( default )
80109
81110 while is_not_valid :
82- options = cast (tuple [str , list [tuple [int , str ]]], project_detail [attr ])[1 ]
111+ options = default [1 ]
112+ print ("Options: " , options )
113+
83114 print (f"Select { attr } :" )
84- for index , option in options :
115+ for index , option in enumerate ( options , start = 1 ) :
85116 print (f"\t { index } - { option } " )
86117
87- prompt_msg = f"Choose from { ', ' .join (str (i ) for i in range (index ))} : [{ cast (tuple , project_detail [attr ])[0 ]} ]: "
118+ prompt_msg = f"Choose from { ', ' .join (str (i ) for i in range (1 , index + 1 ))} : [{ cast (tuple , project_detail [attr ])[0 ]} ]: "
88119 detail_index = input (prompt_msg )
89120
90121 if not detail_index or detail_index .isspace ():
91- detail = default
122+ detail = default_value
92123 is_not_valid = False
93124 elif not detail_index .isdigit ():
94125 warning_print (f"Invalid Value { detail_index } for { attr } ... Please Try Again!" )
95- elif int (detail_index ) not in range (index + 1 ):
126+ elif int (detail_index ) not in range (1 , index + 1 ):
96127 warning_print (f"Invalid Value { detail_index } for { attr } ... Please Try Again!" )
97128 else :
98- detail = detail = cast ( tuple , project_detail [ attr ])[ 1 ][ int (detail_index ) - 1 ][ 1 ]
129+ detail = ProjectOptionConfig . get_option_at ( options , int (detail_index ))
99130 is_not_valid = False
100131
101132 count += 1
@@ -185,8 +216,8 @@ def generate_project_scaffold(project_detail: dict[str, str]):
185216
186217 # create and activate virtual environment
187218 subprocess .Popen (["python3" , "-m" , "venv" , "venv" ]).wait ()
188- subprocess .Popen (["bash" , "-c" , "source" , " venv/bin/activate" ]).wait ()
189- subprocess .Popen (["pip" , "install" , "-r" , "requirements.txt" ]).wait ()
219+ subprocess .Popen (["bash" , "-c" , "source venv/bin/activate && pip install -r requirements.txt " ]).wait ()
220+ # subprocess.Popen(["pip", "install", "-r", "requirements.txt"]).wait()
190221
191222
192223 print ("____________________________________________" )
@@ -228,7 +259,8 @@ def main():
228259
229260 # Generate Projects with the Details Provided by the User
230261 generate_project_scaffold (cast (dict [str , str ], project_details ))
262+
231263
232-
264+
233265if __name__ == "__main__" :
234266 main ()
0 commit comments