#!/usr/bin/python3 import ressenger_exceptions, ressenger_cryptography import pathlib, shutil, pickle def initialise(password, b32address, username='default', port=5273, nick='John Doe', force=False): profile_path=pathlib.Path('~/.ressenger/').expanduser() if profile_path.exists(): if (profile_path.is_file() or profile_path.is_symlink()): if force: profile_path.unlink() else: raise FileExistsError('Cannot create ~/.ressenger/ folder, is a file exists there?') profile_path.mkdir(parents=True, exist_ok=True) user_path=pathlib.Path(f'~/.ressenger/{username}').expanduser() if user_path.exists(): if force: if (user_path.is_file() or user_path.is_symlink()): user_path.unlink() else: shutil.rmtree(user_path) else: raise FileExistsError(f'Cannot create ~/.ressenger/{username} file, is a file exists there?') enc_pri, enc_pub=ressenger_cryptography.generate_keypair() sig_pri, sig_pub=ressenger_cryptography.generate_keypair() with open(user_path, 'wb') as file: file.write(ressenger_cryptography.encrypt_bytes(pickle.dumps({'port':port, 'b32address':b32address, 'enc_pri':enc_pri, 'enc_pub':enc_pub, 'sig_pri':sig_pri, 'sig_pub':sig_pub, 'contacts':{}, 'events':{}}, protocol=pickle.HIGHEST_PROTOCOL), password))