Esempio n. 1
0
def init():
    configfile = assistant.SF("%s/filecrawler.conf" %
                              (os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config = pysmartac.configer.openconfiger(configfile)

    #configer
    conf.pidfile = config.getstr("system", "pidfile", conf.pidfile)
    conf.threadCount = config.getint("system", "threadCount", conf.threadCount)
    conf.logLevel = config.getstr("system", "logLevel", conf.logLevel)
    conf.ftpServerMovieSource = config.getstr("system", "ftpServerMovieSource",
                                              conf.ftpServerMovieSource)
    conf.ftpServerAppSource = config.getstr("system", "ftpServerAppSource",
                                            conf.ftpServerAppSource)
    conf.ftpServerUser = config.getstr("system", "ftpServerUser",
                                       conf.ftpServerUser)
    conf.ftpServerPwd = config.getstr("system", "ftpServerPwd",
                                      conf.ftpServerPwd)
    conf.ftpJsonOutputPath = config.getstr("system", "ftpJsonOutputPath",
                                           conf.ftpJsonOutputPath)
    conf.movieOutputFile = config.getstr("system", "movieOutputFile",
                                         conf.movieOutputFile)
    conf.appOutputFile = config.getstr("system", "appOutputFile",
                                       conf.appOutputFile)
    conf.checkInterval = config.getint("system", "checkInterval",
                                       conf.checkInterval)
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog(
        assistant.SF("%s/log/FLCRAWLER_$(Date8)_$(filenumber2).log" %
                     (os.path.dirname(__file__))))
Esempio n. 2
0
 def get(self):
     result = ""
     jsresult = {}
     cmdlist = self.get_query_arguments("cmd")
     for cmd in cmdlist:
         PLOG.debug("Receive msg %s"%cmd)
         if len(cmd) >0 :
             js = json.loads(cmd.decode('utf8'))
             if js.has_key('msgid') :
                 msg = js["msgid"]
                 if msg == "seturi":
                     if js.has_key('body'):
                         body = js["body"]
                         if body.has_key('uri'):
                             uri = body["uri"]
                             if len(uri) >0:
                                 global lastpageuri
                                 lastpageuri = uri
                                 HandleSetURI(uri)
                                 jsresult["errmsg"] = "OK"
                             else:
                                 jsresult["errmsg"] = "uri is empty!"
                         else:
                             jsresult["errmsg"] = "msg seturi body has no uri,invalid msg"
                     else:
                         jsresult["errmsg"] = "msg seturi has no body,invalid msg"                        
                 else:
                     jsresult["errmsg"] = "not support msgid " + msg
         self.write(json.dumps(jsresult))  
Esempio n. 3
0
 def AddWebSocket(self, wsconn):
     wsname = wsconn.wsname
     if self.websockets.has_key(wsname):
         PLOG.debug("Already has ws connect %s,close old connect" % wsname)
         self.websockets[wsname].close()
     self.websockets[wsname] = wsconn
     PLOG.debug("ws manager add %s" % wsname)
Esempio n. 4
0
 def get(self):
     result = ""
     jsresult = {}
     cmdlist = self.get_query_arguments("cmd")
     for cmd in cmdlist:
         PLOG.debug("Receive msg %s" % cmd)
         if len(cmd) > 0:
             js = json.loads(cmd.decode('utf8'))
             if js.has_key('msgid'):
                 msg = js["msgid"]
                 if msg == "seturi":
                     if js.has_key('body'):
                         body = js["body"]
                         if body.has_key('uri'):
                             uri = body["uri"]
                             if len(uri) > 0:
                                 global lastpageuri
                                 lastpageuri = uri
                                 HandleSetURI(uri)
                                 jsresult["errmsg"] = "OK"
                             else:
                                 jsresult["errmsg"] = "uri is empty!"
                         else:
                             jsresult[
                                 "errmsg"] = "msg seturi body has no uri,invalid msg"
                     else:
                         jsresult[
                             "errmsg"] = "msg seturi has no body,invalid msg"
                 else:
                     jsresult["errmsg"] = "not support msgid " + msg
         self.write(json.dumps(jsresult))
def scanFile(rootpath,filetype):
    PLOG.debug('Type["%s"] file start crawling...dir = %s ' %(filetype,rootpath))
    outputjsfilename = ""
    rootDirname = ""
    if rootpath[-1] == '\\' or rootpath[-1] == '/' :
        rootpath = rootpath[:-1]
    rootDirname = os.path.split(rootpath)[-1]	
    if filetype == "movie":
        outputjsfilename = conf.movieOutputFile
    elif filetype == "app":
        outputjsfilename = conf.appOutputFile
    outputjsfilename = outputjsfilename.decode('utf8')
    rootpath = rootpath.decode('utf8')
    dirlist = enumDir(rootpath)
    allJsonInfo = {}
    allJsonInfo["update"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    allJsonInfo["source"] = conf.httpServerSite + rootDirname + '/'
    allJsonInfo["list"] =[]		    
    for subdir in dirlist:
        fileitems = enumFile(os.path.join(rootpath,subdir))
        for fileitem in fileitems:
            if fileitem[-5:] == ".json" : 	    
                addJsonInfo(fileitem,allJsonInfo)
    with open(outputjsfilename,"w") as f:
        json.dump(allJsonInfo, f,indent=4,ensure_ascii=False)
    PLOG.debug('Type["%s"] file crawl dir %s finished' %(filetype,rootpath))	
Esempio n. 6
0
def init():
    configfile = assistant.SF("%s/filecrawler.conf" %
                              (os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config = pysmartac.configer.openconfiger(configfile)

    #configer
    conf.pidfile = config.getstr("system", "pidfile", conf.pidfile)
    conf.threadCount = config.getint("system", "threadCount", conf.threadCount)
    conf.logLevel = config.getstr("system", "logLevel", conf.logLevel)
    conf.httpServerSite = config.getstr("system", "httpserversite",
                                        conf.httpServerSite)
    conf.movieDir = config.getstr("system", "movieDir", conf.movieDir)
    conf.appDir = config.getstr("system", "appDir", conf.appDir)
    conf.movieOutputFile = config.getstr("system", "movieOutputFile",
                                         conf.movieOutputFile)
    conf.appOutputFile = config.getstr("system", "appOutputFile",
                                       conf.appOutputFile)
    conf.checkInterval = config.getint("system", "checkInterval",
                                       conf.checkInterval)
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog("%s/log/FLCRAWLER_$(Date8)_$(filenumber2).log" %
                       (os.path.dirname(__file__)))
Esempio n. 7
0
def openmysqlconn():
    dboperater =None
    try:
        dboperater = DBOperater()
        dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname)
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s" %(e.args[0], e.args[1]))   
Esempio n. 8
0
 def AddWebSocket(self,wsconn):
     wsname = wsconn.wsname   
     if self.websockets.has_key(wsname) :
         PLOG.debug("Already has ws connect %s,close old connect"%wsname)
         self.websockets[wsname].close()
     self.websockets[wsname] = wsconn     
     PLOG.debug("ws manager add %s"%wsname)
Esempio n. 9
0
def scanFile(rootpath, filetype):
    PLOG.debug('Type["%s"] file start crawling...dir = %s ' %
               (filetype, rootpath))
    outputjsfilename = ""
    rootDirname = ""
    if rootpath[-1] == '\\' or rootpath[-1] == '/':
        rootpath = rootpath[:-1]
    rootDirname = os.path.split(rootpath)[-1]
    if filetype == "movie":
        outputjsfilename = conf.movieOutputFile
    elif filetype == "app":
        outputjsfilename = conf.appOutputFile
    outputjsfilename = outputjsfilename.decode('utf8')
    rootpath = rootpath.decode('utf8')
    dirlist = enumDir(rootpath)
    allJsonInfo = {}
    allJsonInfo["update"] = datetime.datetime.now().strftime(
        "%Y-%m-%d %H:%M:%S")
    allJsonInfo["source"] = conf.httpServerSite + rootDirname + '/'
    allJsonInfo["list"] = []
    for subdir in dirlist:
        fileitems = enumFile(os.path.join(rootpath, subdir))
        for fileitem in fileitems:
            if fileitem[-5:] == ".json":
                addJsonInfo(fileitem, allJsonInfo)
    with open(outputjsfilename, "w") as f:
        json.dump(allJsonInfo, f, indent=4, ensure_ascii=False)
    PLOG.debug('Type["%s"] file crawl dir %s finished' % (filetype, rootpath))
Esempio n. 10
0
 def heartbeatCheck(self):
     if self.isTimeOut():
         PLOG.debug("%s websocket timeout,disconnect it" % self.wsname)
         self.close()
         WSManager.RemoveWebSocket(self.wsname)
     else:
         PLOG.trace("send ping")
         self.ping("ping")
Esempio n. 11
0
 def heartbeatCheck(self):
     if self.isTimeOut():
         PLOG.debug("%s websocket timeout,disconnect it"%self.wsname) 
         self.close()
         WSManager.RemoveWebSocket(self.wsname)
     else:
         PLOG.trace("send ping")
         self.ping("ping")
Esempio n. 12
0
 def closeconnection(self):
     """
     关闭连接
     """
     if self.conn != None:
         self.conn.close()
     else:
         PLOG.error("DBOperater.closeconnection error, conn is none")
     return 0
Esempio n. 13
0
 def createconnection(self, host, user, passwd, dbname):
     """
     创建一个新连接
     """
     self.conn = MySQLdb.Connect(host, user, passwd, dbname, charset="utf8")
     if False == self.conn.open:
         PLOG.error("DBOperater.createconnection error")
         return -1
     return 0
Esempio n. 14
0
def connection():
    global ws
    while(True):
        ws = websocket.WebSocketApp("ws://172.16.5.16:18030/ws",
                                  on_open = on_open,
                                  on_message = on_message,
                                  on_error = on_error,
                                  on_close = on_close)
        ws.run_forever()  
        PLOG.debug("ws may break")
Esempio n. 15
0
 def getPIDForString(self, s):
     pid = None
     try:
         processList = assistant.getProcessList()
         for p in processList:
             if p[1].find(s) != -1:
                 pid = p[0]
                 break
         del processList
     except Exception, e:
         PLOG.error("%s getPIDForString except:%s" % (self.name, e))
Esempio n. 16
0
def addJsonInfo(jsonSourcefile,destJson):
    filedir = os.path.dirname(jsonSourcefile)
    parentDirName = os.path.split(filedir)[-1]
    primaryFilename = ""
    jsSourceFileInfo = None
    with open(jsonSourcefile,"r") as f:
        jsSourceFileInfo = json.load(f,'utf8')	
    if jsSourceFileInfo !=None and isinstance(jsSourceFileInfo,dict):
        if jsSourceFileInfo.has_key("file"):
            primaryFilename = jsSourceFileInfo["file"]  
            if primaryFilename != "":	
                jsSourceFileInfo["id"] = str(uuid.uuid1())   
                if primaryFilename.startswith("https:") :
                    # ios info file
                    filetimestamp = time.localtime( os.path.getmtime(jsonSourcefile)) 
                    primaryFileTime = time.strftime('%Y-%m-%d %H:%M:%S',filetimestamp)
                    jsSourceFileInfo["filetime"] = primaryFileTime
                    if not jsSourceFileInfo.has_key("filesize") :
                        jsSourceFileInfo["filesize"] = "0"
                    #destJson["list"].append(jsSourceFileInfo)
                else:
                    try:
                        primaryFileSize = os.path.getsize(os.path.join(filedir,primaryFilename))
                        filetimestamp = time.localtime( os.path.getmtime(os.path.join(filedir,primaryFilename)) )
                        primaryFileTime = time.strftime('%Y-%m-%d %H:%M:%S',filetimestamp)
                        jsSourceFileInfo["filesize"] = str(primaryFileSize)
                        jsSourceFileInfo["filetime"] = primaryFileTime
                        if jsSourceFileInfo.has_key("file") :
                            jsSourceFileInfo["file"] = parentDirName +'/' + jsSourceFileInfo["file"]                        
                    except:          
                        PLOG.info("generate file info of dir %s failed,primary File %s not find,skip it"% (filedir,primaryFilename))      
                        return 
                if jsSourceFileInfo.has_key("poster") :
                    jsSourceFileInfo["poster"] = parentDirName +'/' + jsSourceFileInfo["poster"]
                if jsSourceFileInfo.has_key("thumbnail") :
                    jsSourceFileInfo["thumbnail"] = parentDirName +'/' + jsSourceFileInfo["thumbnail"]
                if jsSourceFileInfo.has_key("extend") :
                    jsextend = jsSourceFileInfo["extend"]
                    if jsextend.has_key("screenshot") :
                        jsscreenshottmp = []
                        for picture in jsextend["screenshot"] :
                            picture = parentDirName +'/' + picture
                            jsscreenshottmp.append(picture)
                        jsextend["screenshot"] =jsscreenshottmp
                destJson["list"].append(jsSourceFileInfo)
                PLOG.debug('generate file info of dir "%s" success'%(filedir))                    
                 
            else:
                PLOG.debug("generate file info of dir %s failed,primary File name is empty"% (filedir)) 

        else :
            PLOG.debug('not find "file" node in info file %s , skip it' %(jsonSourcefile))
    else:
        PLOG.warn('js file %s is null,maybe path error! skip it' %(jsonSourcefile))
Esempio n. 17
0
 def getCommandForPID(self, pid):
     cmd = None
     try:
         processList = assistant.getProcessList()
         for p in processList:
             if p[0] == pid:
                 cmd = p[1]
                 break
         del processList
     except Exception, e:
         PLOG.error("%s getCommandForPID except:%s" % (self.name, e))
Esempio n. 18
0
 def getCommandForPID(self, pid):
     cmd = None
     try:
         processList = assistant.getProcessList()
         for p in processList:
             if p[0] == pid:
                 cmd = p[1]
                 break
         del processList
     except Exception, e:
         PLOG.error("%s getCommandForPID except:%s" % (self.name, e))
Esempio n. 19
0
 def getPIDForString(self, s):
     pid = None
     try:
         processList = assistant.getProcessList()
         for p in processList:
             if p[1].find(s) != -1:
                 pid = p[0]
                 break
         del processList
     except Exception, e:
         PLOG.error("%s getPIDForString except:%s" % (self.name, e))
Esempio n. 20
0
def on_message(ws, message):
    PLOG.debug( "Recv: "+message)
    msgJson = json.loads(message)
    global logined
    if msgJson["msgid"] == "login":
        if msgJson["errcode"] == 0:
            logined = True
        else:
            PLOG.debug("Userid is wrong,exit")
            #ws.close()
            sys.exit(0)
Esempio n. 21
0
 def login(self):  
     try:  
         FTP.connect(self,self.host,timeout=10)  
     except:  
         PLOG.warn('Can not connect to ftp server "%s"' % self.host) 
         return False  
     try:  
         FTP.login(self,self.user,self.pwd)  
     except:  
         PLOG.warn('Login ftp server "%s" failed ,username or password error' % self.host)
         return False  
     return True  
Esempio n. 22
0
 def reloadStop(self):
     querystopsql = 'SELECT a.innerid,a.`name` FROM sa_region AS a LEFT JOIN sa_region AS b ON b.parentid=a.innerid WHERE b.parentid IS NULL'
     stopresultls = SAPeakDataPublic.querysql(querystopsql)
     if stopresultls != None and len(stopresultls) > 0:
         for row in stopresultls:
             stop = Stop(row[0], row[1])
             if stop != None:
                 self.stops[row[0]] = stop
                 PLOG.debug("load stop %s,id=%s" % (row[1], row[0]))
     else:
         PLOG.debug("load stop failed!")
         return False
     return True
Esempio n. 23
0
def querysql(sqltext,dboperater=None,how = 0):
    resultls = []
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        rowNum, result = dboperater.query(sqltext)
        PLOG.trace("%s query finish"%(sqltext))
        resultls = dboperater.fetch_queryresult(result,rowNum, how = how) 
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],sqltext)) 
        return None
Esempio n. 24
0
def executeproc(procsqlname,dboperater=None,args=None):
    resultls = []
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        cur = dboperater.conn.cursor()
        cur.callproc(procsqlname,args)
        dboperater.conn.commit() #提交SQL语句
        cur.close()
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],procsqlname)) 
Esempio n. 25
0
 def processRPC(self, msg):
     ret = ""
     PLOG.info("RPC:\n%s" % msg)
     if msg == "status":
         ret = "alwayson working...\n"
         items = []
         for p in self.programlist:
             items.append((p.name, p.status))
         fmt = '%-40s %9s'
         ret = '\n'.join([fmt % (x, '[%s]' % y) for x, y in items])
         PLOG.info("report runing status:\n%s" % ret)
     elif msg == "stop":
         pass
     return ret
