Пример #1
0
from flask import Response
import io
import os
from unittest import TestCase
from mapadroid.db.DbFactory import DbFactory
from mapadroid.tests.test_utils import upload_rgc, mimetype, filepath_rgc
from mapadroid.utils.logging import initLogging
from mapadroid.mad_apk import get_storage_obj, APK_Arch, APK_Type, MAD_Package, MAD_Packages, MAD_APKS, get_apk_status,\
    file_generator
from mapadroid.utils.walkerArgs import parseArgs


args = parseArgs()
initLogging(args)


class StorageBase(TestCase):
    cleanup_tables = ['mad_apk_autosearch', 'mad_apks']

    def setUp(self):
        self.storage_init()
        self.db_wrapper, self.db_pool_manager = DbFactory.get_wrapper(args)
        try:
            storage_type = self.storage_type
        except AttributeError:
            storage_type = 'fs'
        if storage_type == 'fs':
            args.apk_storage_interface = 'fs'
        else:
            args.apk_storage_interface = 'db'
        (self.storage_manager, self.storage_elem) = get_storage_obj(args, self.db_wrapper)
Пример #2
0
def main():
    args = Args()
    initLogging(args)

    if len(sys.argv) != 2:
        logger.error("usage: remove_all_spawns_within_geofence.py GEOFENCE_FILENAME")
        sys.exit(1)

    LocationWithID = collections.namedtuple('Location', ['lat', 'lng', 'spawnpoint'])

    geofence_filename = sys.argv[1]
    # print("Argument: '%s'" % (geofence_filename))
    # no .txt, add it
    if ".txt" not in geofence_filename:
        geofence_filename = geofence_filename + ".txt"
    # no / in filename, probably not an absolute path, append standard MAD path
    if "/" not in geofence_filename:
        geofence_filename = "../configs/geofences/" + geofence_filename
    logger.info("Trying to use file: {}", geofence_filename)
    if not os.path.isfile(geofence_filename):
        logger.error("Geofence file {} not found, exit", geofence_filename)
        sys.exit(1)

    geofence_helper = GeofenceHelper(geofence_filename, None)
    minLat, minLon, maxLat, maxLon = geofence_helper.get_polygon_from_fence()
    query = (
        "SELECT latitude, longitude, spawnpoint "
        "FROM trs_spawn "
        "WHERE (latitude >= {} AND longitude >= {} "
        "AND latitude <= {} AND longitude <= {}) "
    ).format(minLat, minLon, maxLat, maxLon)

    delete_query = (
        "DELETE FROM trs_spawn "
        "WHERE spawnpoint = {} "
    )

    list_of_coords: List[LocationWithID] = []

    dbip = get_value_for(r'\s+dbip:\s+([^\s]+)')
    dbport = get_value_for(r'\s+dbport:\s+([^.\s]*)', False)
    if dbport is None:  # if dbport is not set, use default
        dbport = '3306'
    dbusername = get_value_for(r'\s+dbusername:\s+([^.\s]*)')
    dbpassword = get_value_for(r'\s+dbpassword:\s+([^.\s]*)')
    dbname = get_value_for(r'\s+dbname:\s+([^.\s]*)')

    # print("Successfully parsed config.ini, using values:")
    # print("dbport: %s" % dbport)
    # print("dbusername: %s" % dbusername)
    # print("dbname: %s" % dbname)
    # print("dbip: %s" % dbip)

    connection = mysql.connector.connect(
        host=dbip,
        port=dbport,
        user=dbusername,
        passwd=dbpassword,
        database=dbname)
    cursor = connection.cursor()

    cursor.execute(query)
    res = cursor.fetchall()
    for (latitude, longitude, spawnpoint) in res:
        list_of_coords.append(LocationWithID(latitude, longitude, spawnpoint))

    geofenced_coords = geofence_helper.get_geofenced_coordinates(list_of_coords)
    spawnpointcount = len(geofenced_coords)
    for coords in geofenced_coords:
        sql = delete_query.format(coords.spawnpoint)
        cursor.execute(sql)
        # print(sql)

    connection.commit()

    cursor.close()
    connection.close()
    logger.success("Done, deleted {} spawnpoints", spawnpointcount)