diff --git a/.gitignore b/.gitignore index 0fe2c40..a429c83 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.pyc build/ +.idea/ +cpp2python.egg-info/ diff --git a/README.md b/README.md index 1006c1b..a1eb00d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,13 @@ astyle --style=ansi your.cpp source.cpp files.cpp cpp2python.py -v|--version|-h|--help Display the help message After the processing new file is created. -File name is {old file name with suffix}.py. i.e. main.cpp.py +File name is `{old file name with suffix}.py`. i.e. `main.cpp.py` + +### Installation +(Optional, the script can be used from the source tree) + + python3 setup.py install + ### Author Andrei Kopats diff --git a/cpp2python.py b/cpp2python.py index e412d4e..c98e98c 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 help = """The script helps to convert C/C++ sources to C/C++ -like Python sources. @@ -285,9 +285,9 @@ def process_file(in_filename, out_filename): """ generator - outputs processed file """ - with open(in_filename, 'r') as file: + with open(in_filename, 'r', encoding='utf-8') as file: lines = file.readlines() # probably would die on sources more than 100 000 lines :D - with open(out_filename, 'w+') as file: + with open(out_filename, 'w+', encoding='utf-8') as file: for line in lines: file.write(process_line(line)) @@ -297,11 +297,11 @@ def main(): '-h' in sys.argv or \ '--version' in sys.argv or \ '-v' in sys.argv: - print help + print(help) sys.exit(0) if len (sys.argv) != 2: - print >> sys.stderr, 'Invalid parameters count. Must be 1' - print help + print('Invalid parameters count. Must be 1', file=sys.stderr) + print(help) sys.exit(-1) if os.path.isdir(sys.argv[1]): for root, dirs, files in os.walk(sys.argv[1]): @@ -313,7 +313,7 @@ def main(): elif os.path.isfile(sys.argv[1]): process_file(sys.argv[1], sys.argv[1] + '.py') else: - print >> sys.stderr, 'Not a file or directory', sys.argv[1] + print('Not a file or directory', sys.argv[1], file=sys.stderr) sys.exit(-1) if __name__ == '__main__': diff --git a/setup.py b/setup.py index 979a5af..42bb132 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from distutils.core import setup +from setuptools import setup import cpp2python setup(