Package ioids :: Module tools
[hide private]
[frames] | no frames]

Source Code for Module ioids.tools

 1  """ 
 2  Tools module for IOIDS 
 3   
 4  Inter-Organisational Intrusion Detection System (IOIDS) 
 5   
 6  Check README in the IOIDS folder for more information. 
 7   
 8  @author: Michael Pilgermann 
 9  @contact: mailto:mpilgerm@glam.ac.uk 
10  @license: GPL (General Public License) 
11  """ 
12   
13  import output 
14  from sys import stdout 
15   
16  oneindent = ' ' * 3 
17  SUCESS_POS = output.green('  OK  ') 
18  SUCESS_NEG = output.red('FAILED') 
19  SUCESS_SKIP = output.yellow(' SKIP ') 
20  SUCESS_WARN = output.yellow('  !!  ') 
21   
22  COLUMN_SUCESS = 80 
23  COLUMN_INPUT = 70 
24  LENGTH_LINE = 89 
25   
26   
27 -def printAction(indent, text, linebreak = 0, out = stdout):
28 """ 29 Prints a line for an action and puts the cursor on a predefined column. 30 31 Usually, no line break is written, the line should be finished after performing an 32 action using the function L{finishActionLine}. 33 """ 34 print ((oneindent * indent) + text).ljust(COLUMN_SUCESS), 35 if linebreak: 36 print 37 else: 38 out.flush()
39
40 -def finishActionLine(sucess = SUCESS_POS):
41 """ 42 Finishes a line as prepared by L{printAction}. 43 44 Puts the given sucess string in brackets. 45 """ 46 print '[%s]' %(sucess)
47
48 -def requestInput(indent, prompt, default = None):
49 """ 50 Prompts the user for input. 51 """ 52 if default: 53 defaultPr = ' [%s]' %(default) 54 else: 55 defaultPr = ' []' 56 print ((oneindent * indent) + '** ' + prompt + defaultPr).ljust(COLUMN_INPUT) + ' :', 57 input = raw_input() 58 if len(input) != 0: 59 default = input 60 return default
61