#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. """Useful comment swapper for pacman mirrorlist files The swap file is written as the input filename plus ".tmp" then moves it back to the original name, this should not be noticed """ __all__ = ['main'] __author__ = "Cody A. Taylor ( codemister99@yahoo.com )" __copyright__ = "Copyright 2009, Cody A. Taylor" __version__ = "0.3 beta" import sys, os def main(): """Opens sys.argv[1] writes files back swapping comments on the "Server" lines """ with open(sys.argv[1], "r") as fin: with open(sys.argv[1] + ".tmp", "w") as fout: for line in fin: if line.startswith("#S"): fout.write(line[1:]) elif line.startswith("S"): fout.write("#" + line) else: fout.write(line) os.remove(fin.name) os.rename(fout.name, fin.name) if __name__ == "__main__": if len(sys.argv) > 1: main() else: print("Usage: swapComment.py [mirrorlist file]")