def prepare_intrument_data_folder(instrument=INSTRUMENT_TYPE):
    """
    
    """

    # Get program directory.
    prog_dir = os.path.dirname(os.path.abspath(__file__))

    # Load new config file from master copy in /opt/dfn-software
    config_file = os.path.join(prog_dir, r'dfnstation.cfg')
    config_dict = cfg.load_config(config_file)
    config_dict['internal']['config_file'] = config_file

    # Setup new data path for this instrument session
    data_path = dfn.make_data_path(config_dict['internal']['data_directory'],
                                   secs=False,
                                   instrument=instrument)

    # Load lon, lat, alt from dedicated config file dropped by the interval service
    # rather than talking straight to microcontroller
    #location_file = os.path.join(prog_dir, r'location.cfg')
    location_file = loc.CONST_LOCATION_FNAME_DFN

    # try to update config file from location.cfg file
    try:
        location_dict = loc.load_location_file(location_file)

        if location_dict['internal']['currenttime'] == '0.0':
            print('Warning: failed to get location from ',
                  location_file,
                  ', using values from default config file ',
                  config_file,
                  sep='',
                  file=sys.stderr)
            config_dict['station']['gps_lock'] = 'N'

        else:
            config_dict['station']['lon'] = location_dict['station']['lon']
            config_dict['station']['lat'] = location_dict['station']['lat']
            config_dict['station']['altitude'] = location_dict['station'][
                'altitude']
            config_dict['station']['gps_lock'] = location_dict['station'][
                'gps_lock']

    except (Exception, SystemExit) as e:
        print('Fatal problem reading file ',
              location_file,
              ', using config values from default config file ',
              config_file,
              sep='',
              file=sys.stderr)
        config_dict['station']['gps_lock'] = 'N'

    # Save a local copy of the config file
    session_config_fname = os.path.join(data_path, 'dfnstation.cfg')
    #cfg.save_config_file(session_config_fname, config_dict)

    return data_path, session_config_fname, config_dict
Esempio n. 2
0
def creat_book():
    while True:
        try:
            return leveldb.LevelDB(load_config('BOOK_DB'))
        except:
            pass
Esempio n. 3
0
def creat_trxdb():
    while True:
        try:
            return leveldb.LevelDB(load_config('TRANSACTION_POOL_DB'))
        except:
            pass
Esempio n. 4
0
def creat_leveldb():
    while True:
        try:
            return leveldb.LevelDB(load_config('CHAIN_DB'))
        except:
            pass
Esempio n. 5
0
import socket
import leveldb
import threading
import struct
import pickle
from uuid import uuid4

from ECCSign import *
from block_chain import *
from config_handler import load_config

BUF_SIZE = 1024 * 256
HOST = load_config('P2P_HOST')
PORT = load_config('P2P_LISTENING_PORT')
LOCK = threading.Lock()
NOW = None
db = None
tdb = None
ndb = None

FIND_NEW_BLOCK = threading.Event()
BOARDCAST_EVENT = threading.Event()
SYNC_FINISH_EVENT = threading.Event()
MINER_ADDRESS = None

generate_minerid = lambda: str(uuid4())
generate_trxid = lambda: uuid4().hex
MINER_ID = generate_minerid()
MINER_ADDRESS = "1G1NpejXSEtfpeR3E9qqmvs2hTX4tLMbSH"
CON = socket.socket(family=socket.AF_INET, type=socket.SOCK_STREAM)
CON.connect((HOST, PORT))
Esempio n. 6
0
def creat_tlog():
    while True:
        try:
            return leveldb.LevelDB(load_config('TRANSACTION_LOG'))
        except:
            pass
Esempio n. 7
0
import struct
import demjson
import leveldb
import threading
from time import time
from uuid import uuid4
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet.endpoints import TCP4ClientEndpoint, connectProtocol

from config_handler import load_config

LISTENING_PORT = load_config('P2P_LISTENING_PORT')
CONNECTION_PORT = load_config('P2P_CONNECTION_PORT')
HOST = load_config('P2P_HOST')
db = None
ndb = None
tlog = None

generate_nodeid = lambda: str(uuid4())
LOCK = threading.Lock()

HEAD = None


def creat_leveldb():
    while True:
        try: