Scrips valid python3
This commit is contained in:
parent
3e38d1bec9
commit
e25d8150dd
91
fixHeader.py
91
fixHeader.py
|
@ -2,8 +2,10 @@
|
|||
|
||||
import GPS
|
||||
from os.path import *
|
||||
import string
|
||||
|
||||
HEADER="""##############################################################################
|
||||
HEADER = \
|
||||
"""##############################################################################
|
||||
## ##
|
||||
## 0MQ Ada-binding ##
|
||||
## ##
|
||||
|
@ -37,55 +39,56 @@ HEADER="""######################################################################
|
|||
"""
|
||||
|
||||
|
||||
|
||||
import string
|
||||
def to80Comment(s):
|
||||
if len(s) > 76:
|
||||
s = s.replace(" ","");
|
||||
if len(s) > 76:
|
||||
s=s[:-76]
|
||||
n= 76 - len(s)
|
||||
n=n/2
|
||||
ret = "##" + (" " * n) + s
|
||||
ret = ret + (" " * (76 - len(ret))) + "##"
|
||||
return ret
|
||||
if len(s) > 76:
|
||||
s = s.replace(" ", "")
|
||||
if len(s) > 76:
|
||||
s = s[:-76]
|
||||
n = 76 - len(s)
|
||||
n = n/2
|
||||
ret = "##" + (" " * n) + s
|
||||
ret = ret + (" " * (76 - len(ret))) + "##"
|
||||
return ret
|
||||
|
||||
|
||||
def getHeader(f):
|
||||
name,ext=splitext(basename(f.name()))
|
||||
name=name.upper().replace("-",".")
|
||||
name =to80Comment( string.join(name," "))
|
||||
if ext==".ads":
|
||||
ext =to80Comment("S p e c" )
|
||||
return (HEADER % {"name" : name , "ext" : ext}).replace("#","-")
|
||||
elif ext==".adb":
|
||||
ext =to80Comment("B o d y" )
|
||||
return (HEADER % {"name" : name , "ext" : ext}).replace("#","-")
|
||||
elif ext==".gpr":
|
||||
ext =to80Comment( "P r o j e c t" )
|
||||
return (HEADER % {"name" : name , "ext" : ext}).replace("#","-")
|
||||
else:
|
||||
ext =to80Comment("")
|
||||
return HEADER % {"name" : name , "ext" : ext}
|
||||
name, ext = splitext(basename(f.name()))
|
||||
name = name.upper().replace("-", ".")
|
||||
name = to80Comment(string.join(name, " "))
|
||||
if ext == ".ads":
|
||||
ext = to80Comment("S p e c")
|
||||
return(HEADER % {"name": name, "ext": ext}).replace("#", "-")
|
||||
elif ext == ".adb":
|
||||
ext = to80Comment("B o d y")
|
||||
return (HEADER % {"name": name, "ext": ext}).replace("#", "-")
|
||||
elif ext == ".gpr":
|
||||
ext = to80Comment("P r o j e c t")
|
||||
return (HEADER % {"name": name, "ext": ext}).replace("#", "-")
|
||||
else:
|
||||
ext = to80Comment("")
|
||||
return HEADER % {"name": name, "ext": ext}
|
||||
|
||||
def fixFile(f,of):
|
||||
name,ext=splitext(basename(f.name()))
|
||||
ed = GPS.EditorBuffer.get(f)
|
||||
begin=ed.beginning_of_buffer()
|
||||
if (ext not in [".gpr",".adb",".ads",".c",".cpp",".h",".hh",".idl"]):
|
||||
begin=begin.forward_line(1)
|
||||
last=ed.beginning_of_buffer().search(r"\n\n", regexp=True)
|
||||
|
||||
of.write("%s\n" % "///////////////////////////////////////////////////////////////////////////////")
|
||||
of.write("%s\n" % f.name())
|
||||
of.write("%s\n" % "<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
|
||||
of.write("%s\n" % ed.get_chars(begin,last[0]))
|
||||
of.write("%s\n" % "<<<<<<<<<<<<<<<<<<<<<<<<<<<<")
|
||||
of.write("%s\n" % getHeader(f))
|
||||
of.write("%s\n" % "///////////////////////////////////////////////////////////////////////////////")
|
||||
def fixFile(f, of):
|
||||
name, ext = splitext(basename(f.name()))
|
||||
ed = GPS.EditorBuffer.get(f)
|
||||
begin = ed.beginning_of_buffer()
|
||||
if (ext not in [".gpr", ".adb", ".ads",
|
||||
".c", ".cpp", ".h", ".hh", ".idl"]):
|
||||
begin = begin.forward_line(1)
|
||||
last = ed.beginning_of_buffer().search(r"\n\n", regexp=True)
|
||||
|
||||
with file("temp.out","w") as of:
|
||||
for i in GPS.Project("zmq.tests").sources():
|
||||
fixFile(i,of)
|
||||
of.write("%s\n" % 80 * "/")
|
||||
of.write("%s\n" % f.name())
|
||||
of.write("%s\n" % 30 * "<")
|
||||
of.write("%s\n" % ed.get_chars(begin, last[0]))
|
||||
of.write("%s\n" % 30 * "<")
|
||||
of.write("%s\n" % getHeader(f))
|
||||
of.write("%s\n" % 80 * "/")
|
||||
|
||||
with file("temp.out", "w") as of:
|
||||
for i in GPS.Project("zmq.tests").sources():
|
||||
fixFile(i, of)
|
||||
|
||||
|
||||
|
||||
|
|
35
rename.py
35
rename.py
|
@ -34,14 +34,11 @@ header = """--------------------------------------------------------------------
|
|||
-- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR --
|
||||
-- OTHER DEALINGS IN THE SOFTWARE. --
|
||||
-------------------------------------------------------------------------------
|
||||
-- begin read only
|
||||
--
|
||||
-- The contents of this file is derived from zmq.h using the
|
||||
-- -fdump-ada-spec switch for gcc.
|
||||
"""
|
||||
|
||||
tail = "-- end read only"
|
||||
|
||||
renames = [["stddef_h.size_t", "size_t"],
|
||||
["with stddef_h;", ""],
|
||||
["with bits_stdint_uintn_h;", ""],
|
||||
|
@ -80,7 +77,7 @@ obslolete_functions = ["zmq_ctx_shutdown",
|
|||
|
||||
def main(path):
|
||||
dumped = False
|
||||
with file(path) as f:
|
||||
with open(path) as f:
|
||||
buffer = f.read()
|
||||
|
||||
for i in renames:
|
||||
|
@ -106,34 +103,34 @@ def main(path):
|
|||
buffer[i] = "%s : constant := %s;" % (m.group(1), m.group(2))
|
||||
|
||||
for obslolete in obslolete_functions:
|
||||
pattern = r'^.*pragma Import *\(C, *(%s), *"%s"\);' % (obslolete, obslolete)
|
||||
pattern = r'^.*pragma Import *\(C, *(%s), *"%s"\);' %\
|
||||
(obslolete, obslolete)
|
||||
if not dumped:
|
||||
print pattern
|
||||
print (pattern)
|
||||
matcher = re.compile(pattern)
|
||||
if matcher.match(buffer[i]):
|
||||
buffer[i] = " pragma Obsolescent;\n%s" % buffer[i]
|
||||
dumped = True
|
||||
|
||||
buffer = "\n".join(buffer)
|
||||
with file(path, "w") as f:
|
||||
with open(path, "w") as f:
|
||||
f.write(header)
|
||||
f.write(buffer)
|
||||
f.write(tail)
|
||||
|
||||
|
||||
matcher = re.compile(r"\w+ (zmq_\w+) .*")
|
||||
with open("zmq-case_exceptions.xml","w") as outf:
|
||||
outf.write("""<?xml version="1.0" ?>
|
||||
if not exists("zmq-case_exceptions.xml"):
|
||||
matcher = re.compile(r"\w+ (zmq_\w+) .*")
|
||||
with open("zmq-case_exceptions.xml", "w") as outf:
|
||||
outf.write("""<?xml version="1.0" ?>
|
||||
<exceptions>
|
||||
<case_exceptions>
|
||||
""")
|
||||
with open(path) as inf:
|
||||
for line in inf:
|
||||
line = line.strip()
|
||||
m = matcher.match(line)
|
||||
if m:
|
||||
outf.write(" <word>%s</word>\n" % m.group(1))
|
||||
outf.write(""" </case_exceptions>
|
||||
with open(path) as inf:
|
||||
for line in inf:
|
||||
line = line.strip()
|
||||
m = matcher.match(line)
|
||||
if m:
|
||||
outf.write(" <word>%s</word>\n" % m.group(1))
|
||||
outf.write(""" </case_exceptions>
|
||||
</exceptions>""")
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue