def stash_humidity(humidity_value): humidity_stash = Stash("indoor_humidity") humidity_data = { 'date': datetime.datetime.utcnow().isoformat(), 'percent': humidity_value } humidity_stash.add(humidity_data)
def process_system_temperature_data(): system_temperature_stash = Stash("system_temperature") if system_temperature_stash.data: data_created = holly.send_bulk_system_temperature_data(system_temperature_stash.data) if data_created: system_temperature_stash.empty() return system_temperature_stash.close()
def process_humidity_data(): humidity_stash = Stash("indoor_humidity") if humidity_stash.data: data_created = holly.send_bulk_humidity_data(humidity_stash.data) if data_created: humidity_stash.empty() return humidity_stash.close()
def stash_temperature(temperature_value): temperature_stash = Stash("indoor_temperature") temperature_data = { 'date': datetime.datetime.utcnow().isoformat(), 'celsius': temperature_value, 'fahrenheit': utils.celsius_to_fahrenheit(temperature_value) } temperature_stash.add(temperature_data)
def process_temperature_data(): temperature_stash = Stash("indoor_temperature") if temperature_stash.data: data_created = holly.send_bulk_temperature_data(temperature_stash.data) if data_created: temperature_stash.empty() return temperature_stash.close()
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), )
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)
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))
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()
def test_git_host_cannot_be_missing_name_of_repo(): assert Stash._getStashHostname("git@stash") is None
def test_git_host_can_start_with_stash(): assert Stash._getStashHostname("[email protected]:bob") == "stash.yojoe.local"
def test_git_host_can_be_only_stash(): assert Stash._getStashHostname("git@stash:bob") == "stash"
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))
def __init__(self, archive, algorithm='lru:///', serializer='none:///'): self.stash = Stash(archive, algorithm, serializer, key_transform=(self.key_encode, self.key_decode))
def test_url_host_can_start_with_stash(): assert Stash._getStashHostname("https://stash.yojoe.local/bob") == "stash.yojoe.local"
class StashBackend(Backend): def __init__(self, archive, algorithm='lru:///', serializer='none:///'): self.stash = Stash(archive, algorithm, serializer, key_transform=(self.key_encode, self.key_decode)) @property def archive(self): return self.stash.archive @property def cache(self): return self.stash.cache def delete(self, keys): return self.stash.delete(keys) def flush(self): return self.stash.flush() def items(self): return self.stash.items() def iteritems(self): return self.stash.iteritems() def iterkeys(self): return self.stash.iterkeys() def itervalues(self): return self.stash.itervalues() def save(self): return self.stash.save() def __delitem__(self, key): return self.stash.__delitem__(key) def __getitem__(self, key): return self.stash.__getitem__(key) def __iter__(self): return self.stash.__iter__() def __len__(self): return self.stash.__len__() def __setitem__(self, key, value): return self.stash.__setitem__(key, value) def __getstate__(self): return {} def __setstate__(self, state): pass @staticmethod def key_encode(key): if type(key) is tuple: return '/'.join(key) return key @staticmethod def key_decode(key): key = str(key).split('/') if len(key) == 1: return key[0] return tuple(key)
def test_url_host_can_be_only_stash(): assert Stash._getStashHostname("https://stash/bob") == "stash"
def test_git_host_cannot_be_stashattack(): assert Stash._getStashHostname("git@stashattack:bob") is None
import logging 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, MetadataItem.year,
def test_url_host_cannot_be_stashattack(): assert Stash._getStashHostname("https://stashattack") is None
from sets import Set from getpass import getpass from simplecrypt import encrypt, decrypt stash_user = None pretty = False output = 'string' stash_server = None branch = None hookname = None hookstatus = None from_branch = None to_branch = None session = Stash() def initialize(): print '\ninitializing...' cfg = os.environ.get('HOME') + '/.stashcfg' global stash_server global stash_user _pass = None _user = None if (stash_server):
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,
def stash_system_temperature(temperature_value): system_temperature_stash = Stash("system_temperature") system_temperature_stash.add(temperature_value)