示例#1
0
 def __init__(self, env=get_env(), host=None, port=None):
     self.host = None
     self.port = None
     self.connection = None
     self.databasename = None
     self.dbConfig = None
     self.db = None
     # if host and port were not defined then let's get it from config
     if not (host and port):
         if env:
             self.dbConfig = env.config.mainserver.mongodbserver
             if self.dbConfig:
                 self.host = env.config.mainserver.mongodbserver.host
                 self.port = env.config.mainserver.mongodbserver.port
                 self.databasename = env.config.mainserver.mongodbserver.dbname
                 #self.searchkeys = env.mainserver.mongodbserver.tables.public_routes.search_data_keys
                 self.default_limit = env.config.mainserver.mongodbserver.default_limit
     # or host and port were provided then just take it
     elif host and port:
         self.host, self.port = host, port
     # OK host and port are defined. Let's make the connections
     if self.host and self.port and self.databasename:
         self.connection = Connection(self.host, self.port)
         self.db = self.connection[self.databasename]
     # O.. No... host and port are not defined and we have to go away
     else:
         return
示例#2
0
 def __init__(self, env=get_env(), host=None, port=None):
     self.host = None
     self.port = None
     self.connection = None
     self.databasename = None
     self.dbConfig = None
     self.db = None
     # if host and port were not defined then let's get it from config
     if not (host and port):
         if env:
             self.dbConfig = env.config.mainserver.mongodbserver
             if self.dbConfig:
                 self.host = env.config.mainserver.mongodbserver.host
                 self.port = env.config.mainserver.mongodbserver.port
                 self.databasename = env.config.mainserver.mongodbserver.dbname
                 #self.searchkeys = env.mainserver.mongodbserver.tables.public_routes.search_data_keys
                 self.default_limit = env.config.mainserver.mongodbserver.default_limit
     # or host and port were provided then just take it
     elif host and port:
         self.host, self.port = host, port
     # OK host and port are defined. Let's make the connections
     if self.host and self.port and self.databasename:
         self.connection = Connection(self.host, self.port)
         self.db = self.connection[self.databasename]
     # O.. No... host and port are not defined and we have to go away
     else:
         return
示例#3
0
    def __init__(self, configfile):
        logger.info('App: starting ...')
        self.configfile = configfile
        self.config = get_env(self.configfile)
        self.pipe = Pipeline(config=self.config)

        # let's do init according to our purpose: IN next OUT
        self.finput = self.pipe.create_module('file_input')
        self.pipe.append(self.finput)

        self.output = self.pipe.create_module('file_output')
        self.pipe.append(self.output)

        self.pipe.start()
        self.core_processor = ThreadLoop(loop=self.processing_queue_loop)
        self.core_processor.start()
示例#4
0
import sys
import json
from twisted.internet.protocol import Protocol, ServerFactory
#from twisted.application import service, internet
from twisted.internet import reactor, defer, threads
from twisted.python import log

from mongodbservice import MongoBDService
from yamlloader import get_env

env = get_env()
#log.startLogging(open('/var/log/python_server/mongoprocess.log', 'w')) 
log.startLogging(sys.stdout)

def checkMongoProcessToken(fn):
    def wrapper(self,*args, **kwargs):
        if env.config.get('mainserver',{}).get('mongodbprocess',{}).get('token',None) == self.jsonData.get("token"):
            return fn(self, *args, **kwargs)
        else:
            raise ValueError("token is not valid")
    return wrapper

def envReload(fn):
    def wrapper(self,*args, **kwargs):
        env._reload()
        return fn(self, *args, **kwargs)
    return wrapper

class MongoJsonHandler():
    def __init__(self, inc):
        self.jsonData = {"result":"FALT", "reason":None}
示例#5
0
 def setUp(self):
     self.configfile = './server.conf'
     self.config = get_env(self.configfile)
示例#6
0
#!/usr/bin/env python

# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

import json
import sys
from twisted.internet.protocol import Protocol, ClientFactory, ServerFactory, Factory
from twisted.internet.endpoints import TCP4ClientEndpoint
from twisted.application import service, internet
from twisted.internet import reactor, defer, threads
from twisted.python import log, failure
from yamlloader import get_env

env = get_env()
#log.startLogging(open('/var/log/python_server/virtual_guide_serv.log', 'w'))
log.startLogging(sys.stdout)


def checkProtocolVersion(fn):
    def wrapper(self, *args, **kwargs):
        if env.config.mainserver.protocolversion >= self.jsonData.get(
                "protocolversion"):
            return fn(self, *args, **kwargs)
        else:
            raise ValueError("protocolversion is not supported")

    return wrapper


# -------------------  CLIENT ----------------------------------------
# -*- python -*-
# author: [email protected]
# settings: created 2016/10/30.
# copyright

import os
import socket

from log import logger, set_file
from yamlloader import get_env

filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                        'settings.conf')
env = get_env(filepath=filepath, attrdict=True)

##############################
# common #
##############################
ROOT_FOLDER = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

try:
    LOG_FILENAME = env.common.LOG_FILENAME
except:
    LOG_FILENAME = os.path.join(ROOT_FOLDER, 'results.log')

##############################
# Logging #
##############################
set_file(LOG_FILENAME)
LOGGER = logger
logger.debug("ROOT_FOLDER={}".format(ROOT_FOLDER))