@@ -46,33 +46,37 @@ def move_content(source: str, destination: str):
46
46
47
47
def keep_specific_items (directory : str , keep_folder : str , keep_file : str ):
48
48
"""
49
- Delete all items in the directory except for the specified folder and file.
49
+ Deletes all items in the given directory except for the specified folder,
50
+ the specified file, and the '.git' directory.
50
51
51
52
Parameters:
52
53
- directory (str): The path to the directory.
53
54
- keep_folder (str): The name of the folder to keep.
54
55
- keep_file (str): The name of the file to keep.
55
56
"""
56
- try :
57
- if not os .path .exists (directory ) or not os .path .isdir (directory ):
58
- raise ValueError (f"Error: '{ directory } ' is not a valid directory." )
59
-
60
- # Iterate through items in the directory
61
- for item in os .listdir (directory ):
62
- item_path = os .path .join (directory , item )
63
-
64
- # Check if the item is the specified folder or file
65
- if os .path .isdir (item_path ) and item != keep_folder :
57
+ if not os .path .exists (directory ) or not os .path .isdir (directory ):
58
+ console .print (f"[red]Error: '{ directory } ' is not a valid directory." )
59
+ return
60
+
61
+ # Define folders and files to skip
62
+ skip_folders = {keep_folder , ".git" }
63
+ skip_files = {keep_file }
64
+
65
+ # Iterate through items in the directory
66
+ for item in os .listdir (directory ):
67
+ if item in skip_folders or item in skip_files :
68
+ continue
69
+
70
+ item_path = os .path .join (directory , item )
71
+ try :
72
+ if os .path .isdir (item_path ):
66
73
shutil .rmtree (item_path )
67
-
68
- elif os .path .isfile (item_path ) and item != keep_file :
74
+ console . log ( f"[green]Removed directory: { item_path } " )
75
+ elif os .path .isfile (item_path ):
69
76
os .remove (item_path )
70
-
71
- except PermissionError as pe :
72
- console .print (f"[red]PermissionError: { pe } . Check permissions and try again." )
73
-
74
- except Exception as e :
75
- console .print (f"[red]Error: { e } " )
77
+ console .log (f"[green]Removed file: { item_path } " )
78
+ except Exception as e :
79
+ console .log (f"[yellow]Skipping { item_path } due to error: { e } " )
76
80
77
81
78
82
def print_commit_info (commit_info : dict ):
@@ -177,14 +181,14 @@ def main_upload():
177
181
Main function to upload the latest commit of a GitHub repository.
178
182
"""
179
183
cmd_insert = Prompt .ask (
180
- "[bold red]Are you sure you want to delete all files? (Only 'Video' folder and 'update_version .py' will remain)" ,
184
+ "[bold red]Are you sure you want to delete all files? (Only 'Video' folder and 'update .py' will remain)" ,
181
185
choices = ['y' , 'n' ],
182
186
default = 'y' ,
183
187
show_choices = True
184
188
)
185
189
186
190
if cmd_insert .lower ().strip () == 'y' or cmd_insert .lower ().strip () == 'yes' :
187
- console .print ("[red]Deleting all files except 'Video' folder and 'update_version .py'..." )
191
+ console .print ("[red]Deleting all files except 'Video' folder and 'update .py'..." )
188
192
keep_specific_items ("." , "Video" , "upload.py" )
189
193
download_and_extract_latest_commit ()
190
194
else :
0 commit comments