Exemple #1
0
 def setUp(self):
     website = Website([
         '--www_root', WWW_ROOT, '--project_root', PROJECT_ROOT,
         '--show_tracebacks', b'yes'
     ])
     redis.flushdb()
     self.client = TestClient(website)
Exemple #2
0
 def setUp(self):
     website = Website([ '--www_root', WWW_ROOT
                       , '--project_root', PROJECT_ROOT
                       , '--show_tracebacks', b'yes'
                        ])
     redis.flushdb()
     self.client = TestClient(website)
Exemple #3
0
 def test_check_successful_run(self):
     redis.flushdb()
     self.assertEqual(0, redis.dbsize())
     import_data()
     self.assertEqual(2, redis.dbsize())
     self.assertEqual(10, len(redis.lrange('warehouse_whcorp', 0, -1)))
     self.assertEqual(
         10, len(redis.lrange('warehouse_american_storage', 0, -1)))
Exemple #4
0
def redis():
    """ Redis

    We uses a normal(not asyncio) version of redis lib here because of some
    issues using asyncio version and yield fixtures.
    """
    import redis

    redis = redis.StrictRedis(host='127.0.0.1', port=6379)
    yield redis
    redis.flushdb()
Exemple #5
0
def exit_wss(redis):
    db = connectDB()
    log.logger.info("exit web socket server process!!!")
    if db:
        ret = db.update("Device_Status_Basic", {"dev_state": 0}, None)
        if ret is False:
            log.logger.error("set all device status to off-line failed!")
        else:
            log.logger.info("set all device status to off-line success!")
        db.update("System_Config_Network", {"up_ok": 0}, None)
        closeDB(db)
        APSideCommHandler.msg.db = None
    else:
        log.logger.error("db is null")
    if redis:
        redis.flushdb()
    else:
        log.logger.error("redis is null")
    APSideCommHandler.executor.shutdown()
Exemple #6
0
 def delete(redis, name, task_id):
     """
     Function to delete entries (tasks or whole task lists) from Redis
     :param redis: Redis connection
     :param name: task name
     :param task_id: task id
     """
     if task_id == 'all' and name is None:
         # db clear
         redis.flushdb()
         logging.info("All the database was successfully cleared")
         return 0
     elif name and task_id == 'all':
         # deleting a single task list
         redis.delete(name)
         logging.info("Task list was successfully deleted")
         return 0
     else:
         # deleting a single task from concrete list
         tasks = List.pull_from_redis(redis, name)
         del tasks[str(task_id)]
         List.push_to_redis(redis, name, tasks)
         logging.info("The task was successfully deleted")
         return 0
    for url in urls:
        pre = whois_pre_options.get(url,  None)
        post = whois_post_options.get(url,  None)
        keepalive = whois_keepalive_options.get(url,  None)
        port = whois_port_options.get(url,  None)
        if pre:
            redis.set(url + pre_option_suffix, pre)
        if post:
            redis.set(url + post_option_suffix, post)
        if keepalive:
            redis.set(url + keepalive_option_suffix, keepalive)
        if port:
            redis.set(url + port_option_suffix, port)

redis = redis.Redis(port = int(config.get('redis','port_master')), db=4)
redis.flushdb()
urls = set()

regex_ipv4 = '([^#][\d./]*)'
regex_ipv6 = '([^#][\d\w:/]*)'
regex_dns  = '([^#][\d\w.]*)'

f = open('ip_del_list').read()
assignations = re.findall('[\n]*' + regex_ipv4 + '\t' + regex_dns + '\s*',f)
insert(assignations)

f = open('ip6_del_list').read()
assignations = re.findall('[\n]*' + regex_ipv6 + '\t' + regex_dns + '\s*',f)
insert(assignations)

# Self defined servers
Exemple #8
0
def die():
    redis.flushdb()
    return "All is dead!"
Exemple #9
0
 def tearDown(self):
     redis.flushdb()
