def list_applications(): query = "SELECT * FROM application" app_list = [] try: conn = get_connection() if conn: cursor = conn.cursor() cursor.execute(query) for item in cursor: app = Application() app.appid = item[0] app.name = item[1] app.type = item[2] app.image = item[3] app.min_memory = item[4] app.num_cores = item[5] app.comments = item[6] # print('Application: ', vars(app)) app_list.append(app) cursor.close() conn.close() except mysql.connector.Error as err: logging.error('Getting Application List on Database Error: %s', err) finally: if not app_list: logging.info('Not Find any Application on Database') return app_list
def get_application_from_ID(appid: int): query = "SELECT * FROM application WHERE id = %s" info = (appid, ) application = Application() try: conn = get_connection() if conn: cursor = conn.cursor() cursor.execute(query, info) item = cursor.fetchone() if item: application.appid = item[0] application.name = item[1] application.type = item[2] application.image = item[3] application.min_memory = item[4] application.num_cores = item[5] application.comments = item[6] # print('Application: ', vars(application)) cursor.close() conn.close() except mysql.connector.Error as err: logging.error('Getting Application %s Info on Database Error: %s', appid, err) finally: return application
def applicationMenu(): application_list = database.list_applications() if application_list: print('\n' + 'Applications:') for app in application_list: print('ID: ', app.appid, ' Name: ', app.name) while True: application = Application() application.appid = int( input('Enter the Selected Application ID: ')) if application in application_list: return (application.appid) # break else: print('ID: ', application.appid, ' - Wrong Application ID!') else: print('No Applications Available!')