[Commits] python.it commit r161 - admin/trunk/scripts

commit a svn.python.it commit a svn.python.it
Sab 27 Maggio 2006 18:31:37 CEST


Author: manlio
Date: Sat May 27 18:31:36 2006
New Revision: 161

Modified:
   admin/trunk/scripts/blockutils.py
   admin/trunk/scripts/diffparser.py
   admin/trunk/scripts/mark.py
   admin/trunk/scripts/markdiff.py
   admin/trunk/scripts/update-version.py
   admin/trunk/scripts/utils.py
Log:
indentazione non consistente (tabs)

Modified: admin/trunk/scripts/blockutils.py
==============================================================================
--- admin/trunk/scripts/blockutils.py	(original)
+++ admin/trunk/scripts/blockutils.py	Sat May 27 18:31:36 2006
@@ -49,24 +49,24 @@
     global _mode, _blockPattern, _startComment, _endComment
 
     _blocks = {
-	'tex': re.compile(r"^\n+", re.MULTILINE),
-	'rst': re.compile(r"^\n+", re.MULTILINE),
-	'xml': re.compile(r"<[^/>]*>"),
-	'xhtml': re.compile(r"<p.*?>"),
-	'docbook': re.compile(r"<para.*?>")
-	}
+        'tex': re.compile(r"^\n+", re.MULTILINE),
+        'rst': re.compile(r"^\n+", re.MULTILINE),
+        'xml': re.compile(r"<[^/>]*>"),
+        'xhtml': re.compile(r"<p.*?>"),
+        'docbook': re.compile(r"<para.*?>")
+        }
     
     _comments = {
-	'tex': ('%', ''),
-	# XXX explicit markup in reST must end with a blank line;
-	# but adding '\n' as comment terminator is not feasible.
-	# Moreover a warning is issued if the comment is inside a
-	# literal block
-	'rst': ('.. ', ''), 
-	'xml': ('<!-- ', ' -->'),
-	'xhtml': ('<!-- ', ' -->'),
-	'docbook': ('<!-- ', ' -->')
-	}
+        'tex': ('%', ''),
+        # XXX explicit markup in reST must end with a blank line;
+        # but adding '\n' as comment terminator is not feasible.
+        # Moreover a warning is issued if the comment is inside a
+        # literal block
+        'rst': ('.. ', ''), 
+        'xml': ('<!-- ', ' -->'),
+        'xhtml': ('<!-- ', ' -->'),
+        'docbook': ('<!-- ', ' -->')
+        }
 
     
     old = _mode
@@ -74,11 +74,11 @@
 
     _blockPattern = _blocks.get(mode, None)
     if _blockPattern is None:
-	raise RuntimeError("unsupported mode '%s'" % mode)
+        raise RuntimeError("unsupported mode '%s'" % mode)
     
     _startComment, _endComment = _comments.get(mode, (None, None))
     if (_startComment, _endComment) is (None, None):
-	raise RuntimeError("unsupported mode '%s'" % mode)
+        raise RuntimeError("unsupported mode '%s'" % mode)
 
     
     return old
@@ -102,7 +102,7 @@
     mode = _modeMap.get(ext, None)
     
     if mode is None:
-	raise RuntimeError("unsupported document type '%s'" % ext)
+        raise RuntimeError("unsupported document type '%s'" % ext)
 
 
     return setMode(mode)
@@ -164,12 +164,12 @@
     count = 0
     start = 0
     for n, match in enumerate(_blockPattern.finditer(document)):
-	end = match.start() - 1
-	i = document[start:end].count('\n') + count
-	
-	blocks[n + 1] = i
-	count = i
-	start = end
+        end = match.start() - 1
+        i = document[start:end].count('\n') + count
+        
+        blocks[n + 1] = i
+        count = i
+        start = end
 
     return blocks
 
@@ -195,69 +195,69 @@
     recursive = False
     
     opts, args = getopt(sys.argv, "m:cnro:", 
-			["mode=", "check", "count", "recursive",
-			 "override="])
+                        ["mode=", "check", "count", "recursive",
+                         "override="])
     
     for o, a in opts:
