added previous dir choice
This commit is contained in:
parent
3a9ba2f320
commit
f2e17ee603
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
import glob
|
import glob
|
||||||
import uuid
|
import uuid
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -16,11 +17,31 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
|
||||||
|
if os.path.exists('config.json'):
|
||||||
|
with open('config.json', 'r') as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
previous_choice = config.get('directory', '')
|
||||||
|
else:
|
||||||
|
previous_choice = ''
|
||||||
|
|
||||||
|
|
||||||
#fetching the file list
|
#fetching the file list
|
||||||
directory = input("Please enter the path to the directory containing the csv files (or leave empty if the files are in the same directory as this script): ")
|
directory = input(f"Please enter the path to the directory containing the csv files [{previous_choice}]: ")
|
||||||
|
if not directory:
|
||||||
|
directory = previous_choice
|
||||||
|
|
||||||
|
with open('config.json', 'w') as config_file:
|
||||||
|
json.dump({'directory': directory}, config_file)
|
||||||
|
|
||||||
|
print(f"Selected directory: {directory}")
|
||||||
|
|
||||||
|
|
||||||
csv_files = glob.glob(os.path.join(directory, '*csv*'))
|
csv_files = glob.glob(os.path.join(directory, '*csv*'))
|
||||||
self.stdout.write(f"Files found: {len(csv_files)}.")
|
self.stdout.write(f"Files found: {len(csv_files)}.")
|
||||||
self.stdout.write("Populating the file database...")
|
self.stdout.write("Populating the file database...")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#initialize the counter
|
#initialize the counter
|
||||||
new_files_count = 0
|
new_files_count = 0
|
||||||
#add files as catalogfile instances into the database
|
#add files as catalogfile instances into the database
|
||||||
|
Loading…
x
Reference in New Issue
Block a user