From 9bcbbe75187d3ff96e48aa92bb684286c90a4b34 Mon Sep 17 00:00:00 2001 From: wittrup Date: Mon, 4 Jan 2016 13:09:34 +0100 Subject: [PATCH 1/6] Python 3.5.1 Wrote cpp2python running on Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Included .gitignore for JetBrains PyCharm --- .gitignore | 2 ++ cpp2python.py | 8 ++++---- setup.py | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) 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/cpp2python.py b/cpp2python.py index e412d4e..5888b27 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -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( From 90427f6e11ef2b6369192608109e2d2906229b03 Mon Sep 17 00:00:00 2001 From: Andrei Kopats Date: Tue, 22 Mar 2016 10:41:17 +0300 Subject: [PATCH 2/6] Use python3 --- cpp2python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2python.py b/cpp2python.py index 5888b27..d0e13f1 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. From 3f95fccc120bbf1f74e712869f7681da4dc87c99 Mon Sep 17 00:00:00 2001 From: Andrei Kopats Date: Tue, 22 Mar 2016 10:42:55 +0300 Subject: [PATCH 3/6] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 1006c1b..7e81e94 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,12 @@ astyle --style=ansi your.cpp source.cpp files.cpp cpp2python.py FILE Process the file cpp2python.py -v|--version|-h|--help Display the help message +### Installation +(Optional, the script can be used from the source tree) + + python3 setup.py install + + After the processing new file is created. File name is {old file name with suffix}.py. i.e. main.cpp.py From 73ac8111882da435ba77ba9b48dd7ecf049ebc35 Mon Sep 17 00:00:00 2001 From: Andrei Kopats Date: Tue, 22 Mar 2016 10:43:27 +0300 Subject: [PATCH 4/6] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7e81e94..a1eb00d 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,15 @@ astyle --style=ansi your.cpp source.cpp files.cpp cpp2python.py FILE Process the file 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` + ### Installation (Optional, the script can be used from the source tree) python3 setup.py install -After the processing new file is created. -File name is {old file name with suffix}.py. i.e. main.cpp.py - ### Author Andrei Kopats From 11e039b65545c37a6d4232b38720489b6dbd98c1 Mon Sep 17 00:00:00 2001 From: danerlt <1598552894@qq.com> Date: Thu, 21 Nov 2019 21:51:17 +0800 Subject: [PATCH 5/6] fix open file encode error fix read utf-8 file in windows10 read to gbk encode. --- cpp2python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2python.py b/cpp2python.py index d0e13f1..27d8ccf 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -285,7 +285,7 @@ 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: for line in lines: From 5a5b4fd33d6b61114117ddc2d5554f4001ef0d7c Mon Sep 17 00:00:00 2001 From: danerlt <1598552894@qq.com> Date: Thu, 21 Nov 2019 23:43:08 +0800 Subject: [PATCH 6/6] fix write file encode error fix write file to gbk encode error --- cpp2python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp2python.py b/cpp2python.py index 27d8ccf..c98e98c 100755 --- a/cpp2python.py +++ b/cpp2python.py @@ -287,7 +287,7 @@ def process_file(in_filename, out_filename): """ 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))