def process(cfg, parms):
    """ Product processing state flow management and fulfilment

    Args:
        cfg (dict): environmental configuration
        parms (dict): processing request options

    Returns:
        dict: execution status, resources used, and metadata
    """

    # Verify work request schema
    parms = schema.load(parms)

    # Make a sub-directory
    bucket_name = get_product_bucket(parms, cfg.get('output_bucket_fmt'))

    # Initialize the processing directory.
    directories = staging.initialize_processing_directory(cfg.get('work_dir'), bucket_name)

    # Build the product name
    product_name = get_product_name(parms['input_name'],
                                    cfg.get('output_filename_fmt'))

    # Stage the required input data
    staging.stage_input_data(download_urls=parms['input_urls'],
                             staging=directories.get('stage'),
                             destination=directories.get('work'),
                             unpack=cfg.get('auto_unpack_files'),
                             remove_staged=cfg.get('keep_intermediate','').lower() != 'false')

    shell_sequence = providers.sequence(parms['products'][0], product_id=parms['input_name'])
    logging.warning(shell_sequence)

    results = list()
    for cmd in shell_sequence.split(';'):
        r = utilities.execute_cmd(cmd, directories.get('work'))
        r.update(utilities.snapshot_resources(log=False))
        results.append(r)

    # Remove science products and intermediate data not requested
    cleanup_work_dir()

    # Customize products
    customize_products()

    # Generate statistics products
    generate_statistics()

    # Reformat product
    reformat_products()

    # Package and deliver product
    destination_product, destination_cksum = distribute_product()

    # Remove the product directory
    # Free disk space to be nice to the whole system.
    remove_product_directory(directories['base'])

    return results
Exemple #2
0
    def __init__(self):
        self.prefix = cfg.get('mqtt.prefix', '')

        self.client = mqtt_client.Client()
        self.client.connect(cfg.get('mqtt.host', 'localhost'),
                            cfg.get('mqtt.port', 1883), 60)
        # mandatory loop for MQTT
        self.client.loop_start()
Exemple #3
0
def handle(request, db):
    index = str([request.path, request.query])
    if index in cache:
        if time.time() - cache[index][0] < cfg.get('cache_web'):
            print(("{ts} {ip} {path} {query} [cached]".format(
                ts=datetime.now().strftime('%D %T'),
                    ip=request.clientip,
                    path=request.path,
                    query=request.query,
            )))
            return cache[index][1]
    print(("{ts} {ip} {path} {query}".format(
        ts=datetime.now().strftime('%D %T'),
            ip=request.clientip,
            path=request.path,
            query=request.query,
    )))
    # Handle all errors
    try:
        result = safe_handle(request, db)
        if result.cache:
            cache[index] = (time.time(), result)
        return result
    except:
        traceback.print_exc()
        return WebResponse(
            "<h2 class='center'>The server has encountered an error.</h2>",
            title=Response.HTTP_Codes[500],
            status=500)
    def make_single(self, specific):
        if specific in redeclipse().modes:
            mint = redeclipse().modes[specific]
        else:
            try:
                mint = int(specific)
            except TypeError:
                return {'Error': 'Mode does not exist'}
        if mint not in list(range(len(redeclipse().modestr))):
            return {}
        ret = {
            "id": mint,
            "name": redeclipse().modestr[mint],
            "corename": redeclipse().cmodestr[mint],
            "recentgames": {},
            }
        gamerows = list(self.db.execute(
            """SELECT * FROM games
            WHERE mode = re_mode(id, '%s')""" % ret["corename"]))
        ret["games"] = [r[0] for r in gamerows]

        gs = dbselectors.get("game", self.db)
        gs.flags_none()
        gs.weakflags(['players'], True)

        # Recent Games
        if self.flags['recentgames']:
            num = self.q.qint('recentgames', cfg.get('recent'))
            for row in utils.sliceneg(list(reversed(gamerows)), num):
                game = gs.fromrow(row)
                ret["recentgames"][game["id"]] = game

        return ret
def tick(db):
    for index in cache:
        if time.time() - cache[index][0] > cfg.get('cache_ranks'):
            with db:
                cache[index][0] = time.time()
                cache[index][1].db = db
                cache[index][1].update()
 def __init__(self):
     self.lasttick = 0
     self.path = '%s/%s' % (cfg.home, cfg.get("sqlitedb"))
     self.httpd = make_server(cfg.get("host"), cfg.get("port"),
         httpd(self),
         handler_class=httphandler)
     self.db = db.DB(self.path)
     self.tick()
     # This will start the overview caches
     with self.db:
         web.displays.displays['overview'].multi(None, self.db)
     # Start the Daemon Thread
     thread = Thread(target=Server.do_http, args=(self, ))
     thread.setDaemon(True)
     thread.start()
     print("Server running, cache started.")
 def single(self, specific=None):
     specific = self.specific if specific is None else specific
     index = str([self.name, 'single',
         list(self.q.items()), self.flags, specific])
     if index not in cache or (
         time.time() - cache[index][0] > cfg.get('cache_selectors')):
             cache[index] = (time.time(), self.make_single(specific))
     return cache[index][1]
 def vlimit(self, i="game"):
     if "no-vlimit" in self.q:
         return "1 = 1"
     return """%s IN (SELECT game FROM game_servers
     WHERE %s)""" % (i,
         ' OR re_verin(version, '.join(['1 = 0'] + [
             ("'%s', '%s')" % (x[0], x[1]))
             for x in cfg.get('countversions')]),
         )
    def __init__(self, DB, Merra, Extract, log):

        self.DB = DB
        self.Merra = Merra
        self.Extract = Extract
        self.log = log

        if cfg[YOUR_LOCAL_HDFFILE_DIR_PATH] is not None:
            return

        if cfg.has_key(FTP_HOST_ADDR) and cfg.get(FTP_HOST_ADDR) is not None:
            self.host = cfg[FTP_HOST_ADDR]
        else:
            self.host = 'goldsmr2.sci.gsfc.nasa.gov'  # '169.154.132.64' (Both are same. Ping this web addr, you will get ip addr)

        if cfg.has_key(MERRA_DATA_DOWNLOAD_DIR_PATH) and cfg.get(
                MERRA_DATA_DOWNLOAD_DIR_PATH) is not None:
            self.download_path = cfg[MERRA_DATA_DOWNLOAD_DIR_PATH]
        else:
            self.download_path = './merra_downloaded_data'

        if cfg.has_key(FTP_DEBUG_LEVEL) and cfg.get(
                FTP_DEBUG_LEVEL) is not None:
            self.FTP_DEBUG_LEVEL = cfg[FTP_DEBUG_LEVEL]
        else:
            self.FTP_DEBUG_LEVEL = 1

        # NASA asks for email address as password for downloading
        if cfg.has_key(USER_EMAIL_ADDR) and cfg.get(
                USER_EMAIL_ADDR) is not None:
            self.passwd = cfg[USER_EMAIL_ADDR]
        else:
            self.passwd = '*****@*****.**'

        self.login = '******'

        self.directory = ''  # A temp variable - keeps current directory of the ftp server
        self.dir_list = []  # List of sub directory
        self.hdffile_list = []  # List of HDF file

        # For managing file transfers
        self.monitor_interval = 2  # seconds (thread will notify the status of download after every THIS seconds)
        self.ptr = None  # Used to calculate size of downloaded file
        self.waiting = True  # Used for thread

        # If the connection dies, wait this long before reconnecting
        if cfg.has_key(RETRY_TIMEOUT) and cfg.get(RETRY_TIMEOUT) is not None:
            self.retry_timeout = cfg[RETRY_TIMEOUT]
        else:
            self.retry_timeout = 15

        # In case of download/connection failure, number of max tries to download/reconnection
        if cfg.has_key(MAX_ATTEMPTS_TO_DOWNLOAD) and cfg.get(
                MAX_ATTEMPTS_TO_DOWNLOAD) is not None:
            self.max_attempts = cfg[MAX_ATTEMPTS_TO_DOWNLOAD]
        else:
            self.max_attempts = 11

        # sets self.conn
        self.connect()