Exemple #10
0
def cache_clear():
    '''cache - flush the entire cache db'''
    redis.flushdb()
Exemple #11
0
    def act(self, game):

        restricted_zones = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0), (11, 0), (12, 0), (13, 0), (14, 0), (15, 0), (16, 0), (17, 0), (18, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (12, 1), (13, 1), (14, 1), (15, 1), (16, 1), (17, 1), (18, 1), (0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (14, 2), (15, 2), (16, 2), (17, 2), (18, 2), (0, 3), (1, 3), (2, 3), (16, 3), (17, 3), (18, 3), (0, 4), (1, 4), (2, 4), (16, 4), (17, 4), (18, 4), (0, 5), (1, 5), (17, 5), (18, 5), (0, 6), (1, 6), (17, 6), (18, 6), (0, 7), (18, 7), (0, 8), (18, 8), (0, 9), (18, 9), (0, 10), (18, 10), (0, 11), (18, 11), (0, 12), (1, 12), (17, 12), (18, 12), (0, 13), (1, 13), (17, 13), (18, 13), (0, 14), (1, 14), (2, 14), (16, 14), (17, 14), (18, 14), (0, 15), (1, 15), (2, 15), (16, 15), (17, 15), (18, 15), (0, 16), (1, 16), (2, 16), (3, 16), (4, 16), (14, 16), (15, 16), (16, 16), (17, 16), (18, 16), (0, 17), (1, 17), (2, 17), (3, 17), (4, 17), (5, 17), (6, 17), (12, 17), (13, 17), (14, 17), (15, 17), (16, 17), (17, 17), (18, 17), (0, 18), (1, 18), (2, 18), (3, 18), (4, 18), (5, 18), (6, 18), (7, 18), (8, 18), (9, 18), (10, 18), (11, 18), (12, 18), (13, 18), (14, 18), (15, 18), (16, 18), (17, 18), (18, 18), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1), (5, 2), (6, 2), (12, 2), (13, 2), (3, 3), (4, 3),(14, 3), (15, 3), (3, 4), (15, 4), (2, 5), (16, 5), (2, 6), (16, 6), (1, 7), (17, 7),(1, 8), (17, 8), (1, 9), (17, 9), (1, 10), (17, 10), (1, 11), (17, 11), (2, 12), (16, 12),(2, 13), (16, 13), (3, 14), (15, 14), (3, 15), (4, 15), (14, 15), (15, 15), (5, 16), (6, 16),(12, 16), (13, 16), (7, 17), (8, 17), (9, 17), (10, 17), (11, 17)]


        locs = self.close_locs()
        robots = game['robots']

        # Calculate distance:

        def distance(loc1, loc2):
            return abs(loc1[0] - loc2[0]) + abs(loc1[1] - loc2[1])

        # Check current turn and remove previous move log:

        if redis.exists('turn'):
            if int(redis.get('turn')) != game['turn']:
                redis.flushdb()
                redis.set('turn', game['turn'])
        else:
            redis.flushdb()
            redis.set('turn', 1)

        # Look up friendly robots moves and store mine:

        def prevent_collision(loc):
            if redis.exists(loc):
                return False
            else:
                redis.set(loc, '1')
                return True

    # Find the closest enemy for me:

        def find_closest_enemy(loc):
            distance_list = {}

            # Loop over enemies:

            for enemy in robots:
                if len(distance_list) > 0:
                    if distance(loc, enemy) \
                        < distance_list[distance_list.keys()[0]]:
                        distance_list[enemy] = distance(loc, enemy)
                else:
                    distance_list[enemy] = distance(loc, enemy)

            # Return closest enemy

            if len(distance_list) > 0:
                return distance_list.keys()[0]

    # Look up the best available path to get to this enemy:

        def find_best_path(target):
            path_list = {}

            # Loop over paths:

            for loc in locs:
                if len(path_list) > 0:
                    if path_list[path_list.keys()[0]] > distance(loc,
                            target):
                        if prevent_collision(loc):
                            if loc not in restricted_zones:
                                path_list.clear()
                                path_list[loc] = distance(loc, target)
                else:
                    path_list[loc] = distance(loc, target)

            # Return best path
	    # Should be sorted....

            if len(path_list) > 0:
                return path_list.keys()[0]

        for loc in locs:

            # Should I suicide?

            if self.hp < 11:
                print 'Got orders:  suicide'
                return ['suicide']
            elif robots.get(loc):

            # Can I attack?

                print 'Got orders: attack'
                return ['attack', loc]
            elif find_closest_enemy(loc):

        # Are we past turn 10?
        # elif game['turn'] > 10:
        # print "Got orders: move"
        # best path here

            # Can I move?

                if find_best_path:
                    print 'Got orders: march'
                    return ['move',
                            find_best_path(find_closest_enemy(loc))]
            else:

            # I will guard

                print 'Got orders: guard'
                return ['guard']
