def encrypt(journal, filename=None): """ Encrypt into new file. If filename is not set, we encrypt the journal file itself. """ password = util.getpass("Enter new password: "******"Do you want to store the password in your keychain?", default=True): util.set_keychain(journal.name, password) util.prompt("Journal encrypted to {0}.".format(filename or journal.config['journal']))
def install_jrnl(config_path='~/.jrnl_config'): def autocomplete(text, state): expansions = glob.glob(os.path.expanduser(text)+'*') expansions = [e+"/" if os.path.isdir(e) else e for e in expansions] expansions.append(None) return expansions[state] readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(autocomplete) # Where to create the journal? path_query = 'Path to your journal file (leave blank for ~/journal.txt): ' journal_path = util.py23_input(path_query).strip() or os.path.expanduser('~/journal.txt') default_config['journals']['default'] = os.path.expanduser(journal_path) # Encrypt it? if module_exists("Crypto"): password = getpass.getpass("Enter password for journal (leave blank for no encryption): ") if password: default_config['encrypt'] = True if util.yesno("Do you want to store the password in your keychain?", default=True): util.set_keychain("default", password) else: util.set_keychain("default", None) print("Journal will be encrypted.") else: password = None print("PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text.") # Use highlighting: if not module_exists("colorama"): print("colorama not found. To turn on highlighting, install colorama and set highlight to true in your .jrnl_conf.") default_config['highlight'] = False open(default_config['journals']['default'], 'a').close() # Touch to make sure it's there # Write config to ~/.jrnl_conf with open(config_path, 'w') as f: json.dump(default_config, f, indent=2) config = default_config if password: config['password'] = password return config
def install_jrnl(config_path="~/.jrnl_config"): def autocomplete(text, state): expansions = glob.glob(os.path.expanduser(text) + "*") expansions = [e + "/" if os.path.isdir(e) else e for e in expansions] expansions.append(None) return expansions[state] readline.set_completer_delims(" \t\n;") readline.parse_and_bind("tab: complete") readline.set_completer(autocomplete) # Where to create the journal? path_query = "Path to your journal file (leave blank for ~/journal.txt): " journal_path = util.py23_input(path_query).strip() or os.path.expanduser("~/journal.txt") default_config["journals"]["default"] = os.path.expanduser(journal_path) # Encrypt it? if module_exists("Crypto"): password = getpass.getpass("Enter password for journal (leave blank for no encryption): ") if password: default_config["encrypt"] = True if util.yesno("Do you want to store the password in your keychain?", default=True): util.set_keychain("default", password) else: util.set_keychain("default", None) print("Journal will be encrypted.") else: password = None print( "PyCrypto not found. To encrypt your journal, install the PyCrypto package from http://www.pycrypto.org or with 'pip install pycrypto' and run 'jrnl --encrypt'. For now, your journal will be stored in plain text." ) open(default_config["journals"]["default"], "a").close() # Touch to make sure it's there # Write config to ~/.jrnl_conf with open(config_path, "w") as f: json.dump(default_config, f, indent=2) config = default_config if password: config["password"] = password return config