Esempio n. 1
0
    def createManualAnnotationsGivenConfigFile(configFile):
        """
        Assumes a config file as:
        [manual_annotations]
        # annotation3 has blank ('') value
        override:annotation1=value1,annotation2=value2,annotation3=,annotation4=value4
        
        Returns a dictionary:
        {annotation1:value1,annotation2:value2,annotation3:'',annotation4=value4}
        """
        if (configFile is None) or (configFile.strip() == ''):
            return dict()

        if not os.path.exists(configFile):
            logging.getLogger(
                __name__).warn("Could not find annotation config file: " +
                               configFile + "  ... Proceeding without it.")
            return dict()

        config = ConfigUtils.createConfigParser(configFile)
        opts = config.get('manual_annotations', 'override').split(',')
        result = dict()
        for optTmp in opts:
            opt = optTmp.split('=')
            if (len(opt) == 1) or (opt[1] is None):
                opt[1] = ''
            result[opt[0]] = opt[1]
        return result
Esempio n. 2
0
    def createManualAnnotationsGivenConfigFile(configFile):
        """
        Assumes a config file as:
        [manual_annotations]
        # annotation3 has blank ('') value
        override:annotation1=value1,annotation2=value2,annotation3=,annotation4=value4
        
        Returns a dictionary:
        {annotation1:value1,annotation2:value2,annotation3:'',annotation4=value4}
        """
        if (configFile is None) or (configFile.strip() == ""):
            return dict()

        if not os.path.exists(configFile):
            logging.getLogger(__name__).warn(
                "Could not find annotation config file: " + configFile + "  ... Proceeding without it."
            )
            return dict()

        config = ConfigUtils.createConfigParser(configFile)
        opts = config.get("manual_annotations", "override").split(",")
        result = dict()
        for optTmp in opts:
            opt = optTmp.split("=")
            if (len(opt) == 1) or (opt[1] is None):
                opt[1] = ""
            result[opt[0]] = opt[1]
        return result
Esempio n. 3
0
    def main(self):

        config_data = ConfigUtils()
        if not config_data.validate():
            print "Error- invalid data in config file"
            logging.error("Error- invalid data in config file")

            sys.exit(1)

        self.supported_machines_list = config_data.supported_machines
        self.max_machines_limit = config_data.max_machines

        # Set up the listening socket
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = socket.gethostname()  # local
        try:
            s.bind((host, config_data.port))
        except socket.error as err:
            print "Error: socket error\n" + err.message
            logging.error("Error: socket error\n" + err.message)
            sys.exit(1)
        print "Server is listening on port {p}...".format(p=config_data.port)

        s.listen(30)

        # accept connections in a loop
        while True:
            (connection, address) = s.accept()
            print "Got connection"
            self.connection_lock.acquire()

            if len(self.connections) >= config_data.max_clients:
                try:
                    connection.send("Sorry, too many clients connected")
                    logging.error("Sorry, too many clients connected")
                    connection.close()
                except:
                    print "Error on closing connection"
                    logging.error("Error on closing connection")
            else:
                connection.send("Connection succeeded")
                logging.info("Connection succeeded")
                self.connections.add(connection)
                self.client_connections_map[connection] = self.clients_id_rise
                self.clients_id_rise += 1
                self.connection_lock.release()
                threading.Thread(target=self.receive, args=[connection]).start()
Esempio n. 4
0
    def main(self):

        config_data = ConfigUtils()
        if not config_data.validate():
            print "Error- invalid data in config file"
            logging.error("Error- invalid data in config file")

            sys.exit(1)

        self.supported_machines_list = config_data.supported_machines
        self.max_machines_limit = config_data.max_machines

        # Set up the listening socket
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        host = socket.gethostname()  # local
        try:
            s.bind((host, config_data.port))
        except socket.error as err:
            print "Error: socket error\n" + err.message
            logging.error("Error: socket error\n" + err.message)
            sys.exit(1)
        print "Server is listening on port {p}...".format(p=config_data.port)

        s.listen(30)

        # accept connections in a loop
        while True:
            (connection, address) = s.accept()
            print "Got connection"
            self.connection_lock.acquire()

            if len(self.connections) >= config_data.max_clients:
                try:
                    connection.send("Sorry, too many clients connected")
                    logging.error("Sorry, too many clients connected")
                    connection.close()
                except:
                    print "Error on closing connection"
                    logging.error("Error on closing connection")
            else:
                connection.send("Connection succeeded")
                logging.info("Connection succeeded")
                self.connections.add(connection)
                self.client_connections_map[connection] = self.clients_id_rise
                self.clients_id_rise += 1
                self.connection_lock.release()
                threading.Thread(target=self.receive, args=[connection]).start()
Esempio n. 5
0
def refresh_datatable(serverid):
    filedict = {"Data": []}
    config = ConfigUtils()
    for root, dirs, files in os.walk(config.get("root_path") + "/Download/" + serverid):
        for file in files:
            try:
                if file.index(".gz") > 0:
                    continue
                if file.index("hashCode") > 0:
                    continue
            except:
                pass
            filename = root + "/" + file
            f = open(filename, "r")
            content = f.read()
            g =gzip.GzipFile(filename="", mode="wb", compresslevel=9, fileobj=open(filename+".gz", "wb"), mtime=0)
            g.write(content)
            g.close()
            zfile = open(filename+".gz", "rb")
            m = hashlib.md5()
            m.update(zfile.read())
            md5 = m.hexdigest()
            zfile.close()
            index = -1
            try:
                index = filename.index("DataTable")
                filetype = "DataTable"
            except ValueError:
                try:
                    index = filename.index("Dictionary")
                    filetype = "Dictionary"
                except ValueError:
                    continue
            finally:
                name = filename[index:].replace("\\", "/")
            if index < 0:
                continue
            filedict["Data"].append({"Name": name, "Hash": md5, "Type": filetype})
            f.close()
    f = open("".join((config.get("root_path"), "Download/", serverid, "/hashCode.txt")), "w")
    s = json.dumps(filedict)
    f.write(s)
    print s
    return s
Esempio n. 6
0
class DBManager:
    def __init__(self):
        self.configs = ConfigUtils()
        self.__conn = MySQLdb.Connect(
            host=self.configs.get("mysql_host"),
            user=self.configs.get("mysql_user"),
            passwd=self.configs.get("mysql_password"))

    def get_db(self, db):
        try:
            self.__conn.select_db(db)
        except:
            self.__conn = MySQLdb.Connect(
                host=self.configs.get("mysql_host"),
                user=self.configs.get("mysql_user"),
                passwd=self.configs.get("mysql_password"))
            self.__conn.select_db(db)
        finally:
            return self.__conn
Esempio n. 7
0
import redis
import json
from xml.dom import minidom
from ConfigUtils import ConfigUtils

configs = ConfigUtils()
if configs.get("redis_pwd"):
    RedisClient = redis.Redis(host=configs.get("redis_host"),
                              port=configs.get("redis_port"),
                              db=0,
                              password=configs.get("redis_pwd"))
else:
    RedisClient = redis.Redis(host=configs.get("redis_host"),
                              port=configs.get("redis_port"),
                              db=0)
GameResourceVersionKey = "Game_Resource_Version"
GameVersionKey = "Game_Version_Info"
GameServerKey = "Game_Server_Host"
DataFilePath = configs.get("root_path") + "data/"


def get_resource_data():
    resource_data = {}
    version_data = {}
    server_list = RedisClient.hgetall(GameServerKey)
    if len(server_list) == 0 or not server_list["UpdateServer"] \
            or not server_list["CheckServerListUri"] or not server_list["LoginUri"]:
        server_list = load_game_server()
    resource_data["UpdateServer"] = server_list["UpdateServer"]
    resource_data["CheckServerListUri"] = server_list["CheckServerListUri"]
    resource_data["LoginUri"] = server_list["LoginUri"]
Esempio n. 8
0
#!/usr/bin/python

import tweepy

from ConfigUtils import ConfigUtils
from SimpleListener import SimpleListener


config_utils = ConfigUtils()

# # config values
# settings
search_query = config_utils.read_list("settings", "search_query")
tweet_languages = config_utils.read_list("settings", "tweet_language")
userBlacklist = config_utils.read_list("settings", "userBlacklist")
wordBlacklist = config_utils.read_list("settings", "wordBlacklist")
# twitter
consumer_key = config_utils.get("twitter", "consumer_key")
consumer_secret = config_utils.get("twitter", "consumer_secret")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
access_token = config_utils.get("twitter", "access_token")
access_token_secret = config_utils.get("twitter", "access_token_secret")

print ''
# create bot
auth.set_access_token(access_token, access_token_secret)
listener = SimpleListener()
stream = tweepy.Stream(auth, listener)
stream.filter(track=search_query)

Esempio n. 9
0
import db_manager, commands
from ConfigUtils import ConfigUtils
from pb2py import CLServerCommand_pb2, LCServerCommand_pb2
import RequestSender

db = db_manager.DBManager()
conf = ConfigUtils()
Database = conf.get('game_db')
Table = "configs"


def get_configs(serverid):
    m_conn = db.get_db(Database)
    m_conn.select_db(Database)
    m_cursor = m_conn.cursor()
    retlist = []
    m_cursor.execute("select * from " + Table + " order by Name")
    for config in m_cursor.fetchall():
        retlist.append((config[0], config[1]))
    m_cursor.close()
    m_conn.close()
    return retlist


def edit_configs(request):
    m_conn = db.get_db(Database)
    m_cursor = m_conn.cursor()
    keys = request.getlist('keys[]')
    values = request.getlist('values[]')
    for field, value in request.items():
        if field == 'keys[]':
Esempio n. 10
0
# coding=utf-8
import os
from ConfigUtils import ConfigUtils


conf = ConfigUtils()
cf = conf.get_config()

basedir = os.path.dirname(os.path.abspath(__file__))
base = os.path.join(basedir,'images')

serverPort = 5000

# 个人模式
appid = cf.get('MiniProgram','appid')
appsercret = cf.get('MiniProgram','appsercret')

ALLOWED_EXTENSIONS = set(['png', 'jpg', 'JPG', 'PNG', 'gif', 'GIF','mp4','mp4','AVI','flash','wma'])
EXPIRES_TIME = 86400

# 短信服务配置
SmsAccessKeyId = cf.get('Sms','SmsAccessKeyId')
SmsAccessKeySecret = cf.get('Sms','SmsAccessKeySecret')
SmsEndPoint = cf.get('Sms','SmsEndPoint')
SmsLimitCount = cf.get('Sms','SmsLimitCount')

# 阿里云oss配置
AccessKeyId = cf.get('OSS','AccessKeyId')
AccessKeySecret = cf.get('OSS','AccessKeySecret')
EndPoint = cf.get('OSS','EndPoint')
Bucket = cf.get('OSS','Bucket')
Esempio n. 11
0
 def __init__(self):
     self.configs = ConfigUtils()
     db = DBManager()
     self.conn = db.get_db(self.configs.get("master_db"))
     self.cursor = self.conn.cursor()
