<commit_before>#!/usr/bin/env python3

import sys
import os
import stat

import getpass

import hash_algos

def create_pass_hash(filename):

    if os.path.exists(hash_fn_full):
        print("[%s] already exists. Aborting." % hash_fn_full)
        return False

    # ask passphrase
    passphrase = getpass.getpass("Type in...\n")

    # generate hash
    v, r = hash_algos.hash_sha_512_app_content(passphrase)
    if not v:
        print("Failed generating hash")
        sys.exit(1)

    # write out to file
    with open(filename, "w") as f:
        f.write(r)

    # set user-read-only permissions
    os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    return True

if __name__ == "__main__":

    filename_base = os.path.expanduser("~/")
    hash_filename = ".private_passphrase_hash"

    if len(sys.argv) == 2:
        filename_base = os.getcwd()
        hash_filename = sys.argv[1]

    hash_fn_full = os.path.join(filename_base, hash_filename)
    if not create_pass_hash(hash_fn_full):
        print("Failed creating pass hash file")
        sys.exit(1)
    else:
        print("Successfuly created hash file [%s]." % hash_fn_full)<commit_msg>bugfix: create_pass_hash should return False instead of exit(1)<commit_after>#!/usr/bin/env python3

import sys
import os
import stat

import getpass

import hash_algos

def create_pass_hash(filename):

    if os.path.exists(hash_fn_full):
        print("[%s] already exists. Aborting." % hash_fn_full)
        return False

    # ask passphrase
    passphrase = getpass.getpass("Type in...\n")

    # generate hash
    v, r = hash_algos.hash_sha_512_app_content(passphrase)
    if not v:
        return False

    # write out to file
    with open(filename, "w") as f:
        f.write(r)

    # set user-read-only permissions
    os.chmod(filename, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)

    return True

if __name__ == "__main__":

    filename_base = os.path.expanduser("~/")
    hash_filename = ".private_passphrase_hash"

    if len(sys.argv) == 2:
        filename_base = os.getcwd()
        hash_filename = sys.argv[1]

    hash_fn_full = os.path.join(filename_base, hash_filename)
    if not create_pass_hash(hash_fn_full):
        print("Failed creating pass hash file")
        sys.exit(1)
    else:
        print("Successfuly created hash file [%s]." % hash_fn_full)
{'fraction_non_alphanumeric': 0.10955414012738854, 'fraction_numerical': 0.006794055201698514, 'mean_word_length': 2.9201331114808653, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4484880', 'n_tokens_mistral': 829, 'n_tokens_neox': 796, 'n_words': 188}