Ejemplo n.º 1
0
def ValidateTag(parameter_list, studentdir, goal_type, inputtag, allowed_special_answer, logger):
    # if allowed_special_answer is true, then allow 'answer=<string>'
    # UNLESS if the goal_type is matchacross
    returntag = ""
    if '=' in inputtag:
        if not allowed_special_answer:
            logger.error("goals.config only answertag is allowed answer=<string>, resulttag (%s) is not" % inputtag)
            sys.exit(1)
        if goal_type == "matchacross":
            logger.error("goals.config answer=<string> and goal_type==matchacross is not allowed")
            sys.exit(1)
        (target, finaltag) = inputtag.split('=')
        returntag = getTagValue(parameter_list, target, finaltag, logger)
 
    elif inputtag.startswith('(') and inputtag.endswith(')'):
        returntag = 'result.%s' % inputtag
    elif '.' in inputtag:
        logger.debug("tag %s contains '.'" % inputtag)
        (target, finaltag) = inputtag.split('.')
        if not target in answer_tokens:
            logger.error("goals.config tag=<string> then tag must be:(%s), got %s" % (','.join(answer_tokens), inputtag))
            sys.exit(1)
        if not MyUtil.CheckAlphaDashUnder(finaltag):
            logger.error("Invalid characters in goals.config's tag (%s)" % inputtag)
            sys.exit(1)

        returntag = getTagValue(parameter_list, target, finaltag, logger)
    else:
        logger.debug("tag is %s" % inputtag)
        if not MyUtil.CheckAlphaDashUnder(inputtag):
            logger.error("Invalid characters in goals.config's tag (%s)" % inputtag)
            sys.exit(1)
        returntag = 'result.%s' % inputtag

    return returntag
Ejemplo n.º 2
0
    def __startSipLib(self):
        isSuccess = True
        global lib
        if lib:
            self.__stopSipLib()

        lib =  pj.Lib()
        self._listCallInfo=[]

        try:
        # if True:
            dao = self.configDao;
            mediaConfig=MediaConfig()
            mediaConfig.enable_ice = MyUtil.db_str2bool(dao.GetIsUseIce())
            mediaConfig.enable_turn =MyUtil.db_str2bool(dao.GetIsUseTurn())
            if mediaConfig.enable_turn:
                mediaConfig.turn_server = str(dao.GetTurnServer())

            uaConfig=UAConfig()
            if (MyUtil.db_str2bool(dao.GetIsUseStun())):
                uaConfig.stun_srv = [str(dao.GetStunServer())]

            lib.init(ua_cfg = uaConfig,log_cfg = pj.LogConfig(level=int(dao.GetLogLevel()), callback=self.log_cb), media_cfg=mediaConfig)
            lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(int(dao.GetSipSendPort())))
            lib.start()
        except:
            isSuccess=False
            self.show_err_msg()

        if isSuccess:
            isSuccess=self.reRegister()


        return isSuccess
Ejemplo n.º 3
0
def make_cid(dirpath, CID_coll, htmlfile, outroot):
    # Get list of DCC documents from a Word file saved as html
    GetUrlWord.get_url_word(dirpath + outroot, dirpath + htmlfile)  

    # Login to DCC
    s = DCC.login(CF.dcc_url + CF.dcc_login)

    json_handlelist = dirpath + outroot + 'bothlist.txt'
    json_ssdata = dirpath + outroot + 'CID.txt'
    get_cid_ssdata(s, json_handlelist, json_ssdata)

    xlfile = dirpath + outroot + 'CID_Analysis.xls'
    write_spreadsheet(json_ssdata, xlfile)

    json_verlist = dirpath + outroot + 'ver_list.txt'
    json_doclist = dirpath + outroot + 'doc_list.txt'
    make_handle_lists(json_ssdata, json_doclist, json_verlist)

    ## Remove the files that are currently located in the collection for the CID

    if MyUtil.get_yn('Remove location (not delete) of files from ' + CID_coll[0] +'(Y/N)?: '):
        doclist = DCC.list_obj_in_coll(s, CID_coll[0],Print=True,Jwrite=False,Depth='infinity',Type='Doc')
        for doc in doclist:
            DCC.dcc_remove_doc_from_coll(s, doc, CID_coll[0])

    ## Add CID files to the collection
    fh = open(json_doclist, 'r')
    dl = json.load(fh)
    fh.close()

    if MyUtil.get_yn('Add CID files to ' + CID_coll[0] +' (Y/N)?: '):
        DCC.add_docs_2_collections(s, dl, CID_coll)

    # Check that the expected docs are in the collection
    DCC.check_docs_in_coll(s, dl, CID_coll)
Ejemplo n.º 4
0
    def SvcDoRun(self):
        try:
            global LOG,DBIP,DBPort,_3ds,log,socksize,innerIP,CPUCores
            socksize = 64000
            _3ds = MyUtil._secret()
            cf1 = ConfigParser.ConfigParser()
            cf1.read(MyUtil.cur_file_dir() + "\\agent.ini")
            agentpath = cf1.get("main", "path").decode('gbk').encode("utf-8")
            agentlogfile = cf1.get("main", "agentlogfile").decode('gbk').encode("utf-8")
            MyUtil.DBIP = cf1.get("main", "DBIP").decode('gbk').encode("utf-8")
            MyUtil.DBPort = cf1.get("main", "DBPort").decode('gbk').encode("utf-8")          
            LOG = os.path.join(agentpath,agentlogfile)
            #创建日志实例
            log = MyUtil.CLogInfo(LOG)        
            
            cf = ConfigParser.ConfigParser()
            cf.read(MyUtil.cur_file_dir()+"\\auto.ini")
            #强制读取配置文件中的IP地址设置,当前的问题是第一次必须手工更改配置文件中的IP,否则传出的IP错误
            innerIP = cf.get("Configuration", "localip").decode('gbk').encode("utf-8")            
            try:
                CPUCores = cf.get("Configuration","cpucores").decode('gbk').encode("utf-8")
                CPUCores = int(CPUCores)
            except:
                CPUCores = int('1')

            rc = runCron()
            rc.run()
        except:
            #print "main Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
            pass
Ejemplo n.º 5
0
    def updatePic(self):

        pixmap = self.anchorDialog.currentPixmap
        self.currentPixmap = pixmap

        if (self.anchorDialog.ClickPointable):
            #set child anchor pos info
            self.posx = self.anchorDialog.childAnchor.x(
            ) - self.anchorDialog.x()
            self.posy = self.anchorDialog.childAnchor.y(
            ) - self.anchorDialog.y()
            self.posWidth = self.anchorDialog.childAnchor.width()
            self.posHeight = self.anchorDialog.childAnchor.height()
            self.lbl_uploadImg.setClickableArea(self.posx, self.posy,
                                                self.posWidth, self.posHeight)
        else:
            self.posx = None
            self.posy = None
            self.posWidth = None
            self.posHeight = None
            self.lbl_uploadImg.setClickableArea(None, None, None, None)
            pass
        # self.anchorDialog.setPixmap(pixmap)

        # project text match using tesseract
        if (self.checkbt_imageRec.isChecked() == True and
                self.combo_imageRec.currentText() == Settings.textMatchText):
            cv2_image = MyUtil.convertPixmapToGray(pixmap, isgray=False)
            str_Match = MyUtil.getTextFromImage(cv2_image)
            self.edit_TextMatch.setText(str_Match)
        self.lbl_uploadImg.setPixmap(pixmap)
        pass
