0

小さな xml 構成ファイルで数行を更新する必要がある、簡単で汚いビルド スクリプトがあります。ファイルが非常に小さいため、単純化するために、明らかに非効率的なプロセスを使用してファイルを更新しています。

def hide_osx_dock_icon(app):
    for line in fileinput.input(os.path.join(app, 'Contents', 'Info.plist'), inplace=True):
        line = re.sub(r'(<key>CFBundleDevelopmentRegion</key>)', '<key>LSUIElement</key><string>1</string>\g<1>', line.strip(), flags=re.IGNORECASE)

    print line.strip()

アイデアは、<key>CFBundleDevelopmentRegion</key>テキストを見つけて、そのLSUIElement前にコンテンツを挿入することです。私は別の分野でこのようなことをしていて、うまく機能しているので、何かが欠けているだけだと思いますが、それはわかりません。

私は何を間違っていますか?

4

1 に答える 1

0

ステートメントが for ループの外にあるため、最後の行のみを出力しています。print

for line in fileinput.input(os.path.join(app, 'Contents', 'Info.plist'), inplace=True):
    line = re.sub(r'(<key>CFBundleDevelopmentRegion</key>)', '<key>LSUIElement</key><string>1</string>\g<1>', line.strip(), flags=re.IGNORECASE)

print line.strip()

その行を前のものと一致するようにインデントします。

for line in fileinput.input(os.path.join(app, 'Contents', 'Info.plist'), inplace=True):
    line = re.sub(r'(<key>CFBundleDevelopmentRegion</key>)', '<key>LSUIElement</key><string>1</string>\g<1>', line.strip(), flags=re.IGNORECASE)

    print line.strip()
于 2013-06-20T12:18:58.693 に答える