Hello community, here is the log from the commit of package setconf for openSUSE:Factory checked in at 2015-03-09 10:10:21 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/setconf (Old) and /work/SRC/openSUSE:Factory/.setconf.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "setconf" Changes: -------- --- /work/SRC/openSUSE:Factory/setconf/setconf.changes 2014-12-19 09:37:54.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.setconf.new/setconf.changes 2015-03-09 10:10:22.000000000 +0100 @@ -1,0 +2,8 @@ +Sun Mar 8 18:03:19 UTC 2015 - sor.ale...@meowr.ru + +- Update to 0.6.6 (changes since 0.6.4): + * Can now use += or -= for increasing or decreasing integer + values. + * Fix a problem with files without newline endings. + +------------------------------------------------------------------- Old: ---- setconf-0.6.4.tar.xz New: ---- setconf-0.6.6.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ setconf.spec ++++++ --- /var/tmp/diff_new_pack.G2viQL/_old 2015-03-09 10:10:22.000000000 +0100 +++ /var/tmp/diff_new_pack.G2viQL/_new 2015-03-09 10:10:22.000000000 +0100 @@ -1,7 +1,7 @@ # # spec file for package setconf # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: setconf -Version: 0.6.4 +Version: 0.6.6 Release: 0 Summary: Utility to easily change settings in configuration files License: GPL-2.0+ @@ -45,6 +45,6 @@ %defattr(-,root,root) %doc COPYING %{_bindir}/%{name} -%{_mandir}/man1/%{name}.1.gz +%{_mandir}/man?/%{name}.?%{ext_man} %changelog ++++++ setconf-0.6.4.tar.xz -> setconf-0.6.6.tar.xz ++++++ Files old/setconf-0.6.4/setconf.1.gz and new/setconf-0.6.6/setconf.1.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/setconf-0.6.4/setconf.py new/setconf-0.6.6/setconf.py --- old/setconf-0.6.4/setconf.py 2014-12-03 13:25:32.000000000 +0100 +++ new/setconf-0.6.6/setconf.py 2015-03-03 21:52:29.000000000 +0100 @@ -20,6 +20,7 @@ # Aug 2014 # Oct 2014 # Dec 2014 +# Mar 2015 # from sys import argv @@ -31,8 +32,9 @@ # TODO: Use optparse or argparse if shedskin is no longer a target. -VERSION = "0.6.4" -ASSIGNMENTS = ['==', '=>', '=', ':=', '::', ':'] +VERSION = "0.6.6" +ASSIGNMENTS = ['==', '=>', '+=', '-=', '=', ':=', '::', ':'] + def get_encoding(filename): """Use the output from the file command to guess the encoding. @@ -43,17 +45,24 @@ else: return (False, None) -def firstpart(line, including_assignment=True): + +def parts(line, including_assignment=True): + """Return the key and value parts of a line, if there is an assignment there. + May include the assignment as part of the key.""" stripline = line.strip() if not stripline: - return None + return None, None # Skip lines that start with #, // or /* if (stripline[0] == "#") or (stripline[:2] in ["//", "/*"]): - return None + return None, None # These assignments are supported, in this order assignment = "" found = [] for ass in ASSIGNMENTS: + # Skip the += and -= operators when finding keys and values + if ass in ['+=', '-=']: + continue + # Collect the rest if ass in line: found.append(ass) if len(found) == 1: @@ -71,12 +80,21 @@ assignment = firstassignment # Return the "key" part of the line if assignment: + fields = line.split(assignment, 1) if including_assignment: - return line.split(assignment, 1)[0] + assignment + return fields[0] + assignment, fields[1] else: - return line.split(assignment, 1)[0] + return fields[0], fields[1] # No assignments were found - return None + return None, None + + +def firstpart(line, including_assignment=True): + return parts(line, including_assignment)[0] + + +def secondpart(line, including_assignment=True): + return parts(line, including_assignment)[1] def changeline(line, newvalue): @@ -137,13 +155,13 @@ testcontent = """LIGHTS = ON bananas= not present tea := yes - crazyclown :ok + randombob :ok """ testcontent_changed = """LIGHTS = off bananas= not present tea := yes - crazyclown :ok + randombob :ok """ passes = True @@ -165,10 +183,16 @@ except IOError: print("Can't read %s" % (filename)) sysexit(2) + final_nl = True + if linesep not in data: + lines = [data] + final_nl = False + elif not data.endswith(linesep): + final_nl = False # Change and write the file changed_contents = linesep.join(change(lines, key, value)) # Only add a final newline if the original contents had one at the end - if data.endswith(linesep): + if final_nl: changed_contents += linesep if dummyrun: return data != changed_contents @@ -180,7 +204,6 @@ file.write(changed_contents) file.close() - def addtofile(filename, line): """Tries to add a line to a file. UTF-8. No questions asked.""" # Read the file @@ -192,6 +215,10 @@ except IOError: print("Can't read %s" % (filename)) sysexit(2) + if data.strip() == "": + lines = [] + elif linesep not in data: + lines = [data] # Change and write the file try: file = open(filename, "w") @@ -516,6 +543,31 @@ return True return False +def get_value(data, key): + """Return the first value for a given key.""" + lines = data.split(linesep)[:-1] + for line in lines: + if not line.strip(): + # Skip blank lines + continue + first, second = parts(line, False) + if key == first: + return second + return "" + +def inc(startvalue, s): + """Increase the number in the string with the given string, or return the same string.""" + try: + return str(int(startvalue)+int(s)) + except ValueError: + return s + +def dec(startvalue, s): + """Decrease the number in the string with the given string, or return the same string.""" + try: + return str(int(startvalue)-int(s)) + except ValueError: + return s def main(args=argv[1:], exitok=True): if len(args) == 1: @@ -549,10 +601,32 @@ elif args[0] in ["-v", "--version"]: print(VERSION) elif len(args) == 2: - # Single line replace ("x=123") + # Single line replace: "x=123" or "x+=2" filename = args[0] keyvalue = args[1] - if "=" in keyvalue: + if "+=" in keyvalue: + key, value = keyvalue.split("+=", 1) + try: + f = open(filename) + except IOError: + print("Can't read %s" % (filename)) + sysexit(2) + data = f.read() + f.close() + datavalue = get_value(data, key) + changefile(filename, key, inc(datavalue, value)) + elif "-=" in keyvalue: + key, value = keyvalue.split("-=", 1) + try: + f = open(filename) + except IOError: + print("Can't read %s" % (filename)) + sysexit(2) + data = f.read() + f.close() + datavalue = get_value(data, key) + changefile(filename, key, dec(datavalue, value)) + elif "=" in keyvalue: key, value = keyvalue.split("=", 1) changefile(filename, key, value) else: @@ -567,6 +641,7 @@ # Change the file if possible, if not, add the key value assignment = None + special = None for ass in ASSIGNMENTS: if ass in keyvalue: assignment = ass -- To unsubscribe, e-mail: opensuse-commit+unsubscr...@opensuse.org For additional commands, e-mail: opensuse-commit+h...@opensuse.org