我在寫一個可以在各種系統上運行的通用python腳本。我被困在一個條件,我需要檢查變量的內容。直到現在我簡單的代碼看起來像:如何解析變量內容,然後根據它來評估條件,python
log_path = parser.get('default', 'log_path')
# name and location of tar file
tar_file = 'logs.tar.gz'
working_path = os.getcwd()
file_location = os.path.join(working_path,tar_file)
# open conection to s3 and get bucket object
s3_conn = S3Connection()
bucket = s3_conn.get_bucket('smso-eng-log-share')
# make tar.gz
with tarfile.open(tar_file, 'w:gz') as tar:
tar.add(log_path, arcname='tomcat7')
變量log_path
正在從一個.ini文件回升。
說出當前值log_path = /var/log/tomcat7/
然後它創建名爲tomcat7
的日誌焦油。
現在假設log_path = /var/log/haproxy/
,那麼它應該有一個名爲 'haproxy
'
我有點糊塗了,我想寫一個條件語句中的.ini文件內 '{%其他%} 如果在/ var /日誌/ HAProxy的/存在 然後log_path = /無功/日誌/ HAProxy的/ 的elif的/ var /日誌/ tomcat7存在 然後log_path = /無功/日誌/ tomcat7/ {%ENDIF%}' 我想知道如果語法是正確的? –
這是新問題 - 創建新問題。 – furas
是的,我想你是對的 –