Example #1
0
 def initEnv(self):
     commandDict = self.configReader.getDict(self.KEY_COMMAND)
     openDict = self.configReader.getDict(self.KEY_OPEN)
     server = self.configReader.getDict(self.KEY_Server)
     print 'Server is: %s' % str(server)
     self.timeLimit = int(
         self.configReader.readConfig(self.KEY_Client, self.KEY_TIMELIMIT))
     self.excutor = executor(commandDict, openDict)
     self.dbManager = DataBaseManager(server['host'], int(server['port']))
     print 'init finished'
Example #2
0
class WCC(object):
    CONFIGPATH = '_config.ini'
    KEY_COMMAND = 'Command'
    KEY_OPEN = 'Open'
    KEY_Server = 'Server'
    KEY_Client = 'Client'
    KEY_TIMELIMIT = 'timelimit'

    def __init__(self):
        self.configReader = configReader(self.CONFIGPATH)
        self.initEnv()
        self.toRun()

    def initEnv(self):
        commandDict = self.configReader.getDict(self.KEY_COMMAND)
        openDict = self.configReader.getDict(self.KEY_OPEN)
        server = self.configReader.getDict(self.KEY_Server)
        print 'Server is: %s' % str(server)
        self.timeLimit = int(
            self.configReader.readConfig(self.KEY_Client, self.KEY_TIMELIMIT))
        self.excutor = executor(commandDict, openDict)
        self.dbManager = DataBaseManager(server['host'], int(server['port']))
        print 'init finished'

    def toRun(self):
        while True:
            print 'try:'
            self.run()
            time.sleep(self.timeLimit)

    def run(self):
        commandList = self._generateCommandList()
        print 'commandList is: %s' % str(commandList)
        if commandList:
            finishCommandList = self.excutor.execute(commandList)
            self.flagFinish(finishCommandList)

    def flagFinish(self, commandList):
        for each in commandList:
            self.dbManager.update(each, 'run', True)

    def _generateCommandList(self):
        commandObj = self.dbManager.find('run', False)
        commandList = []
        if commandObj:
            print 'in command obj'
            for each in commandObj:
                commandDict = {
                    '_id': each['_id'],
                    'innerCommand': each['innerCommand'],
                    'writeCommand': each['writeCommand'],
                    'run': each['run']
                }
                commandList.append(commandDict)
            return commandList[::-1]  #将列表倒序
Example #3
0
class WCC(object):
    CONFIGPATH = '_config.ini'
    KEY_COMMAND = 'Command'
    KEY_OPEN = 'Open'
    KEY_Server = 'Server'
    KEY_Client = 'Client'
    KEY_TIMELIMIT = 'timelimit'

    def __init__(self):
        self.configReader = configReader(self.CONFIGPATH)
        self.initEnv()
        self.toRun()

    def initEnv(self):
        commandDict = self.configReader.getDict(self.KEY_COMMAND)
        openDict = self.configReader.getDict(self.KEY_OPEN)
        server = self.configReader.getDict(self.KEY_Server)
        print 'Server is: %s' % str(server)
        self.timeLimit = int(self.configReader.readConfig(self.KEY_Client, self.KEY_TIMELIMIT))
        self.excutor = executor(commandDict, openDict)
        self.dbManager = DataBaseManager(server['host'], int(server['port']))
        print 'init finished'

    def toRun(self):
        while True:
            print 'try:'
            self.run()
            time.sleep(self.timeLimit)

    def run(self):
        commandList = self._generateCommandList()
        print 'commandList is: %s' % str(commandList)
        if commandList:
            finishCommandList = self.excutor.execute(commandList)
            self.flagFinish(finishCommandList)

    def flagFinish(self, commandList):
        for each in commandList:
            self.dbManager.update(each, 'run', True)

    def _generateCommandList(self):
        commandObj = self.dbManager.find('run', False)
        commandList = []
        if commandObj:
            print 'in command obj'
            for each in commandObj:
                commandDict = {'_id': each['_id'],
                               'innerCommand': each['innerCommand'],
                               'writeCommand': each['writeCommand'],
                               'run': each['run']}
                commandList.append(commandDict)
            return commandList[::-1]
Example #4
0
def index():
    form = contentForm()
    dataBaseManager = DataBaseManager()
    if form.validate_on_submit():
        innerCommand = form.commandInConfig.data
        writeCommand = form.commandInWrite.data

        if not (innerCommand or writeCommand):
            errorinfo = u'内置命令和自定义代码至少要写一个!'
            return render_template('index.html', form=form, errorinfo=errorinfo)
        else:
            info = {'innerCommand': innerCommand, 'writeCommand': writeCommand, 'run': False}
            dataBaseManager.insert(info)
        return redirect('/')
    return render_template('index.html', form=form, errorinfo='')
def index():
    form = contentForm()
    dataBaseManager = DataBaseManager()

    if form.validate_on_submit():

        innerCommand = form.commandInConfig.data
        writeCommand = form.commandInWrite.data
        userName = form.userName.data
        password = form.password.data
        info = {'innerCommand': innerCommand, 'writeCommand': writeCommand,
                'userName': userName, 'password': password}
        dataBaseManager.insert(info)
        return redirect('/')
    return render_template('index.html', form=form)
Example #6
0
 def initEnv(self):
     commandDict = self.configReader.getDict(self.KEY_COMMAND)
     openDict = self.configReader.getDict(self.KEY_OPEN)
     server = self.configReader.getDict(self.KEY_Server)
     print 'Server is: %s' % str(server)
     self.timeLimit = int(self.configReader.readConfig(self.KEY_Client, self.KEY_TIMELIMIT))
     self.excutor = executor(commandDict, openDict)
     self.dbManager = DataBaseManager(server['host'], int(server['port']))
     print 'init finished'
Example #7
0
def index():
    form = contentForm()
    dataBaseManager = DataBaseManager()

    if form.validate_on_submit():

        innerCommand = form.commandInConfig.data
        writeCommand = form.commandInWrite.data
        userName = form.userName.data
        password = form.password.data
        info = {
            'innerCommand': innerCommand,
            'writeCommand': writeCommand,
            'userName': userName,
            'password': password
        }
        dataBaseManager.insert(info)
        return redirect('/')
    return render_template('index.html', form=form)
Example #8
0
def index():
    form = contentForm()
    dataBaseManager = DataBaseManager()
    if form.validate_on_submit():
        innerCommand = form.commandInConfig.data
        writeCommand = form.commandInWrite.data

        if not (innerCommand or writeCommand):
            errorinfo = u'内置命令和自定义代码至少要写一个!'
            return render_template('index.html',
                                   form=form,
                                   errorinfo=errorinfo)
        else:
            info = {
                'innerCommand': innerCommand,
                'writeCommand': writeCommand,
                'run': False
            }
            dataBaseManager.insert(info)
        return redirect('/')
    return render_template('index.html', form=form, errorinfo='')