Esempio n. 26
0
def run():
    init()
    # radius 日志检查
    beforeInvoketime = datetime.datetime.now()
    currentLogFile = getCurrentLogfile()
    beforeInvokeLogFileSize = os.path.getsize(currentLogFile)
    # radius auth请求检查
    ret = InvokeProc()
    # radius auth请求检查 end
    if (ret == 1):
        # radius 运行状态正常,检查log
        afterInvoketime = datetime.datetime.now()
        if beforeInvoketime.day == afterInvoketime.day:
            if os.path.getsize(currentLogFile) > beforeInvokeLogFileSize:
                PLOG.info("radius log status is ok")
            else:
                PLOG.info("radius log status error,no growth,stop radius")
                InvokeStopRadius()
        else:
            # 调用前后不是同一天(可能写入新日志,也可能写入旧日志,or判断)
            logfile = getCurrentLogfile()
            if (logfile != None and len(logfile) > 0
                    and os.path.getsize(logfile) > 0
                ) or os.path.getsize(currentLogFile) > beforeInvokeLogFileSize:
                PLOG.info("radius log status is ok")
            else:
                PLOG.info(
                    "radius log status error,no growth or no new log,stop radius"
                )
                InvokeStopRadius()
Esempio n. 27
0
def run():
    init() 
    # radius 日志检查
    beforeInvoketime = datetime.datetime.now()
    currentLogFile = getCurrentLogfile()
    beforeInvokeLogFileSize = os.path.getsize(currentLogFile)
    # radius auth请求检查
    ret = InvokeProc()
    # radius auth请求检查 end
    if (ret == 1) :
        # radius 运行状态正常,检查log
        afterInvoketime = datetime.datetime.now()
        if beforeInvoketime.day == afterInvoketime.day:
            if os.path.getsize(currentLogFile) > beforeInvokeLogFileSize :
                PLOG.info("radius log status is ok")
            else:
                PLOG.info("radius log status error,no growth,stop radius")
                InvokeStopRadius()
        else:
            # 调用前后不是同一天(可能写入新日志,也可能写入旧日志,or判断)
            logfile = getCurrentLogfile()
            if ( logfile != None and len(logfile) >0 and os.path.getsize(logfile) > 0 ) or os.path.getsize(currentLogFile) > beforeInvokeLogFileSize:
                PLOG.info("radius log status is ok")
            else:
                PLOG.info("radius log status error,no growth or no new log,stop radius")
                InvokeStopRadius()
