From d3b9d9be837ae04a11a4b4a2632fe255a1ad4c5b Mon Sep 17 00:00:00 2001 From: "Srivats P." Date: Sat, 7 Jun 2014 20:12:51 +0530 Subject: [PATCH] Updated python packaging --- binding/README.txt | 7 +++++++ binding/__init__.py | 9 +++++++++ binding/setup.py | 40 ++++++++++++++++++++++++++++++++++------ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/binding/README.txt b/binding/README.txt index e69de29..e709125 100644 --- a/binding/README.txt +++ b/binding/README.txt @@ -0,0 +1,7 @@ +======== +Ostinato +======== + +Ostinato provides a scripting interface to the Ostinato Packet/Traffic Generator and Analyzer + +Documentation is available in the wiki at http://ostinato.org diff --git a/binding/__init__.py b/binding/__init__.py index 161ae68..8d68b2f 100644 --- a/binding/__init__.py +++ b/binding/__init__.py @@ -15,3 +15,12 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see +import json +from os.path import dirname + +with open(dirname(__file__) + '/pkg_info.json') as f: + _info = json.load(f) + +__version__ = _info['version'] +__revision__ = _info['revision'] + diff --git a/binding/setup.py b/binding/setup.py index a36face..e09bcc4 100644 --- a/binding/setup.py +++ b/binding/setup.py @@ -15,28 +15,56 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see +import json import os +import re import shutil import sys from setuptools import setup def read(fname): - return open(os.path.join(os.path.dirname(__file__), fname)).read() + return open(fname).read() -if sys.argv[1] == 'clean_sdist': +def get_pkg_info(): + info = {} + t = open('../server/version.cpp').read() + info['version'] = re.search('version = "([^"]*)"', t).group(1) + info['revision'] = re.search('revision = "([^"]*)"', t).group(1) + return info + +# ------- script starts from here ------- # + +if len(sys.argv) >= 2 and sys.argv[1] == 'clean_sdist': shutil.rmtree('dist', ignore_errors = True) shutil.rmtree('ostinato.egg-info', ignore_errors = True) + if os.path.exists('pkg_info.json'): + os.remove('pkg_info.json') sys.exit(0) +if len(sys.argv) >= 2 and sys.argv[1] == 'sdist': + if os.path.split(os.getcwd())[1] != 'binding': + print 'This script needs to be run from the binding directory' + print 'Current Working Directory is %s' % os.getcwd() + sys.exit(1) + + pkg_info = get_pkg_info() + with open('pkg_info.json', 'wt') as f: + json.dump(pkg_info, f, indent=4) +else: + with open('pkg_info.json') as f: + pkg_info = json.load(f) + setup(name = 'ostinato', - version = 'FIXME', + version = pkg_info['version'], author = 'Srivats P', author_email = 'pstavirs@gmail.com', license = "GPLv3+", url = 'http://ostinato.org', description = 'Ostinato is a network packet and traffic generator and analyzer. It aims to be "Wireshark in Reverse" and become complementary to Wireshark. It features custom packet crafting via a GUI or a script', long_description = read('README.txt'), - install_requires = ['google.protobuf>=2.3'], - packages=['ostinato', 'ostinato.protocols'], - package_dir={'ostinato': ''} + install_requires = ['protobuf>=2.3.0'], + packages = ['ostinato', 'ostinato.protocols'], + package_dir = {'ostinato': '.'}, + package_data = {'ostinato': ['pkg_info.json']}, ) +