Ejemplo n.º 1
0
	def on_scan_pressed(self, event):
		# Clear output areas
		self.output.Clear()
		self.source.Clear()
		self.identifiers.Clear()
		
		scanner = Scanner_Class()
		try:
			scanner.read_characters(self.edit.GetValue())
			
			self.source.AppendText(scanner.source())
			
			ids = scanner.identifiers()
			self.identifiers.AppendText("Identifier\tTimes Used\n")
			for v in ids.keys():
				self.identifiers.AppendText(v+":\t"+str(ids[v])+"\n")
				
			if self.out_file.GetValue() != '':
				try:
					file = open(self.out_file.GetValue(), 'w')
					
					if self.opt_verbose.GetValue():
						for line in scanner.output():
							file.write(str(line)+"\n")
					else:
						for line in scanner.tokens():
							file.write(str(line)+"\n")
					file.write("\n\nDiscovered Identifier:Times Used\n")
					ids = scanner.identifiers()
					for v in ids.keys():
						file.write(v+":"+str(ids[v])+"\n")
							
					file.close()
				except Exception as strerror:
					self.show_error('Error: '+str(strerror))
			
			# Verbose output
			if self.opt_verbose.GetValue():
				for line in scanner.output():
					self.output.AppendText(str(line+"\n"))
			# Token only output
			else:
				for line in scanner.tokens():
					self.output.AppendText(str(line+"\n"))
			
			self.show_message("Scan completed successfully!")
		
		except Exception as strerror:
			self.source.AppendText(scanner.source())
			for line in scanner.output():
					self.output.AppendText(str(line+"\n"))
			self.show_error('Error: '+str(strerror))
Ejemplo n.º 2
0
# GUI mode
if __name__ == "__main__" and not nogui:
    app = wxScannerApp()
    app.MainLoop()

# Command line mode
else:
    scanner = Scanner_Class()

    try:
        scanner.read_characters(in_file)

    except Exception as strerror:
        sys.stderr.write("Error: " + str(strerror))
        sys.exit(1)

    if verbose:
        for line in scanner.output():
            print line
    else:
        for line in scanner.tokens():
            print line

    print "\nDiscovered Identifier: Times Used"
    ids = scanner.identifiers()
    for v in ids.keys():
        print v + ": " + str(ids[v])

# End Large Scanner Client