def JobPut(self, inCommand, inSecond=1): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # cronが有効か? if self.FLG_Cron != True: wRes['Reason'] = " JobPut: Cron disabled" return wRes ############################# # ダブってるjobがないか wJobList = self.GetList(inCommand) if wJobList['Result'] != True: ###ここは通らないかも wRes['Reason'] = wRes['Reason'] #中継 return wRes if wJobList['Responce']['isJob'] == True: wRes['Reason'] = " JobPut: Detect booking job: " + inCommand return wRes ############################# # jobをrconに登録 (実行するわけではない) job = self.OBJ_Cron.new(command=inCommand) job.minute.every(inSecond) ############################# # crontabに書き込み self.OBJ_Cron.write() wRes['Result'] = True return wRes
def JobDel(self, inCommand): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # cronが有効か? if self.FLG_Cron != True: wRes['Reason'] = " JobDel: Cron disabled" return wRes ############################# # jobが存在しない wJobList = self.GetList(inCommand) if wJobList['Result'] != True: ###ここは通らないかも wRes['Reason'] = wRes['Reason'] #中継 return wRes if wJobList['Responce']['isJob'] == False: wRes['Reason'] = " JobDel: Job is not found: " + inCommand return wRes ############################# # commandをキーにjobを削除 self.OBJ_Cron.remove_all(command=inCommand) ############################# # crontabに書き込み self.OBJ_Cron.write() wRes['Result'] = True return wRes
def GetList(self, inCommand=None): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # カレントパスを取得 wCHR_Curr = CLS_OSIF.sGetCwd() ############################# # cronが有効か? if self.FLG_Cron != True: wRes['Reason'] = " GetJoblist: Cron disabled" return wRes ############################# # jobの文字列リスト化 wRes['Responce'] = {} wRes['Responce'].update({'isJob': False, 'List': []}) for wJob in self.OBJ_Cron: wJobStr = str(wJob) if wJobStr.find(wCHR_Curr) < 0: #同一カレントか continue if inCommand != None: #ダブってるJobがあればTrue if wJobStr.find(inCommand) >= 0: wRes['Responce']['isJob'] = True wRes['Responce']['List'].append(str(wJob)) wRes['Result'] = True return wRes
def __registUser( self, inFulluser, inMail, inPass ): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # ユーザ名の妥当性チェック(いちお再チェック) wSTR_user = CLS_UserData.sUserCheck( inFulluser ) if wSTR_user['Result']!=True : wRes['Reason'] = wSTR_user['Reason'] return wRes ############################# # 入力間違いのチェック wFlg = True if inFulluser==inMail : wFlg = False elif inFulluser==inPass : wFlg = False elif inMail==inPass : wFlg = False if wFlg!=True : wRes['Reason'] = "ユーザ名、メールアドレス、パスワードの入力が誤ってます。(重複検出)" return wRes wRes['Result'] = True return wRes
def sGetUserPath(cls, inFulluser): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # フォルダの存在チェック wFilename = gVal.DEF_USERDATA_PATH + inFulluser + "/" ## if CLS_File.sExist( wFilename )!=True : ## wRes['Reason'] = "CLS_UserData: sGetUserPath: User Folder is not found: " + wFilename ## return wRes if CLS_File.sExist(wFilename) == True: wRes['Result'] = True wRes['Responce'] = wFilename ## wRes['Result'] = True return wRes
def sGetTrafficUser(cls): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # 読み出し先初期化 wTrafficUser = [] ############################# # ファイル読み込み wFile_path = gVal.DEF_STR_FILE['TrafficFile'] if CLS_File.sReadFile(wFile_path, outLine=wTrafficUser) != True: return wRes #失敗 wRes['Responce'] = wTrafficUser wRes['Result'] = True return wRes #OK
def Clear(self): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # cronが有効か? if self.FLG_Cron != True: wRes['Reason'] = " Clear: Cron disabled" return wRes ############################# # cronからすべてのjobを削除 self.OBJ_Cron.remove_all() ############################# # crontabに書き込み self.OBJ_Cron.write() wRes['Result'] = True return wRes
def __getCommand(self, inKind, inAccount): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # cronが有効か? if self.OBJ_CronCtrl.Check() != True: wRes['Reason'] = "Cron disable" return wRes ############################# # inKindが有効か? if inKind not in gVal.STR_CronInfo: wRes['Reason'] = "inKind is disable: " + inKind return wRes ############################# # 登録のあるアカウントか? if inKind == gVal.DEF_CRON_MASTER or inKind == gVal.DEF_CRON_SUB: wUserList = CLS_UserData.sGetUserList() if inAccount not in wUserList: wRes['Reason'] = "Unregistered account: " + inAccount return wRes ############################# # コマンドの組み立て if inKind == gVal.DEF_CRON_MASTER or inKind == gVal.DEF_CRON_SUB: wRes['Responce'] = self.Command_Temp + inKind + " " + inAccount ## elif inKind==gVal.DEF_CRON_BACK : ## wRes['Responce'] = self.Command_Temp + inKind + " " + gVal.DEF_CRON_ACCOUNT_BACKGROUND else: wRes['Responce'] = "Type that can not issue command: " + inKind return wRes wRes['Result'] = True return wRes
def __sendToot(self, inKind, inFileName): ############################# # 応答形式の取得 # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_OSIF.sGet_Resp() ############################# # ファイル読み出し wToot = [] wFile_path = gVal.DEF_STR_FILE['Toot_path'] + inFileName if CLS_File.sReadFile(wFile_path, outLine=wToot) != True: wRes[ 'Reason'] = "CLS_CircleToot: __sendToot: Toot file read failed: " + wFile_path return wRes #失敗 if len(wToot) <= 1: wRes[ 'Reason'] = "CLS_CircleToot: __sendToot: Toot is sortest: " + wFile_path return wRes #失敗 ############################# # 範囲の設定 wRange = CLS_UserData.sGetRange(wToot[0]) del wToot[0] ############################# # 種別=CWトゥート if inKind == "w": wTitle = self.DEF_TITLE_PRTOOT + " " + wToot[0] del wToot[0] wSetToot = "" else: wSetToot = self.DEF_TITLE_PRTOOT + " " ############################# # トゥートの組み立て for wLine in wToot: wSetToot = wSetToot + wLine + '\n' ## wSetToot = wSetToot + " " + gVal.STR_MasterConfig['prTag'] ## ## # 管理者がいれば通知する ## if gVal.STR_MasterConfig['AdminUser']!="" and gVal.STR_MasterConfig['AdminUser']!=self.Obj_Parent.CHR_Account: ## wSetToot = wSetToot + '\n' + '\n' + "[Admin] @" + gVal.STR_MasterConfig['AdminUser'] ## wSetToot = wSetToot + '\n' + "#" + gVal.STR_MasterConfig['prTag'] if len(wSetToot) > 500: wRes[ 'Reason'] = "CLS_CircleToot: __sendToot: Create toot is over length" return wRes #失敗 ############################# # トゥートの送信 if inKind == "w": wRes = self.Obj_Parent.OBJ_MyDon.Toot(status=wSetToot, visibility=wRange, spoiler_text=wTitle) else: wRes = self.Obj_Parent.OBJ_MyDon.Toot(status=wSetToot, visibility=wRange) if wRes['Result'] != True: wRes[ 'Reason'] = "CLS_LookRIP: __copeFavo: Mastodon error: " + wRes[ 'Reason'] return wRes wRes['Result'] = True return wRes
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