def __init__(self, message, originalException=None): """ A generic system exception @type message: str @param message: The exception message @type originalException: Exception @param originalException: The original exception raised """ logger = Logger(level=logging.ERROR) if originalException is not None: message += "\nOriginal exception:\n\t" + originalException.message Exception.__init__(self, message) logger.log(message)
global db, logger checkin_count = db.query("SELECT COUNT(*) FROM " + table)[0][0] traj_count = db.query("SELECT COUNT(DISTINCT(" + tidcol + ")) FROM " + table)[0][0] class_count = db.query("SELECT COUNT(DISTINCT(" + classcol + ")) FROM " + table)[0][0] logger.log(Logger.INFO, "Table " + table + " Stats: ") logger.log(Logger.INFO, " Check-in count: " + str(checkin_count)) logger.log(Logger.INFO, " Trajectory count: " + str(traj_count)) logger.log(Logger.INFO, " Class count: " + str(class_count)) if (db.connect()): logger.log(Logger.INFO, "Succesfully connected to database \'" + args.dbname + "\'!") else: logger.log(Logger.ERROR, "Failed connecting to database \'" + args.dbname + "\'!") logger.log(Logger.ERROR, "Database status: " + db.status()) exit() insert_table_query = "CREATE TABLE " + args.totable + \ " AS (SELECT * FROM " + args.origtable + " WHERE " + \ args.tidcol + " IS NOT NULL :where)" no_cat_query = """DELETE FROM :table WHERE :venue_id IN ( SELECT :venue_id FROM :table EXCEPT SELECT v.id FROM fq_venue v INNER JOIN fq_venue_category vc ON v.id = vc.:venue_id
# check if python version is 3.7+ (needed) # still, this file should be python2-compliant for the check to run. major, minor = sys.version_info[:2] if sys.version_info < (3, 7): print( "You need to use at least python 3.7 (current is ~{}.{})".format( major, minor), file=sys.stderr, ) sys.exit(1) from core.logger import Logger # import pygame and try to supress the annoying startup message. Logger.log("Loading pygame...") os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1" import pygame Logger.log("Pygame loaded.") # start the game if __name__ == "__main__": from game import GameCore # paths save_path = (Path(__file__) / "../save").resolve() resources_path = (Path(__file__) / "../resources").resolve() audio_path = (Path(__file__) / "../audio").resolve() save_path.mkdir(parents=True, exist_ok=True)
CREATE_SCHEMA_FILE = 'sql/create_schema.sql' DROP_SCHEMA_FILE = 'sql/drop_schema.sql' CONFIG_FILE = args.config config = configparser.ConfigParser() config.read(CONFIG_FILE) db = Database() db.config(config['DATABASE']['NAME'], config['DATABASE']['HOST'], config['DATABASE']['USER'], config['DATABASE']['PASS']) if(db.connect()): logger.log(Logger.INFO, "Succesfully connected to database \'" + str(config['DATABASE']['NAME']) + "\'!") else: logger.log(Logger.ERROR, "Failed connecting to database \'" + str(config['DATABASE']['NAME']) + "\'!") if args.operation == 'create': logger.log(Logger.INFO, "Creating schema for database '" + str(config['DATABASE']['NAME']) + "'... ") db.execute(open(CREATE_SCHEMA_FILE, "r").read()) logger.log(Logger.INFO, "Creating schema for database '" + str(config['DATABASE']['NAME']) + "'... SUCCESS!") logger.log(Logger.INFO, "Importing data... ") users = sorted(os.listdir(args.folder)) count = 0 transp = {'walk': '1',
type=str) arg_parser.add_argument( '--userfilter', help= 'A filter on the selected users (in the format of a SQL WHERE expression).', type=str) #arg_parser.add_argument('--plot', action='store_true', help='Pass.') args = arg_parser.parse_args() db.config(name=args.dbname, host=args.dbhost, user=args.dbuser, passwd=args.dbpass) if (db.connect()): logger.log(Logger.INFO, "Succesfully connected to database \'" + args.dbname + "\'!") else: logger.log(Logger.ERROR, "Failed connecting to database \'" + args.dbname + "\'!") logger.log(Logger.ERROR, "Database status: " + db.status()) exit() tidcol_query = "ALTER TABLE " + args.dbtable + \ " ADD COLUMN " + args.tidcol + " INTEGER" users_query = "SELECT DISTINCT(anonymized_user_id) FROM " + \ args.dbtable + " :where ORDER BY anonymized_user_id" checkins_query = "SELECT id, anonymized_user_id, date_time FROM " + \ args.dbtable + " WHERE anonymized_user_id = :user_id " + \ "ORDER BY date_time ASC"
########################## MISC ########################## def print_valid_ops(): logger.log( Logger.INFO, """Valid operations: create - creates the database schema and populates basic info (no params) drop - drops the database schema (no params) init - imports data from file to database (params = checkin_file friend_file)""" ) ########################################################## ####################### ARGS CHECK ####################### if (len(sys.argv) < 3): logger.log( Logger.ERROR, "Please inform the configuration file and the desired operation!") logger.log(Logger.ERROR, "Example: python3 config_database.py config.ini op params") print_valid_ops() exit() ########################################################## ######################### PARAMS ######################### VALID_OPS = ['create', 'drop', 'init'] OPS_PARAMS = [0, 0, 2] CREATE_SCHEMA_FILE = 'sql/create_schema.sql' DROP_SCHEMA_FILE = 'sql/drop_schema.sql' INSERT_FILES = [] CONFIG_FILE = sys.argv[1]