mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Add flag to overwrite existing file when exporting records
This commit is contained in:
		
							
								
								
									
										6
									
								
								tasks.py
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								tasks.py
									
									
									
									
									
								
							| @@ -282,8 +282,8 @@ def content_excludes(): | |||||||
|     return output |     return output | ||||||
|  |  | ||||||
|  |  | ||||||
| @task(help={'filename': "Output filename (default = 'data.json')"}) | @task(help={'filename': "Output filename (default = 'data.json')", 'overwrite': "Overwrite existing files without asking first (default False)"}) | ||||||
| def export_records(c, filename='data.json'): | def export_records(c, filename='data.json', overwrite = False): | ||||||
|     """Export all database records to a file""" |     """Export all database records to a file""" | ||||||
|     # Get an absolute path to the file |     # Get an absolute path to the file | ||||||
|     if not os.path.isabs(filename): |     if not os.path.isabs(filename): | ||||||
| @@ -292,7 +292,7 @@ def export_records(c, filename='data.json'): | |||||||
|  |  | ||||||
|     print(f"Exporting database records to file '{filename}'") |     print(f"Exporting database records to file '{filename}'") | ||||||
|  |  | ||||||
|     if os.path.exists(filename): |     if os.path.exists(filename) and overwrite is False: | ||||||
|         response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ") |         response = input("Warning: file already exists. Do you want to overwrite? [y/N]: ") | ||||||
|         response = str(response).strip().lower() |         response = str(response).strip().lower() | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user