Ejemplo n.º 6
0
def cronAdd(cmds, cmd):
    """增加守护进程列表的方法
    cmd=cronadd,cronadd=*;*;*;*;*;/usr/bin/tomcat.sh;JAVA
    """
    try:
        if not 'cronadd' in cmds.keys():
            return "-1", "Lost cronadd.缺少cronadd参数".encode("utf-8")
        cronNew = cmds['cronadd'].upper() + '\n'
        if not cronNew.find(';'):
            return "-1", "parameter Error.请使用;分号为分隔符".encode("utf-8")
        cronNew = cronNew.replace(';', ',')
        if os.path.isfile(MyUtil.cur_file_dir() + '/crontab.ini'):
            f = open(MyUtil.cur_file_dir() + '/crontab.ini', "r+")
            cronMatch = False
            for eachLine in f:
                if cronNew == eachLine.upper():
                    cronMatch = True
                    break
                else:
                    cronMatch = False
            str1 = 'Find duplicate cron.'
            if not cronMatch:
                f.write(cronNew + '\n')
                str1 = 'cronadd OK.'
            f.close()
            return "1", str1
        else:
            return "-1", 'crontab.ini not found.'
    except:
        return "-1", "CronAdd.Error"
Ejemplo n.º 7
0
def macd_to_sql(data):
    '''
    :param data: macd data
    :return: None,Write data to the database
    '''
    conn = MyUtil.get_conn('stock_data')
    cur = conn.cursor()
    #sql="insert into macd(code,date,open,high,low,close,vol,ema,diff,dea,macd,ma,var,std,reg,mul) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    sql="insert into macd(code,date,open,high,low,close,vol,ema,diff,dea,macd,ma10,ma30,ma60,var,std,reg,reg_min,reg_max,ma_reg,ma_min,ma_max,mul,cd) " \
        "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ON DUPLICATE KEY UPDATE mul={},cd={}"
    count = 0
    data = data.fillna(0)
    for d in data.values:
        try:
            cur.execute(
                sql.format(d[21], d[22]),
                ('HSIc1', str(d[0]), d[1], d[2], d[3], d[4], d[5], d[6], d[7],
                 d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15], d[16],
                 d[17], d[18], d[19], d[20], d[21], d[22]))
            count += 1
            if not count % 10000:
                conn.commit()
        except Exception as exc:
            print(exc)
            continue
    conn.commit()
    MyUtil.closeConn(conn)
Ejemplo n.º 8
0
def cronAdd(cmds, cmd):
    """增加守护进程列表的方法
    cmd=cronadd,cronadd=*;*;*;*;*;c:\WINDOWS\NOTEPAD.EXE;NOTEPAD.EXE
    """
    try:
        if not 'cronadd' in cmds.keys():
            return "-1", "Lost cronadd.缺少cronadd参数".decode('gbk').encode("utf-8")
        cronNew = cmds['cronadd'].upper() + '\n'
        if not cronNew.find(';'):
            return "-1", "parameter Error.请使用;分号为分隔符".decode('gbk').encode("utf-8")
        cronNew = cronNew.replace(';', ',')
        if os.path.isfile(MyUtil.cur_file_dir() + '\\crontab.ini'):
            f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "r+")
            cronMatch = False
            for eachLine in f:
                if cronNew == eachLine.upper():
                    cronMatch = True
                    break
                else:
                    cronMatch = False
            str1 = 'Find duplicate cron.'
            if not cronMatch:
                f.write(cronNew + '\n')
                str1 = 'cronadd OK.'
            f.close()
            return "1", str1
        else:
            return "-1", 'crontab.ini not found.'
    except:
        return "-1", "CronAdd.Error"
Ejemplo n.º 9
0
    def SvcDoRun(self):
        try:
            global LOG, DBIP, DBPort, _3ds, log, socksize, innerIP, CPUCores
            socksize = 64000
            _3ds = MyUtil._secret()
            cf1 = ConfigParser.ConfigParser()
            cf1.read(MyUtil.cur_file_dir() + "\\agent.ini")
            agentpath = cf1.get("main", "path").decode('gbk').encode("utf-8")
            agentlogfile = cf1.get(
                "main", "agentlogfile").decode('gbk').encode("utf-8")
            MyUtil.DBIP = cf1.get("main", "DBIP").decode('gbk').encode("utf-8")
            MyUtil.DBPort = cf1.get("main",
                                    "DBPort").decode('gbk').encode("utf-8")
            LOG = os.path.join(agentpath, agentlogfile)
            #创建日志实例
            log = MyUtil.CLogInfo(LOG)

            cf = ConfigParser.ConfigParser()
            cf.read(MyUtil.cur_file_dir() + "\\auto.ini")
            #强制读取配置文件中的IP地址设置,当前的问题是第一次必须手工更改配置文件中的IP,否则传出的IP错误
            innerIP = cf.get("Configuration",
                             "localip").decode('gbk').encode("utf-8")
            try:
                CPUCores = cf.get("Configuration",
                                  "cpucores").decode('gbk').encode("utf-8")
                CPUCores = int(CPUCores)
            except:
                CPUCores = int('1')

            rc = runCron()
            rc.run()
        except:
            #print "main Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
            pass
Ejemplo n.º 10
0
def setLocalIP():
    #强写本地IP地址到配置文件中去
    cf1 = ConfigParser.ConfigParser()
    cf1.read(MyUtil.cur_file_dir() + "/auto.ini")
    ipMac = ServerInfo.GetinnerIPMac()
    innerIP = str(ipMac[0])
    cf1.set("Configuration", "localIP", innerIP)
    cf1.write(open(MyUtil.cur_file_dir() + "/auto.ini", "w"))
Ejemplo n.º 11
0
def setLocalIP():
    #强写本地IP地址到配置文件中去
    cf1 = ConfigParser.ConfigParser()
    cf1.read(MyUtil.cur_file_dir() + "\\auto.ini")
    ipMac = ServerInfo.GetinnerIPMac()
    innerIP = str(ipMac[0])
    cf1.set("Configuration", "localIP", innerIP)
    cf1.write(open(MyUtil.cur_file_dir() + "\\auto.ini", "w"))
Ejemplo n.º 12
0
def make_cid(dirpath, CID_coll, htmlfile, outroot):
    # Get list of DCC documents from a Word file saved as html
    GetUrlWord.get_url_word(dirpath + outroot, dirpath + htmlfile)  

    # Login to DCC
    prod = ['prod', 'production', 'p', ' ']
    tes = ['test', 'tes', 't']
    checker = False
    print("Would you like to log into the production site or the test site?")
    print("Valid Inputs are as follows: Production, prod, p, test, t :", end="")
    choice = input().lower()
    #while loop to continue asking the user for input until a correct input has been entered
    while (checker == False):
        #Production site login choice
        if(choice in prod):
            print("You are now logging into the Production version of DocuShare")
            s = DCC.login(Site ='Production')
            checker = True
        #test site login choice
        elif(choice in tes):
            print("You are now logging into the test VM DocuShare")
            s = DCC.login(Site ='Test')
            checker = True
        #cf.dcc_url + cf.dcc_login
        #error message alerting user to enter a valid choice
        else:
            print("Please enter a valid choice, (P)roduction or (T)est")
            choice = input().lower()

    json_handlelist = dirpath + outroot + 'bothlist.txt'
    json_ssdata = dirpath + outroot + 'CID.txt'
    get_cid_ssdata(s, json_handlelist, json_ssdata)

    xlfile = dirpath + outroot + 'CID_Analysis.xls'
    write_spreadsheet(json_ssdata, xlfile)

    json_verlist = dirpath + outroot + 'ver_list.txt'
    json_doclist = dirpath + outroot + 'doc_list.txt'
    make_handle_lists(json_ssdata, json_doclist, json_verlist)

    ## Remove the files that are currently located in the collection for the CID

    if MyUtil.get_yn('Remove location (not delete) of files from ' + CID_coll[0] +'(Y/N)?: '):
        doclist = DCC.list_obj_in_coll(s, CID_coll[0],Print=True,Jwrite=False,Depth='infinity',Type='Doc')
        for doc in doclist:
            DCC.dcc_remove_doc_from_coll(s, doc, CID_coll[0])

    ## Add CID files to the collection
    fh = open(json_doclist, 'r')
    dl = json.load(fh)
    fh.close()

    if MyUtil.get_yn('Add CID files to ' + CID_coll[0] +' (Y/N)?: '):
        DCC.add_docs_2_collections(s, dl, CID_coll)

    # Check that the expected docs are in the collection
    DCC.check_docs_in_coll(s, dl, CID_coll)