-	if o in ("-m", "--mode"):
-	    mode = a
-	elif o in ("-c", "--check"):
-	    doCheck = True
-	elif o in ("-n", "--count"):
-	    doCount = True
-	elif o in ("-r", "--recursive"):
-	    recursive = True
-	elif o in ("-o", "--override"):
-	    ext, mode_ = a.split(':')
-	    setModeForDocumentType(ext, mode_)
+        if o in ("-m", "--mode"):
+            mode = a
+        elif o in ("-c", "--check"):
+            doCheck = True
+        elif o in ("-n", "--count"):
+            doCount = True
+        elif o in ("-r", "--recursive"):
+            recursive = True
+        elif o in ("-o", "--override"):
+            ext, mode_ = a.split(':')
+            setModeForDocumentType(ext, mode_)
 
 
     if mode is not None:
-	setMode(mode)
+        setMode(mode)
     elif not recursive:
-	setModeFromFileName(args[1])
+        setModeFromFileName(args[1])
 
     if doCheck:
-	if not recursive:
-	    lx = file(args[1]).read()
-	    rx = file(args[2]).read()
-	
-	    N = countBlocks(lx) - countBlocks(rx)
-	    if N != 0:
-		log("blocks number differ: %d", N)
-	else:
-	    # this assume that the two directories contain the same
-	    # files 
-	    # for semplicity move to the first directory
-	    os.chdir(args[1])
-	    for root, dirs, files in os.walk('.'):
-		for name in files:
-		    path = os.path.join(root, name)
-		    path2 = os.path.join(args[2], path)
-		    
-		    if '.svn' in dirs:
-			# ignore Subversion entries
-			dirs.remove('.svn')
-		
-		    if mode is None:
-			try:
-			    setModeFromFileName(path)
-			except RuntimeError, err:
-			    # simply compare files
-			    if not cmpFiles(path, path2):
-				log("%s: files differ", path[1:])
-			    continue
-		    
-		    lx = file(path).read()
-		    try:
-			rx = file(path2).read()
-		    except IOError:
-			log("%s: file not found", path[1:])
-			continue
-		    
-		    N = countBlocks(lx) - countBlocks(rx)
-		    if N != 0:
-			log("%s: blocks number differ, %d", path[1:], N)
+        if not recursive:
+            lx = file(args[1]).read()
+            rx = file(args[2]).read()
+        
+            N = countBlocks(lx) - countBlocks(rx)
+            if N != 0:
+                log("blocks number differ: %d", N)
+        else:
+            # this assume that the two directories contain the same
+            # files 
+            # for semplicity move to the first directory
+            os.chdir(args[1])
+            for root, dirs, files in os.walk('.'):
+                for name in files:
+                    path = os.path.join(root, name)
+                    path2 = os.path.join(args[2], path)
+                    
+                    if '.svn' in dirs:
+                        # ignore Subversion entries
+                        dirs.remove('.svn')
+                
+                    if mode is None:
+                        try:
+                            setModeFromFileName(path)
+                        except RuntimeError, err:
+                            # simply compare files
+                            if not cmpFiles(path, path2):
+                                log("%s: files differ", path[1:])
+                            continue
+                    
+                    lx = file(path).read()
+                    try:
+                        rx = file(path2).read()
+                    except IOError:
+                        log("%s: file not found", path[1:])
+                        continue
+                    
+                    N = countBlocks(lx) - countBlocks(rx)
+                    if N != 0:
+                        log("%s: blocks number differ, %d", path[1:], N)
     elif doCount:
-	data = file(args[1]).read()
-	log("number of blocks: %d", countBlocks(data))
+        data = file(args[1]).read()
+        log("number of blocks: %d", countBlocks(data))

Modified: admin/trunk/scripts/diffparser.py
==============================================================================
--- admin/trunk/scripts/diffparser.py	(original)
+++ admin/trunk/scripts/diffparser.py	Sat May 27 18:31:36 2006
@@ -26,7 +26,7 @@
         """position is a tuple of 4 elements.
         """
         
-	self.position = map(int, position)
+        self.position = map(int, position)
 
         self.lines = []
     
@@ -76,95 +76,95 @@
     pattern = re.compile(r"@@ -(\d+),(\d+) \+(\d+),(\d+) @@")
     
     def __init__(self, context=5):
-	self.context = context
-	
-	self.addedFiles = []
-	self.removedFiles = []
-	self.changedFiles = {}
-	
-	self.resetState()
+        self.context = context
+        
+        self.addedFiles = []
+        self.removedFiles = []
+        self.changedFiles = {}
+        
+        self.resetState()
     
     def resetState(self):
-	"""reset internal state.
-	"""
-	
-	self.differ = None
-	self.hunk = None
-	self.currentPath = None # used only for an useless check
+        """reset internal state.
+        """
+        
+        self.differ = None
+        self.hunk = None
+        self.currentPath = None # used only for an useless check
 
     def diff(self, old, new):
-	"""Compute the differences between old and new directories.
-	"""
-	
-	self.resetState()
-
-	# XXX svn diff does not support this operation
-	# XXX use with cares. It computes all files even if they are
-	# not under version control.
-	# Ignore white spaces?
-	# Problem with $Id and $Revision
-
-	cmd = "diff -U %d -rx .svn %s %s" % (self.context, old, new)
-	fp = os.popen(cmd, 'r') 
-	
-	for line in fp:
-	    self.feedLine(line, old, new)
-	
-	return self.getResult()
+        """Compute the differences between old and new directories.
+        """
+        
+        self.resetState()
+
+        # XXX svn diff does not support this operation
+        # XXX use with cares. It computes all files even if they are
+        # not under version control.
+        # Ignore white spaces?
+        # Problem with $Id and $Revision
+
+        cmd = "diff -U %d -rx .svn %s %s" % (self.context, old, new)
+        fp = os.popen(cmd, 'r') 
+        
+        for line in fp:
+            self.feedLine(line, old, new)
+        
+        return self.getResult()
 
     def feedLine(self, line, old, new):
-	if line.startswith("Only in "):
-	    path, name = line[8:].split(': ')
-	    name = name.rstrip()
-
-	    if path.startswith(old):
-		path = path[len(old):]
-		l = self.removedFiles
-	    else:
-		path = path[len(new):]
-		l = self.addedFiles
+        if line.startswith("Only in "):
+            path, name = line[8:].split(': ')
+            name = name.rstrip()
+
+            if path.startswith(old):
+                path = path[len(old):]
+                l = self.removedFiles
+            else:
+                path = path[len(new):]
+                l = self.addedFiles
         
-	    if isabs(path):
-		path = path[1:] # we don't want absolute paths
+            if isabs(path):
+                path = path[1:] # we don't want absolute paths
             
-	    path = normpath(join(path, name))
-	    l.append(path)
-	elif line.startswith("diff"):
-	    return
-	elif line.startswith('--- '):
-	    try:
-		path, info = line[4:].split('\t')
-	    except ValueError:
-		return
-        
-	    path = path[len(old):]
-	    if isabs(path):
-		path = path[1:] # we don't want absolute paths
-
-	    self.differ = Differ()
-	    self.currentPath = path
-        
-	    self.changedFiles[path] = self.differ
-	elif line.startswith('+++ '):
-	    # do an useless check
-	    try:
-		path, info = line[4:].split('\t')
-	    except ValueError:
-		return
-        
-	    path = path[len(new):]
-	    if isabs(path):
-		path = path[1:] # we don't want absolute paths
-
-	    assert path == self.currentPath
-	elif line.startswith("@@"):
-	    match = self.pattern.match(line)
-	    self.hunk = self.differ.createHunk(match.groups())
-	else:
-	    self.hunk.addLine(line)
+            path = normpath(join(path, name))
+            l.append(path)
+        elif line.startswith("diff"):
+            return
+        elif line.startswith('--- '):
+            try:
+                path, info = line[4:].split('\t')
+            except ValueError:
+                return
+        
+            path = path[len(old):]
+            if isabs(path):
+                path = path[1:] # we don't want absolute paths
+
+            self.differ = Differ()
+            self.currentPath = path
+        
+            self.changedFiles[path] = self.differ
+        elif line.startswith('+++ '):
+            # do an useless check
+            try:
+                path, info = line[4:].split('\t')
+            except ValueError:
+                return
+        
+            path = path[len(new):]
+            if isabs(path):
+                path = path[1:] # we don't want absolute paths
+
+            assert path == self.currentPath
+        elif line.startswith("@@"):
+            match = self.pattern.match(line)
+            self.hunk = self.differ.createHunk(match.groups())
+        else:
+            self.hunk.addLine(line)
 
     def getResult(self):
-	return self.changedFiles, self.addedFiles, self.removedFiles
+        return self.changedFiles, self.addedFiles, self.removedFiles
     
 
 if __name__ == "__main__":
@@ -180,22 +180,22 @@
     opts, args = getopt(sys.argv, "c:", ["context="])
 
     for o, a in opts:
-	if o in ("-c", "--context"):
-	    context = int(a)
+        if o in ("-c", "--context"):
+            context = int(a)
 
     parser = Parser(context)
     changedFiles, addedFiles, removedFiles = parser.diff(args[1],
-							 args[2])
+                                                         args[2])
 
     log("added files:")
     for name in addedFiles:
-	log(name, level=1)
+        log(name, level=1)
 
     log("removed files:")
     for name in removedFiles:
-	log(name, level=1)
+        log(name, level=1)
 
     log("changed files:")
     for name, diff in changedFiles.iteritems():
-	log(name, level=1)
-	log(diff, level=1)
+        log(name, level=1)
+        log(diff, level=1)

Modified: admin/trunk/scripts/mark.py
==============================================================================
--- admin/trunk/scripts/mark.py	(original)
+++ admin/trunk/scripts/mark.py	Sat May 27 18:31:36 2006
@@ -30,14 +30,14 @@
 
     # XXX for XML documents, the <?xml> should be the first element
     if "<?xml" in lines[0]:
-	prolog = [lines[0]]
-	lines = lines[1:]
+        prolog = [lines[0]]
+        lines = lines[1:]
     else:
-	prolog = []
+        prolog = []
     
     N = len(lines) / splitLines + 1
     for i in range(N):
-	pos = (splitLines + 1) * i
+        pos = (splitLines + 1) * i
         marker = insertMark("BEGIN PART %03d of %d" % (i + 1, N))
         lines.insert(pos, marker + '\n')
     
@@ -60,15 +60,15 @@
     del blocks[0] # we don't want the first block
     
     if block == "all":
-	for n, (i, pos) in enumerate(blocks.iteritems()):
-	    marker = insertMark("BLOCK %03d of %d" % (i, N))
-	    lines.insert(pos + n + 1, marker + '\n')
-	
+        for n, (i, pos) in enumerate(blocks.iteritems()):
+            marker = insertMark("BLOCK %03d of %d" % (i, N))
+            lines.insert(pos + n + 1, marker + '\n')
+        
     else:
-	pos = blocks[block]
-	marker = insertMark("BLOCK %03d of %d" % (block, N))
-	lines.insert(pos + 1, marker + '\n')
-	
+        pos = blocks[block]
+        marker = insertMark("BLOCK %03d of %d" % (block, N))
+        lines.insert(pos + 1, marker + '\n')
+        
     file(path, 'wb').writelines(lines)
 
     return N
@@ -105,30 +105,30 @@
     
 
     opts, args = getopt(sys.argv, "m:us:b:", 
-			["mode=", "unmark", "split=", "block="])
+                        ["mode=", "unmark", "split=", "block="])
     
     for o, a in opts:
-	if o in ("-m", "--mode"):
-	    mode = a
-	elif o in ("-u", "--unmark"):
-	    doUnmark = True
-	elif o in ("-s", "--split"):
-	    split = int(a)
-	elif o in ("-b", "--block"):
-	    block = a == "all" and "all" or int(a)
+        if o in ("-m", "--mode"):
+            mode = a
+        elif o in ("-u", "--unmark"):
+            doUnmark = True
+        elif o in ("-s", "--split"):
+            split = int(a)
+        elif o in ("-b", "--block"):
+            block = a == "all" and "all" or int(a)
     
     if mode is None:
-	setModeFromFileName(args[1])
+        setModeFromFileName(args[1])
     else:
-	setMode(mode)
+        setMode(mode)
 
     if block is not None:
-	N = markBlock(args[1], block)
-	log("marked %s block of %d", block, N)
+        N = markBlock(args[1], block)
+        log("marked %s block of %d", block, N)
     else:
