mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +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
|
||||
|
||||
|
||||
@task(help={'filename': "Output filename (default = 'data.json')"})
|
||||
def export_records(c, filename='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', overwrite = False):
|
||||
"""Export all database records to a file"""
|
||||
# Get an absolute path to the file
|
||||
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}'")
|
||||
|
||||
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 = str(response).strip().lower()
|
||||
|
||||
|
Reference in New Issue
Block a user