2021-10-17 19:27:15 +02:00
|
|
|
# standard imports
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def initialize_dirs(user_dir, force_reset=False):
|
|
|
|
|
|
|
|
dirs = {}
|
|
|
|
|
|
|
|
dirs['old'] = os.path.join(user_dir, 'old')
|
|
|
|
dirs['new'] = os.path.join(user_dir, 'new')
|
|
|
|
dirs['meta'] = os.path.join(user_dir, 'meta')
|
|
|
|
dirs['custom'] = os.path.join(user_dir, 'custom')
|
|
|
|
dirs['phone'] = os.path.join(user_dir, 'phone')
|
2021-10-20 17:02:36 +02:00
|
|
|
dirs['preferences'] = os.path.join(user_dir, 'preferences')
|
2021-10-17 19:27:15 +02:00
|
|
|
dirs['txs'] = os.path.join(user_dir, 'txs')
|
|
|
|
dirs['keyfile'] = os.path.join(user_dir, 'keystore')
|
|
|
|
dirs['custom_new'] = os.path.join(dirs['custom'], 'new')
|
|
|
|
dirs['custom_meta'] = os.path.join(dirs['custom'], 'meta')
|
|
|
|
dirs['phone_meta'] = os.path.join(dirs['phone'], 'meta')
|
2021-10-20 17:02:36 +02:00
|
|
|
dirs['preferences_meta'] = os.path.join(dirs['preferences'], 'meta')
|
|
|
|
dirs['preferences_new'] = os.path.join(dirs['preferences'], 'new')
|
2021-10-17 19:27:15 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.stat(dirs['old'])
|
|
|
|
except FileNotFoundError:
|
|
|
|
sys.stderr.write('no users to import. please run create_import_users.py first\n')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if force_reset:
|
|
|
|
for d in dirs.keys():
|
|
|
|
if d == 'old':
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
shutil.rmtree(dirs[d])
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
for d in dirs.keys():
|
|
|
|
if d == 'old':
|
|
|
|
continue
|
2021-10-27 10:43:35 +02:00
|
|
|
os.makedirs(dirs[d], exist_ok=True)
|
2021-10-17 19:27:15 +02:00
|
|
|
|
|
|
|
return dirs
|