def __getLucibotVer(cls): if CLS_File.sExist(gVal.DEF_STR_FILE['Readme']) != True: ###readmeファイル消すなwww CLS_OSIF.sPrn( "CLS_Main_Console: __getLucibotVer: Readme file is not found: " + gVal.DEF_STR_FILE['Readme']) return False for wLine in open(gVal.DEF_STR_FILE['Readme'], 'r'): #ファイルを開く ############################# # 分解+要素数の確認 wLine = wLine.strip() wGetLine = wLine.split("= ") if len(wGetLine) != 2: continue wGetLine[0] = wGetLine[0].replace("::", "") ############################# # キーがあるか確認 if wGetLine[0] not in gVal.STR_SystemInfo: continue ############################# # キーを設定 gVal.STR_SystemInfo[wGetLine[0]] = wGetLine[1] return
def CnfMasterConfig(self): ############################# # ファイルの存在チェック if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True: ###ありえない CLS_OSIF.sPrn( "CLS_Config: CnfMasterConfig: MasterConfig file is not found : " + gVal.DEF_STR_FILE['MasterConfig']) return False #ない ############################# # 選択画面を表示する self.MasterConfig_Disp() wSelect = self.__cnfMasterConfig_SelectDisp() if wSelect == 'c': ###変更してセーブ self.__cnfMasterConfig_Change() self.sSetMasterConfig() CLS_OSIF.sPrn("変更した内容でMaster環境情報をセーブしました。" + '\n') elif wSelect == 's': ###セーブ CLS_Config.sSetMasterConfig() CLS_OSIF.sPrn("Master環境情報をセーブしました。" + '\n') return True
def sViewDisp(cls, inDisp): ############################# # ディスプレイファイルの確認 wKeylist = gVal.DEF_STR_DISPFILE.keys() if inDisp not in wKeylist: ###キーがない(指定ミス) CLS_OSIF.sPrn( "CLS_Main_Console: __viewDisp: Display key is not found: inDisp= " + inDisp) return False if CLS_File.sExist(gVal.DEF_STR_DISPFILE[inDisp]) != True: ###ファイルがない...(消した?) CLS_OSIF.sPrn( "CLS_Main_Console: __viewDisp: Display file is not found: " + gVal.DEF_STR_DISPFILE[inDisp]) return False ############################# # 画面クリア CLS_OSIF.sDispClr() ############################# # 中身表示 wStr = "" for wLine in open(gVal.DEF_STR_DISPFILE[inDisp], 'r'): #ファイルを開く wStr = wStr + wLine CLS_OSIF.sPrn(wStr) return True
def __init__( self, inPath=None ): ############################# # ログフォルダの存在チェック if CLS_File.sExist( inPath )!=True : self.CHR_LogPath = "" return #ない self.CHR_LogPath = inPath return
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 CnfMasterRun(self): ############################# # ファイルの存在チェック if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True: ###ありえない CLS_OSIF.sPrn( "CLS_Config: cCnfMasterRun: masterConfig file is not found : " + gVal.DEF_STR_FILE['MasterConfig']) return False #ない ############################# # メニューの表示 wStr = '\n' + "botの運用を設定します。現在の設定。 mRun= " + gVal.STR_MasterConfig[ 'mRun'] CLS_OSIF.sPrn(wStr) wStr = "" if gVal.STR_MasterConfig['mRun'] == "on": wStr = wStr + "c: on→off" wChg = "off" else: wStr = wStr + "c: off→on" wChg = "on" wStr = wStr + " / other: 変更しない => " wSelect = input(wStr) if wSelect != "c": ###変更しない CLS_OSIF.sPrn("キャンセルされました") return True ############################# # 変更 gVal.STR_MasterConfig['mRun'] = wChg self.sSetMasterConfig() wStr = "botの運用設定を変更しました。 mRun= " + wChg + '\n' wStr = wStr + "変更した内容でMaster環境情報をセーブしました: " + gVal.DEF_STR_FILE[ 'MasterConfig'] + '\n' CLS_OSIF.sPrn(wStr) return True
def sGetMasterConfig(cls): ############################# # ファイルの存在チェック if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True: return False #ない ############################# # 読み込み for wLine in open(gVal.DEF_STR_FILE['MasterConfig'], 'r'): ############################# # 分解+要素数の確認 wLine = wLine.strip() wGet_Line = wLine.split("=") if len(wGet_Line) != 2: continue ############################# # キーがあるか確認 if wGet_Line[0] not in gVal.STR_MasterConfig: continue ############################# # 更新する gVal.STR_MasterConfig[wGet_Line[0]] = wGet_Line[1] ## ############################# ## # 文字→数値へ変換 ## gVal.STR_MasterConfig["getPTLnum"] = int( gVal.STR_MasterConfig["getPTLnum"] ) ## gVal.STR_MasterConfig["getRandVal"] = int( gVal.STR_MasterConfig["getRandVal"] ) ## gVal.STR_MasterConfig["getRandRange"] = int( gVal.STR_MasterConfig["getRandRange"] ) ## gVal.STR_MasterConfig["studyNum"] = int( gVal.STR_MasterConfig["studyNum"] ) ## gVal.STR_MasterConfig["studyMax"] = int( gVal.STR_MasterConfig["studyMax"] ) ## gVal.STR_MasterConfig["studyDay"] = int( gVal.STR_MasterConfig["studyDay"] ) ## gVal.STR_MasterConfig["clazListNum"] = int( gVal.STR_MasterConfig["clazListNum"] ) ## gVal.STR_MasterConfig["getMcDelay"] = int( gVal.STR_MasterConfig["getMcDelay"] ) ## ############################# ## # 数値補正 ## if gVal.STR_MasterConfig["getMcDelay"]<1 or gVal.STR_MasterConfig["getMcDelay"]>30 : ## gVal.STR_MasterConfig["getMcDelay"] = 5 return True
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
def MasterSetup(self): ############################# # フォルダの存在チェック if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )==True : CLS_OSIF.sPrn( "フォルダが既に存在します。セットアップを中止します。" ) return False #既にある wStr = '\n' + "Master環境情報のセットアップを開始します。" wStr = wStr + "データのテンプレートをコピーします....." CLS_OSIF.sPrn( wStr ) ############################# # テンプレートデータのコピー(データ作成) if CLS_File.sCopytree( gVal.DEF_STR_FILE['defMasterdata_path'], gVal.DEF_STR_FILE['MasterConfig_path'] )!=True : ###テンプレートが消えてる (IOエラーはOSが出す) CLS_OSIF.sPrn( "CLS_Config: MasterSetup: Master Data Template is not found" ) return False ############################# # フォルダの存在チェック if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )!=True : CLS_OSIF.sPrn( "CLS_Config: MasterSetup: Data Copy check failed" ) return False #失敗 ############################# # コピー完了 CLS_OSIF.sPrn( "Master環境情報のコピーが完了しました。" + '\n' ) ############################# # 使うクラスの作成 wCLS_Config = CLS_Config() wCLS_Regist = CLS_Regist() wCLS_Botjob = CLS_Botjob() wCLS_Bot_Ctrl = CLS_Bot_Ctrl() ############################# # Master環境情報の変更 wStr = "Master環境情報の変更をおこないますか?" + '\n' wStr = wStr + "(あとで変更することもできます)" CLS_OSIF.sPrn( wStr ) wSelect = CLS_OSIF.sInp( "変更する?(y/N)=> " ) if wSelect=="y" : wRes = wCLS_Config.CnfMasterConfig() if wRes!=True : ##失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) return False ############################# # 初期起動直後なので、メンテをOFFにする # cronを全て剥がす ## gVal.STR_MasterConfig['mMainte'] = "off" ## wCLS_Botjob.Stop() wCLS_Bot_Ctrl.CronAllStop() ############################# # ユーザ登録=0の時、ユーザ登録させる wList = CLS_UserData.sGetUserList() if len(wList)==0 : wFLG_regist = False while True: wStr = '\n' + "Master User(mastodonでbotとして使うユーザ)の登録をおこないます。" + '\n' wStr = wStr + "ユーザ名をドメインを含めて入力してください。: 例= " + gVal.DEF_EXAMPLE_ACCOUNT CLS_OSIF.sPrn( wStr ) wMasterUser = CLS_OSIF.sInp( "MasterUser?=> " ) wRes = wCLS_Regist.Regist( wMasterUser ) if wRes==True : ###登録できたので次へ wFLG_regist = True break else : ###登録できないと、登録できるまで継続したい CLS_OSIF.sPrn( "ユーザの登録がないとbotが動作できません。" ) wRes = CLS_OSIF.sInp( "登録を中止しますか?(y)=> " ) if wRes=='y' : return False #セットアップいちお完了だけどユーザ未登録 if wFLG_regist!=True : ##中止なので消す CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) return False ############################# # ユーザ登録がされている時 # もしくは1件だけ登録した時 # masterユーザを登録する wRes = wCLS_Config.CnfMasterUser() if wRes!=True : ##失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) return False ############################# # AdminUserの変更 wCLS_Config.CnfAdminUser() ## ############################# ## # MasterとBackgroundのbotを起動する ## wRes = wCLS_Botjob.Put( gVal.DEF_CRON_MASTER, gVal.STR_MasterConfig['MasterUser'] ) ## if wRes['Result']!=True : ## wStr = "Master botの起動に失敗しました。: " + wRes['Reason'] ## CLS_OSIF.sPrn( wStr ) ## return False ## ## wRes = wCLS_Botjob.Put( gVal.DEF_CRON_BACK, gVal.DEF_CRON_ACCOUNT_BACKGROUND ) ## if wRes['Result']!=True : ## wStr = "Background botの起動に失敗しました。: " + wRes['Reason'] ## CLS_OSIF.sPrn( wStr ) ## return False ############################# # Databaseの作成 ############################# # DB接続情報ファイルのチェック if CLS_File.sExist( gVal.DEF_STR_FILE['DBinfo_File'] )!=True : ## ###DB接続情報ファイルの作成(空ファイル) ## if CLS_File.sCopy( ## gVal.STR_File['defDBinfo_File'], gVal.STR_File['DBinfo_File'] )!=True : ## ##失敗 ## CLS_File.sRmtree( gVal.STR_File['MasterConfig_path'] ) ## CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) ## ## wStr = "CLS_Setup: DataBase file copy failed: src=" + gVal.STR_File['defDBinfo_File'] ## wStr = wStr + " dst=" + gVal.STR_File['DBinfo_File'] ## CLS_OSIF.sPrn( wStr ) ## return False ## wOBJ_DB = CLS_PostgreSQL_Use() ## if wOBJ_DB.CreateDBdata( gVal.STR_File['DBinfo_File'] )!=True : if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'], gVal.DEF_STR_FILE['defDBinfo_File'] )!=True : ##失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) wStr = "CLS_Setup: DataBase file create failed: src=" + gVal.DEF_STR_FILE['defDBinfo_File'] wStr = wStr + " dst=" + gVal.DEF_STR_FILE['DBinfo_File'] CLS_OSIF.sPrn( wStr ) return False ## ## wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] ) else : ###DB接続情報変更 wStr = "DataBaseの接続情報の更新をおこないます。DataBaseの接続情報の更新をおこないますか?" print( wStr ) wSelect = input( "更新する?(y/N)=> " ).strip() if wSelect=="y" : wOBJ_DB = CLS_PostgreSQL_Use() ## if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'] )!=True : if wOBJ_DB.CreateDBdata( gVal.DEF_STR_FILE['DBinfo_File'], gVal.DEF_STR_FILE['defDBinfo_File'] )!=True : ##失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) wStr = "CLS_Setup: DataBase file create failed: src=" + gVal.DEF_STR_FILE['defDBinfo_File'] wStr = wStr + " dst=" + gVal.DEF_STR_FILE['DBinfo_File'] CLS_OSIF.sPrn( wStr ) return False ## ## wOBJ_DB = CLS_PostgreSQL_Use( gVal.DEF_STR_FILE['DBinfo_File'] ) ## ############################# ## # DBの状態チェック ## wRes = wOBJ_DB.GetIniStatus() ## if wRes['Result']!=True : ## ###失敗 ## CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) ## CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) ## ## wStr = "CLS_Setup: DB Connect test is failed: " + wRes['Reason'] ## CLS_OSIF.sPrn( wStr ) ## return False ## ## wStr = "テーブルの作成中......" + '\n' ## print( wStr ) ## ############################# ## # テーブルの作成 ## self.__create_TBL_USER_DATA( wOBJ_DB ) ## self.__create_TBL_TRAFFIC_DATA( wOBJ_DB ) ## self.__create_TBL_WORD_CORRECT( wOBJ_DB ) ## self.__create_TBL_CLAZ_LIST( wOBJ_DB ) ## ## ############################# ## # DBのクローズ ## wOBJ_DB.Close() ## wStr = "作成完了!! DataBaseから切断しました。" + '\n' ## print( wStr ) ## ############################# # DBの初期化 wRes = self.__initDB() if wRes!=True : ###失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) wStr = "CLS_Setup: DB Connect test is failed: " + wRes['Reason'] CLS_OSIF.sPrn( wStr ) return False ############################# # Twitter接続情報の作成 wOBJ_Twitter = CLS_Twitter_Use() wOBJ_Twitter.CreateTwitter( gVal.DEF_STR_FILE['Twitter_File'], gVal.DEF_STR_FILE['defTwitter_File'] ) wCLS_Config.CnfTwitter() #有効無効設定 ############################# # MasterとBackgroundのbotを起動する wRes = wCLS_Botjob.Put( gVal.DEF_CRON_MASTER, gVal.STR_MasterConfig['MasterUser'] ) if wRes['Result']!=True : ##失敗 CLS_File.sRmtree( gVal.DEF_STR_FILE['MasterConfig_path'] ) CLS_File.sRmtree( gVal.DEF_USERDATA_PATH + gVal.STR_MasterConfig['MasterUser'] ) wStr = "Master botの起動に失敗しました。: " + wRes['Reason'] CLS_OSIF.sPrn( wStr ) return False return True
def AllInit(self): ############################# # フォルダの存在チェック if CLS_File.sExist( gVal.DEF_STR_FILE['MasterConfig_path'] )!=True : CLS_OSIF.sPrn( "CLS_Config: Init: Master Data is not Exist" ) return False #失敗 ############################# # Master環境情報の変更 wStr = "データベースと全ての作業ファイルをクリアします。" + '\n' wStr = wStr + "よろしいですか?(y/N)=> " wSelect = CLS_OSIF.sInp( wStr ) if wSelect!="y" : ##キャンセル CLS_OSIF.sInp( "リターンキーを押して再度コンソールアプリを起動してください。[RT]" ) return True CLS_OSIF.sPrn( "cronを停止中。2分ほどお待ちください..." + '\n' ) ############################# # ユーザ一覧取得 wUserList = CLS_UserData.sGetUserList() ############################# # cronの停止 ## wCLS_Botjob = CLS_Botjob() wCLS_Bot_Ctrl = CLS_Bot_Ctrl() wFlg_CronStop = wCLS_Bot_Ctrl.CronAllStop() if wFlg_CronStop==True : ### 停止したbotあり CLS_OSIF.sSleep(120) #とりあえずcronが停止する2分は待つ ## wFLG_Wait = False ## wWaitRestart = {} ## wIndex = 0 ## for wUser in wUserList : ## ############################# ## # 種別を判定 ## if gVal.STR_MasterConfig['MasterUser']==wUser : ## wKind = gVal.DEF_CRON_MASTER ## else : ## wKind = gVal.DEF_CRON_SUB ## ## ############################# ## # ジョブの削除 ## wRes = wCLS_Botjob.Del( wKind, wUser ) ## if wRes['Result']!=True : ## ###おそらく動いてないcronのためスキップ ## continue ## ## ############################# ## # 停止cronをメモ ## wWaitRestart.update({ wIndex : wIndex }) ## wWaitRestart[wIndex] = {} ## wWaitRestart[wIndex].update({ "Kind" : wKind }) ## wWaitRestart[wIndex].update({ "User" : wUser }) ## wFLG_Wait = True ## wIndex += 1 ## ## ############################# ## # 1つでも停止cronがあれば2分待つ ## if wFLG_Wait==True : ## CLS_OSIF.sSleep(120) CLS_OSIF.sPrn( "各ユーザの作業ファイルを初期化しています..." + '\n' ) ############################# # ファイルの初期化(各ユーザ) for wUser in wUserList : CLS_OSIF.sPrn( "ユーザ " + wUser + " 初期化中..." ) ############################# # ユーザフォルダチェック wRes = CLS_UserData.sGetUserPath( wUser ) if wRes['Result']!=True : CLS_OSIF.sPrn( "CLS_Setup: Init: User folder is not Exist: user="******"masterConfig 初期化中..." + '\n' ) ############################# # ドメイン情報 wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['MstdnDomains_File'] wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['MstdnDomains_File'] self.__initFile( wDefFile_path, wDstFile_path ) ############################# # 過去ツイート wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['TweetFile'] wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['TweetFile'] self.__initFile( wDefFile_path, wDstFile_path ) ############################# # 周期トゥート wDefFile_path = gVal.DEF_STR_FILE['defMasterdata_path'] + gVal.DEF_STR_FILE['CLDataFile'] wDstFile_path = gVal.DEF_STR_FILE['MasterConfig_path'] + gVal.DEF_STR_FILE['CLDataFile'] self.__initFile( wDefFile_path, wDstFile_path ) ############################# CLS_OSIF.sPrn( "データベースを初期化しています..." + '\n' ) ############################# # DBの初期化 wFLG_Init = True ### 初期化 if self.__initDB()!=True : wFLG_Init = False ### 修復 if self.__recovery_TBL_TRAFFIC_DATA()!=True : wFLG_Init = False if wFLG_Init==True : CLS_OSIF.sPrn( "データベースの初期化をおこないました" + '\n' ) else : ##ありえない CLS_OSIF.sPrn( "*** データベースの初期化に失敗しました" + '\n' ) ############################# # cronの再起動 ## if wFLG_Wait==True : ## CLS_OSIF.sPrn( "停止していたcronを再開します..." + '\n' ) ## ## wKeylist = wWaitRestart.keys() ## for wKey in wKeylist : ## ############################# ## # ジョブの登録 ## wRes = wCLS_Botjob.Put( wWaitRestart[wKey]["Kind"], wWaitRestart[wKey]["User"] ) ## if wRes['Result']!=True : ## ###失敗 ## CLS_OSIF.sPrn( "cronの起動に失敗しました: user="******"User"] + '\n' ) ## if wFlg_CronStop==True : ### 停止したbotあり CLS_OSIF.sPrn( "停止していたcronを再開します..." + '\n' ) wCLS_Bot_Ctrl.CronReStart() ############################# # 終わり CLS_OSIF.sPrn( "初期化が正常終了しました。" ) ## CLS_OSIF.sInp( "リターンキーを押して再度コンソールアプリを起動してください。[RT]" ) return True
def CreateMastodon( self, inFulluser ): ############################# # 応答形式の取得(mastodon形式) # "Result" : False, "Reason" : None, "Responce" : None wRes = CLS_Mastodon_Use.sGet_API_Resp() ############################# # 出力先領域のチェック #辞書型か? if isinstance( self.STR_Mastodon, dict )!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: STR_Mastodon is not dict: type= " + type(self.STR_Mastodon) return wRes #重複してるか? if inFulluser in self.STR_Mastodon : wRes['Reason'] = "CLS_Regist: CreateMastodon: Overlap user: "******"CLS_Regist: CreateMastodon: Domain check error: " + inFulluser return wRes ############################# # ping疎通チェック if CLS_OSIF.sPing( wSTR_user['Domain'] )!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: Ping check error: " + wSTR_user['Domain'] return wRes #失敗 ############################# # レジストファイルの存在チェック wGetPath = CLS_UserData.sGetUserPath( inFulluser ) ## if wGetPath['Result']!=True : ## wRes['Reason'] = "CLS_Regist: CreateMastodon: User path ng: " + wGetPath['Reason'] ## return wRes wRegFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_RegFile'] if CLS_File.sExist( wRegFile )!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: Regist File not is found: " + wRegFile return wRes #ファイルがない wUserFile = wGetPath['Responce'] + gVal.DEF_STR_FILE['Reg_UserFile'] if CLS_File.sExist( wUserFile )!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: Userreg File not is found: " + wUserFile return wRes #ファイルがない ############################# # mastodon APIオブジェクトを生成する self.STR_Mastodon.update({ inFulluser : CLS_Mastodon_Use( api_base_url = "https://" + wSTR_user['Domain'], client_id = wRegFile, access_token = wUserFile ) }) ### flg_orginit=True ) }) wIniStatus = self.STR_Mastodon[inFulluser].GetIniStatus() if wIniStatus['Result']!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: Create Mastodon object failuer: " + wIniStatus['Reason'] return wRes #mastodon error ############################# # 通信テスト(トークンチェック) if self.STR_Mastodon[inFulluser].TokenCheck()!=True : wRes['Reason'] = "CLS_Regist: CreateMastodon: Mastodon Token is None (mastodon error): " + inFulluser 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
def CnfAdminUser(self): ############################# # ファイルの存在チェック if CLS_File.sExist(gVal.DEF_STR_FILE['MasterConfig']) != True: ###ありえない CLS_OSIF.sPrn( "CLS_Config: cCnfAdminUser: masterConfig file is not found : " + gVal.DEF_STR_FILE['MasterConfig']) return False #ない ############################# # 変更メニュー表示 if gVal.STR_MasterConfig['AdminUser'] == "": wStr = "現在AdminUserは設定されていません。設定することで登録ユーザから通知を受け取ることができるようになります。" wSt2 = "AdminUserの設定をおこないますか?(y/N)=> " else: wStr = "現在AdminUserは次のアカウントが設定されています。: " + gVal.STR_MasterConfig[ 'AdminUser'] wSt2 = "AdminUserの設定をおこないますか?(y:変更 /D:解除 /other: キャンセル)=> " CLS_OSIF.sPrn(wStr) wSelect = CLS_OSIF.sInp(wSt2) if wSelect == "D": ###削除 gVal.STR_MasterConfig['AdminUser'] = "" self.sSetMasterConfig() CLS_OSIF.sPrn("AdminUserの設定を解除しました。" + '\n') CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " + gVal.DEF_STR_FILE['MasterConfig'] + '\n') return True elif wSelect != "y": ###設定しない CLS_OSIF.sPrn("キャンセルされました") return True ############################# # 名前入力 wStr = "AdminUser(通知先アカウント)をドメインを含めて入力してください。 例= " + gVal.DEF_EXAMPLE_ACCOUNT + '\n' wStr = wStr + " ※ユーザ登録してないユーザも指定できます" CLS_OSIF.sPrn(wStr) wAdminUser = CLS_OSIF.sInp("AdminUser? => ") if wAdminUser=="" or \ gVal.STR_MasterConfig['AdminUser'] ==wAdminUser : ###設定しない CLS_OSIF.sPrn("キャンセルされました") return True ############################# # ユーザ名の妥当性チェック wSTR_user = CLS_UserData.sUserCheck(wAdminUser) if wSTR_user['Result'] != True: return False ############################# # 通信テスト CLS_OSIF.sPrn("通信テスト中...") if CLS_OSIF.sPing(wSTR_user['Domain']) != True: CLS_OSIF.sPrn("mastodonとの通信テストに失敗したため、設定をキャンセルします。") return False CLS_OSIF.sPrn("通信OK") ############################# # 変更 gVal.STR_MasterConfig['AdminUser'] = wAdminUser self.sSetMasterConfig() CLS_OSIF.sPrn("設定内容をMaster環境情報にセーブしました: " + gVal.DEF_STR_FILE['MasterConfig'] + '\n') return True