Esempio n. 1
0
    def sRun(cls):
        #############################
        # システム情報を取得する
        cls().__getSystemInfo()
        cls().__getLucibotVer()

        #############################
        # 初期化
        gVal.FLG_Console_Mode = True  #コンソールモード

        #############################
        # データフォルダのチェック
        if CLS_File.sExist(gVal.DEF_USERDATA_PATH) != True:
            ###手順ミスorデータ消した
            wStr = '\n' + gVal.STR_SystemInfo[
                'Client_Name'] + " データフォルダがないため起動できません。" + '\n'
            wStr = wStr + "フォルダは " + gVal.STR_SystemInfo[
                'Client_Name'] + " のcloneを置いた上位フォルダ(=cloneと同一階層)に作成します。" + '\n'
            wStr = wStr + "詳しくはreadme_setup.txtをご参照ください。" + '\n'
            CLS_OSIF.sPrn(wStr)
            return

        #############################
        # Master環境情報の読み込み
        if CLS_Config.sGetMasterConfig() != True:
            # MasterConfigがないのでセットアップするか?
            wStr = '\n' + "データフォルダにMaster環境情報がないため起動できません。" + '\n'
            wStr = wStr + "データが初期セットアップされていない可能性があります。"
            CLS_OSIF.sPrn(wStr)
            wRes = CLS_OSIF.sInp("セットアップしますか?(y/N)=> ")
            if wRes != "y":
                CLS_OSIF.sPrn("起動を中止しました。")
                return

            #############################
            # 環境のセットアップ
            wCLS_Setup = CLS_Setup()
            if wCLS_Setup.MasterSetup() != True:
                CLS_OSIF.sPrn("セットアップを中止します。")
                return

            wCLS_Setup = ""
            CLS_OSIF.sInp('\n' + "セットアップが完了しました。リターンキーを押してください。[RT]")

        #####################################################
        # MasterUserが未登録
        if gVal.STR_MasterConfig['MasterUser'] == "":
            CLS_OSIF.sPrn(
                "MasterUserが登録されていないため、bot動作ができません。MasterUserを登録します。")
            wCLS_Config = CLS_Config()
            wRes = wCLS_Config.CnfMasterUser()
            if wRes != True:
                #############################
                # 0件の場合は、ユーザ登録させる
                wList = CLS_UserData.sGetUserList()
                if len(wList) == 0:
                    wCLS_work = CLS_Regist()
                    wCLS_work.Regist()

                CLS_OSIF.sInp("リターンキーを押して再度コンソールアプリを起動してください。[RT]")
                return

            wCLS_Config = ""

        #############################
        # ** 初期化モード **
        wArg = CLS_OSIF.sGetArg()
        if len(wArg) == 2:
            if wArg[1] == "init":
                wCLS_Setup = CLS_Setup()
                wCLS_Setup.AllInit()
                CLS_OSIF.sInp("リターンキーを押して再度コンソールアプリを起動してください。[RT]")
            return

        #############################
        # コンソールを表示
        while True:
            wCommand = cls().sViewMainConsole()

            if wCommand.find("\\q") >= 0 or wCommand == "exit":
                ###終了
                CLS_OSIF.sPrn("コンソールを停止します。" + '\n')
                break

            wRes = cls().sRunCommand(wCommand)
            if wRes == True:
                CLS_OSIF.sInp("リターンキーを押すと戻ります。[RT]")

        return
