dotfiles/bin/genpw

38 lines
667 B
Python
Executable file

#!/usr/bin/env python
"""Module to generate a random string
Attributes:
LENGTH (int): Defaults to a length of 16
"""
import sys
import optparse
import os
import base64
LENGTH = 16
def generate(length):
"""Simple function to call OpenSSL
Args:
length (int): length of string to return
"""
return base64.encodestring(os.urandom(256))[:length]
def main():
"""Main function to call
"""
parser = optparse.OptionParser()
parser.add_option('-n', dest='length', default=LENGTH, type=int)
opts, _ = parser.parse_args()
sys.stdout.write(generate(opts.length))
if __name__ == '__main__':
main()
sys.exit(0)