示例#1
0
def dosave(msg):
    if msg.entity == 'pool':
        #save the new named pool
        pool_type = name = url = user = priority = None
        for pair in msg.values:
            if 'pool_type' in pair:
                pool_type = pair['pool_type']
            if 'name' in pair:
                name = pair['name']
            if 'url' in pair:
                url = pair['url']
            if 'user' in pair:
                user = pair['user']
            if 'priority' in pair:
                priority = pair['priority']
        pool = Pool(pool_type, name, url, user, priority)
        sch = PoolSchema()
        pools = PoolRepository()
        pools.add(pool,
                  COMPONENTSAVE.app.getconfigfilename('config/pools.conf'),
                  sch)

        #update the known pools
        for known in COMPONENTSAVE.app.knownpools():
            if pool.is_same_as(known):
                oldkey = known.key
                known.named_pool = pool
                #this changes the pool key!
                known.user = pool.user
                #update the known pool (with new key)
                COMPONENTSAVE.app.update_pool(oldkey, known)
示例#2
0
    def save_pool(self, pool: Pool):
        sch = PoolSchema()
        pools = PoolRepository()
        pools.add(pool, self.getconfigfilename('config/pools.conf'), sch)

        #update the known pools
        for known in self.knownpools():
            if pool.is_same_as(known):
                oldkey = known.key
                known.named_pool = pool
                #this changes the pool key!
                known.user = pool.user
                #update the known pool (with new key)
                self.update_pool(oldkey, known)
示例#3
0
 def initpoolcache(self):
     if self.__cache.get(CacheKeys.pools) is None:
         spools = PoolRepository().readrawfile(
             self.getconfigfilename('config/pools.conf'))
         self.tryputcache(CacheKeys.pools, spools)
     for pool in self.pools():
         #pool isinstance of Pool
         availablepool = AvailablePool(pool.pool_type, pool, pool.url,
                                       pool.user, pool.password,
                                       pool.priority)
         minerpool = MinerPool(miner=None, priority=0, pool=availablepool)
         self.putpool(pool)
         self.add_pool(minerpool)
示例#4
0
    def initminercache(self):
        '''put known miners into cache'''
        if self.__cache.get(CacheKeys.pools) is None:
            spools = PoolRepository().readrawfile(self.getconfigfilename('config/pools.conf'))
            self.tryputcache(CacheKeys.pools, spools)

        if self.__cache.get(CacheKeys.miners) is None:
            sminers = MinerRepository().readrawfile(self.getconfigfilename('config/miners.conf'))
            self.tryputcache(CacheKeys.miners, sminers)

        for miner in self.miners():
            #status is not persisted yet so init from name
            if miner.is_manually_disabled():
                miner.status = MinerStatus.Disabled
            if self.getminer(miner) is None:
                self.putminer(miner)
示例#5
0
 def pools(self):
     '''configured pools'''
     pools = PoolRepository().readpools(self.getconfigfilename('config/pools.conf'))
     return pools
示例#6
0
'''test writing to config file'''
import json
from marshmallow import pprint
from domain.mining import Pool
from domain.rep import PoolRepository
from messaging.schema import PoolSchema

SCH = PoolSchema()
POOLS = PoolRepository()
SAVEDPOOLS = POOLS.readpools("backend/config/pools.conf")

POOL1 = Pool('Antminer 1', 'Name 1', 'http://url1', 'user1.', 1)
#pools.add(pool1,PoolSchema())
POOL2 = Pool('Antminer 2', 'Name 2', 'http://url2', 'user2.', 2)
#pools.add(pool2,PoolSchema())
SAVEDPOOLS.append(POOL1)
SAVEDPOOLS.append(POOL2)

JSON_POOLS = [SCH.dump(k).data for k in SAVEDPOOLS]

FORMATTED_JSON = json.dumps(JSON_POOLS,
                            sort_keys=True,
                            indent=4,
                            ensure_ascii=False)
pprint(FORMATTED_JSON)
input('any key')
示例#7
0
 def test_rep_pool_repository(self):
     homedirectory = os.path.dirname(__file__)
     config = os.path.join(homedirectory, '../backend/config/pools.conf')
     rep = PoolRepository()
     pools = rep.readpools(config)
     self.assertTrue(pools)