Esempio n. 2
0
    def Run(self):
        #############################
        # 応答形式の取得
        #   "Result" : False, "Reason" : None, "Responce" : None
        wRes = CLS_OSIF.sGet_Resp()

        #############################
        # 引数取得
        wArg = CLS_OSIF.sGetArg()
        if len(wArg) == 3:  #テストモードか
            if wArg[2] == gVal.DEF_TEST_MODE:
                gVal.FLG_Test_Mode = True

        elif len(wArg) != 2:  #引数が足りない
            wStr = "CLS_CronTest: Argument deficiency: argument=" + str(wArg)
            CLS_OSIF.sPrn(wStr)  #メールに頼る
            return wRes

        wKind = wArg[0]
        wAccount = wArg[1]

        ##		#############################
        ##		# Backgroundのチェックは別でやる
        ##		if wKind==gVal.DEF_CRON_BACK and wAccount==gVal.DEF_CRON_ACCOUNT_BACKGROUND :
        ##			wRes = self.__backgroundTest( outRes=wRes )
        ##			return wRes

        #############################
        # 1.jobチェック
        #     実行ファイルチェック
        #     ユーザ登録チェック(Master、Subの場合)
        wCLS_Botjob = CLS_Botjob()
        wRes = wCLS_Botjob.isJob(wKind, wAccount)
        if wRes['Result'] != True:
            wStr = "CLS_CronTest: Job check NG: " + wRes['Reason']
            CLS_OSIF.sPrn(wStr)  #メールに頼る
            return wRes

        if wRes['Responce']['isJob'] == False and gVal.FLG_Test_Mode == False:
            ##			wStr = "CLS_CronTest: Job is not found: kind=" + wKind + ": account=" + wAccount
            wStr = "CLS_CronTest: Job is not found: kind=" + wKind + ": account=" + wAccount + " current: " + CLS_OSIF.sGetCwd(
            )
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        wFlg_ok = True
        #############################
        # 2.データフォルダのチェック
        if CLS_File.sExist(gVal.DEF_USERDATA_PATH) != True:
            wFlg_ok = False

        #############################
        # 3.Master環境情報の読み込み
        if CLS_Config.sGetMasterConfig() != True:
            wFlg_ok = False

        #############################
        # Master環境情報に異常はないか
        if wFlg_ok == False:
            ##			wRes = wCLS_Botjob.Stop()	#全cronを削除する
            ##			if wRes['Result']!=True :
            ##				wStr = "CLS_CronTest: Cron stop failed: " + wRes['Reason']
            ##				CLS_OSIF.sPrn( wStr  )	#メールに頼る
            ##
            ##			wStr = "Master環境情報に異常があったため、" + gVal.STR_SystemInfo['Client_Name']
            ##			wStr = wStr + "で登録した全cronを停止しました。"
            wStr = "Master環境情報に異常があったため、処理を中止します。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        #############################
        # 4.Userフォルダチェック
        wRes = CLS_UserData.sGetUserPath(wAccount)
        if wRes['Result'] != True:
            wRes = wCLS_Botjob.Del(wKind, wAccount)  #cronを削除する
            if wRes['Result'] != True:
                wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
                CLS_OSIF.sPrn(wStr)  #メールに頼る

            wStr = "Userフォルダが存在しないため、" + wAccount
            wStr = wStr + "のcronを停止しました。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        wUserPath = wRes['Responce']

        ##		#############################
        ##		# 5.User環境情報の読み込み
        ##		wRes = CLS_Config.sGetUserConfig( wAccount )
        ##		if wRes['Result']!=True :
        ##			wRes = wCLS_Botjob.Del( wKind, wAccount )	#cronを削除する
        ##			if wRes['Result']!=True :
        ##				wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
        ##				CLS_OSIF.sPrn( wStr  )	#メールに頼る
        ##
        ##			wStr = "User環境情報に異常があったため、" + wAccount
        ##			wStr = wStr + "のcronを停止しました。"
        ##			CLS_OSIF.sPrn( wStr  )		#メールに頼る
        ##
        ##			wRes['Result'] = False	#テストはNG
        ##			return wRes

        #############################
        # 5.実行権限チェック
        wFlg_Authority = True
        #############################
        # コマンドの組み立て
        if wKind == gVal.DEF_CRON_MASTER:  # Masuer User以外か
            if wAccount != gVal.STR_MasterConfig['MasterUser']:
                wFlg_Authority = False

##		elif wKind==gVal.DEF_CRON_BACK :	# Background以外か
##			if wAccount!=gVal.DEF_CRON_ACCOUNT_BACKGROUND :
##				wFlg_Authority = False

        elif wKind == gVal.DEF_CRON_SUB:  # Sub以外か
            ##			if wAccount==gVal.STR_MasterConfig['MasterUser'] or \
            ##			   wAccount==gVal.DEF_CRON_ACCOUNT_BACKGROUND :
            if wAccount == gVal.STR_MasterConfig['MasterUser']:
                wFlg_Authority = False

        else:
            ###ここではありえない
            wFlg_Authority = False

        if wFlg_Authority == False:
            wRes = wCLS_Botjob.Del(wKind, wAccount)  #cronを削除する
            if wRes['Result'] != True:
                wStr = "CLS_CronTest: Cron delete failed: " + wRes['Reason']
                CLS_OSIF.sPrn(wStr)  #メールに頼る

            wStr = "実行権限に問題があったため、" + wAccount
            wStr = wStr + "のcronを停止しました。"
            CLS_OSIF.sPrn(wStr)  #メールに頼る

            wRes['Result'] = False  #テストはNG
            return wRes

        # ここまででtestは合格してる
        #############################

        #############################
        # 6.testログ
        self.__testLog(wKind, wAccount)

        wRes['Responce'] = {}
        wRes['Responce'].update({
            "Kind": wKind,
            "Account": wAccount,
            "User_path": wUserPath
        })
        wRes['Result'] = True
        return wRes