[ovs-dev] [PATCH 03/14] check-structs: Make Python 3 compatible.
Russell Bryant
russell at ovn.org
Tue Feb 2 22:36:45 UTC 2016
The only Python 3 errors here were the use of print. The rest of the
changes make it so we can check this file with flake8.
Signed-off-by: Russell Bryant <russell at ovn.org>
---
Makefile.am | 2 +-
build-aux/check-structs | 30 ++++++++++++++++++++++++------
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 4ca5e9c..d53353d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -142,7 +142,7 @@ SUFFIXES =
check_DATA =
check_SCRIPTS =
pkgconfig_DATA =
-FLAKE8_PYFILES =
+FLAKE8_PYFILES = build-aux/check-structs
scriptsdir = $(pkgdatadir)/scripts
completiondir = $(sysconfdir)/bash_completion.d
diff --git a/build-aux/check-structs b/build-aux/check-structs
index f79f235..217f738 100755
--- a/build-aux/check-structs
+++ b/build-aux/check-structs
@@ -1,5 +1,7 @@
#! /usr/bin/python
+from __future__ import print_function
+
import os.path
import sys
import re
@@ -26,6 +28,8 @@ includePath = ''
inComment = False
inDirective = False
inputStack = []
+
+
def getToken():
global token
global line
@@ -78,37 +82,45 @@ def getToken():
if inputStack:
fileName, inputFile, lineNumber = inputStack.pop()
continue
- if token == None:
+ if token is None:
fatal("unexpected end of input")
token = None
return False
break
-
+
+
def fatal(msg):
- sys.stderr.write("%s:%d: error at \"%s\": %s\n" % (fileName, lineNumber, token, msg))
+ sys.stderr.write("%s:%d: error at \"%s\": %s\n" %
+ (fileName, lineNumber, token, msg))
sys.exit(1)
-
+
+
def warn(msg):
global anyWarnings
anyWarnings = True
sys.stderr.write("%s:%d: warning: %s\n" % (fileName, lineNumber, msg))
+
def skipDirective():
getToken()
while token != '$':
getToken()
+
def isId(s):
return re.match(idRe + "$", s) != None
+
def forceId():
if not isId(token):
fatal("identifier expected")
+
def forceInteger():
if not re.match('[0-9]+$', token):
fatal("integer expected")
+
def match(t):
if token == t:
getToken()
@@ -116,10 +128,12 @@ def match(t):
else:
return False
+
def forceMatch(t):
if not match(t):
fatal("%s expected" % t)
+
def parseTaggedName():
assert token in ('struct', 'union')
name = token
@@ -129,6 +143,7 @@ def parseTaggedName():
getToken()
return name
+
def parseTypeName():
if token in ('struct', 'union'):
name = parseTaggedName()
@@ -143,6 +158,7 @@ def parseTypeName():
else:
fatal("unknown type \"%s\"" % name)
+
def parseStruct():
isStruct = token == 'struct'
structName = parseTaggedName()
@@ -203,6 +219,7 @@ def parseStruct():
types[structName] = {"size": size, "alignment": alignment}
return structName
+
def checkStructs():
if len(sys.argv) < 2:
sys.stderr.write("at least one non-option argument required; "
@@ -211,7 +228,7 @@ def checkStructs():
if '--help' in sys.argv:
argv0 = os.path.basename(sys.argv[0])
- print '''\
+ print('''\
%(argv0)s, for checking struct and struct member alignment
usage: %(argv0)s -Ipath HEADER [HEADER]...
@@ -226,7 +243,7 @@ assertions using OFP_ASSERT.
This program is specialized for reading Open vSwitch's OpenFlow header
files. It will not work on arbitrary header files without extensions.\
-''' % {"argv0": argv0}
+''' % {"argv0": argv0})
sys.exit(0)
global fileName
@@ -287,5 +304,6 @@ files. It will not work on arbitrary header files without extensions.\
if anyWarnings:
sys.exit(1)
+
if __name__ == '__main__':
checkStructs()
--
2.5.0
More information about the dev
mailing list