Ejemplo n.º 13
0
 def loadData(self,isAws=False):
     """ 
     Load data from api or any other data source and return json object
     """
     # return data for test
     if(self.fromAws):
         return MyUtil.getDataFromBucket()
     else:
         return MyUtil.getDataFromCurrentTeacherFolder()
Ejemplo n.º 14
0
    def downfile(self,filename,cmdStr):
#        """下载文件
#        """
#        try:
            jieguo = ""
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((self.host,self.port ))
            sock.sendall('au,'+cmdStr)
            self.response = sock.recv(self.sockSize)
            l = string.split(self.response)
            #如果返回有文件名,而且一致,说明有MD5码
            if l[0] == filename:
                returnMD5=l[1]
                #确认本地存放路径
                MyUtil.mkpath(path)
                # 'please wait...'
                Fname = os.path.join(path,filename)
                f = open(Fname, 'wb')
                #print '开始下载。。。'
                i = 0
                while True:
                    data = sock.recv(10485760)
                    #print '接受文件中。。。。','  ',i
                    i+=1
                    if not data:
                        break
                    if str(data).endswith('4423718C61C4E8A4362D955BBC7B9711'):
                        data = data[:len(data)-len('4423718C61C4E8A4362D955BBC7B9711')]
                        f.write(data)
                        break
                    f.write(data)
                f.flush()    
                f.close()
                #print '接受完毕。。。。'
                FMD5 = string.split(md5sum(Fname))
                if FMD5[0] > int("0"):
                    if FMD5[1] == returnMD5:
                        if 'updateself' in cmdStr:
                            jieguo = 2
                        else:
                            jieguo = 1
                    else:
                        jieguo = -2
                else:
                    jieguo = -3

            elif l[0] == '-1':
                jieguo = -4
            elif l[0] == '-2':
                jieguo = -5
            else:
                jieguo = -6
                
            sock.close()
            #print jieguo
            return jieguo
Ejemplo n.º 15
0
    def downfile(self, filename, cmdStr):
        """下载文件
        """
        try:
            jieguo = ""
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((self.host, self.port))
            sock.sendall('au,' + cmdStr)
            self.response = sock.recv(self.sockSize)
            l = string.split(self.response)
            #如果返回有文件名,而且一致,说明有MD5码
            if l[0] == filename:
                returnMD5 = l[1]
                #确认本地存放路径
                MyUtil.mkpath(path)
                Fname = os.path.join(path, filename)
                f = open(Fname, 'wb')
                i = 0
                while True:
                    data = sock.recv(10485760)
                    i += 1
                    if not data:
                        break
                    if str(data).endswith('4423718C61C4E8A4362D955BBC7B9711'):
                        data = data[:len(data) -
                                    len('4423718C61C4E8A4362D955BBC7B9711')]
                        f.write(data)
                        break
                    f.write(data)
                f.flush()
                f.close()
                FMD5 = string.split(md5sum(Fname))
                if FMD5[0] > int("0"):
                    if FMD5[1] == returnMD5:
                        if 'updateself' in cmdStr:
                            jieguo = 2
                        else:
                            jieguo = 1
                    else:
                        jieguo = -2
                else:
                    jieguo = -3

            elif l[0] == '-1':
                jieguo = -4
            elif l[0] == '-2':
                jieguo = -5
            else:
                jieguo = -6

            sock.close()
            return jieguo

        except:
            updateselflog("Client.downfile Error:" + str(sys.exc_info()[0]) +
                          str(sys.exc_info()[1]))
Ejemplo n.º 16
0
    def setValue(self,isUseIce,isUseStun,stunServer,isUseTurn,turnServer):
        if MyUtil.db_str2bool(isUseIce):
            self.useIce.SetValue(True)
        if MyUtil.db_str2bool(isUseStun):
            self.useStun.SetValue(True)
        if MyUtil.db_str2bool(isUseTurn):
            self.useTurn.SetValue(True)

        self.stunServer.SetValue(stunServer)
        self.turnServer.SetValue(turnServer)
Ejemplo n.º 17
0
    def log_cb(self,level, str2, len):
        if (level==1):
            MyUtil.saveErrorLog(str2)
            self.lastErrorInfo += str(str2)

        ### this is the err can't be caught by the program
        if (level ==1):
            if "[status=370004]" in str2:
                self.show_err_msg()
        print str2
Ejemplo n.º 18
0
def get_data(dates):
    conn = MyUtil.get_conn('stock_data')
    #for i in range(9):
    #dates=dates[:8]+str(int(dates[-2:])+i)
    sql = "SELECT datetime,open,high,low,close,vol FROM index_min WHERE code='HSIc1' AND DATE_FORMAT(datetime,'%Y-%m-%d')='{}'".format(
        dates)
    df = pd.read_sql(sql, conn)
    df.columns = ['date', 'open', 'high', 'low', 'close', 'vol']
    return df
    MyUtil.closeConn(conn)