Exemple #10
0
 def on_post(self, req, resp):
     try:
         if req.content_length:
             body = json.load(req.stream)
         exc = processor.process(cfg.get('processing', lower=True), body)
         resp.body = exc
         resp.status = falcon.HTTP_200
     except Exception as exc:
         logging.error('Server Error: %s', exc.message)
         logging.debug('Server Error: %s', exc.message, exc_info=1)
         resp.body = {"Sever Error": exc.message}
         resp.status = falcon.HTTP_500
     resp.body = json.dumps(resp.body)
 def tick(self):
     rankselectors.tick(self.db)
     if time.time() - self.lasttick >= 60 * 1:
         self.lasttick = time.time()
         #Create a backup
         backupfile = (cfg.home +
         "/statsdbbackups/" +
         time.strftime("%Y%m%d") + '.bak')
         if not os.path.exists(backupfile):
             self.db.backup(backupfile)
             print("Creating backup.")
         #Clear old backups
         flushdir(cfg.home + "/statsdbbackups",
             60 * 60 * 24 * cfg.get("backupkeepdays"))
def redeclipse(s=None):
    if s is None:
        s = {"version": defaultversion}
    if type(s) is str:
        s = {"version": s}
    if s["version"] in cache:
        return cache[s["version"]]
    version = utils.version(s["version"])
    for m, v in list(cfg.get('versions').items()):
        if (version >= utils.version(v[0]) and version <= utils.version(v[1])):
            cache[s["version"]] = importlib.import_module(
                "redeclipse.re%s" % m).RE()
            return cache[s["version"]]
    cache[s["version"]] = importlib.import_module(
        "redeclipse.re%s" % defaultversion).RE()
    return cache[s["version"]]
Exemple #13
0
def main():
    from twisted.internet import reactor
    from twisted.internet.serialport import SerialPort
    import serial                                           # for SerialException
    from twisted.python.logfile import DailyLogFile
    from serialClient import serialClient
    from tcpServer import tcpServer, tcpServerFactory

    machine_ids = db.getMachineIdsForBaseStation(cfg.get('basestation'))

    for machine_id in machine_ids:
        sport = db.getSerialPortForMachine(machine_id)
        #id, name, path, baudrate
        name = sport[1].encode('ascii', 'ignore')
        print "Machine found: ", sport[0], name

        try:
            SerialPort(serialClient(int(sport[0]),name), sport[2], reactor, baudrate=sport[3])
        except serial.SerialException, errortext:
            print("Unable to open serial port: %s" % errortext)
Exemple #14
0
    def make_single(self, specific):
        ret = {
            "name": specific,
            "recentgames": {},
            "toprace": {
                "game": None,
                "gameplayer": None,
                "time": 0,
                },
            "toperace": {
                "game": None,
                "gameplayer": None,
                "time": 0,
                },
            "topraces": [],
            "toperaces": [],
            }
        gamerows = list(self.db.execute(
            """SELECT * FROM games
            WHERE map = ?""", (ret['name'],)))
        ret["games"] = [r[0] for r in gamerows]
        if not ret["games"]:
            return {'error': 'Map has no games'}
        gs = dbselectors.get("game", self.db)
        gs.flags_none()
        gs.weakflags(['players'], True)

        # Recent Games
        if self.flags['recentgames']:
            num = self.q.qint('recentgames', cfg.get('recent'))
            for row in utils.sliceneg(list(reversed(gamerows)), num):
                game = gs.fromrow(row)
                ret["recentgames"][game["id"]] = game

        # Race Times
        if self.flags['race']:
            self.getracetimes(ret, gs, "toprace")
            self.getracetimes(ret, gs, "toperace",
                "AND(mutators & re_mut(id, 'endurance'))")
        return ret
Exemple #15
0
def check(word, main):

    try:
        if re.match(r'^\#', word):
            type = 0

            if re.match(r'^\#%', word):
                word = word[2:]
                type = 1
            elif re.match(r'^\#\$', word):
                word = word[2:]
                type = 2
            else:
                word = word[1:]

            return const(word, type)
        elif re.match(r'^\$', word):

            word = word[1:]  # remove '$'

            # convert it to hex
            numb = int(str(word), 16)

            # if it is see if we have a map set
            map = main.Maps

            if map == "":  # if we don't try the defualt map
                map = cfg.get("CMD", "Maps")

            # if we don't have a map set return
            if map == "":
                return

            return addr(map, numb)
        else:
            return opcode(word)
    except:
        return
