Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions 24 cpp2python.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,18 @@ def process_line(line):

return line

def process_file(filename):
with open(filename, 'rw+') as file:
def process_file(in_filename, out_filename):
"""
generator - outputs processed file
"""
with open(in_filename, 'r') as file:
lines = file.readlines() # probably would die on sources more than 100 000 lines :D
file.seek(0)
file.truncate(0)
with open(out_filename, 'w+') as file:
for line in lines:
file.write(process_line(line))


if __name__ == '__main__':
def main():
if '--help' in sys.argv or \
'-h' in sys.argv or \
'--version' in sys.argv or \
Expand All @@ -292,11 +294,15 @@ def process_file(filename):
if os.path.isdir(sys.argv[1]):
for root, dirs, files in os.walk(sys.argv[1]):
for file in files:
filename = root + '/' + file
if is_source(filename):
process_file(filename)
in_filename = root + '/' + file
if is_source(in_filename):
out_filename = in_filename + '.py' # not ideal
process_file(in_filename, out_filename)
elif os.path.isfile(sys.argv[1]):
process_file(sys.argv[1])
process_file(sys.argv[1], sys.argv[1] + '.py')
else:
print >> sys.stderr, 'Not a file or directory', sys.argv[1]
sys.exit(-1)

if __name__ == '__main__':
main()
107 changes: 107 additions & 0 deletions 107 setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import os
import subprocess
import sys
import pkg_resources

import subprocess
import sys

from glob import glob
from os.path import abspath, basename, dirname, join, normpath, relpath
from shutil import rmtree
from textwrap import dedent

from setuptools import setup
from setuptools import Command

here = normpath(abspath(dirname(__file__)))

class CleanCommand(Command):
"""Custom clean command to tidy up the project root."""
CLEAN_FILES = './build ./dist ./*.pyc ./*.tgz ./*.egg-info ./__pycache__'.split(' ')

user_options = []

def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
global here

for path_spec in self.CLEAN_FILES:
# Make paths absolute and relative to this path
abs_paths = glob(normpath(join(here, path_spec)))
for path in [str(p) for p in abs_paths]:
if not path.startswith(here):
# Die if path in CLEAN_FILES is absolute + outside this directory
raise ValueError("%s is not a path inside %s" % (path, here))
print('removing %s' % relpath(path))
try:
rmtree(path)
except:
pass

long_description=dedent("""
cpp2python

Script helps to convert C/C++ sources to C/C++ -like Python sources.

It does few simple edit operations, like removing semicolons and type declarations. After it you must edit code manually, but you'll spend less time to do it.

Utility will make mistaces and will not generate ready for use code, so, it won't help you, unless if you know either C/C++ and Python

For better result, it is recomented to format your code to ANSI style before doing conversion.

NO ANY BACKUPS ARE CREATED. YOU MAY PERMANENTLY CORRUPT YOR SOURCES

Usage:

cpp2python.py DIR|FILE
cpp2python.py -v|--version|-h|--help

When directory name is given - tries to find source files by C/C++ suffixes, when file name is given - processes given file

Author: Andrei Kopats hlamer@tut.by License: GPL
""")

setup(
cmdclass={
'clean': CleanCommand,
},

name='cpp2python',
version='0.1.0',

description='Helps to convert C/C++ sources to C/C++ -like Python sources.',
long_description=long_description,
url='https://github.com/hlamer/cpp2python',
author='Andrei Kopats',
author_email='hlamer@tut.by',
license='GPL',
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 3 - Alpha',

# Indicate who your project is intended for
'Intended Audience :: Developers',
'Topic :: Software Development',

# Pick your license as you wish (should match "license" above)
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',

'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
],
keywords='cpp python',

entry_points = {
'console_scripts': [
'cpp2python = cpp2python:main'
]
},
)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.