2017-09-13 8 views
0

私はPythonには新しく、2つの設定ファイルからいくつかのURLを抽出するスクリプトを書いています。次のようにようサーバ設定のPython健全性チェッカー

import os 
import sys 
import logging 

logger = logging.getLogger('check_store') 
logger.setLevel(logging.DEBUG) 

env= raw_input("Enter environmentname (ex. dev/qa/prod): ") 
cust= raw_input("Enter customer name: ") 

engage_properties= '/opt/engage/engageconf.properties' 
symmetric_properties= '/opt/engage/symmetric.properties' 

with open ("%s" % (engage_properties)) as inF: 
    for line in inF: 
     if ("%s-%s.%sfqdn.com" % (env,cust,env)) in line: 
      print line 

出力:

Enter environmentname (ex. dev/qa/prod): qa 
Enter customer name: cust 
connect.rest.address=http://connect.qa-cust.qafqdn.com 

connect.rest.ssl.address=https://connect.qa-cust.qafqdn.com 

connect.rest.giftregistry.service=http://connect.qa-cust.qafqdn.com:8280/services 

receipt.server.host=engage.central.qa-cust.qafqdn.com 

を私は何を達成しようとしていることも示したように、スクリプトは、具体的には、以下を探して持っている以下は、今のように、スクリプトの本体ですカストため、その後のenv名前のための「QA」と「カストを」:上記:私は入力した場合に促さので

connect.rest.address= 
connect.rest.ssl.address= 
connect.rest.giftregistry.service= 

し、それらのいずれかが正しくない場合、ユーザーに報告.. 、いずれかのURLがそうのようにフォーマット何か以外のものがあれば名前オメル、:

connect.qa-cust.qafqdn.com 

を、それは正しくフォーマットされていない3つのURL変数のユーザーを教えてくれます。

したがって、 'connect.rest.ssl.address ='が私が入力した(qa-cust.qafqdn.comに等しい)入力と等しくなかった場合、それらの残りの部分は、エラーは次のようになります。

connect.rest.address - OK 
connect.rest.ssl.address - ERROR: does not match value provided 
connect.rest.giftregistry.service - OK 

このスクリプトは基本的に環境健全性チェッカーです。 私はこれを可能な限り明確にしようとしました。私は助けに感謝します。

答えて

0

私は質問を正しく理解していませんが、ファイル内のどの行にも正しいプロパティがあることを期待している場合は、行の一部に正しい書式がない場合は間違っています。

with open ("%s" % (engage_properties)) as inF: 
for line in inF: 
    if ("%s-%s.%srhythmforstores.com" % (env,cust,env)) in line: 
     print line 
    elif "rhythmforstores.com" in line: 
     print error_message 
+0

ねえ、私の質問に答えてくれてありがとう..私はちょうど私の目標をクリアする質問を編集しました - 私はそれが助けになると思います – aphexlog

関連する問題