Exemple #16
0
from . import __version__


class Ping(object):
    def on_get(self, req, resp):
        resp.body = 'This is an ESPA processing node'
        resp.status = falcon.HTTP_200


class Resource(object):
    def on_post(self, req, resp):
        try:
            if req.content_length:
                body = json.load(req.stream)
            exc = processor.process(cfg.get('processing', lower=True), body)
            resp.body = exc
            resp.status = falcon.HTTP_200
        except Exception as exc:
            logging.error('Server Error: %s', exc.message)
            logging.debug('Server Error: %s', exc.message, exc_info=1)
            resp.body = {"Sever Error": exc.message}
            resp.status = falcon.HTTP_500
        resp.body = json.dumps(resp.body)


DEBUG = cfg.get('http', lower=True).get('debug')
configure_base_logger(level='debug' if DEBUG else 'info')
api = application = falcon.API()
api.add_route('/', Ping())
api.add_route('/v{}'.format(__version__), Resource())
Exemple #17
0
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import sys, os
import cfg

configFile = 'autowx.ini'

if len(sys.argv) > 2:
    print("Usage: {} [autowx.ini]".format(sys.argv[0]))
    exit(-1)
elif len(sys.argv) == 2:
    configFile = sys.argv[1]

config = cfg.get(configFile)

# Config
passImgDir = config.get("DIRS", 'passesImgs')
tleFileName = os.path.join(config.get('DIRS', 'tle'), config.get('DIRS', 'tleFile'))
elNOAA = config.getint('QTH', 'minElev')
elMETEOR = config.getint('QTH', 'minElevMeteor')
qth = (config.getfloat('QTH', 'lat'), config.getfloat('QTH', 'lon'), config.getint('QTH', 'alt'))

# The rest
NOAA15 = []
NOAA18 = []
NOAA19 = []
METEORM2 = []
birds = [NOAA15, NOAA18, NOAA19, METEORM2]
g = []
Exemple #18
0
  -h --help         Show this screen.
  --version         Show version.
  --debug           Log debug.
  --config=<cfg>    Configuration file to use [default: autowx.ini]