Ejemplo n.º 19
0
    def downfile(self,filename,cmdStr):
        """下载文件
        """
        try:
            jieguo = ""
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((self.host,self.port ))
            sock.sendall('au,'+cmdStr)
            self.response = sock.recv(self.sockSize)
            l = string.split(self.response)
            #如果返回有文件名,而且一致,说明有MD5码
            if l[0] == filename:
                returnMD5=l[1]
                #确认本地存放路径
                MyUtil.mkpath(path)
                Fname = os.path.join(path,filename)
                f = open(Fname, 'wb')
                i = 0
                while True:
                    data = sock.recv(10485760)
                    i+=1
                    if not data:
                        break
                    if str(data).endswith('4423718C61C4E8A4362D955BBC7B9711'):
                        data = data[:len(data)-len('4423718C61C4E8A4362D955BBC7B9711')]
                        f.write(data)
                        break
                    f.write(data)
                f.flush()    
                f.close()
                FMD5 = string.split(md5sum(Fname))
                if FMD5[0] > int("0"):
                    if FMD5[1] == returnMD5:
                        if 'updateself' in cmdStr:
                            jieguo = 2
                        else:
                            jieguo = 1
                    else:
                        jieguo = -2
                else:
                    jieguo = -3

            elif l[0] == '-1':
                jieguo = -4
            elif l[0] == '-2':
                jieguo = -5
            else:
                jieguo = -6
                
            sock.close()
            return jieguo
            
        except:
            updateselflog("Client.downfile Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
Ejemplo n.º 20
0
def mysql_date(code='HSIc1'):
    """
    :param code: Product name
    :return: Database date tuple. example:('2017-12-01',...)
    """
    conn = MyUtil.get_conn('stock_data')
    cur = conn.cursor()
    cur.execute("SELECT DATE_FORMAT(datetime,'%Y-%m-%d') FROM index_min WHERE CODE='{}' GROUP BY DATE_FORMAT(datetime,'%Y%m%d') ORDER BY datetime".format(code))
    dates = cur.fetchall()
    MyUtil.closeConn(conn)
    dates = tuple(i[0] for i in dates)
    return dates
Ejemplo n.º 21
0
def updateselflog(data):
    """写日志方法
    """
    f = open(MyUtil.cur_file_dir()+"\\updateself.log","w")
    f.write(data)
    f.close()
    
Ejemplo n.º 22
0
def check_perms(s, set, handles, **kwargs):
    ask_flag = kwargs.get('Ask', True)
    if not ask_flag:
        if not MyUtil.get_yn('!!! Warning !!! ask = False: Will not ask to make changes, okay? Enter N to Exit, Y to Continue:'):
            print('exiting...')
            sys.exit(0)
    for handle in handles:
        if 'Document-' in handle:
            fd = DCC.prop_get(s, handle, InfoSet = 'DocBasic')
        elif 'Collection-' in handle:
            fd = DCC.prop_get(s, handle, InfoSet = 'CollData')
        else:
            fd = DCC.prop_get(s, handle, InfoSet = 'Title')    
        fd['permissions'] = DCC.prop_get(s, handle, InfoSet = 'Perms')
#         print(fd['handle'], ':', fd['title'])    
        
        print('\n>>>>>>>>>>>>>>       DCC Information       <<<<<<<<<<<<<<')
        if 'Document-' in handle:
            DCC.print_doc_basic(fd)
        elif 'Collection-' in handle:
            DCC.print_coll_data(fd)
        else:
            print('Not Document or Collection:', handle, ':', fd['title'])   
        print('\n\tDoc Properties URL: ',Tree.url_view(handle))
        print('\tPermissions URL: ',Tree.url_perm(handle))
        print('\tGet Document URL: ',Tree.url_access(handle))

        
        print()
    
        fix_objact(s, fd, handle, set, **kwargs)
        fix_permact(s, fd, handle, set, **kwargs)
Ejemplo n.º 23
0
def writeCfgfile(setIP,setinnerMAC,setWAIIP,setOS,setCodeSet,setCPUCores,setHostname,setPlatform,setSysDir,setCPUInfo,setPHMEM):
    #强写本地IP地址到配置文件中去
    cf1 = ConfigParser.ConfigParser()
    cf1.read(MyUtil.cur_file_dir()+"/auto.ini")
    cf1.set("Configuration", "localIP", setIP)
    cf1.set("Configuration","localMACAddress",setinnerMAC)
    cf1.set("Configuration","OuterIP",setWAIIP)
    cf1.set("Configuration","OS",setOS)
    cf1.set("Configuration","CodeSet",setCodeSet)
    cf1.set("Configuration","CPUCores",setCPUCores)
    cf1.set("Configuration","hostname",setHostname)
    cf1.set("Configuration","Platform",setPlatform)
    cf1.set("Configuration","CPUInfo",setCPUInfo)
    cf1.set("Configuration","SystemDirectory",setSysDir)
    cf1.set("Configuration","Physicalmemory",setPHMEM)
    cf1.write(open(MyUtil.cur_file_dir()+"/auto.ini", "w"))
Ejemplo n.º 24
0
 def handle(self):
     try:
         while True:
             cmd = self.request.recv(sockSize)
             cmd = _3ds.Decrypt(cmd)
             print "recevied command: " + str(cmd)
             cmds = MyUtil.splitCmd(cmd)
             keys = cmds.keys()
             if len(keys) > 0:
                 if cmds['cmd'] in fm.keys():
                     self.request.sendall(str(fm[cmds['cmd']](cmds, cmd)))
                     break
                 else:
                     self.request.sendall("-1")
                     break
             else:
                 self.request.sendall("-1")
                 break
         self.request.close()
     except:
         self.request.close()
         writeLog("CmdServer.handle:" + str(sys.exc_info()[0]) +
                  str(sys.exc_info()[1]))
         print "CmdServer.handle:" + str(sys.exc_info()[0]) + str(
             sys.exc_info()[1])
Ejemplo n.º 25
0
    def createNewFolder(self):

        pmgr = Globals.projectmgr
        path = ""
        if (pmgr.projectPath is None):
            path = pmgr.getTeacherProjectsLocalPath()
        else:
            path = pmgr.projectPath

        name, done = QInputDialog.getText(self, 'Input Dialog',
                                          'ENTER YOUR PROGRAM NAME:')
        if (done):
            pass
        else:
            return

        #if leaf. select parent directory
        if (MyUtil.isLeaf(path)):
            path = os.path.dirname(path)

        #if this same name dir exist, replace with new one
        path = os.path.join(path, name)
        if os.path.exists(path):
            shutil.rmtree(path, ignore_errors=True)
        try:
            os.mkdir(path)
        except:
            logging.info("can't create program folder in path: " + path)

        #refresh tree object
        self.landing_page.refresh()
        pass
Ejemplo n.º 26
0
	def __saveCategoryFile(self, fname):

		f = open(fname, 'w')


		data = []
		keys = self.gene_category.keys()
		keys.sort()

		for g in keys:

			gene = g
			txt = []


			for cat in MyUtil.sortDict( self.gene_category[g], descending_order=True ):

				ttt = cat+'('+str( round( self.gene_category[g][cat], 2)).strip()+')'
				if cat == Categorizer.CATEGORY_NO_ANNOTATION:
					ttt = '-'

				txt.append(ttt)

			sss = gene + '\t' + ', '.join(txt)
			f.write(sss+'\n')

		f.close()
Ejemplo n.º 27
0
	def __showCategories(self, all_categories, gene_category):


		self.listCtrlCategory.ClearAll()
		self.listCtrlCategory.InsertColumn(0, 'Gene')
		self.listCtrlCategory.InsertColumn(1, 'Category')
		self.listCtrlCategory.SetColumnWidth(0, 110)
		self.listCtrlCategory.SetColumnWidth(1, 220)

		data = []
		keys = gene_category.keys()
		keys.sort()

		for g in keys:

			gene = g
			txt = []


			for cat in MyUtil.sortDict( gene_category[g], descending_order=True ):

				ttt = cat+'('+str( round( gene_category[g][cat], 2)).strip()+')'
				if cat == Categorizer.CATEGORY_NO_ANNOTATION:
					ttt = '-'


				txt.append(ttt)


			self.listCtrlCategory.Append(
				( g, ', '.join(txt) )
			)

			self.listCtrlCategory.Refresh()
Ejemplo n.º 28
0
 def run(self):
     while True:
         try:
             try:
                 cpuload = ServerInfo.getCPUUsage()
             except:
                 self.writeLog("ServerMonitorInfo.cpuload:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
                 cpuload = '999'
             mem = ServerInfo.getPhyMem()
             memload = int(mem[1])
             try:
                 disk = ServerInfo.getDiskWarning()
             except:
                 disk = "GetdiskstatusError."
             try:
                 send = MyUtil.SendMsgToDB()
                 send.send(_3ds.Encrypt('agentHeart;' + computerId))
                 send.sock.recv(sockSize)
                 send.send(_3ds.Encrypt("ServerMonitorInfo;" + str(computerId) + ";" + str(cpuload) + ";" + str(memload) + ";" + str(disk) + ";" + str(CmdServerIP)))
                 send.sock.recv(sockSize)
                 send.send(_3ds.Encrypt('end'))
             except:
                 print "ServerMonitorInfo.run.send.error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
                 writeLog("ServerMonitorInfo.run.send.error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
             finally:
                 send.closeSock()
                 time.sleep(60)
         except:
             print "ServerMonitorInfo.run error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
             writeLog("ServerMonitorInfo.run error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
             time.sleep(60)
Ejemplo n.º 29
0
def get_min_data(code='HSIc1'):
    '''
    :param code: Product name
    :return: Minute data that removes excess data
    '''
    conn = MyUtil.get_conn('stock_data')
    cur = conn.cursor()
    cur.execute(
        "SELECT DATETIME,OPEN,high,low,CLOSE,amount,vol FROM index_min WHERE CODE='%s' ORDER BY DATETIME" % code)
    mins = cur.fetchall()
    conn.close()
    mi = []

    def is_node(last, now):
        if last.hour == 11 and last.minute == 59 and now.hour == 12 and now.minute == 0:
            return 1
        elif last.hour == 16 and last.minute == 29 and now.hour == 16 and now.minute == 30:
            return 1
        elif last.hour == 23 and last.minute == 44 and now.hour == 23 and now.minute == 45:
            return 1
        return 0

    for i in range(len(mins)):
        if is_node(mins[i - 1][0], mins[i][0]):
            mi[-1][2] = mi[-1][2] if mi[-1][2] > mins[i][2] else mins[i][2]
            mi[-1][3] = mi[-1][3] if mi[-1][3] < mins[i][3] else mins[i][3]
            mi[-1][4] = mins[i][4]
            mi[-1][5] = mi[-1][5] + mins[i][5]
            mi[-1][6] = mi[-1][6] + mins[i][6]
        else:
            mi.append(list(mins[i]))
    m=0
    while 1:
        yield m
        m=mi
Ejemplo n.º 30
0
def forever():
    try:
        print "CmdServer启动"
        writeLog('CmdServer Start')
        cmdserver = cmdServerThread("cmdserver")
        cmdserver.start()
        try:
            send = MyUtil.SendMsgToDB()
            send.send(_3ds.Encrypt('startAgent;' + computerId))
            send.sock.recv(sockSize)
            
            info1 = _3ds.Encrypt("insertServer;" + computerId + ";" + infos)
            send.send(info1)
            send.sock.recv(sockSize)
            send.send(_3ds.Encrypt('end'))
            send.closeSock()
        except:
            writeLog("CMDServer.handle:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
        serverinfo = ServerMonitorInfo("ServerMonitorInfo")
        serverinfo.start()
        serverinfo.join()
        cmdserver.join()
    except:
        print "runCron Error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
        writeLog("CMDServer.forever Error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
Ejemplo n.º 31
0
def read_idioma_trabalhos(filepath, idiomas):
    registers = MyUtil.read_file('trabalhos_conclusao.tsv', filepath)
    trabalhos = defaultdict(lambda: defaultdict())
    for row in registers:
        i_programa = 16
        i_idioma = 7

        #tratamento de casos especificos
        while len(row[i_programa]) != 13:
            i_programa += 1

        while not row[i_idioma].isupper():
            i_idioma += 1

        # [code][idioma] = quantidade
        if row[i_programa] in trabalhos:
            if row[i_idioma] in trabalhos[row[i_programa]]:
                trabalhos[row[i_programa]][row[i_idioma]] += 1
            else:
                trabalhos[row[i_programa]][row[i_idioma]] = 1
            trabalhos[row[i_programa]]['total'] += 1
        else:
            trabalhos[row[i_programa]]['total'] = 1
            trabalhos[row[i_programa]][row[i_idioma]] = 1

        if row[i_idioma] not in idiomas:
            idiomas.append(row[i_idioma])

    return trabalhos
Ejemplo n.º 32
0
def func_macd(code):
    conn = MyUtil.get_conn('stockDate')
    cur = conn.cursor()
    cur.execute('select date,close from transaction_data where code="%s" order by date'%code)
    data = cur.fetchall()
    result = list()
    for i in range(1, len(data)):
        jg = dict()
        if i == 1:
            ac = data[i - 1][1]
            this_c = data[i][1]
            jg['ema_short'] = ac + (this_c - ac) * 2 / 13
            jg['ema_long'] = ac + (this_c - ac) * 2 / 27
            jg['diff'] = jg['ema_short'] - jg['ema_long']
            jg['dea'] = jg['diff'] * 2 / 10
            jg['macd'] = 2 * (jg['diff'] - jg['dea'])
        else:
            n_c = data[i][1]
            jg['ema_short'] = result[i - 2]['ema_short'] * 11 / 13 + n_c * 2 / 13
            jg['ema_long'] = result[i - 2]['ema_long'] * 25 / 27 + n_c * 2 / 27
            jg['diff'] = jg['ema_short'] - jg['ema_long']
            jg['dea'] = result[i - 2]['dea'] * 8 / 10 + jg['diff'] * 2 / 10
            jg['macd'] = 2 * (jg['diff'] - jg['dea'])
        jg['date'] = data[i][0]
        jg['close'] = data[i][1]
        result.append(jg)
        cur.execute('insert into macd(code_id,date,close,code,ema_short,ema_long,diff,dea,macd) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)',
                    (i,jg['date'],jg['close'],code,jg['ema_short'],jg['ema_long'],jg['diff'],jg['dea'],jg['macd']))
    print(code)
    conn.commit()
    cur.close()
    conn.close()
Ejemplo n.º 33
0
    def run(self):

        self.parent.sig_startUpDown.emit(0)

        if self.mode == Settings.refreshProjectsListMode:
            data = MyUtil.getDataFromBucket()
            self.parent.sig_NewBucketData.emit(data)
            pass
        else:
            if (self.isUpLoad == True):

                #upload project
                if (self.localPath is None):
                    return
                UploadProject("", self.localPath)
                pass

            else:

                if (self.remotePath is None or self.localPath is None):
                    return
                else:
                    DownloadProject(self.remotePath, self.localPath)

        self.parent.sig_startUpDown.emit(1)

        pass
Ejemplo n.º 34
0
def start():
    try:
        global fm, _3ds
        _3ds = MyUtil._secret()
        fm = {
            "startAgent": startAgent,
            "insertServer": insertServer,
            "insertProLog": insertProLog,
            "ServerMonitorInfo": ServerMonitorInfo,
            "agentHeart": agentHeart,
            "processRestart": processRestart,
            "NotRUNProess": NotRUNProess
        }

        cf = ConfigParser.ConfigParser()
        cf.read("MonitorDB.ini")

        DBUtil.DBHost = cf.get("main", "DBHost")
        DBUtil.DBPort = cf.get("main", "DBPort")
        DBUtil.DBUser = cf.get("main", "DBUser")
        DBUtil.DBPwd = cf.get("main", "DBPwd")
        serverIP = cf.get("main", "serverip")
        serverPORT = cf.get("main", "serverport")

        print u"数据库服务启动"
        print version.__doc__, MyUtil.version.__doc__, DBUtil.version.__doc__
        print u"DataManagerServerIP %s   PORT:%s" % (serverIP, serverPORT)
        srv = SocketServer.ThreadingTCPServer((serverIP, int(serverPORT)),
                                              DataManager)
        srv.serve_forever()
    except:
        print "start Error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
Ejemplo n.º 35
0
def MyUnZIP(cmds, cmd):
    """收到命令后进行解压的方法
    cmd=unzip,unzipfile=c:\\a.zip,path=c:\\test
    """
    try:
        if not 'unzipfile' in cmds.keys():
            return "-1", "Lost unzip filename.缺少zip压缩文件参数".decode(
                'gbk').encode("utf-8")
        if not 'path' in cmds.keys():
            return "-1", "Lost unzip path.缺少解压目录路径".decode('gbk').encode(
                "utf-8")
        #unzip方法只支持/,所以要转义
        zpath = cmds['path'].replace('\\', '/')
        zfile = cmds['unzipfile']
        if os.path.isfile(zfile):
            zfile = zfile.replace('\\', '/')
            result1 = MyUtil.UnZIP(zfile, zpath)
            if result1 <> '-1':
                return "1", "unzip OK.解压完成."
            else:
                return "-1", "unzip failed.解压失败."
        else:
            return "-1", 'zipfile not found.压缩文件未找到.'
    except:
        return "-1", "MyUnZIP.Error"
Ejemplo n.º 36
0
    def __init__(self):

        self.root = Tk()  # 用库中的 Tk() 方法创建主窗口,并把窗口名称赋值给 root
        self.root.title("指数分钟K线")
        self.root.geometry("600x400+100+100")
        self.textpad = Text(self.root,
                            undo=True,
                            font=('华康少女字体', 12),
                            bg='black',
                            fg='green')
        self.textpad.pack(expand=YES, fill=BOTH)
        self.isRun = True
        try:
            config = configparser.ConfigParser()
            config.read('index_conf.conf')
            host = config['MINK']['host']
            port = config['MINK']['port']
            user = config['MINK']['user']
            passwd = config['MINK']['passwd']
            db_name = config['MINK']['db']
            self.min_input = config['MINK']['filedir']
            self.conn = pymysql.connect(host=host,
                                        db=db_name,
                                        user=user,
                                        passwd=passwd,
                                        port=int(port))
        except:
            self.min_input = '\\\\Seo3\\同花顺港股版\\history\\hz\\min\\'  #'D:\\同花顺软件\\同花顺港股版\\history\hz\min\\'
            self.conn = MyUtil.get_conn('stock_data')
            #self.min_input='D:\\tools\\Tools\\2017年12月\\2017-12-18\\min\\'

        # self.conn = pymysql.connect(db='stockDate', user='******', passwd='123456')
        logging.info('程序开始。。。')
        self.textpad.insert(1.0, '您好! 欢迎使用!')
Ejemplo n.º 37
0
def modify_dcc_perms(s, handle, permdata, **kwargs):
    ask_flag = kwargs.get('Ask',True)
    print('\n   Modifying Permissions to:',handle)
    DCC.print_perms(permdata)       
    if ask_flag == False or MyUtil.get_yn('Change Permissions (Y/N)?'):
        print('Changing permissions...')
        DCC.set_permissions(s, handle, permdata)
Ejemplo n.º 38
0
def fix_objact(s, fd, handle, set, **kwargs):
    ask_flag = kwargs.get('Ask',True)
    
    if not check_fd_sel(fd, set):
        return
        
    for obj_act in set['ObjAct']:
        if not obj_act['Action']:
            pass

        if Match.parse(obj_act['Criteria'], fd):
            if obj_act['Action']['Action'] == 'SetOwner':
                nu = DCC.prop_get(s, obj_act['Action']['Owner'], InfoSet = 'User')
                print('??? Change Owner from [', fd['owner-userid'], ',', fd['owner-username'], '] to [', 
                                        nu['owner-userid'], ',', nu['owner-username'], ']', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.change_owner(s, handle, obj_act['Action']['Owner'])
                    
            elif obj_act['Action']['Action'] == 'AddKeyword':
                print('??? Add Keyword "', obj_act['Action']['Keyword'], '" to "', fd['keywords'].strip(), '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    kw = obj_act['Action']['Keyword'] + fd['keywords'].strip(' ')
                    DCC.set_metadata(s, handle, Keywords = kw)

            elif obj_act['Action']['Action'] == 'DelKeyword':
                print('??? Remove Keyword "', obj_act['Action']['Keyword'], '" from "', fd['keywords'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    kw = fd['keywords'].strip(' ').replace(obj_act['Action']['Keyword'], '')
                    DCC.set_metadata(s, handle, Keywords = kw)
                
            elif obj_act['Action']['Action'] == 'RepTitle':
                print('??? Change Title to "', obj_act['Action']['Title'], '" from "', fd['title'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.set_metadata(s, handle, Title = obj_act['Action']['Title'])

            elif obj_act['Action']['Action'] == 'RepTmtNum':
                print('??? Change TmtNum to "', obj_act['Action']['TmtNum'], '" from "', fd['tmtnum'], '"', sep = '', end = '') 
                if ask_flag == False or MyUtil.get_yn(': (Y/N)? '):
                    DCC.set_metadata(s, handle, Summary = obj_act['Action']['TmtNum'])
                pass
                
            elif obj_act['Action']['Action'] == 'Message':
                print(obj_act['Action']['Message'])
                
            else:
                print('Error in PERM.fix_objact: ObjAct Action not recognized:', obj_act['Action']['Action'])
Ejemplo n.º 39
0
def writeCfgfile(setIP, setinnerMAC, setWAIIP, setOS, setCodeSet, setCPUCores,
                 setHostname, setPlatform, setSysDir, setCPUInfo, setPHMEM):
    #强写本地IP地址到配置文件中去
    cf1 = ConfigParser.ConfigParser()
    cf1.read(MyUtil.cur_file_dir() + "/auto.ini")
    cf1.set("Configuration", "localIP", setIP)
    cf1.set("Configuration", "localMACAddress", setinnerMAC)
    cf1.set("Configuration", "OuterIP", setWAIIP)
    cf1.set("Configuration", "OS", setOS)
    cf1.set("Configuration", "CodeSet", setCodeSet)
    cf1.set("Configuration", "CPUCores", setCPUCores)
    cf1.set("Configuration", "hostname", setHostname)
    cf1.set("Configuration", "Platform", setPlatform)
    cf1.set("Configuration", "CPUInfo", setCPUInfo)
    cf1.set("Configuration", "SystemDirectory", setSysDir)
    cf1.set("Configuration", "Physicalmemory", setPHMEM)
    cf1.write(open(MyUtil.cur_file_dir() + "/auto.ini", "w"))
Ejemplo n.º 40
0
def printItemInfo(resList):
    print "%15s|%4s=%4s|%3s|%s|%s|%s" % ('记录时间', '人', '推荐', '收藏数', '价格', '价格',
                                         '标题')
    cnt = 0
    for itemInfo in resList:
        log = "%11s|%4s=%4s%%|%3s|%6s|%s|%s" % (
            itemInfo['time'], itemInfo['up'] + itemInfo['down'],
            itemInfo['uprate'], itemInfo['star'], itemInfo['rmbprice'],
            itemInfo['price'], itemInfo['title'])
        if cnt % 2 == 0:
            color = 32
        else:
            color = 32
        cnt = cnt + 1
        if itemInfo['uprate'] > 70:
            color = 31
        print Util.colorLog(log, color)
Ejemplo n.º 41
0
def read_docentes(filepath):
    registers = MyUtil.read_file('docentes.xlsx', path=filepath)
    docentes = defaultdict(lambda: list())

    for row in registers:
        docentes[row[3]].append({'name': row[8], 'category': row[12]})

    return docentes
Ejemplo n.º 42
0
def read_trabalhos(filepath):
    registers = MyUtil.read_file('trabalhos_conclusao.xlsx', filepath)
    trabalhos = defaultdict(lambda: defaultdict(lambda: set()))

    for row in registers:
        # trabalhos[code][tipo].add(autor)
        trabalhos[row[3]][row[10]].add(row[9])

    return trabalhos
Ejemplo n.º 43
0
 def __init__(self):
     dbUser, dbPw = MyUtil.get_db_conf()
     self.db = MySQLdb.connect('localhost',
                               dbUser,
                               dbPw,
                               'life',
                               charset='utf8')
     self.cursor = self.db.cursor()
     self.dictCursor = self.db.cursor(MySQLdb.cursors.DictCursor)
Ejemplo n.º 44
0
    def deleteCurrentProject(self):
        projectPath = self.projectPath[:-1]

        if (self.projectPath[-1] == '/' or self.projectPath[-1] == '\\'):
            projectPath = self.projectPath[:-1]
        if (self.__localPathForTeacher == projectPath):
            return False

        if os.path.exists(self.projectPath):
            bucket_prefix = self.projectPath.replace(
                self.__localPathForTeacher, '')
            if (bucket_prefix[0] == '\\' or bucket_prefix[0] == '/'):
                bucket_prefix = bucket_prefix[1:]
            MyUtil.deleteByThread(bucket_prefix)
            shutil.rmtree(self.projectPath, ignore_errors=True)
            return True
        else:
            return False
Ejemplo n.º 45
0
def check_perms(s, set, handle, treename, **kwargs):
    ask_flag = kwargs.get('Ask', True)
    if not ask_flag:
        if not MyUtil.get_yn('!!! Warning !!! ask = False: Will not ask to make changes, okay? Enter N to Exit, Y to Continue:'):
            print('exiting...')
            sys.exit(0)
    tr = Tree.return_tree(s, handle, treename)
    handles = Tree.get_flat_tree(tr)
    for handle in handles:
        fix_set(s, handle, set, **kwargs)
Ejemplo n.º 46
0
def updateselflog(data):
    """写日志方法
    """
    f = open(MyUtil.cur_file_dir()+"/updateself.log","w")
    f.write(data)
    f.close()
    
#if __name__ == '__main__':
#    serverIp = "172.18.165.253"
#    serverPort = 50000
#    aa = updateSelf(1,2)
#    print aa[1].decode('utf-8').encode("gbk")
Ejemplo n.º 47
0
def return_tree(s, target, rootfilename, **kwargs):
    load_flag = kwargs.get("Load")

    if load_flag != False and FileSys.file_check_json(s, rootfilename):
        if load_flag == None:
            load_flag = MyUtil.get_yn("File already exists.  [Load from disk = Y, re-create = N] (Y/N)?")
        tr = FileSys.file_read_json(rootfilename)
        return tr

    tr = get_tree(s, target)
    #     print_tree(s, tr)
    FileSys.file_write_json(tr, rootfilename, path=CF.dccfilepath)
    return tr
Ejemplo n.º 48
0
    def doNatTravelConfig(self,e):
        dlg = MyWidget.NetTraversalConfigDialog(self, -1, _("nat traversal config"))
        dao = self.configDao
        dlg.setValue(dao.GetIsUseIce(),dao.GetIsUseStun(),dao.GetStunServer(),dao.GetIsUseTurn(),dao.GetTurnServer())

        # this does not return until the dialog is closed.
        dlg.CenterOnScreen()
        val = dlg.ShowModal()

        if val == wx.ID_OK:
            dao.SetIsUseIce(MyUtil.db_bool2str(dlg.useIce.GetValue()))
            dao.SetIsUseStun(MyUtil.db_bool2str(dlg.useStun.GetValue()))
            dao.SetIsUseTurn(MyUtil.db_bool2str(dlg.useTurn.GetValue()))
            dao.SetStunServer(dlg.stunServer.GetValue())
            dao.SetTurnServer(dlg.turnServer.GetValue())

            if self.__startSipLib():
                dao.commitSession()
            else:
                dao.rollbackSession()

        dlg.Destroy()
Ejemplo n.º 49
0
def md5sum(fname):
    #其他类型错误,例如目录是否空,返回-2
    try:
        MyUtil.mkpath(path)
        #给文件名前加上绝对地址,避免出错
        Fname=os.path.join(path,fname)
        #检查文件是否存在,如果存后返回其MD5值,如果不存在返回-1
        if os.path.isfile(Fname):
            try:
                f = file(Fname, 'rb')
                ret = sumfile(f)
            except:
                return '-1'
            finally:
                f.close()
                return fname+' '+ret
        else:
            return '-2'
    except:
        print "md5sum Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
        writeLog("md5sum Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
        return '-2'
Ejemplo n.º 50
0
def md5sum(fname):
    """生成文件md5
    """
    #其他类型错误,例如目录是否空,返回-2
    try:
        MyUtil.mkpath(path)
        #给文件名前加上绝对地址,避免出错
        Fname=os.path.join(path,fname)
        #检查文件是否存在,如果存后返回其MD5值,如果不存在返回-1
        if os.path.isfile(Fname):
            try:
                f = file(Fname, 'rb')
                ret = sumfile(f)
            except:
                return '-1',"none"
            finally:
                f.close()
                return fname+' '+ret
        else:
            return '-1',"none"
    except:
        return '-2',"none"
Ejemplo n.º 51
0
 def readCron(self,csvfile):
     '''首次读入定时调度配置,确认当前时间,设定离下一分钟的秒数,分析定时调度
 *,*,*,*,*,c:\WINDOWS\NOTEPAD.EXE
 *,*,*,*,*,e:\1.bat
     '''
     try:
         self.writeLog("readCron:"+str(csvfile))
         if os.path.isfile(csvfile):
             spamReader = csv.reader(open(csvfile))
             #初始化内存中的列表,计数器,注意这样会强制占用列表0单位
             global AMinutes,AHours,ADays,AMonths,AWeeks,ACmd,AExe
             AMinutes=['AMinutes']
             AHours=['AHours']
             ADays=['ADays']
             AMonths=['AMonths']
             AWeeks=['AWeeks']
             ACmd=['cmd']
             AExe=["exe"]
             listcount=1
             if os.path.isfile(csvfile):
                 f = open(csvfile,"r")
                 for eachline in f:
                     e = eachline.split(',')
                     if len(e) == 7:
                         AMinutes.append(e[0])
                         AHours.append(e[1])
                         ADays.append(e[2])
                         AMonths.append(e[3])
                         AWeeks.append(e[4])
                         ACmd.append(e[5])
                         AExe.append(e[6])
                         listcount=listcount+1
                     else:
                         pass
                 f.close()
                 #永久守护CMDServer程序
                 AMinutes.append('*')
                 AHours.append('*')
                 ADays.append('*')
                 AMonths.append('*')
                 AWeeks.append('*')
                 ACmd.append(MyUtil.cur_file_dir()+'/CMDServer4Linux')
                 AExe.append('CMDServer4Linux')
                 listcount = listcount+1
                 return listcount
             else:
                 pass
                 self.writeLog("readCron else:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
     except:
         self.writeLog("readCron Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
Ejemplo n.º 52
0
def cronRemove(cmds, cmd):
    """删除已有守护进程列表的方法
    cmd=cronremove,cronremove=*;*;*;*;*;c:\windows\notepad.exe
    """
    try:
        if not 'cronremove' in cmds.keys():
            return "-1", "Lost cronremove.缺少cronremove参数".decode('gbk').encode("utf-8")
        cronNew = cmds['cronremove'].upper() + '\n'
        if not cronNew.find(';'):
            return "-1", "parameter Error.请使用;分号为分隔符".decode('gbk').encode("utf-8")
        cronNew = cronNew.replace(';', ',')
        crons = ''
        if os.path.isfile(MyUtil.cur_file_dir() + '\\crontab.ini'):
            f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "r+")
            cronMatch = False
            for eachLine in f:
                if cronNew == eachLine.upper():
                    cronMatch = True
                    break
                else:
                    crons += eachLine
                    cronMatch = False
            f.close()
            print crons
            if cronMatch:
                f = open(MyUtil.cur_file_dir() + '\\crontab.ini', "w")
                f.write(crons + '\n')
                str1 = 'cronRemove OK.'
                f.close()
            else:
                str1 = cmds['cronremove'] + ' Cron not found.'
            return "1", str1
        else:
            return "-1", 'crontab.ini not found.'
    except:
        return "-1", "CronRemove.Error"
Ejemplo n.º 53
0
 def enterCmd(self,cmd):
     """登录成功,进入登录解释行
     """
     try:
         if 'cmd=uploads' in cmd:
             self.uploadFile(cmd,MyUtil.splitCmd(cmd))
         else:
             cmd = _3ds.Encrypt(cmd)
             self.sock.sendall(cmd)
             self.response = self.sock.recv(sockSize)
             result = self.response
             result = result.decode('utf-8').encode("gbk")
             print result
     except:
         print "enterCmd Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
Ejemplo n.º 54
0
def return_tree(s, target, rootfilename, **kwargs):
    load_flag = kwargs.get('Load')
        
    if FileSys.file_check_json(s, rootfilename) == True:
        if load_flag == None:
            print('File [',rootfilename,'] already exists - use existing file? ', sep = '', end = '')
            load_flag = MyUtil.get_yn('[Load from disk = Y, re-create = N] (Y/N)? ')
        if load_flag == True:       
            tr = FileSys.file_read_json(rootfilename)
            FileSys.file_write_json(tr, rootfilename, path = CF.dccfilepath)
            return(tr)
            
    tr = get_tree(s,target, **kwargs)
    FileSys.file_write_json(tr, rootfilename, path = CF.dccfilepath)
#     print_tree(s, tr)
    return(tr)
Ejemplo n.º 55
0
def make_perm_changes(s, handle, permdata, removelist, changelist, addlist, **kwargs):
    ask_flag = kwargs.get('Ask',True)
    mod_flag = False
    
    if ask_flag == True:
        ans = MyUtil.get_all_none_indiv('Make Changes? All/None/Individual (A/N/I)?')
        if ans == 'All':
            ask_flag = False
        elif ans == 'None':
            return
    
    for perm in removelist:
        print('Remove?: ',end='')
        DCC.print_perm(perm) 
        if ask_flag == False or MyUtil.get_yn(': (Y/N)?'):
            if ask_flag == False: print()
            mod_flag = True
            MyUtil.remove_dict_from_list(permdata['perms'],'handle',perm['handle'])

    for chperm in changelist:
        print('Change?:', end='')
        DCC.print_perm(chperm) 
        if ask_flag == False or MyUtil.get_yn(': (Y/N)?'):
            if ask_flag == False: print()
            mod_flag = True
            for perm in permdata['perms']:
                if perm['handle'] == chperm['handle']:
                    if 'Read' in perm: del(perm['Read'])
                    if 'Write'in perm: del(perm['Write'])
                    if 'Manage' in perm: del(perm['Manage'])
                    for key,val in chperm.items():
                        perm[key] = val
                              
    for addperm in addlist:
        print('Add?:', end='')
        DCC.print_perm(addperm)    
        if ask_flag == False or MyUtil.get_yn(': (Y/N)?'):
            if ask_flag == False: print()
            mod_flag = True
            permdata['perms'].append(addperm)
        if debug: DCC.print_perms(permdata)
    
    if mod_flag:
        # check ask_flag since it may have been modified from kwargs value
        if ask_flag == False:
            modify_dcc_perms(s, handle, permdata, Ask=False)
        else:
            modify_dcc_perms(s,handle,permdata, **kwargs)
Ejemplo n.º 56
0
def start():
    try:
        global fm,_3ds
        _3ds = MyUtil._secret()
        fm = {"startAgent":startAgent,"insertServer":insertServer,"insertProLog":insertProLog,"ServerMonitorInfo":ServerMonitorInfo,"agentHeart":agentHeart,"processRestart":processRestart,"NotRUNProess":NotRUNProess}
        
        cf = ConfigParser.ConfigParser()
        cf.read("MonitorDB.ini")
        
        DBUtil.DBHost = cf.get("main", "DBHost")
        DBUtil.DBPort=cf.get("main", "DBPort")
        DBUtil.DBUser=cf.get("main", "DBUser")
        DBUtil.DBPwd=cf.get("main", "DBPwd")
        serverIP=cf.get("main", "serverip")
        serverPORT=cf.get("main", "serverport")
        
        print u"数据库服务启动"
        print version.__doc__,MyUtil.version.__doc__,DBUtil.version.__doc__
        print u"DataManagerServerIP %s   PORT:%s"%(serverIP,serverPORT)
        srv = SocketServer.ThreadingTCPServer((serverIP,int(serverPORT)), DataManager)
        srv.serve_forever()
    except:
        print "start Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1])
Ejemplo n.º 57
0
 def handle(self):
     try:
         while True:
             cmd = self.request.recv(sockSize)
             cmd = _3ds.Decrypt(cmd)
             print "recevied command: "+str(cmd)
             cmds = MyUtil.splitCmd(cmd)
             keys = cmds.keys()
             if len(keys) > 0:
                 if cmds['cmd'] in fm.keys():
                     self.request.sendall(str(fm[cmds['cmd']](cmds, cmd)))
                     break
                 else:
                     self.request.sendall("-1")
                     break
             else:
                 self.request.sendall("-1")
                 break
         self.request.close()
     except:
         self.request.close()
         writeLog("CmdServer.handle:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1]))
         print "CmdServer.handle:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
Ejemplo n.º 58
0
    except:
        print "writeLog Error:" + str(sys.exc_info()[0]) + str(sys.exc_info()[1])
        pass

def setLocalIP():
    #强写本地IP地址到配置文件中去
    cf1 = ConfigParser.ConfigParser()
    cf1.read(MyUtil.cur_file_dir() + "\\auto.ini")
    ipMac = ServerInfo.GetinnerIPMac()
    innerIP = str(ipMac[0])
    cf1.set("Configuration", "localIP", innerIP)
    cf1.write(open(MyUtil.cur_file_dir() + "\\auto.ini", "w"))
   
if __name__ == '__main__':
    global computerId, fm, sockSize, _3ds
    _3ds = MyUtil._secret()
    sockSize = 64000
    computerId = MyUtil.getComputerId()
    setLocalIP()
    fm = {
          "downloads":AgentUpdateClient.downloads,
          "updateself":AgentUpdateClient.updateSelf,
          "cronlist":cronlist,
          "agentlist":isOnLine,
          "command":command,
          "version":version,
          "password":Cpassword,
          "cronadd":cronAdd,
          "cronremove":cronRemove,
          "unzip":MyUnZIP
          }
Ejemplo n.º 59
0
 def run(self):
     '''首次读入定时调度配置,确认当前时间,设定离下一分钟的秒数,分析定时调度'''
     self.writeLog('Agent4Linux start.')
     while True:
         try:
             nowTime=string.split(time.strftime('%w,%m,%d,%H,%M,%S',time.localtime(time.time())), sep=',')
             timesWait=60-int(nowTime[5])
             #读入定时作业用的配置文件
             listcount=self.readCron(MyUtil.cur_file_dir()+'/crontab.ini')
             
             cf = ConfigParser.ConfigParser()
             cf.read(MyUtil.cur_file_dir()+"/agent.ini")
             MonitorProcess = cf.get("main", "MonitorProcess").encode("utf-8").split(',')
             
             allProcess = []
             _allPro = []
             _allProcess = []
             _allProcess = ServerInfo.getAllProcessNameId()
             for ProcessList in _allProcess:
                 allProcess.append(ProcessList[0])
             _allPro = ServerInfo.getAllProcessInfo()
             insertTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
             #循环需要定时守护的进程数
             for i in range(1,int(listcount)):
                 #如果当前进程中不存在守护的进程,调用定时守护启动程序,并发送重启信息给DB
                 if not str(AExe[i]).upper() in allProcess:
                     self.Cronjob(i,nowTime)
                     send = MyUtil.SendMsgToDB()
                     send.send(_3ds.Encrypt('processRestart;'+str(innerIP)+";"+str(AExe[i])+";"+str(ACmd[i])+";"+str(insertTime)))
                     send.sock.recv(socksize)
                     send.send(_3ds.Encrypt('end'))
                     send.closeSock()
                 else:
                     pass
             
             #如果当前进程中存在要监控的进程,循环找出该进程的相关信息发送至DB服务器    
             for MProcess in MonitorProcess:
                 ProcessStatus = 'NOTRUN'
                 for MPro in _allPro:
                     #如果进程在所有进程中找到一个相同的就发进程状态消息
                     if str(MProcess).upper() == str(MPro[0]).upper():
                         send = MyUtil.SendMsgToDB()
                         #发现psutil取出的进程CPU使用率,需要除CPU个数,否则不准
                         send.send(_3ds.Encrypt('insertProLog;'+innerIP+";"+str(MPro[0])+";"+str(MPro[1])+";"+str(MPro[2])+";"+str(MPro[3])+";"+str(int(MPro[4])/CPUCores)+";"+str(insertTime)))
                         send.sock.recv(socksize)
                         send.send(_3ds.Encrypt('end'))
                         send.closeSock()
                         ProcessStatus = 'running'
                         break
                     else:
                         ProcessStatus = 'NOTRUN'
                 #如果全部检查后进程状态为未运行,发送进程未启动信息
                 if ProcessStatus == 'NOTRUN':
                     try:
                         send = MyUtil.SendMsgToDB()
                         send.send(_3ds.Encrypt('NotRUNProess;'+innerIP+";"+str(MProcess).upper()+";"+str(insertTime)))
                         send.sock.recv(socksize)
                         send.send(_3ds.Encrypt('end'))
                     except:
                         self.writeLog("runCron.send.Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
                     finally:
                         send.closeSock()
                         
             time.sleep(timesWait)
         except:
             self.writeLog("runCron Error:"+str(sys.exc_info()[0])+str(sys.exc_info()[1]))
             time.sleep(timesWait)