Ejemplo n.º 1
0
 def __init__(self):
     self.megaminx = megaminx.Megaminx()
     temp = tempfile.gettempdir()
     queuefile = os.path.join(temp, 'megaminx_queue')
     self.queue = Deque(directory=queuefile)
     cachedir = os.path.join(temp, 'megaminx_cache')
     self.cache = Index(cachedir)
Ejemplo n.º 2
0
 def __init__(self,
              name,
              on,
              off=None,
              trigger=3,
              release=10,
              time_limit=120):
     self.policies = Deque(trigger * ["ON"], f"/tmp/breaker/{name}")
     self.time_limit = time_limit
     self.on_func = on
     self.off_func = off
     self.release = release
     self.trigger = trigger
     self.name = name
     self.enabled = True
Ejemplo n.º 3
0
    def _initialise_forwards(self):
        temp = tempfile.gettempdir()
        queuefile = os.path.join(temp, 'megaminx_forward_queue')
        cachedir = os.path.join(temp, 'megaminx_forward_cache')

        self.forward_queue = Deque(directory=queuefile)
        self.forward_cache = Index(cachedir)
        # Check it to see if it begins with the same state
        if 'ostate' in self.forward_cache and self.forward_cache[
                'ostate'] != self.ostate:
            self.forward_queue.clear()
            self.forward_cache.clear()
        if not 'ostate' in self.forward_cache:
            with DelayedKeyboardInterrupt():
                self.forward_queue.append(self.ostate)
                self.forward_cache['ostate'] = self.ostate
Ejemplo n.º 4
0
    def initialize_cache(self, shards=None, timeout=1, queue=False):
        self.reset_cache()

        # Create a temporary directory for the cache
        self.cache_directory = mkdtemp()

        # Create a queue?
        if queue:
            self.cache = Deque(directory=self.cache_directory)
            self.queue = True
        elif shards:
            self.cache = FanoutCache(self.cache_directory,
                                     shards=shards,
                                     timeout=timeout)
            self.queue = False
        else:
            self.cache = Cache(self.cache_directory, timeout=timeout)
            self.queue = False

        return self.cache
Ejemplo n.º 5
0
           'objtype': 'network',
           'private': True,
           'remoteTraceLevel': 0,
           'remoteTraceTarget': None,
           'revision': 1,
           'routes': [],
           'rules': [{'not': False, 'or': False, 'type': 'ACTION_ACCEPT'}],
           'rulesSource': '',
           'tags': [],
           'v4AssignMode': {'zt': False},
           'v6AssignMode': {'6plane': False, 'rfc4193': False, 'zt': False}}


# has_aging = False
cache = Index(get_cachedir(dir_name='fpn_test', user_dirs=True))
net_q = Deque(get_cachedir(dir_name='net_queue', user_dirs=True))
max_age = NODE_SETTINGS['max_cache_age']
utc_stamp = datetime.datetime.now(utc)  # use local time for console

client = mock_zt_api_client()


# special test cases
def json_check(data):
    import json

    json_dump = json.dumps(data, indent=4, separators=(',', ': '))
    json_load = json.loads(json_dump)
    assert data == json_load

def _spawn_variation(disk_cache_dir, lock_file, readers, writers):
    visits = Deque(directory=str(disk_cache_dir / 'w'))
    pool = Pool(readers + writers)
    pool.map(_spawling, [(lock_file, visits, type_)
                         for type_ in ['w'] * writers + ['r'] * readers])
    return visits
Ejemplo n.º 7
0
def deque():
    disk_cache_dir_ = tempfile.mkdtemp()
    with Cache(directory=disk_cache_dir_) as dc:
        yield Deque.fromcache(dc)
    shutil.rmtree(disk_cache_dir_, ignore_errors=True)