-	if doUnmark:
-	    N = unmark(args[1])
-	    log("%d markers removed", N)
-	else:
-	    N = mark(args[1], split)
-	    log("%d blocks marked", N)    
+        if doUnmark:
+            N = unmark(args[1])
+            log("%d markers removed", N)
+        else:
+            N = mark(args[1], split)
+            log("%d blocks marked", N)    

Modified: admin/trunk/scripts/markdiff.py
==============================================================================
--- admin/trunk/scripts/markdiff.py	(original)
+++ admin/trunk/scripts/markdiff.py	Sat May 27 18:31:36 2006
@@ -40,16 +40,16 @@
     
     # XXX for XML documents, the <?xml> should be the first element
     if "<?xml" in baseLines[0]:
-	prolog = [baseLines[0]]
-	baseLines = baseLines[1:]
+        prolog = [baseLines[0]]
+        baseLines = baseLines[1:]
     else:
-	prolog = []
+        prolog = []
 
     # check that the original and the translated document have the
     # same number of blocks
     N = abs(countBlocks(old) - countBlocks(base))
     if N != 0:
-	# XXX raise an exception?
+        # XXX raise an exception?
         return -N
             
     blocks = blocksToLines(base)
@@ -61,7 +61,7 @@
         offset = hunk.context()
         idx = lineToBlock(oldLines, pos - 1 + offset)
         
-	mark = [insertMark("BEGIN DIFF %03d of %d" % (i + 1, N))]
+        mark = [insertMark("BEGIN DIFF %03d of %d" % (i + 1, N))]
         mark.append(insertMark("@@ %d" % hunk.position[0]))
         mark += [insertMark(line[:-1]) for line in hunk.lines]
         mark.append(insertMark("END DIFF"))
@@ -87,21 +87,21 @@
     context = 5 # context line to use for the diff in unified format
     
     opts, args = getopt(sys.argv, "m:c:", 
-			["mode=", "context="])
+                        ["mode=", "context="])
     
     old, new, base = args[1:4]
 
 
     for o, a in opts:
-	if o in ("-m", "--mode"):
-	    mode = a
-	elif o in ("-u", "--context"):
-	    context = int(a)
+        if o in ("-m", "--mode"):
+            mode = a
+        elif o in ("-u", "--context"):
+            context = int(a)
     
     if mode is None:
-	setModeFromFileName(base)
+        setModeFromFileName(base)
     else:
-	setMode(mode)
+        setMode(mode)
     
     
     lx = file(old, 'r').readlines()
@@ -130,6 +130,6 @@
     N =  markDiff(old, base, diff)
     if N < 0:
         log("the number of blocks does not correspond with the "\
-		  "original (%d), skip", N)
+                  "original (%d), skip", N)
     else:
         log("%d markers applied", N)

Modified: admin/trunk/scripts/update-version.py
==============================================================================
--- admin/trunk/scripts/update-version.py	(original)
+++ admin/trunk/scripts/update-version.py	Sat May 27 18:31:36 2006
@@ -42,22 +42,22 @@
 dry_run = False
 
 opts, args = getopt(sys.argv, "c:s:p:do:", 
-		    ["context=", "split=", "profile=", "dry-run",
-		     "override="])
+                    ["context=", "split=", "profile=", "dry-run",
+                     "override="])
     
 for o, a in opts:
     if o in ("-c", "--context"):
-	context = int(a)
+        context = int(a)
     elif o in ("-s", "--split"):
-	splitLines = int(a)
+        splitLines = int(a)
     elif o in ("-p", "--profile"):
-	profileName = a
-	profile = loadProfile(a)
+        profileName = a
+        profile = loadProfile(a)
     elif o in ("-d", "--dry-run"):
-	dry_run = True
+        dry_run = True
     elif o in ("-o", "--override"):
-	    ext, mode_ = a.split(':')
-	    setModeForDocumentType(ext, mode_)
+            ext, mode_ = a.split(':')
+            setModeForDocumentType(ext, mode_)
 
 
 workingPath = args[1]
@@ -108,8 +108,8 @@
     log(path, level=1)
     
     if not dry_run:
-	if os.system("svn delete %s" % path) != 0:
-	    raise RuntimeError("unable to delete the file")
+        if os.system("svn delete %s" % path) != 0:
+            raise RuntimeError("unable to delete the file")
 
 
 print
@@ -118,22 +118,22 @@
     log(path, level=1)
     
     if not dry_run:
-	src = join(tagsPath, new, path)
-	if os.system("svn copy %s %s" % (src, path)) != 0:
-	    raise RuntimeError("unable to copy the file")
-	
+        src = join(tagsPath, new, path)
+        if os.system("svn copy %s %s" % (src, path)) != 0:
+            raise RuntimeError("unable to copy the file")
+        
     try:
-	setModeFromFileName(path)
+        setModeFromFileName(path)
     except RuntimeError, err:
-	log(err, level=2)
-	continue
+        log(err, level=2)
+        continue
 
     log("marking file", level=2)
     if not dry_run:
-	N = mark(path, splitLines)
-	log("%d markers applied", N, level=2)
+        N = mark(path, splitLines)
+        log("%d markers applied", N, level=2)
     else:
-	log("some markers applied", level=2)
+        log("some markers applied", level=2)
 
 
 print
@@ -150,31 +150,31 @@
     
     
     if cmpFiles(oldPath, basePath):
-	# the file has not been translated at all
-	log("nothing to do", level=2)
-	continue
-	
+        # the file has not been translated at all
+        log("nothing to do", level=2)
+        continue
+        
     try:
-	setModeFromFileName(path)
+        setModeFromFileName(path)
     except RuntimeError, err:
-	log(err, level=2)
-	continue
+        log(err, level=2)
+        continue
     
     if not dry_run:
-	log("marking changed file", level=2)
-	N =  markDiff(oldPath, basePath, diff)
-	if N < 0:
-	    log("warning: the number of blocks does not correspond "\
-		"with the original (%d), skip", abs(N), level=2)
-	else:
-	    log("%d markers applied", N, level=2)
+        log("marking changed file", level=2)
+        N =  markDiff(oldPath, basePath, diff)
+        if N < 0:
+            log("warning: the number of blocks does not correspond "\
+                "with the original (%d), skip", abs(N), level=2)
+        else:
+            log("%d markers applied", N, level=2)
     else:
-	oldDoc = file(oldPath).read()
-	baseDoc = file(basePath).read()
-	    
-	N = countBlocks(oldDoc) - countBlocks(baseDoc)
-	if N != 0:
-	    log("warning: the numbers of blocks does not correspond "\
-		"(%d)" , N, level=2)
-	else:
-	    log("%d markers applied", len(diff.hunks), level=2)
+        oldDoc = file(oldPath).read()
+        baseDoc = file(basePath).read()
+            
+        N = countBlocks(oldDoc) - countBlocks(baseDoc)
+        if N != 0:
+            log("warning: the numbers of blocks does not correspond "\
+                "(%d)" , N, level=2)
+        else:
+            log("%d markers applied", len(diff.hunks), level=2)

Modified: admin/trunk/scripts/utils.py
==============================================================================
--- admin/trunk/scripts/utils.py	(original)
+++ admin/trunk/scripts/utils.py	Sat May 27 18:31:36 2006
@@ -22,9 +22,9 @@
     
     fp = file(path, 'rb')
     try:
-	return imp.load_source("profile", path, fp)
+        return imp.load_source("profile", path, fp)
     finally:
-	fp.close()
+        fp.close()
 
 
 def cmpFiles(lx, rx):
@@ -43,14 +43,14 @@
     ret = fp.close()
     
     if ret is None:
-	return True
+        return True
     elif ret == 1:
-	return False
+        return False
     else:
-	# XXX BUG?
-# 	errmsg = "unable to compare files '%s' and '%s'" % (lx, rx)
-# 	raise RuntimeError(errmsg)
-	return False
+        # XXX BUG?
+#       errmsg = "unable to compare files '%s' and '%s'" % (lx, rx)
+#       raise RuntimeError(errmsg)
+        return False
 
 
 
@@ -63,9 +63,9 @@
 
     
     try:
-	level = kwargs['level']
+        level = kwargs['level']
     except KeyError:
-	level = 0
+        level = 0
     
     pad = '   ' * level
     # make sure to first convert to a string


More information about the Commits mailing list