Erste beta, auslassen von commentstring im diff
This commit is contained in:
parent
31fd2d2c06
commit
04b9e7884c
31
Tools.py
31
Tools.py
@ -13,10 +13,11 @@ Copyright (c) 2013 __MyCompanyName__. All rights reserved.
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import cfgfile
|
import cfgfile
|
||||||
import filecmp
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
class Debug(object):
|
class Debug(object):
|
||||||
verbose = 0
|
verbose = 0
|
||||||
@ -74,9 +75,19 @@ def getConfig(filename):
|
|||||||
return ret
|
return ret
|
||||||
# def getConfig
|
# 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):
|
def diff(destfile, tempfile, commentstring, debug):
|
||||||
"""diff destfile and tempfile, returns True if files differ, False if they are the same"""
|
"""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))
|
debug.debug("Diffing %s and %s" % (destfile, tempfile))
|
||||||
if not os.path.isfile(destfile):
|
if not os.path.isfile(destfile):
|
||||||
debug.debug("Destfile %s does not exist, returning True." % 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)
|
error("Temporary file %s does not exist, this should not happen." % tempfile)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# if not tempfile
|
# 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 diff
|
||||||
|
|
||||||
def userConfigGenerated(filename, cfg):
|
def userConfigGenerated(filename, cfg):
|
||||||
|
@ -51,8 +51,10 @@ def workconf(directory, depth=2):
|
|||||||
# fixme: create name if it does not exist
|
# fixme: create name if it does not exist
|
||||||
workconf(name, depth+1)
|
workconf(name, depth+1)
|
||||||
# if dir
|
# if dir
|
||||||
ret.append(name)
|
if not name.endswith(".swp"):
|
||||||
debug.debug("workconf: found file %s" % name, depth)
|
ret.append(name)
|
||||||
|
debug.debug("workconf: found file %s" % name, depth)
|
||||||
|
# if not .swp
|
||||||
# for d
|
# for d
|
||||||
return ret
|
return ret
|
||||||
# def workconf
|
# def workconf
|
||||||
|
Loading…
Reference in New Issue
Block a user