def init_redis(redis, capacity, error_rate):
    redis.flushdb()
    ChatNode.zero_redis_filter(redis, capacity, error_rate, force=False)
    return
def startup():
    redis.flushdb()
    redis.set('total_players', '0')
    redis.set('leader', '1')
    redis.set('next_id',0)
    redis.set('state', 'find')
Exemple #14
0
def flushdb():
    """TBD"""
    _flash_log('Database cleared')
    redis.flushdb()
    return redirect(url_for('logout'))
import redis
import pika
import time

redis = redis.Redis()
redis.flushdb()
rabbit_conn = pika.BlockingConnection(
    pika.ConnectionParameters(host='localhost'))
channel = rabbit_conn.channel()

channel.queue_declare(queue='team6_queue', durable=True)

def get_values(message):
    split_mes = message.split()
    index = int(split_mes[0][:-1])
    text = split_mes[1] + ' ' + split_mes[2]
    mes_time = int(split_mes[3])
    return index, text, mes_time

def callback(ch, method, properties, body):
    print("Receiver_three got the message!")
    print(body.decode('utf-8'))
    index, text, mes_time = get_values(body.decode('utf-8'))

    time.sleep(int(mes_time))

    redis.hmset(f"MESG_{index}",
                {"TEXT": text,
                 "TIME": mes_time,
                 "I": index})
