def module_test(): """Run the module test""" try: # Assume office PC and just try and connect to db database = BarDatabase("servcinf-sql", 3306) through_tunnel = False except MySQLdb.OperationalError: # If not, try and create a tunnel from ssh_tunnel import create_tunnel, close_tunnel create_tunnel() time.sleep(1) database = BarDatabase("127.0.0.1", 9000) through_tunnel = True #DATABASE.insert_user(1234567890128,"test2") username, id_ = database.get_user('test') print "For barcode 'test' fetch name '{}' and id '{}'".format(username, id_) print "For id {} fetch sum {}".format(id_, database.sum_log(id_)) database.cursor.execute('select * from fridays_items') for line in database.cursor.fetchall(): print line if through_tunnel: close_tunnel() time.sleep(1)
def module_test(): """Run the module test""" try: # Assume office PC and just try and connect to db database = BarDatabase("servcinf-sql", 3306) through_tunnel = False except MySQLdb.OperationalError: # If not, try and create a tunnel from ssh_tunnel import create_tunnel, close_tunnel create_tunnel() time.sleep(1) database = BarDatabase("127.0.0.1", 9000) through_tunnel = True #DATABASE.insert_user(1234567890128,"test2") username, id_ = database.get_user('test') print "For barcode 'test' fetch name '{}' and id '{}'".format( username, id_) print "For id {} fetch sum {}".format(id_, database.sum_log(id_)) database.cursor.execute('select * from fridays_items') for line in database.cursor.fetchall(): print line if through_tunnel: close_tunnel() time.sleep(1)
def start_up(self): """Starting up initials""" self.picaso.clear_screen() # Testing demon connection attempt_number = 0 while not test_demon_connection(): self.picaso.move_cursor(2, 0) attempt_number += 1 status_string = "Demon connection attempt {} failed".format( attempt_number) self.picaso.put_string(status_string) time.sleep(1) # Demon connection successful self.picaso.clear_screen() self.picaso.move_cursor(2, 0) status_string = "Demon connection attempt succeeded".format( attempt_number) self.picaso.put_string(status_string) # Create ssh tunnel self.picaso.move_cursor(3, 0) if create_tunnel(): self.picaso.put_string('Created SSH tunnel') else: self.picaso.put_string('Unable to create SSH tunnel. Quitting!') time.sleep(5) raise SystemExit('Unable to create ssh tunnel') # Print network interface and ip address interface, ip_address = get_ip_address() self.picaso.move_cursor(5, 0) interface_string = "Interface: {}".format(interface) self.picaso.put_string(interface_string) self.picaso.move_cursor(6, 0) ip_address_string = "Ip address: {}".format(ip_address) self.picaso.put_string(ip_address_string) # Start the database backend time.sleep(1) for _ in range(10): try: self.bar_database = BarDatabase('127.0.0.1', 9000) break except OperationalError: time.sleep(1) self.picaso.move_cursor(7, 0) self.picaso.put_string('Connection to database') # Start barcode scanner dev_ = detect_barcode_device() print dev_ self.tbs = ThreadedBarcodeReader(dev_) self.tbs.start() time.sleep(1)
def start_up(self): """Starting up initials""" self.picaso.clear_screen() # Testing demon connection attempt_number = 0 while not test_demon_connection(): self.picaso.move_cursor(2, 0) attempt_number += 1 status_string = "Demon connection attempt {} failed".format(attempt_number) self.picaso.put_string(status_string) time.sleep(1) # Demon connection successful self.picaso.clear_screen() self.picaso.move_cursor(2, 0) status_string = "Demon connection attempt succeeded".format(attempt_number) self.picaso.put_string(status_string) # Create ssh tunnel self.picaso.move_cursor(3, 0) if create_tunnel(): self.picaso.put_string('Created SSH tunnel') else: self.picaso.put_string('Unable to create SSH tunnel. Quitting!') time.sleep(5) raise SystemExit('Unable to create ssh tunnel') # Print network interface and ip address interface, ip_address = get_ip_address() self.picaso.move_cursor(5, 0) interface_string = "Interface: {}".format(interface) self.picaso.put_string(interface_string) self.picaso.move_cursor(6, 0) ip_address_string = "Ip address: {}".format(ip_address) self.picaso.put_string(ip_address_string) # Start the database backend time.sleep(1) for _ in range(10): try: self.bar_database = BarDatabase('127.0.0.1', 9000) break except OperationalError: time.sleep(1) self.picaso.move_cursor(7, 0) self.picaso.put_string('Connection to database') # Start barcode scanner dev_ = detect_barcode_device() print dev_ self.tbs = ThreadedBarcodeReader(dev_) self.tbs.start() time.sleep(1)