From 04b9e7884cbaa79839e9a650d1f76cd67da53787 Mon Sep 17 00:00:00 2001 From: Marcus Stoegbauer Date: Sun, 13 Jan 2013 12:27:33 +0000 Subject: [PATCH] Erste beta, auslassen von commentstring im diff --- Tools.py | 31 +++++++++++++++++++++++++++---- userconfig.py | 6 ++++-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Tools.py b/Tools.py index 3b9f90d..9f1b409 100644 --- a/Tools.py +++ b/Tools.py @@ -13,10 +13,11 @@ Copyright (c) 2013 __MyCompanyName__. All rights reserved. import sys import os import cfgfile -import filecmp import re import time import shutil +import itertools + class Debug(object): verbose = 0 @@ -74,9 +75,19 @@ def getConfig(filename): return ret # def getConfig +def read_skip_comment(fp, commentstring): + """Read line from filehandle fp and skip all empty (whitespace) lines and lines starting with commentstring + """ + for line in fp: + line = line[:-1] + if (commentstring != "" and not re.match("^"+re.escape(commentstring), line)) and line !="" and not re.match("^\s+$", line): + yield line + # if not match + # for line +# def read_skip_comment + def diff(destfile, tempfile, commentstring, debug): """diff destfile and tempfile, returns True if files differ, False if they are the same""" - # FIXME: filter out comments, SVN-Header and STAMP are causing diff errors debug.debug("Diffing %s and %s" % (destfile, tempfile)) if not os.path.isfile(destfile): debug.debug("Destfile %s does not exist, returning True." % destfile) @@ -88,8 +99,20 @@ def diff(destfile, tempfile, commentstring, debug): error("Temporary file %s does not exist, this should not happen." % tempfile) sys.exit(1) # if not tempfile - return not filecmp.cmp(tempfile, destfile) - + + fp1 = open(tempfile) + fp2 = open(destfile) + + for line1, line2 in itertools.izip(read_skip_comment(fp1, commentstring), read_skip_comment(fp2, commentstring)): + if line1 != line2: + fp1.close() + fp2.close() + return True + # if differ + # for line + fp1.close() + fp2.close() + return False # def diff def userConfigGenerated(filename, cfg): diff --git a/userconfig.py b/userconfig.py index 3738d2d..62d6e95 100755 --- a/userconfig.py +++ b/userconfig.py @@ -51,8 +51,10 @@ def workconf(directory, depth=2): # fixme: create name if it does not exist workconf(name, depth+1) # if dir - ret.append(name) - debug.debug("workconf: found file %s" % name, depth) + if not name.endswith(".swp"): + ret.append(name) + debug.debug("workconf: found file %s" % name, depth) + # if not .swp # for d return ret # def workconf