"""

from docopt import docopt
import cfg
import keps
import noaa
import web

if __name__ == '__main__':
    arguments = docopt(__doc__, version='AutoWX 1.0')

    config = cfg.get(arguments['--config'])

    print "Using config file: {}".format(arguments['--config'])

    try:
        if arguments['update-keps']:
            keps.update_keps(config, arguments['--force'])
        elif arguments['auto']:
            if arguments['--force-keps-update']:
                keps.update_keps(config, force=True)

            noaa.auto_sat_magic(config, arguments['--config'])
        elif arguments['web']:
            web.static_web_generation(config)
    except KeyboardInterrupt, e:
        print "Exiting."
 def recent(self, k):
     num = self.q.qint(k, cfg.get('recent'))
     if num < 0:
         return ""
     return "ORDER by ROWID DESC LIMIT %d" % (num)
Exemple #20
0
    def setupUi(self, Form, main, Config):
        Form.setObjectName(_fromUtf8("Form"))
        Form.resize(410, 383)
        Form.setWindowIcon(QIcon('includes/imgs/icon.png'))
        Form.setWindowFlags(Qt.Window)
        Form.setAttribute(Qt.WA_QuitOnClose, False)
        # close this window when the mainwindow gets closed

        self.gridLayout = QGridLayout(Form)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))

        self.lineEdit_3 = QLineEdit(Form)
        #self.lineEdit_3.setGeometry(QRect(20, 140, 181, 20))
        self.lineEdit_3.setReadOnly(True)
        self.lineEdit_3.setObjectName(_fromUtf8("lineEdit_3"))
        self.gridLayout.addWidget(self.lineEdit_3, 4, 0, 1, 2)

        text = main.Emulator
        if text == "":
            text = cfg.get("CMD", "Emulator")
        self.lineEdit_3.setText(text)

        self.lineEdit_4 = QLineEdit(Form)
        #self.lineEdit_4.setGeometry(QRect(20, 190, 181, 20))
        self.lineEdit_4.setReadOnly(True)
        self.lineEdit_4.setObjectName(_fromUtf8("lineEdit_4"))
        self.gridLayout.addWidget(self.lineEdit_4, 6, 0, 1, 2)

        text = main.Debugger
        if text == "":
            text = cfg.get("CMD", "Debugger")
        self.lineEdit_4.setText(text)

        self.lineEdit_5 = QLineEdit(Form)
        #self.lineEdit_5.setGeometry(QRect(20, 290, 181, 20))
        self.lineEdit_5.setReadOnly(True)
        self.lineEdit_5.setObjectName(_fromUtf8("lineEdit_5"))
        self.gridLayout.addWidget(self.lineEdit_5, 10, 0, 1, 2)

        text = main.Maps
        if text == "":
            text = cfg.get("CMD", "Maps")
        self.lineEdit_5.setText(text)

        self.lineEdit_6 = QLineEdit(Form)
        #self.lineEdit_6.setGeometry(QRect(20, 240, 181, 20))
        self.lineEdit_6.setReadOnly(True)
        self.lineEdit_6.setObjectName(_fromUtf8("lineEdit_6"))
        self.gridLayout.addWidget(self.lineEdit_6, 8, 0, 1, 2)

        text = main.ROM
        if text == "":
            text = cfg.get("CMD", "ROM")
        self.lineEdit_6.setText(text)

        self.textEdit = QTextEdit(Form)
        #self.textEdit.setGeometry(QRect(20, 40, 261, 71))
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.gridLayout.addWidget(self.textEdit, 1, 0, 2, 3)

        text = main.CMDS
        if text == "":
            text = cfg.get("CMD", "CMDS")
        self.textEdit.setText(text)

        self.pushButton = QPushButton(Form)
        #self.pushButton.setGeometry(QRect(300, 50, 75, 23))
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.pushButton.sizePolicy().hasHeightForWidth())
        self.pushButton.setSizePolicy(sizePolicy)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton.clicked.connect(lambda: self.Append(Form))
        self.gridLayout.addWidget(self.pushButton, 1, 3, 1, 1)

        self.pushButton_3 = QPushButton(Form)
        #self.pushButton_3.setGeometry(QRect(210, 140, 75, 23))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.pushButton_3.clicked.connect(
            lambda: self.Browse(Form, self.lineEdit_3))
        self.gridLayout.addWidget(self.pushButton_3, 4, 2, 1, 1)

        self.pushButton_4 = QPushButton(Form)
        #self.pushButton_4.setGeometry(QRect(210, 190, 75, 23))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.pushButton_4.clicked.connect(
            lambda: self.Browse(Form, self.lineEdit_4))
        self.gridLayout.addWidget(self.pushButton_4, 6, 2, 1, 1)

        self.pushButton_9 = QPushButton(Form)
        #self.pushButton_9.setGeometry(QRect(210, 290, 75, 23))
        self.pushButton_9.setObjectName(_fromUtf8("pushButton_9"))
        self.pushButton_9.clicked.connect(
            lambda: self.Browse(Form, self.lineEdit_5))
        self.gridLayout.addWidget(self.pushButton_9, 10, 2, 1, 1)

        self.pushButton_12 = QPushButton(Form)
        #self.pushButton_12.setGeometry(QRect(210, 240, 75, 23))
        self.pushButton_12.setObjectName(_fromUtf8("pushButton_12"))
        self.pushButton_12.clicked.connect(
            lambda: self.Browse(Form, self.lineEdit_6))
        self.gridLayout.addWidget(self.pushButton_12, 8, 2, 1, 1)

        # set as defualt
        self.pushButton_5 = QPushButton(Form)
        #self.pushButton_5.setGeometry(QRect(300, 90, 91, 23))
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.pushButton_5.clicked.connect(lambda: self.Default(
            Form, self.textEdit.toPlainText(), "CMDS", Config, main))
        self.gridLayout.addWidget(self.pushButton_5, 2, 3, 1, 1)

        self.pushButton_6 = QPushButton(Form)
        #self.pushButton_6.setGeometry(QRect(300, 140, 91, 23))
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        self.pushButton_6.clicked.connect(lambda: self.Default(
            Form, self.lineEdit_3.text(), "Emulator", Config, main))
        self.gridLayout.addWidget(self.pushButton_6, 4, 3, 1, 1)

        self.pushButton_7 = QPushButton(Form)
        #self.pushButton_7.setGeometry(QRect(300, 190, 91, 23))
        self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
        self.pushButton_7.clicked.connect(lambda: self.Default(
            Form, self.lineEdit_4.text(), "Debugger", Config, main))
        self.gridLayout.addWidget(self.pushButton_7, 6, 3, 1, 1)

        self.pushButton_11 = QPushButton(Form)
        #self.pushButton_11.setGeometry(QRect(300, 240, 91, 23))
        self.pushButton_11.setObjectName(_fromUtf8("pushButton_11"))
        self.pushButton_11.clicked.connect(lambda: self.Default(
            Form, self.lineEdit_6.text(), "ROM", Config, main))
        self.gridLayout.addWidget(self.pushButton_11, 8, 3, 1, 1)

        self.pushButton_8 = QPushButton(Form)
        #self.pushButton_8.setGeometry(QRect(300, 290, 91, 23))
        self.pushButton_8.setObjectName(_fromUtf8("pushButton_8"))
        self.pushButton_8.clicked.connect(lambda: self.Default(
            Form, self.lineEdit_5.text(), "Maps", Config, main))
        self.gridLayout.addWidget(self.pushButton_8, 10, 3, 1, 1)

        self.label = QLabel(Form)
        #self.label.setGeometry(QRect(20, 20, 81, 16))
        self.label.setObjectName(_fromUtf8("label"))
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)

        self.label_3 = QLabel(Form)
        #self.label_3.setGeometry(QRect(20, 120, 61, 16))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.gridLayout.addWidget(self.label_3, 3, 0, 1, 1)

        self.label_4 = QLabel(Form)
        #self.label_4.setGeometry(QRect(20, 170, 61, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.gridLayout.addWidget(self.label_4, 5, 0, 1, 1)

        self.label_5 = QLabel(Form)
        #self.label_5.setGeometry(QRect(20, 270, 81, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.gridLayout.addWidget(self.label_5, 9, 0, 1, 1)

        self.label_6 = QLabel(Form)
        #self.label_6.setGeometry(QRect(20, 220, 111, 16))
        self.label_6.setObjectName(_fromUtf8("label_6"))
        self.gridLayout.addWidget(self.label_6, 7, 0, 1, 1)

        self.gridLayout_2 = QGridLayout()
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))

        self.pushButton_2 = QPushButton(Form)
        #self.pushButton_2.setGeometry(QRect(210, 340, 75, 23))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_2.clicked.connect(lambda: self.Ok(Form, main))
        self.gridLayout_2.addWidget(self.pushButton_2, 2, 0, 1, 1)

        self.pushButton_10 = QPushButton(Form)
        #self.pushButton_10.setGeometry(QRect(310, 340, 75, 23))
        self.pushButton_10.setObjectName(_fromUtf8("pushButton_10"))
        self.pushButton_10.clicked.connect(Form.close)
        self.gridLayout_2.addWidget(self.pushButton_10, 2, 1, 1, 1)
        self.gridLayout.addLayout(self.gridLayout_2, 11, 3, 2, 1)

        self.retranslateUi(Form)
        QMetaObject.connectSlotsByName(Form)
 def multi(self):
     index = str([self.name, 'multi', list(self.q.items()), self.flags])
     if index not in cache or (
         time.time() - cache[index][0] > cfg.get('cache_selectors')):
             cache[index] = (time.time(), self.make_multi())
     return cache[index][1]
    def __init__(self, DB, Merra, Extract, log):

        self.DB      =  DB
        self.Merra   =  Merra
        self.Extract =  Extract
        self.log     =  log
      
        if cfg[YOUR_LOCAL_HDFFILE_DIR_PATH] is not None:
            return
        
        if cfg.has_key(FTP_HOST_ADDR) and cfg.get(FTP_HOST_ADDR) is not None:
            self.host = cfg[FTP_HOST_ADDR]
        else:
            self.host = 'goldsmr2.sci.gsfc.nasa.gov' # '169.154.132.64' (Both are same. Ping this web addr, you will get ip addr)


        if cfg.has_key(MERRA_DATA_DOWNLOAD_DIR_PATH) and cfg.get(MERRA_DATA_DOWNLOAD_DIR_PATH) is not None:
            self.download_path = cfg[MERRA_DATA_DOWNLOAD_DIR_PATH]
        else:
            self.download_path = './merra_downloaded_data'


        if cfg.has_key(FTP_DEBUG_LEVEL) and cfg.get(FTP_DEBUG_LEVEL) is not None:
            self.FTP_DEBUG_LEVEL = cfg[FTP_DEBUG_LEVEL]
        else:
            self.FTP_DEBUG_LEVEL = 1


        # NASA asks for email address as password for downloading
        if cfg.has_key(USER_EMAIL_ADDR) and cfg.get(USER_EMAIL_ADDR) is not None:
            self.passwd = cfg[USER_EMAIL_ADDR]
        else:
            self.passwd = '*****@*****.**'
        
        self.login = '******'

        
        self.directory    =  ''       # A temp variable - keeps current directory of the ftp server
        self.dir_list     =  [ ]      # List of sub directory
        self.hdffile_list =  [ ]      # List of HDF file


        # For managing file transfers
        self.monitor_interval = 2     # seconds (thread will notify the status of download after every THIS seconds)
        self.ptr = None               # Used to calculate size of downloaded file
        self.waiting = True           # Used for thread


        # If the connection dies, wait this long before reconnecting
        if cfg.has_key(RETRY_TIMEOUT) and cfg.get(RETRY_TIMEOUT) is not None:
            self.retry_timeout = cfg[RETRY_TIMEOUT]
        else:
            self.retry_timeout = 15


        # In case of download/connection failure, number of max tries to download/reconnection
        if cfg.has_key(MAX_ATTEMPTS_TO_DOWNLOAD) and cfg.get(MAX_ATTEMPTS_TO_DOWNLOAD) is not None:
            self.max_attempts = cfg[MAX_ATTEMPTS_TO_DOWNLOAD]
        else:
            self.max_attempts = 11
       
        # sets self.conn 
        self.connect()
Exemple #23
0
    def setupUi(self, Form, text, Config):
        Form.setObjectName(_fromUtf8("Syntax Highlighting Editor"))
        Form.resize(301, 338)
        Form.setWindowIcon(QIcon('includes/imgs/icon.png'))
        Form.setAttribute( Qt.WA_QuitOnClose, False );    # close this window when the mainwindow gets closed
        
        self.gridLayout_2 = QtGui.QGridLayout(Form)
        self.gridLayout_2.setHorizontalSpacing(9)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        
        self.plainTextEdit = QtGui.QPlainTextEdit(Form)
        #self.plainTextEdit.setGeometry(QtCore.QRect(10, 40, 271, 51))
        self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
        self.plainTextEdit.setPlainText(cfg.get("SyntaxHighlighting", "Opcodes"))
        self.gridLayout_2.addWidget(self.plainTextEdit, 1, 0, 1, 6)
        
        self.plainTextEdit_2 = QtGui.QPlainTextEdit(Form)
        #self.plainTextEdit_2.setGeometry(QtCore.QRect(10, 130, 271, 51))
        self.plainTextEdit_2.setObjectName(_fromUtf8("plainTextEdit_2"))
        self.plainTextEdit_2.setPlainText(cfg.get("SyntaxHighlighting", "Keywords"))
        self.gridLayout_2.addWidget(self.plainTextEdit_2, 3, 0, 1, 6)
        
        self.checkBox = QtGui.QCheckBox(Form)
        #self.checkBox.setGeometry(QtCore.QRect(100, 20, 70, 17))
        self.checkBox.setObjectName(_fromUtf8("checkBox"))        
        self.checkBox.setChecked(cfg.getBool("SyntaxHighlighting", "opBold"))
        self.gridLayout_2.addWidget(self.checkBox, 0, 2, 1, 1)
        
        self.checkBox_2 = QtGui.QCheckBox(Form)
        #self.checkBox_2.setGeometry(QtCore.QRect(150, 20, 70, 17))
        self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
        self.checkBox_2.setChecked(cfg.getBool("SyntaxHighlighting", "opUnderline"))
        self.gridLayout_2.addWidget(self.checkBox_2, 0, 3, 1, 2)
        
        self.checkBox_3 = QtGui.QCheckBox(Form)
        #self.checkBox_3.setGeometry(QtCore.QRect(230, 20, 70, 17))
        self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
        self.checkBox_3.setChecked(cfg.getBool("SyntaxHighlighting", "opItalic"))
        self.gridLayout_2.addWidget(self.checkBox_3, 0, 5, 1, 1)
        
        self.checkBox_4 = QtGui.QCheckBox(Form)
        #self.checkBox_4.setGeometry(QtCore.QRect(100, 110, 70, 17))
        self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
        self.checkBox_4.setChecked(cfg.getBool("SyntaxHighlighting", "keyBold"))
        self.gridLayout_2.addWidget(self.checkBox_4, 2, 3, 1, 2)
        
        self.checkBox_5 = QtGui.QCheckBox(Form)
        #self.checkBox_5.setGeometry(QtCore.QRect(150, 110, 70, 17))
        self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
        self.checkBox_5.setChecked(cfg.getBool("SyntaxHighlighting", "keyUnderline"))
        self.gridLayout_2.addWidget(self.checkBox_5, 2, 2, 1, 1)
        
        self.checkBox_6 = QtGui.QCheckBox(Form)
        #self.checkBox_6.setGeometry(QtCore.QRect(230, 110, 70, 17))
        self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
        self.checkBox_6.setChecked(cfg.getBool("SyntaxHighlighting", "keyItalic"))
        self.gridLayout_2.addWidget(self.checkBox_6, 2, 5, 1, 1)
        
        self.label = QtGui.QLabel(Form)
        #self.label.setGeometry(QtCore.QRect(10, 20, 46, 13))
        self.label.setObjectName(_fromUtf8("label"))
        self.gridLayout_2.addWidget(self.label, 0, 0, 1, 1)
        
        self.label_2 = QtGui.QLabel(Form)
        #self.label_2.setGeometry(QtCore.QRect(10, 110, 46, 13))
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.gridLayout_2.addWidget(self.label_2, 2, 0, 1, 1)

        self.label_3 = QtGui.QLabel(Form)
        #self.label_3.setGeometry(QtCore.QRect(10, 200, 51, 16))
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.gridLayout_2.addWidget(self.label_3, 4, 0, 1, 1)
        
        self.label_4 = QtGui.QLabel(Form)
        #self.label_4.setGeometry(QtCore.QRect(10, 230, 51, 16))
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.gridLayout_2.addWidget(self.label_4, 5, 0, 1, 1)
        
        self.label_5 = QtGui.QLabel(Form)
        #self.label_5.setGeometry(QtCore.QRect(10, 260, 51, 16))
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.gridLayout_2.addWidget(self.label_5, 6, 0, 1, 1)
        
        self.checkBox_7 = QtGui.QCheckBox(Form)
        #self.checkBox_7.setGeometry(QtCore.QRect(100, 200, 70, 17))
        self.checkBox_7.setObjectName(_fromUtf8("checkBox_7"))
        self.checkBox_7.setChecked(cfg.getBool("SyntaxHighlighting", "cmntBold"))
        self.gridLayout_2.addWidget(self.checkBox_7, 4, 2, 1, 1)
        
        self.checkBox_8 = QtGui.QCheckBox(Form)
        #self.checkBox_8.setGeometry(QtCore.QRect(150, 200, 70, 17))
        self.checkBox_8.setObjectName(_fromUtf8("checkBox_8"))
        self.checkBox_8.setChecked(cfg.getBool("SyntaxHighlighting", "cmntUnderline"))
        self.gridLayout_2.addWidget(self.checkBox_8, 4, 3, 1, 2)
        
        self.checkBox_9 = QtGui.QCheckBox(Form)
        #self.checkBox_9.setGeometry(QtCore.QRect(230, 200, 70, 17))
        self.checkBox_9.setObjectName(_fromUtf8("checkBox_9"))
        self.checkBox_9.setChecked(cfg.getBool("SyntaxHighlighting", "cmntItalic"))
        self.gridLayout_2.addWidget(self.checkBox_9, 4, 5, 1, 1)
        
        self.checkBox_10 = QtGui.QCheckBox(Form)
        #self.checkBox_10.setGeometry(QtCore.QRect(100, 230, 70, 17))
        self.checkBox_10.setObjectName(_fromUtf8("checkBox_10"))
        self.checkBox_10.setChecked(cfg.getBool("SyntaxHighlighting", "addrBold"))
        self.gridLayout_2.addWidget(self.checkBox_10, 5, 5, 1, 1)
        
        self.checkBox_11 = QtGui.QCheckBox(Form)
        #self.checkBox_11.setGeometry(QtCore.QRect(150, 230, 70, 17))
        self.checkBox_11.setObjectName(_fromUtf8("checkBox_11"))
        self.checkBox_11.setChecked(cfg.getBool("SyntaxHighlighting", "addrUnderline"))
        self.gridLayout_2.addWidget(self.checkBox_11, 5, 2, 1, 1)
        
        self.checkBox_12 = QtGui.QCheckBox(Form)
        #self.checkBox_12.setGeometry(QtCore.QRect(230, 230, 70, 17))
        self.checkBox_12.setObjectName(_fromUtf8("checkBox_12"))
        self.checkBox_12.setChecked(cfg.getBool("SyntaxHighlighting", "addrItalic"))
        self.gridLayout_2.addWidget(self.checkBox_12, 5, 3, 1, 2)
        
        self.checkBox_13 = QtGui.QCheckBox(Form)
        #self.checkBox_13.setGeometry(QtCore.QRect(100, 260, 70, 17))
        self.checkBox_13.setObjectName(_fromUtf8("checkBox_13"))
        self.checkBox_13.setChecked(cfg.getBool("SyntaxHighlighting", "lblBold"))
        self.gridLayout_2.addWidget(self.checkBox_13, 6, 3, 1, 2)
        
        self.checkBox_14 = QtGui.QCheckBox(Form)
        #self.checkBox_14.setGeometry(QtCore.QRect(150, 260, 70, 17))
        self.checkBox_14.setObjectName(_fromUtf8("checkBox_14"))
        self.checkBox_14.setChecked(cfg.getBool("SyntaxHighlighting", "lblUnderline"))
        self.gridLayout_2.addWidget(self.checkBox_14, 6, 5, 1, 1)
        
        self.checkBox_15 = QtGui.QCheckBox(Form)
        #self.checkBox_15.setGeometry(QtCore.QRect(230, 260, 70, 17))
        self.checkBox_15.setObjectName(_fromUtf8("checkBox_15"))
        self.checkBox_15.setChecked(cfg.getBool("SyntaxHighlighting", "lblItalic"))
        self.gridLayout_2.addWidget(self.checkBox_15, 6, 2, 1, 1)
        
        self.pushButton = QtGui.QPushButton(Form)
        #self.pushButton.setMinimumSize(QtCore.QSize(16, 16))
        self.pushButton.setMaximumSize(QtCore.QSize(16, 16))
        #self.pushButton.setGeometry(QtCore.QRect(70, 20, 16, 16))
        self.pushButton.setStyleSheet(_fromUtf8("background-color: rgb( " + 
        str(cfg.getInt("SyntaxHighlighting", "opR")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "opG")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "opB")) + " );"))
        self.pushButton.setText(_fromUtf8(""))
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.pushButton.clicked.connect(lambda: self.changeColor(self.pushButton))
        self.gridLayout_2.addWidget(self.pushButton, 0, 1, 1, 1)
                
        self.pushButton_2 = QtGui.QPushButton(Form)
        #self.pushButton_2.setGeometry(QtCore.QRect(70, 110, 16, 16))
        self.pushButton_2.setMaximumSize(QtCore.QSize(16, 16))
        self.pushButton_2.setStyleSheet(_fromUtf8("background-color: rgb( " + 
        str(cfg.getInt("SyntaxHighlighting", "keyR")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "keyG")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "keyB")) + " );"))
        self.pushButton_2.setText(_fromUtf8(""))
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.pushButton_2.clicked.connect(lambda: self.changeColor(self.pushButton_2))
        self.gridLayout_2.addWidget(self.pushButton_2, 2, 1, 1, 1)
        
        self.pushButton_3 = QtGui.QPushButton(Form)
        #self.pushButton_3.setGeometry(QtCore.QRect(70, 200, 16, 16))
        self.pushButton_3.setMaximumSize(QtCore.QSize(16, 16))
        self.pushButton_3.setStyleSheet(_fromUtf8("background-color: rgb( " + 
        str(cfg.getInt("SyntaxHighlighting", "cmntR")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "cmntG")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "cmntB")) + " );"))
        self.pushButton_3.setText(_fromUtf8(""))
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.pushButton_3.clicked.connect(lambda: self.changeColor(self.pushButton_3))
        self.gridLayout_2.addWidget(self.pushButton_3, 4, 1, 1, 1)
        
        self.pushButton_4 = QtGui.QPushButton(Form)
        #self.pushButton_4.setGeometry(QtCore.QRect(70, 230, 16, 16))
        self.pushButton_4.setMaximumSize(QtCore.QSize(16, 16))
        self.pushButton_4.setStyleSheet(_fromUtf8("background-color: rgb( " + 
        str(cfg.getInt("SyntaxHighlighting", "addrR")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "addrG")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "addrB")) + " );"))
        self.pushButton_4.setText(_fromUtf8(""))
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.pushButton_4.clicked.connect(lambda: self.changeColor(self.pushButton_4))
        self.gridLayout_2.addWidget(self.pushButton_4, 5, 1, 1, 1)
        
        self.pushButton_5 = QtGui.QPushButton(Form)
        #self.pushButton_5.setGeometry(QtCore.QRect(70, 260, 16, 16))
        self.pushButton_5.setMaximumSize(QtCore.QSize(16, 16))
        self.pushButton_5.setStyleSheet(_fromUtf8("background-color: rgb( " + 
        str(cfg.getInt("SyntaxHighlighting", "lblR")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "lblG")) + " , " + 
        str(cfg.getInt("SyntaxHighlighting", "lblB")) + " );"))
        self.pushButton_5.setText(_fromUtf8(""))
        self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
        self.pushButton_5.clicked.connect(lambda: self.changeColor(self.pushButton_5))
        self.gridLayout_2.addWidget(self.pushButton_5, 6, 1, 1, 1)
        
        self.pushButton_6 = QtGui.QPushButton(Form)
        #self.pushButton_6.setGeometry(QtCore.QRect(130, 300, 71, 23))
        self.pushButton_6.setStyleSheet(_fromUtf8(""))
        self.pushButton_6.setDefault(True)
        self.pushButton_6.setObjectName(_fromUtf8("pushButton_6"))
        self.pushButton_6.clicked.connect(lambda: self.saveChanges(Form, text, Config))
        self.gridLayout_2.addWidget(self.pushButton_6, 7, 2, 1, 2)

        self.pushButton_7 = QtGui.QPushButton(Form)
        #self.pushButton_7.setGeometry(QtCore.QRect(210, 300, 75, 23))
        self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
        self.pushButton_7.clicked.connect(Form.close)
        self.gridLayout_2.addWidget(self.pushButton_7, 7, 4, 1, 2)
        
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)
Exemple #24
0
#!env/bin/python
# -*- coding: UTF-8 -*-
'''
@author: rafex
'''
from cfg import get
from cfg import getInt
from cfg import getBoolean
import netifaces as ni
from application import app

INTERFACE = get("server", "interface")
PORT = getInt("server", "port")
DEBUG = getBoolean("server", "debug")

ni.ifaddresses(INTERFACE)
IP = ni.ifaddresses(INTERFACE)[2][0]['addr']

if __name__ == '__main__':
    app.run(host=IP, port=PORT, debug=DEBUG)
Exemple #25
0
from __future__ import print_function
from __future__ import unicode_literals

import sys
import os
import shutil
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.Qsci import QsciScintilla, QsciLexerPython

if sys.version_info.major == 2:
    str = unicode

import cfg

fontconfig = cfg.get("colors", "font", "Monospace")
sizeconfig = cfg.get("colors", "size", 11)
backgroundcolor = cfg.get("colors", "background", 0xFFFFFF)
actualline = cfg.get("colors", "actualline", 0xFFE4E4)
fontcolor = cfg.get("colors", "fontcolor", 0x000000)
commentcol = cfg.get("colors", "comment", 0x9FBE52)
numbercol = cfg.get("colors", "number", 0x000000)


class SimplePythonEditor(QsciScintilla):
    ARROW_MARKER_NUM = 8

    def __init__(self, parent=None):
        super(SimplePythonEditor, self).__init__(parent)
        # Set the default font
        font = QtGui.QFont()
Exemple #26
0
    from tcpServer import tcpServer, tcpServerFactory

    machine_ids = db.getMachineIdsForBaseStation(cfg.get('basestation'))

    for machine_id in machine_ids:
        sport = db.getSerialPortForMachine(machine_id)
        #id, name, path, baudrate
        name = sport[1].encode('ascii', 'ignore')
        print "Machine found: ", sport[0], name

        try:
            SerialPort(serialClient(int(sport[0]),name), sport[2], reactor, baudrate=sport[3])
        except serial.SerialException, errortext:
            print("Unable to open serial port: %s" % errortext)

    reactor.listenTCP(cfg.getInt('port'), tcpServerFactory(), interface=cfg.get('interface'))
    reactor.run()

#-- Command line detection
if __name__ == "__main__":
    import argparse, daemon, sys
    from twisted.python.logfile import DailyLogFile
    from setproctitle import setproctitle

    parser = argparse.ArgumentParser(description="Robot7 core server")
    parser.add_argument('-d','--daemon',help='Detach from console',action='store_true')
    parser.add_argument('-v','--verbose',help='Be more verbose when running in console',action='store_true')
    parser.add_argument('-c','--cfgfile',help='Read configuration from file',default='/etc/monitor/mcore.cfg',type=str)
    args = parser.parse_args()

    cfg.readFrom(args.cfgfile)
Exemple #27
0
# along with Stellar.  If not, see <http://www.gnu.org/licenses/>.

from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals

import os

from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import *
from PyQt4.Qsci import QsciScintilla, QsciLexerPython

import cfg

fontconfig = cfg.get('colors', 'font', 'Monospace')
sizeconfig = cfg.get('colors', 'size', 10)
backgroundcolor = cfg.get('colors', 'background', 0xFFFFFF)
actualline = cfg.get('colors', 'actualline', 0xFFE4E4)
fontcolor = cfg.get('colors', 'fontcolor', 0x000000)
commentcol = cfg.get('colors', 'comment', 0x9FBE52)
numbercol = cfg.get('colors', 'number', 0x000000)


class SimplePythonEditor(QsciScintilla):
    ARROW_MARKER_NUM = 8


    def __init__(self, parent=None):
        super(SimplePythonEditor, self).__init__(parent)
        
    def fromrow(self, row):
        if not row:
            return {}
        recentgames = self.q.qint('recentgames', cfg.get('recent'))
        recentsums = self.recent('recentsums')
        ret = {
            "recentgames": {},
            }
        dbselectors.rowtodict(ret, row, [
            "name", "handle"
            ], start=1)
        handle = ret['handle']
        # Games
        if self.flags['games']:
            gamerows = list(self.db.execute(
                """SELECT * FROM games
                WHERE id in (SELECT game FROM game_players
                WHERE handle=?)""", (handle,)))
            ret["games"] = [r[0] for r in gamerows]
            # Recent Games
            if self.flags['recentgames']:
                gs = dbselectors.get("game", self.db)
                gs.flags_none()
                gs.weakflags(['players'], True)
                for row in utils.sliceneg(
                    list(reversed(gamerows)), recentgames):
                    game = gs.fromrow(row)
                    game['player'] = [p for p in list(game["players"].values())
                        if p["handle"] == handle][0]
                    # Count FFA rounds for this player in a new index
                    ffarounds = []
                    for ffaround_row in self.db.execute(
                        """SELECT * FROM game_ffarounds
                        WHERE playerhandle = ?
                        AND game = %d""" % game['id'], (handle,)):
                            ffaround = {}
                            dbselectors.rowtodict(
                                ffaround, ffaround_row, ["game",
                                None, None, "round", "winner"])
                            ffarounds.append(ffaround)
                    if ffarounds:
                        game['player_ffarounds'] = ffarounds
                    ret["recentgames"][game["id"]] = game

        #Data from games
        recentsum = lambda x: self.db.execute(
            """SELECT sum(%s) FROM
            (SELECT * FROM game_players
            WHERE game IN (SELECT id FROM games
            %s)
            AND %s
            AND handle = ?
            %s)""" % (x,
                "WHERE mode != re_mode(id, 'race')" if x not in
                ['timeactive'] else "",
                self.vlimit(),
                recentsums), (ret['handle'],)).fetchone()[0]
        recent = {
            'weapons': {},
            }

        # Affinity data
        if self.flags['affinities']:
            captures = []
            for capture_row in self.db.execute(
                """SELECT * FROM game_captures WHERE playerhandle = ?
                AND game in (SELECT id FROM games
                %s)""" % (recentsums), (handle,)):
                    capture = {}
                    dbselectors.rowtodict(capture, capture_row, ["game",
                        None, None, "capturing", "captured"])
                    captures.append(capture)
            if captures:
                ret['captures'] = captures
            bombings = []
            for bombing_row in self.db.execute(
                """SELECT * FROM game_bombings WHERE playerhandle = ?
                AND game in (SELECT id FROM games
                %s)""" % (recentsums), (handle,)):
                    bombing = {}
                    dbselectors.rowtodict(bombing, bombing_row, ["game",
                        None, None, "bombing", "bombed"])
                    bombings.append(bombing)
            if bombings:
                ret['bombings'] = bombings

        # Sums of data
        if self.flags['recentsums']:
            for t in ['frags', 'deaths', 'timealive', 'timeactive']:
                recent[t] = recentsum(t)

            # Damage
            if self.flags['damage']:
                recent["damage"] = self.db.execute(
                    """SELECT (sum(damage1) + sum(damage2)) FROM game_weapons
                        WHERE %s
                        AND playerhandle = ?
                        AND game IN (SELECT id FROM games
                        WHERE mode != re_mode(id, 'race'))
                        %s""" % (self.vlimit(),
                        recentsums),
                            (ret["handle"],)).fetchone()[0]

            if self.flags['weapons']:
                #Weapon Data
                for weapon in redeclipse().weaponlist:
                    wr = {'name': weapon}
                    recentsum = lambda x: self.db.execute(
                        """SELECT sum(%s) FROM
                        (SELECT * FROM game_weapons
                        WHERE weapon = ? AND playerhandle = ?
                        AND game IN (SELECT id FROM games
                        WHERE mode != re_mode(id, 'race'))
                        AND %s
                        %s)""" % (x,
                        self.vlimit(),
                        recentsums),
                        (weapon, ret['handle'])).fetchone()[0]
                    for t in redeclipse().weapcols:
                        wr[t] = recentsum(t)
                    recent['weapons'][weapon] = wr
        ret["recent"] = recent
        return ret
# -*- coding: utf-8 -*-
import importlib
import cfg
import utils
cache = {}
fcache = {
    "mode": {},
    "mut": {},
    }
vcache = {}
functions = []
defaultversion = cfg.get("defaultversion")


def redeclipse(s=None):
    if s is None:
        s = {"version": defaultversion}
    if type(s) is str:
        s = {"version": s}
    if s["version"] in cache:
        return cache[s["version"]]
    version = utils.version(s["version"])
    for m, v in list(cfg.get('versions').items()):
        if (version >= utils.version(v[0]) and version <= utils.version(v[1])):
            cache[s["version"]] = importlib.import_module(
                "redeclipse.re%s" % m).RE()
            return cache[s["version"]]
    cache[s["version"]] = importlib.import_module(
        "redeclipse.re%s" % defaultversion).RE()
    return cache[s["version"]]