Esempio n. 12
0
class ManageServerList:
    def __init__(self):
        self.configs = ConfigUtils()
        db = DBManager()
        self.conn = db.get_db(self.configs.get("master_db"))
        self.cursor = self.conn.cursor()

    def get_server_list(self):
        retlist = []
        self.cursor.execute("set names utf8")
        self.cursor.execute("select * from " + Table)
        for ln in self.cursor.fetchall():
            retlist.append((ln[0], ln[1], ln[2], ln[3], ln[4], ln[5], ln[6],
                            ln[7], ln[8], ln[9], ln[10], ln[11]))
        return retlist

    def get_server_info(self, Id):
        self.cursor.execute("set names utf8")
        self.cursor.execute("select * from %s where Id='%s'" % (Table, Id))
        ln = self.cursor.fetchone()
        return ln[0], ln[1], ln[2], ln[3], ln[4], ln[5], ln[6], ln[7], ln[
            8], ln[9], ln[10], ln[11]

    def edit_server_list(self, id, name, description, status, address, port,
                         tabid, recommended, dictionaryurl, datatableurl,
                         metafileurl):
        self.conn.set_character_set('utf8')
        self.cursor.execute("set names utf8")
        self.cursor.execute('SET CHARACTER SET utf8;')
        self.cursor.execute('SET character_set_connection=utf8;')
        rowCount = self.cursor.execute(
            "update %s set Name='%s',Description='%s',Status='%s',Address='%s',Port='%s',TabId=%s,Recommended=%s,DictionaryDownloadUrl='%s',DataTableDownloadUrl='%s',DownloadMetaDataUrl='%s' where Id=%s"
            % (Table, name, description, status, address, port, tabid,
               recommended, dictionaryurl, datatableurl, metafileurl, id))
        if rowCount:
            self.conn.commit()
            serverlistStr = self.get_server_list_in_json()
            f = open(
                self.configs.get("root_path") + "data/serverlist.txt", "w")
            f.write(serverlistStr)
            return True
        return False

    def add_server_list(self, id, name, description, status, address, port,
                        tabid, recommended, dictionaryurl, datatableurl,
                        metafileurl):
        name = MySQLdb.escape_string(name)
        description = MySQLdb.escape_string(description)
        address = MySQLdb.escape_string(address)
        self.conn.set_character_set('utf8')
        self.cursor.execute("set names utf8")
        self.cursor.execute('SET CHARACTER SET utf8;')
        self.cursor.execute('SET character_set_connection=utf8;')
        rowCount = self.cursor.execute(
            "insert into %s(`Id`,`Name`,`Description`,`Load`,`Status`,`Address`,`Port`,`TabId`,`Recommended`,`DictionaryDownloadUrl`,`DataTableDownloadUrl`,`DownloadMetaDataUrl`) values (%s,'%s','%s',0,%s,'%s','%s',%s,%s,'%s','%s','%s')"
            % (Table, id, name, description, status, address, port, tabid,
               recommended, dictionaryurl, datatableurl, metafileurl))
        if rowCount:
            self.conn.commit()
            serverlistStr = self.get_server_list_in_json()
            f = open(
                self.configs.get("root_path") + "data/serverlist.txt", "w")
            f.write(serverlistStr)
            return True
        return False

    def update_server_load(self, request):
        if request.META.has_key('HTTP_X_FORWARDED_FOR'):
            ip = request.META['HTTP_X_FORWARDED_FOR']
        else:
            ip = request.META['REMOTE_ADDR']
        serverId = request.GET['sid']
        self.cursor.execute("set names utf8")
        self.cursor.execute("select * from %s where Id='%s'" %
                            (Table, serverId))
        server = self.cursor.fetchone()
        if not server[ServerProperties.Address] == ip:
            return "failed"
        rowCount = self.cursor.execute(
            "update %s set `Load`=%s where Id=%s" %
            (Table, request.GET['load'], request.GET['sid']))
        if rowCount:
            self.conn.commit()
        return "success"

    def get_server_list_in_json(self):
        serverlist = self.get_server_list()
        retlist = []
        keylist = [
            "Id", "Name", "Description", "Status", "Load", "HostOrIPString",
            "Port", "TabId", "Recommended", "DictionaryDownloadUrl",
            "DataTableDownloadUrl", "DownloadMetaDataUrl"
        ]
        for server in serverlist:
            retlist.append(dict(zip(keylist, server)))
        retdict = {"Data": retlist}
        return json.dumps(retdict)
Esempio n. 13
0
 def __init__(self):
     self.configs = ConfigUtils()
     self.__conn = MySQLdb.Connect(
         host=self.configs.get("mysql_host"),
         user=self.configs.get("mysql_user"),
         passwd=self.configs.get("mysql_password"))
Esempio n. 14
0
import socket
import struct
from pb2py import CLPacketHead_pb2, LCPacketHead_pb2
from ConfigUtils import ConfigUtils

conf = ConfigUtils()
address = (conf.get("lobby_server"), 9001)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(address)


def send(action_id, request):
    head = CLPacketHead_pb2.CLPacketHead()
    head.MsgId = 0
    head.ActionId = action_id
    head.SessionId = ""
    head.UserId = 0
    head_buff = head.SerializeToString()
    tmp_head = struct.pack("i%ds" % len(head_buff), len(head_buff), head_buff)
    req_buff = request.SerializeToString()
    buff_stream = struct.pack("i%ds%ds" % (len(tmp_head), len(req_buff)),
                              len(tmp_head) + len(req_buff), tmp_head,
                              req_buff)
    try:
        s.send(buff_stream)
    except:
        s.connect(address)
        s.send(buff_stream)
    while True:
        size_buffer = s.recv(4)
        buff_size = struct.unpack("i", size_buffer)