# -*- coding: utf-8 -*-
#
# Autore: Amedeo Salvati
# e-mail: amedeo.salvati@gmail.com
#
# Simple script that takes from char array and put every 
# combination to file
import sys
from optparse import OptionParser

version="0.0.1"

# input char
inputChar = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 
		'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
		'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
		'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
		' ',
		'à', 'è', 'é', 'ì', 'ò', 'ù',
		'.', '!', '-', '_' ]

# file in
infile = ''

# file out default
outfile = 'filePW.txt'

# newLine
newLine = '\n'

def getArg():
	usage = "usage: %prog -r|--read readfile -o|--outfile OutputFile"
	parser = OptionParser(usage=usage, version="%prog " + version)
	parser.add_option("-r", "--read",
			dest="infile",
			help="Input file")
	parser.add_option("-o", "--output",
			dest="outfile", 
			help="Output file")

	(options, args) = parser.parse_args()
	if not (options.outfile == None):
		global outfile
		outfile = options.outfile
	if not (options.infile == None):
		global infile
		infile = options.infile

def composeSimple( initial, buf ):
	sTmp = ""
	for s in range( len(buf) ):
		sTmp = sTmp + initial + buf[s] + newLine
	return sTmp


def main():
	getArg()
	# clean outfile
	OUTFILE = open( outfile, 'w' )
	OUTFILE.close()
	OUTFILE = open( outfile, 'a' )
	sTmp = ""
	if infile <> '':
		INFILE = open( infile, 'r' )
		for s in INFILE:
			s = s.replace( '\n', '' )
			sTmp = composeSimple( s, inputChar )
			OUTFILE.write( sTmp )
			#sys.exit( 0 )
		INFILE.close()
	else:
		for s in inputChar:
			sTmp = composeSimple( s, inputChar )
			OUTFILE.write( sTmp )
			#sys.exit( 0 )
	OUTFILE.close()

if __name__ == "__main__":
	main()

