Skip to content

Commit

Permalink
simple py3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdunn2001 committed Nov 20, 2014
1 parent 9aa6144 commit bd1e895
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 103 deletions.
14 changes: 7 additions & 7 deletions amalgamate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def amalgamate_source( source_top_dir=None,
target_source_path: output .cpp path
header_include_path: generated header path relative to target_source_path.
"""
print ("Amalgating header...")
print("Amalgating header...")
header = AmalgamationFile( source_top_dir )
header.add_text( "/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/)." )
header.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
Expand All @@ -77,12 +77,12 @@ def amalgamate_source( source_top_dir=None,
header.add_text( "#endif //ifndef JSON_AMALGATED_H_INCLUDED" )

target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )
print ("Writing amalgated header to %r" % target_header_path)
print("Writing amalgated header to %r" % target_header_path)
header.write_to( target_header_path )

base, ext = os.path.splitext( header_include_path )
forward_header_include_path = base + "-forwards" + ext
print ("Amalgating forward header...")
print("Amalgating forward header...")
header = AmalgamationFile( source_top_dir )
header.add_text( "/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/)." )
header.add_text( "/// It is intented to be used with #include <%s>" % forward_header_include_path )
Expand All @@ -99,10 +99,10 @@ def amalgamate_source( source_top_dir=None,

target_forward_header_path = os.path.join( os.path.dirname(target_source_path),
forward_header_include_path )
print ("Writing amalgated forward header to %r" % target_forward_header_path)
print("Writing amalgated forward header to %r" % target_forward_header_path)
header.write_to( target_forward_header_path )

print ("Amalgating source...")
print("Amalgating source...")
source = AmalgamationFile( source_top_dir )
source.add_text( "/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/)." )
source.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
Expand All @@ -118,7 +118,7 @@ def amalgamate_source( source_top_dir=None,
source.add_file( os.path.join(lib_json, "json_value.cpp") )
source.add_file( os.path.join(lib_json, "json_writer.cpp") )

print ("Writing amalgated source to %r" % target_source_path)
print("Writing amalgated source to %r" % target_source_path)
source.write_to( target_source_path )

def main():
Expand All @@ -144,7 +144,7 @@ def main():
sys.stderr.write( msg + "\n" )
sys.exit( 1 )
else:
print ("Source succesfully amalagated")
print("Source succesfully amalagated")

if __name__ == "__main__":
main()
11 changes: 6 additions & 5 deletions devtools/antglob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# encoding: utf-8
# Baptiste Lepilleur, 2009

from __future__ import print_function
from dircache import listdir
import re
import fnmatch
Expand Down Expand Up @@ -190,12 +191,12 @@ def local_path( paths ):
test_cases.append( (ant_pattern, local_path(accepted_matches), local_path( rejected_matches )) )
for ant_pattern, accepted_matches, rejected_matches in test_cases:
rex = ant_pattern_to_re( ant_pattern )
print 'ant_pattern:', ant_pattern, ' => ', rex.pattern
print('ant_pattern:', ant_pattern, ' => ', rex.pattern)
for accepted_match in accepted_matches:
print 'Accepted?:', accepted_match
self.assert_( rex.match( accepted_match ) is not None )
print('Accepted?:', accepted_match)
self.assertTrue( rex.match( accepted_match ) is not None )
for rejected_match in rejected_matches:
print 'Rejected?:', rejected_match
self.assert_( rex.match( rejected_match ) is None )
print('Rejected?:', rejected_match)
self.assertTrue( rex.match( rejected_match ) is None )

unittest.main()
7 changes: 4 additions & 3 deletions devtools/fixeol.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import os.path

def fix_source_eol( path, is_dry_run = True, verbose = True, eol = '\n' ):
Expand All @@ -7,23 +8,23 @@ def fix_source_eol( path, is_dry_run = True, verbose = True, eol = '\n' ):
try:
f = open(path, 'rb')
except IOError as msg:
print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
print("%s: I/O Error: %s" % (file, str(msg)), file=sys.stderr)
return False
try:
raw_lines = f.readlines()
finally:
f.close()
fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines]
if raw_lines != fixed_lines:
print '%s =>' % path,
print('%s =>' % path, end=' ')
if not is_dry_run:
f = open(path, "wb")
try:
f.writelines(fixed_lines)
finally:
f.close()
if verbose:
print is_dry_run and ' NEED FIX' or ' FIXED'
print(is_dry_run and ' NEED FIX' or ' FIXED')
return True
##
##
Expand Down
9 changes: 5 additions & 4 deletions devtools/licenseupdater.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Updates the license text in source file.
"""
from __future__ import print_function

# An existing license is found if the file starts with the string below,
# and ends with the first blank line.
Expand Down Expand Up @@ -34,11 +35,11 @@ def update_license( path, dry_run, show_diff ):
if not dry_run:
with open( path, 'wb' ) as fout:
fout.write( new_text.replace('\n', newline ) )
print 'Updated', path
print('Updated', path)
if show_diff:
import difflib
print '\n'.join( difflib.unified_diff( original_text.split('\n'),
new_text.split('\n') ) )
print('\n'.join( difflib.unified_diff( original_text.split('\n'),
new_text.split('\n') ) ))
return True
return False

Expand Down Expand Up @@ -83,7 +84,7 @@ def main():
parser.enable_interspersed_args()
options, args = parser.parse_args()
update_license_in_source_directories( args, options.dry_run, options.show_diff )
print 'Done'
print('Done')

if __name__ == '__main__':
import sys
Expand Down
28 changes: 14 additions & 14 deletions doxybuild.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Script to generate doxygen documentation.
"""

from __future__ import print_function
from devtools import tarball
import re
import os
import os.path
import sys
import shutil
from devtools import tarball

def find_program(*filenames):
"""find a program in folders path_lst, and sets env[var]
Expand All @@ -33,17 +33,17 @@ def do_subst_in_file(targetfile, sourcefile, dict):
contents = f.read()
f.close()
except:
print "Can't read source file %s"%sourcefile
print("Can't read source file %s"%sourcefile)
raise
for (k,v) in dict.items():
for (k,v) in list(dict.items()):
v = v.replace('\\','\\\\')
contents = re.sub(k, v, contents)
try:
f = open(targetfile, 'wb')
f.write(contents)
f.close()
except:
print "Can't write target file %s"%targetfile
print("Can't write target file %s"%targetfile)
raise

def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
Expand All @@ -53,12 +53,12 @@ def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
try:
os.chdir( working_dir )
cmd = [doxygen_path, config_file]
print 'Running:', ' '.join( cmd )
print('Running:', ' '.join( cmd ))
try:
import subprocess
except:
if os.system( ' '.join( cmd ) ) != 0:
print 'Documentation generation failed'
print('Documentation generation failed')
return False
else:
if is_silent:
Expand All @@ -67,8 +67,8 @@ def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
process = subprocess.Popen( cmd )
stdout, _ = process.communicate()
if process.returncode:
print 'Documentation generation failed:'
print stdout
print('Documentation generation failed:')
print(stdout)
return False
return True
finally:
Expand Down Expand Up @@ -107,23 +107,23 @@ def yesno( bool ):
}

if os.path.isdir( output_dir ):
print 'Deleting directory:', output_dir
print('Deleting directory:', output_dir)
shutil.rmtree( output_dir )
if not os.path.isdir( output_dir ):
os.makedirs( output_dir )

do_subst_in_file( 'doc/doxyfile', 'doc/doxyfile.in', subst_keys )
ok = run_doxygen( options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent )
if not options.silent:
print open(warning_log_path, 'rb').read()
print(open(warning_log_path, 'rb').read())
index_path = os.path.abspath(os.path.join('doc', subst_keys['%HTML_OUTPUT%'], 'index.html'))
print 'Generated documentation can be found in:'
print index_path
print('Generated documentation can be found in:')
print(index_path)
if options.open:
import webbrowser
webbrowser.open( 'file://' + index_path )
if options.make_tarball:
print 'Generating doc tarball to', tarball_path
print('Generating doc tarball to', tarball_path)
tarball_sources = [
output_dir,
'README.txt',
Expand Down
Loading

0 comments on commit bd1e895

Please sign in to comment.