try: opts = getopt(sys.argv[1:], 'd:') except GetoptError as error: sys.stderr.write("ERROR: {0}.\n".format(error.msg)) _print_help() sys.exit(1) for opt in opts[0]: if opt[0] == '-d': ossec_dir = opt[1] if len(opts[1]) < 1: sys.stderr.write("ERROR: Version not specified.\n") print_help() sys.exit(1) old_version = opts[1][0][1:] if opts[1][0][0] == 'v' else opts[1][0] if old_version not in versions: sys.stderr.write("ERROR: Version not supported.\n") sys.exit(0) dbpath = ossec_dir + '/var/db' if versions.index(old_version) < len(versions) - 1: print("Upgrading database") database.insert_fim(dbpath) database.insert_pm(dbpath)