Esempio n. 28
0
 def login(self):
     try:
         FTP.connect(self, self.host, timeout=10)
     except:
         PLOG.warn('Can not connect to ftp server "%s"' % self.host)
         return False
     try:
         FTP.login(self, self.user, self.pwd)
     except:
         PLOG.warn(
             'Login ftp server "%s" failed ,username or password error' %
             self.host)
         return False
     return True
Esempio n. 29
0
 def processRPC(self, msg):
     ret = ""
     PLOG.info("RPC:\n%s" % msg)
     if msg == "status":
         ret = "alwayson working...\n"
         items = []
         for p in self.programlist:
             items.append((p.name, p.status))
         fmt = '%-40s %9s'
         ret = '\n'.join([fmt % (x, '[%s]' % y) for x, y in items])
         PLOG.info("report runing status:\n%s" % ret)
     elif msg == "stop":
         pass
     return ret
Esempio n. 30
0
def init():    
    configfile=assistant.SF("%s/radiusCheck.conf"%(os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config=pysmartac.configer.openconfiger(configfile)

    #configer
    conf.logLevel=config.getstr("system","logLevel",conf.logLevel)
    conf.clientPath=config.getstr("system","clientPath",conf.clientPath)
    conf.logDir=config.getstr("system","logDir",conf.logDir)
    conf.radiusIP=config.getstr("system","radiusIP",conf.radiusIP)
    conf.reponseTimeout=config.getint("system","reponseTimeout",conf.reponseTimeout)
    conf.secret=config.getstr("system","secret",conf.secret)
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog("%s/log/RADCK_$(Date8).log"%(os.path.dirname(__file__)))
Esempio n. 31
0
def loadconfig():
    config = ConfigParser.ConfigParser()
    configfile = assistant.SF("%s/SAPeakData.conf" % (os.path.dirname(__file__)))

    PLOG.info("Load configer file:%s" % configfile)
    config.readfp(open(configfile, "rb"))
    SAPeakDataPublic.st.loglevel = config.get("system", "loglevel")
    SAPeakDataPublic.st.queryunit = config.getint("system", "queryunit")
    SAPeakDataPublic.st.queryrepeattimes = config.getint("system", "queryrepeattimes")
    if 24%SAPeakDataPublic.st.queryunit != 0:
        PLOG.debug("queryunit is invalid,please check config!")
        sys.exit(2)
    SAPeakDataPublic.sadb.host = config.get("system", "datasource")
    SAPeakDataPublic.sadb.dbuser = config.get("system", "dbuser") 
    SAPeakDataPublic.sadb.dbpwd = config.get("system", "dbpwd")
    SAPeakDataPublic.sadb.dbname = config.get("system", "dbname")  
    SAPeakDataPublic.sadb.tablename = config.get("system", "tablename") 
Esempio n. 32
0
def init():    
    configfile=assistant.SF("%s/filecrawler.conf"%(os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config=pysmartac.configer.openconfiger(configfile)

    #configer
    conf.logLevel=config.getstr("system","logLevel",conf.logLevel)
    conf.httpServerSite=config.getstr("system","httpserversite",conf.httpServerSite)
    conf.movieDir=config.getstr("system","movieDir",conf.movieDir)
    conf.iosDir=config.getstr("system","iosDir",conf.iosDir)
    conf.androidDir=config.getstr("system","androidDir",conf.androidDir)
    conf.movieOutputFile=config.getstr("system","movieOutputFile",conf.movieOutputFile)
    conf.iosOutputFile=config.getstr("system","iosOutputFile",conf.iosOutputFile) 
    conf.androidOutputFile=config.getstr("system","androidOutputFile",conf.androidOutputFile) 
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog("%s/log/FLCRAWLER_$(Date8)_$(filenumber2).log"%(os.path.dirname(__file__)))
Esempio n. 33
0
 def query(self, sqltext, mode = STORE_RESULT_MODE):
     """
     作用:使用connection对象的query方法,并返回一个元组(影响行数(int),结果集(result))
     参数:sqltext:sql语句
     mode=STORE_RESULT_MODE(0) 表示返回store_result,mode=USESTORE_RESULT_MODE(1) 表示返回use_result
     返回:元组(影响行数(int),结果集(result)
     """  
     if None == self.conn or False == self.conn.open:
         return -1
     self.conn.query(sqltext)
     if 0 == mode:
         result = self.conn.store_result()
     elif 1 == mode:
         result = self.conn.use_result()
     else:
         PLOG.error("DBOperater.closeconnection error, mode value is wrong")
         return -1
     return (self.conn.affected_rows(), result)
Esempio n. 34
0
def loadconfig():
    config = ConfigParser.ConfigParser()
    configfile = assistant.SF("%s/SAPeakData.conf" %
                              (os.path.dirname(__file__)))

    PLOG.info("Load configer file:%s" % configfile)
    config.readfp(open(configfile, "rb"))
    SAPeakDataPublic.st.loglevel = config.get("system", "loglevel")
    SAPeakDataPublic.st.queryunit = config.getint("system", "queryunit")
    SAPeakDataPublic.st.queryrepeattimes = config.getint(
        "system", "queryrepeattimes")
    if 24 % SAPeakDataPublic.st.queryunit != 0:
        PLOG.debug("queryunit is invalid,please check config!")
        sys.exit(2)
    SAPeakDataPublic.sadb.host = config.get("system", "datasource")
    SAPeakDataPublic.sadb.dbuser = config.get("system", "dbuser")
    SAPeakDataPublic.sadb.dbpwd = config.get("system", "dbpwd")
    SAPeakDataPublic.sadb.dbname = config.get("system", "dbname")
    SAPeakDataPublic.sadb.tablename = config.get("system", "tablename")
def init():    
    configfile=assistant.SF("%s/filecrawler.conf"%(os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config=pysmartac.configer.openconfiger(configfile)

    #configer
    conf.pidfile=config.getstr("system","pidfile",conf.pidfile)
    conf.threadCount=config.getint("system","threadCount",conf.threadCount)
    conf.logLevel=config.getstr("system","logLevel",conf.logLevel)
    conf.httpServerSite=config.getstr("system","httpserversite",conf.httpServerSite)
    conf.movieDir=config.getstr("system","movieDir",conf.movieDir)
    conf.appDir=config.getstr("system","appDir",conf.appDir)
    conf.movieOutputFile=config.getstr("system","movieOutputFile",conf.movieOutputFile)
    conf.appOutputFile=config.getstr("system","appOutputFile",conf.appOutputFile)    
    conf.checkInterval=config.getint("system","checkInterval",conf.checkInterval)
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog("%s/log/FLCRAWLER_$(Date8)_$(filenumber2).log"%(os.path.dirname(__file__)))
Esempio n. 36
0
def init():
    configfile = assistant.SF("%s/radiusCheck.conf" %
                              (os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config = pysmartac.configer.openconfiger(configfile)

    #configer
    conf.logLevel = config.getstr("system", "logLevel", conf.logLevel)
    conf.clientPath = config.getstr("system", "clientPath", conf.clientPath)
    conf.logDir = config.getstr("system", "logDir", conf.logDir)
    conf.radiusIP = config.getstr("system", "radiusIP", conf.radiusIP)
    conf.reponseTimeout = config.getint("system", "reponseTimeout",
                                        conf.reponseTimeout)
    conf.secret = config.getstr("system", "secret", conf.secret)
    config.save()
    #log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog("%s/log/RADCK_$(Date8).log" %
                       (os.path.dirname(__file__)))
Esempio n. 37
0
def run():
    time.sleep(5)
    global logined
    if logined:
        global ser
        while (ser.isOpen()):    
            text = ser.readline()          # read one, with timout
            if text:                    # check if not timeout
                n = ser.inWaiting()
                while n >0:
                     # look if there is more to read
                    text = text + ser.readline() #get it   
                    n = ser.inWaiting()
                PLOG.debug( text)
                if logined :
                    processData(text)
            
            # 50ms 读取一次数据
            time.sleep(0.05)
    ser.close()
Esempio n. 38
0
def init():
    configfile = assistant.SF("%s/filecrawler.conf" % (os.path.dirname(__file__)))
    print os.path.dirname(__file__)
    config = pysmartac.configer.openconfiger(configfile)

    # configer
    conf.pidfile = config.getstr("system", "pidfile", conf.pidfile)
    conf.threadCount = config.getint("system", "threadCount", conf.threadCount)
    conf.logLevel = config.getstr("system", "logLevel", conf.logLevel)
    conf.ftpServerMovieSource = config.getstr("system", "ftpServerMovieSource", conf.ftpServerMovieSource)
    conf.ftpServerAppSource = config.getstr("system", "ftpServerAppSource", conf.ftpServerAppSource)
    conf.ftpServerUser = config.getstr("system", "ftpServerUser", conf.ftpServerUser)
    conf.ftpServerPwd = config.getstr("system", "ftpServerPwd", conf.ftpServerPwd)
    conf.ftpJsonOutputPath = config.getstr("system", "ftpJsonOutputPath", conf.ftpJsonOutputPath)
    conf.movieOutputFile = config.getstr("system", "movieOutputFile", conf.movieOutputFile)
    conf.appOutputFile = config.getstr("system", "appOutputFile", conf.appOutputFile)
    conf.checkInterval = config.getint("system", "checkInterval", conf.checkInterval)
    config.save()
    # log settings
    PLOG.setlevel(conf.logLevel)
    PLOG.enableFilelog(assistant.SF("%s/log/FLCRAWLER_$(Date8)_$(filenumber2).log" % (os.path.dirname(__file__))))
Esempio n. 39
0
 def load(self):
     config = ConfigParser.ConfigParser()
     conf1 = assistant.SF("%s/alwayson.conf" % (os.path.dirname(__file__)))
     conf2 = assistant.SF("%s/alwayson.conf" % (os.getcwd()))
     conf3 = "/etc/alwayson.conf"
     if os.path.isfile(conf1):conf = conf1
     elif os.path.isfile(conf2):conf = conf2
     else:conf = conf3
     PLOG.info("using configer file:%s" % conf)
     config.readfp(open(conf1, "rb"))
     checkinterval = config.getint("alwayson", "interval")
     for section in config.sections():
         try:
             if section == "alwayson":continue
             name = section
             newprog = program(name)
             newprog.command = config.get(section, "command")
             newprog.runpath = config.get(section, "runpath")
             # newprog.matchingregular=config.get(section, "matchingregular")
             newprog.matchingstring = config.get(section, "matchingstring")
             newprog.pidfile = config.get(section, "pidfile")
             newprog.bootwait = config.getint(section, "bootwait")
             newprog.rebootwait = config.getint(section, "rebootwait")
             newprog.enabled = config.getboolean(section, "enabled")
             newprog.init(self);
             PLOG.info("confim:%s" % name)
         except:
             PLOG.error("read configerfile failed!program=%s,Pass!" % name)
             continue
         self.programlist.append(newprog)
Esempio n. 40
0
 def load(self):
     config = ConfigParser.ConfigParser()
     conf1 = assistant.SF("%s/alwayson.conf" % (os.path.dirname(__file__)))
     conf2 = assistant.SF("%s/alwayson.conf" % (os.getcwd()))
     conf3 = "/etc/alwayson.conf"
     if os.path.isfile(conf1): conf = conf1
     elif os.path.isfile(conf2): conf = conf2
     else: conf = conf3
     PLOG.info("using configer file:%s" % conf)
     config.readfp(open(conf1, "rb"))
     checkinterval = config.getint("alwayson", "interval")
     for section in config.sections():
         try:
             if section == "alwayson": continue
             name = section
             newprog = program(name)
             newprog.command = config.get(section, "command")
             newprog.runpath = config.get(section, "runpath")
             # newprog.matchingregular=config.get(section, "matchingregular")
             newprog.matchingstring = config.get(section, "matchingstring")
             newprog.pidfile = config.get(section, "pidfile")
             newprog.bootwait = config.getint(section, "bootwait")
             newprog.rebootwait = config.getint(section, "rebootwait")
             newprog.enabled = config.getboolean(section, "enabled")
             newprog.init(self)
             PLOG.info("confim:%s" % name)
         except:
             PLOG.error("read configerfile failed!program=%s,Pass!" % name)
             continue
         self.programlist.append(newprog)
Esempio n. 41
0
def InvokeStopRadius():
    strStopradiusCMD = "service radiusd stop"
    try: 
        PLOG.info("call:%s\n"%(strStopradiusCMD))
        stopret = os.popen(strStopradiusCMD).read()
        PLOG.debug("output:%s\n"%(stopret) )
    except Exception, e:
        PLOG.info("执行命令失败,CMD=%s\nError=%s\n"%(strStopradiusCMD,e.args[1]))
        exit(1)
Esempio n. 42
0
def InvokeStopRadius():
    strStopradiusCMD = "service radiusd stop"
    try:
        PLOG.info("call:%s\n" % (strStopradiusCMD))
        stopret = os.popen(strStopradiusCMD).read()
        PLOG.debug("output:%s\n" % (stopret))
    except Exception, e:
        PLOG.info("执行命令失败,CMD=%s\nError=%s\n" % (strStopradiusCMD, e.args[1]))
        exit(1)
Esempio n. 43
0
 def execute(self, sqltext, args = None, mode = CURSOR_MODE, many = False):
     """
     作用:使用游标(cursor)的execute 执行query
     参数:sqltext: 表示sql语句
     args: sqltext的参数
     mode:以何种方式返回数据集
     CURSOR_MODE = 0 :store_result , tuple
     DICTCURSOR_MODE = 1 : store_result , dict
     SSCURSOR_MODE = 2 : use_result , tuple
     SSDICTCURSOR_MODE = 3 : use_result , dict
     many:是否执行多行操作(executemany)
     返回:元组(影响行数(int),游标(Cursor))
     """
     if CURSOR_MODE == mode:
         curclass = MySQLdb.cursors.Cursor
     elif DICTCURSOR_MODE == mode :
         curclass = MySQLdb.cursors.DictCursor
     elif SSCURSOR_MODE == mode:
         curclass = MySQLdb.cursors.SSCursor
     elif SSDICTCURSOR_MODE == mode:
         curclass = MySQLdb.cursors.SSDictCursor
     else :
         PLOG.error("DBOperater.closeconnection error, mode value is wrong")
         return -1
     cur = self.conn.cursor(cursorclass=curclass)
     line = 0
     if False == many:
         if None == args:
             line = cur.execute(sqltext)
         else :
             line = cur.execute(sqltext,args)
     else :
         if None == args:
             line = cur.executemany(sqltext)
         else :
             line = cur.executemany(sqltext,args)
     return (line , cur)
Esempio n. 44
0
def executearrsql(sqltext,dboperater=None,arrsql=None,sqlnum=100,mode = DBHelper.CURSOR_MODE):
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        if arrsql!=None and len(arrsql)>0:
            totalnum = len(arrsql)
            if totalnum%sqlnum == 0:
                foocount = totalnum/sqlnum
            else:
                foocount = totalnum/sqlnum+1
            i = 0
            while i<foocount:
                arr = arrsql[i*sqlnum:(i+1)*sqlnum]
                dboperater.execute(sqltext,args=arr,mode=mode,many=True)#执行SQL语句
                dboperater.conn.commit() #提交SQL语句
                i+=1  
        else:
            # 执行单条sql语句
            dboperater.execute(sqltext,mode=mode)
            dboperater.conn.commit()
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],sqltext))  
Esempio n. 45
0
 def update_pid(self):
     try:
         self._pid = 0
         if len(self.pidfile) > 0:
             pidfile = open(self.pidfile, 'r')
             pid = int(pidfile.readline())
             if pid != 0:
                 if self.getCommandForPID(pid) != None:
                     self._pid = pid
                     PLOG.info("%s PID confim for pid:%d" % (self.name, pid))
         elif len(self.matchingstring) > 0:
             pid = self.getPIDForString(self.matchingstring)
             if pid != None:
                 self._pid = pid
                 PLOG.info("%s PID confim for regular:%d" % (self.name, pid))
         else:
             PLOG.error("%s Unknow check type!!!" % self.name)
     except Exception, e:
         PLOG.error("%s update_pid except!err=%s" % (self.name, e))
Esempio n. 46
0
 def update_pid(self):
     try:
         self._pid = 0
         if len(self.pidfile) > 0:
             pidfile = open(self.pidfile, 'r')
             pid = int(pidfile.readline())
             if pid != 0:
                 if self.getCommandForPID(pid) != None:
                     self._pid = pid
                     PLOG.info("%s PID confim for pid:%d" %
                               (self.name, pid))
         elif len(self.matchingstring) > 0:
             pid = self.getPIDForString(self.matchingstring)
             if pid != None:
                 self._pid = pid
                 PLOG.info("%s PID confim for regular:%d" %
                           (self.name, pid))
         else:
             PLOG.error("%s Unknow check type!!!" % self.name)
     except Exception, e:
         PLOG.error("%s update_pid except!err=%s" % (self.name, e))
Esempio n. 47
0
def run():
    init()  
    if conf.httpServerSite[-1] != '/' : conf.httpServerSite += '/'
      
    # 爬取文件,生成最终json文件 start	
    if len(conf.movieDir) != 0 :
        scanFile(conf.movieDir,"movie")
    else:
        PLOG.warn("moviedir is empty,please check config file")
    if len(conf.androidDir) != 0 :
        scanFile(conf.androidDir,"android")
    else:
        PLOG.warn("androiddir is empty,please check config file")   
    if len(conf.iosDir) != 0 :
        scanFile(conf.iosDir,"ios")
    else:
        PLOG.warn("iosdir is empty,please check config file")        
Esempio n. 48
0
def processData(text):
    #提取最后一次摇杆位置坐标
    index = text.rfind("(")
    indexEnd = text.rfind(")")
    PLOG.debug( "last location is "+text[index:indexEnd+1])
    text = text[index:indexEnd+1]
    text = text.replace("(","")
    text = text.replace(")","")
    arr = text.split(',')
    x = int(arr[0])
    y = int(arr[1])
    z = int(arr[2])
    #根据坐标判断是哪种运动状态
    vx = x - 512
    vy = y - 512
    active_operation = ""
    if abs(vx) < admissibleError and abs(vy) < admissibleError:
        active_operation = "stop"
        PLOG.debug( "stop")
    elif abs(vx) < 512*1.414/2:
        if vy >0 and vy -admissibleError > 0:    
            active_operation = "up"
            PLOG.debug( "up")
        else:
            active_operation = "down"
            PLOG.debug( "down" )  
    elif abs(vy) < 512*1.414/2:
        if vx >0 and vx -admissibleError > 0:  
            active_operation = "spin_right"
            PLOG.debug( "spin_right")
        else:
            active_operation = "spin_left"
            PLOG.debug( "spin_left")
    """
    {
	"invoke_id":"调用ID",
	// 消息ID
	"msgid":"active_robot",
	// 机器人id
	"robot_id":"1212",
	// 运动模式
	"active_mode":{
		"operation":"spin", // up-前进,down-后退,spin_up-调头前进,spin_left-左旋转,spin_right-右旋转
		"distance":10,  // 单位cm  移动距离(up和down时有此参数)
		"angle":180		// 旋转角度 (spin时有此参数)
	}
    }"""
    if active_operation is not "":    
        now = int(time.time()*1000)
        global lastSendTime
        global lastActive

        if active_operation != lastActive or now - lastSendTime >= 950:
            global logined
            if not logined: 
                login()
            msg = {}
            msg["invoke_id"] = "1"
            msg["msgid"] = "active_robot"
            msg["robot_id"] = "37bf0a26359e37d"
            msg["active_mode"] = {}
            msg["active_mode"]["operation"] = active_operation
            strmsg = json.dumps(msg)
            global ws
            ws.send(strmsg)
            PLOG.debug( "Send: "+strmsg )
            lastSendTime = now
            lastActive = active_operation
Esempio n. 49
0
def on_close(ws):
    PLOG.debug("### closed ###" )
Esempio n. 50
0
def InvokeProc():
    #echo "User-Name = radiusSelfCheck, User-Password = radiusSelfCheck" | ./radclient -xxxx 127.0.0.1:1812 auth testing123
    strCMD="echo \"User-Name = radiusSelfCheck,User-Password = radiusSelfCheck\" | %s -xxxx %s:1812 auth %s" % \
    (conf.clientPath,conf.radiusIP,conf.secret)
    try:
        PLOG.info("call:%s\n" % (strCMD))
        beforeInvokeAuth = int(time.time())
        retstr = os.popen(strCMD).read()
        afterInvokeAuth = int(time.time())
        PLOG.debug("output:%s\n" % (retstr))
        if (afterInvokeAuth - beforeInvokeAuth > conf.reponseTimeout):
            PLOG.info("radius auth reponse timeout,stop radius")
            InvokeStopRadius()
            return 0
        if (retstr.find("rad_recv:") != -1
                and retstr.find("Reply-Message") != -1):
            # 收到回应
            if (retstr.find("radius status is ok") != -1):
                # radius运行正常
                PLOG.info("radius run status is ok")
                return 1
            else:
                # radius状态不正确,关掉radius
                repmsg = ""
                repMsgpattern = re.compile(
                    'Reply-Message\s*=\s*(?P<repmsg>.*)\s*')
                m = repMsgpattern.search(retstr)
                if (m != None and m.group('repmsg') != None):
                    repmsg = m.group('repmsg')
                PLOG.info("radius run status error,errmsg = %s ,stop radius" %
                          repmsg)
                InvokeStopRadius()
                return 0
        else:
            # radius状态不正确,关掉radius
            PLOG.info("radius run status error,no response,stop radius")
            InvokeStopRadius()
            return 0
    except Exception, e:
        PLOG.info("执行命令失败,CMD=%s\nError=%s\n" % (strCMD, e.args[1]))
        exit(1)