From 2f29b009eadaa24d004577bedb5d647d2049c447 Mon Sep 17 00:00:00 2001 From: fhdk <fh@uex.dk> Date: Fri, 31 Mar 2017 11:00:56 +0200 Subject: [PATCH] reorderd --- pacman_mirrors/configfn.py | 52 +++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/pacman_mirrors/configfn.py b/pacman_mirrors/configfn.py index f92056e3..1ae359f9 100644 --- a/pacman_mirrors/configfn.py +++ b/pacman_mirrors/configfn.py @@ -26,6 +26,32 @@ from . import txt from . import configuration as conf +def api_write_branch(branch, filename): + """Write branch""" + branch = "Branch = {}".format(branch) + + try: + with open( + filename) as cnf, tempfile.NamedTemporaryFile( + "w+t", dir=os.path.dirname( + filename), delete=False) as tmp: + replaced = False + for line in cnf: + if "Branch" in line: + tmp.write(branch) + replaced = True + else: + tmp.write("{}".format(line)) + if not replaced: + tmp.write(branch) + os.replace(tmp.name, filename) + os.chmod(filename, 0o644) + except OSError as err: + print(".: {} {}: {}: {}".format(txt.ERR_CLR, txt.CANNOT_READ_FILE, + err.filename, err.strerror)) + exit(1) + + def build_config(): """Get config informations :returns: config, custom @@ -102,32 +128,6 @@ def modify_config(config, custom=False): custom=custom) -def api_write_branch(branch, filename): - """Write branch""" - branch = "Branch = {}".format(branch) - - try: - with open( - filename) as cnf, tempfile.NamedTemporaryFile( - "w+t", dir=os.path.dirname( - filename), delete=False) as tmp: - replaced = False - for line in cnf: - if "Branch" in line: - tmp.write(branch) - replaced = True - else: - tmp.write("{}".format(line)) - if not replaced: - tmp.write(branch) - os.replace(tmp.name, filename) - os.chmod(filename, 0o644) - except OSError as err: - print(".: {} {}: {}: {}".format(txt.ERR_CLR, txt.CANNOT_READ_FILE, - err.filename, err.strerror)) - exit(1) - - def write_configuration(filename, selection, custom=False): """Writes the configuration to file :param filename: -- GitLab