def parseArgs():
	"Analyse the commandline parameters; Calls resize function if things are okay "
	arglist=['-d','-o','-e','-c'] # -c is alone (no additional data); others work in pairs
	global size
	global extlist
	global directory
	global getchild
	
	if '--help' in sys.argv or '--start' not in sys.argv:     # --help is the show stopper :)
		print """		
Usage: imageresize --start [options] 
		
Scale images to given size
  * Default directory is current directory (includes subdirectories)
  * Default resize option is '1024' 
    (scale width of image if it exceeds 1024px; retain aspect ratio)
  * Default extensions are jpg, jpeg (not case-sensitive)
  * Overwrites original image
           
Parameters:
  --start              begins the process  
  -d <path>	       <path> is the path to the required directory 	
  -o '<option>'	       <option> can be of the following formats   
     '100'      : scale width of image to 100px
     'x60'      : scale height of image to 60px
     '100x60'   : scale image within given bounds
     (aspect ratio preserved)
  -e <ext1>,<ext2>...  <extn> is any valid extension (.png, .gif) 
  -c                   Scale images in sub-folders  		   			
  --help	       Displays this help
"""
	else:
		sys.argv.remove('--start')
		l=len(sys.argv)
		i=1
		while i<l:
			arg=sys.argv[i]
			if arg in arglist:
				if arg=='-c':     # -c is alone 
					getchild=True
					i+=1
					continue
				elif i+1<l:
					data=sys.argv[i+1]
					if data in arglist or data==None:
						invalidArgs()   #only pairs; no odd args after -c!
					elif arg=='-d':
						if not path.exists(data):
							print "Directory does not exist"
							invalidArgs()
						directory=data	
					elif arg=='-o':				 					
						validOptionChars=[str(letter) for letter in range(0,10)]
						validOptionChars.extend(['x'])
						for letter in data:  #validating option string
							if letter not in validOptionChars:
								invalidArgs()
						if 'x' in data.replace('x',''): 
							invalidArgs()		
						dim=data.split('x')
						if data.startswith('x'): #scale height
							height=int(dim[0])
							size=height*9,height
						elif 'x' not in data:   #scale width
							width=int(dim[0])
							size=width,width*9
						else:   #scale to fit bounding box
							size=int(dim[0]),int(dim[1])				
					else:				
						extlist.extend(data.lower().split(","))
					i+=2  #Done with the pair, move on
				else:
					invalidArgs() #Expected data not found 		
						
			else:  #if a stranger is present in positions where args are expected
				invalidArgs()		
		resize(directory)   #Okies!				
Analyse the commandline parameters; Calls resize function if things are okay 
recipes/Python/577189_Mass_image_resizing_progress_bar_details/recipe-577189.py