from werkzeug.security import generate_password_hash
import getpass
import os
import sys

if __name__ == "__main__":
    print("""
    This utility will generate a new password, if you prefer to print it to a file
    and then copy it from there, provide a filename as argument, the file must not
    already exist. If no file is provided, the password will be printed to the screen.
    
    """)
    password = generate_password_hash(
        getpass.getpass(prompt="Enter a password to hash: ").strip()
    )
    if len(sys.argv) < 2:
        print("""
            The following is your password, paste the entire string into the config.yml file
            at the root. Once you have logged in, you can create a user via the interface 
            and remove the user from the config.yml if you prefer:
            """)
        print(password)
        print("\n")
    else:
        if os.path.isfile(sys.argv[1].strip()):
            print("The file provided as an argument already exists, remove it and try again.")
            exit()
        with open(sys.argv[1], "w") as passwordFile:
            passwordFile.write(password)

        print("""
            Your password has been written to {}, paste the entire string into the config.yml 
            file at the root. Once you have logged in, you can create a user via the interface 
            and remove the user from the config.yml if you prefer:
            """.format(sys.argv[1]))


from werkzeug.security import generate_password_hash
import getpass
import os
import sys

if __name__ == "__main__":
    print("""
    This utility will generate a new password, if you prefer to print it to a file
    and then copy it from there, provide a filename as argument, the file must not
    already exist. If no file is provided, the password will be printed to the screen.
    
    """)
    password = generate_password_hash(
        getpass.getpass(prompt="Enter a password to hash: ").strip()
    )
    if len(sys.argv) < 2:
        print("""
            The following is your password, paste the entire string into the config.yml file
            at the root. Once you have logged in, you can create a user via the interface 
            and remove the user from the config.yml if you prefer:
            """)
        print(password)
        print("\n")
    else:
        if os.path.isfile(sys.argv[1].strip()):
            print("The file provided as an argument already exists, remove it and try again.")
            exit()
        with open(sys.argv[1], "w") as passwordFile:
            passwordFile.write(password)

        print("""
            Your password has been written to {}, paste the entire string into the config.yml 
            file at the root. Once you have logged in, you can create a user via the interface 
            and remove the user from the config.yml if you prefer:
            """.format(sys.argv[1]))


This utility will generate a new password, if you prefer to print it to a file     and then copy it from there, provide a filename as argument, the file must not     already exist. If no file is provided, the password will be printed to the screen. The following is your password, paste the entire string into the config.yml file             at the root. Once you have logged in, you can create a user via the interface              and remove the user from the config.yml if you prefer: Your password has been written to {}, paste the entire string into the config.yml              file at the root. Once you have logged in, you can create a user via the interface              and remove the user from the config.yml if you prefer: