示例#1
0
文件: stash.py 项目: jayvdb/dns-cache
    def __init__(
        self,
        filename=None,
        archive=None,
        algorithm=AlgorithmNone,
        serializer="pickle:///?protocol=4",
        cache="memory:///",
        *args,
        **kwargs
    ):
        # serializer='jsonpickle:///' also works
        assert filename or archive
        super(StashCacheBase, self).__init__(*args, **kwargs)

        if not archive:
            # https://github.com/fuzeman/stash.py/issues/2
            filename = os.path.relpath(filename)
            archive = "sqlite://../{}?table=dns".format(filename)
        elif not archive.startswith("memory:") and archive.find("?") == -1:
            archive += "?table=dns"

        self.data = Stash(
            archive,
            algorithm,
            serializer,
            cache,
            key_transform=(key_encode, key_decode),
        )
示例#2
0
    def __init__(
            self,
            nplayers=2,
            onmove=0,
            systems=None,
            stash=None,
            alive=None,  # list of player statuses, None for not yet created
    ):
        self.nplayers = nplayers
        self.onmove = onmove

        if systems is None:
            systems = []
            alive = [None] * nplayers
        self.systems = systems

        if stash is None:
            stash = Stash(nplayers + 1)
            for sys in systems:
                for m in sys.markers:
                    stash.request(m)
                for s in sys.ships:
                    stash.request(s.piece)
        self.stash = stash

        if alive is None:
            # This assumes that players with no home have been eliminated
            alive = [False] * nplayers
            for sys in systems:
                if not sys.home is None:
                    alive[sys.home] = True

        self.alive = alive
        # This turn will be built one event as a time
        self.curTurn = Turn(self)
示例#3
0
    def _construct(key, serializer=DEFAULT_SERIALIZER):
        # Parse `key`
        fragments = key.split('.')

        if len(fragments) != 2:
            raise ValueError('Invalid "key" format')

        database, table = tuple(fragments)

        # Construct cache
        return Stash(ApswArchive(Database.cache(database), table),
                     'lru:///?capacity=500&compact_threshold=1500',
                     serializer=serializer,
                     key_transform=(lambda k: str(k), lambda k: k))
示例#4
0
    def __init__(self, channels=[0], nb_taps=3, do_save_data=False):
        """See if we can find a valid biomonitor device"""
        Thread.__init__(self)
        self.do_save_data = do_save_data
        self.port = None
        self.go = True
        self.last_time = time()
        self.nb_taps = nb_taps

        # self.allowed_channels = [0, 1]
        self.allowed_channels = channels

        # Connect to the hardware.
        self.connect_to_board()

        # Connect to the juffer file.
        self.buffer = {}
        do_filter = self.nb_taps != 0
        for chn in self.allowed_channels:
            self.buffer[chn] = Stash(
                self.nb_taps,
                demand_uniqueness=True,
                do_filter=do_filter,
                save_data=self.do_save_data,
            )

        # Define the workers.
        self.q = Queue()
        nb_workers = len(self.allowed_channels)
        target = self.save_data
        for _ in range(nb_workers):
            worker = Thread(target=target, args=(self.q, ), daemon=True)
            worker.start()

        # Start local.
        self.start()
示例#5
0
logging.basicConfig(level=logging.DEBUG)

from plex import Plex
from plex_database.library import Library
from plex_database.matcher import Matcher
from plex_database.models import LibrarySection, LibrarySectionType, MediaItem, MetadataItem

from stash import Stash
import os
import sys
import time

# Build caches
cache_dir = os.path.abspath('cache')
matcher_cache = Stash('apsw:///cache.db?table=matcher',
                      'lru:///?capacity=500&compact_threshold=1500',
                      'msgpack:///')


def fetch_movies(library):
    movies = {}

    # Retrieve movie sections
    sections = library.sections(LibrarySectionType.Movie,
                                LibrarySection.id).tuples()

    # Fetch movies with account settings
    elapsed, items = measure(library.movies.mapped,
                             sections,
                             fields=[
                                 MetadataItem.added_at, MetadataItem.title,
示例#6
0
if __name__ == '__main__':
    if 0:
        # Ship test
        s = Ship(Piece(3, color.BLUE), 0)
        drawShip(s, 0, 0)
        plt.show()
    if 0:
        # Ship test
        marker = Piece(3, color.BLUE)
        drawMarker(marker, 0, 0)
        plt.show()
    if 0:
        # Stash test
        from stash import Stash
        stash = Stash(3)
        drawStash(stash)
        plt.xlim([-1, 5])
        plt.ylim([-2, 8])
        plt.show()
    if 1:
        from hwstate import HWState
        from text2turn import applyTextTurn as att
        state = HWState()
        i = 0
        att('homeworld r2 b1 g3 Alice', state)
        i += 1
        drawState(state, "../stateImages/game{}.png".format(i))
        att('homeworld b3 y1 g3 Bob', state)
        i += 1
        drawState(state, "../stateImages/game{}.png".format(i))
示例#7
0
 def __init__(self, archive, algorithm='lru:///', serializer='none:///'):
     self.stash = Stash(archive,
                        algorithm,
                        serializer,
                        key_transform=(self.key_encode, self.key_decode))