Erste beta, auslassen von commentstring im diff
This commit is contained in:
parent
31fd2d2c06
commit
04b9e7884c
29
Tools.py
29
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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user