Exemple #16
0
    def act(self, game):

        restricted_zones = [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0),
                            (6, 0), (7, 0), (8, 0), (9, 0), (10, 0), (11, 0),
                            (12, 0), (13, 0), (14, 0), (15, 0), (16, 0),
                            (17, 0), (18, 0), (0, 1), (1, 1), (2, 1), (3, 1),
                            (4, 1), (5, 1), (6, 1), (12, 1), (13, 1), (14, 1),
                            (15, 1), (16, 1), (17, 1), (18, 1), (0, 2), (1, 2),
                            (2, 2), (3, 2), (4, 2), (14, 2), (15, 2), (16, 2),
                            (17, 2), (18, 2), (0, 3), (1, 3), (2, 3), (16, 3),
                            (17, 3), (18, 3), (0, 4), (1, 4), (2, 4), (16, 4),
                            (17, 4), (18, 4), (0, 5), (1, 5), (17, 5), (18, 5),
                            (0, 6), (1, 6), (17, 6), (18, 6), (0, 7), (18, 7),
                            (0, 8), (18, 8), (0, 9), (18, 9), (0, 10),
                            (18, 10), (0, 11), (18, 11), (0, 12), (1, 12),
                            (17, 12), (18, 12), (0, 13), (1, 13), (17, 13),
                            (18, 13), (0, 14), (1, 14), (2, 14), (16, 14),
                            (17, 14), (18, 14), (0, 15), (1, 15), (2, 15),
                            (16, 15), (17, 15), (18, 15), (0, 16), (1, 16),
                            (2, 16), (3, 16), (4, 16), (14, 16), (15, 16),
                            (16, 16), (17, 16), (18, 16), (0, 17), (1, 17),
                            (2, 17), (3, 17), (4, 17), (5, 17), (6, 17),
                            (12, 17), (13, 17), (14, 17), (15, 17), (16, 17),
                            (17, 17), (18, 17), (0, 18), (1, 18), (2, 18),
                            (3, 18), (4, 18), (5, 18), (6, 18), (7, 18),
                            (8, 18), (9, 18), (10, 18), (11, 18), (12, 18),
                            (13, 18), (14, 18), (15, 18), (16, 18), (17, 18),
                            (18, 18), (7, 1), (8, 1), (9, 1), (10, 1), (11, 1),
                            (5, 2), (6, 2), (12, 2), (13, 2), (3, 3), (4, 3),
                            (14, 3), (15, 3), (3, 4), (15, 4), (2, 5), (16, 5),
                            (2, 6), (16, 6), (1, 7), (17, 7), (1, 8), (17, 8),
                            (1, 9), (17, 9), (1, 10), (17, 10), (1, 11),
                            (17, 11), (2, 12), (16, 12), (2, 13), (16, 13),
                            (3, 14), (15, 14), (3, 15), (4, 15), (14, 15),
                            (15, 15), (5, 16), (6, 16), (12, 16), (13, 16),
                            (7, 17), (8, 17), (9, 17), (10, 17), (11, 17)]

        locs = self.close_locs()
        robots = game['robots']

        # Calculate distance:

        def distance(loc1, loc2):
            return abs(loc1[0] - loc2[0]) + abs(loc1[1] - loc2[1])

        # Check current turn and remove previous move log:

        if redis.exists('turn'):
            if int(redis.get('turn')) != game['turn']:
                redis.flushdb()
                redis.set('turn', game['turn'])
        else:
            redis.flushdb()
            redis.set('turn', 1)

        # Look up friendly robots moves and store mine:

        def prevent_collision(loc):
            if redis.exists(loc):
                return False
            else:
                redis.set(loc, '1')
                return True

    # Find the closest enemy for me:

        def find_closest_enemy(loc):
            distance_list = {}

            # Loop over enemies:

            for enemy in robots:
                if len(distance_list) > 0:
                    if distance(loc, enemy) \
                        < distance_list[distance_list.keys()[0]]:
                        distance_list[enemy] = distance(loc, enemy)
                else:
                    distance_list[enemy] = distance(loc, enemy)

            # Return closest enemy

            if len(distance_list) > 0:
                return distance_list.keys()[0]

    # Look up the best available path to get to this enemy:

        def find_best_path(target):
            path_list = {}

            # Loop over paths:

            for loc in locs:
                if len(path_list) > 0:
                    if path_list[path_list.keys()[0]] > distance(loc, target):
                        if prevent_collision(loc):
                            if loc not in restricted_zones:
                                path_list.clear()
                                path_list[loc] = distance(loc, target)
                else:
                    path_list[loc] = distance(loc, target)

            # Return best path
# Should be sorted....

            if len(path_list) > 0:
                return path_list.keys()[0]

        for loc in locs:

            # Should I suicide?

            if self.hp < 11:
                print 'Got orders:  suicide'
                return ['suicide']
            elif robots.get(loc):

                # Can I attack?

                print 'Got orders: attack'
                return ['attack', loc]
            elif find_closest_enemy(loc):

                # Are we past turn 10?
                # elif game['turn'] > 10:
                # print "Got orders: move"
                # best path here

                # Can I move?

                if find_best_path:
                    print 'Got orders: march'
                    return ['move', find_best_path(find_closest_enemy(loc))]
            else:

                # I will guard

                print 'Got orders: guard'
                return ['guard']
Exemple #17
0
 def tearDown(self):
     redis.flushdb()