Ejemplo n.º 1
0
def main():
   ''' Main function for the lifecycle of the server. '''

   # Parse self.arguments
   parser = argparse.ArgumentParser()
   parser.add_argument('-p', '--port', type=int, default=8080,
                       help='Server port, (8080 by default)')
   parser.add_argument('-H', '--hostname', type=str, default='localhost',
                       help='Server hostname (localhost by default).')
   parser.add_argument('-d', '--dir', type=str, default='.',
                       help='Path to directory with bitmaps and ' +
                            'configuration file (current directory by default).')
   parser.add_argument('-c', '--config', type=str, default='config',
                       help='Name configuration file (config by default).')
   parser.add_argument('-f', '--filename', type=str, default='bitmap',
                       help='Filename of bitmap storage files (bitmap by default).')
   arguments = vars(parser.parse_args())

   # Check their validity
   filename_convention = re.compile('^[A-Za-z][A-Za-z0-9_\-]+$')

   if re.match(filename_convention, arguments['filename']) is None:
      print('Invalid bitmap filename.', file=sys.stderr)
      sys.exit(1)

   if not os.path.isdir(arguments['dir']):
      print('Directory for bitmaps and configuration file does not exist.', file=sys.stderr)
      sys.exit(1)

   if not os.path.isfile(arguments['dir'] + '/' + arguments['config'] + '.yaml'):
      print('Configuration file does not exist.', file=sys.stderr)
      sys.exit(1)

   # Check port range
   if (arguments['port'] > 65535) or (arguments['port'] < 1):
      print('Port not within allowed range.', file=sys.stderr)
      sys.exit(1)

   # Validate configuration file, create values
   visualisation_handler = activity_visualisation.Visualisation_Handler()
   visualisation_handler.load_config(arguments['dir'], arguments['filename'],
                                     arguments['config'])

   # Create handler
   server = HTTPServer((arguments['hostname'], arguments['port']),
                       create_handler(arguments, visualisation_handler))

   # Set SIGTERM handler
   signal.signal(signal.SIGTERM, sigterm_handler)

   # Serve forever
   try:
      server.serve_forever()
   except KeyboardInterrupt:
      pass

   # Close server
   server.server_close()
Ejemplo n.º 2
0
def test5():
   handler = activity_visualisation.Visualisation_Handler()
   handler.directory = path
   handler.byte_vector_size = 2
   handler.bit_vector_size = 16
   handler.intervals = 10
   handler.time_window = 11
   bitmap = handler.binary_read("test5.bmap")

   if bitmap is None:
      sys.exit(1)

   for i in range(16):
      print(str(bitmap[i]))
Ejemplo n.º 3
0
def test6():
    handler = activity_visualisation.Visualisation_Handler()
    handler.load_config(path, 'test6', 'config_test')