Skip to content

Commit

Permalink
Merge pull request #5 from jbarlow-mcafee/python_3
Browse files Browse the repository at this point in the history
Python 3 support
  • Loading branch information
chrissmith-mcafee authored May 8, 2018
2 parents 1d889d5 + e5b2831 commit b11afaf
Show file tree
Hide file tree
Showing 35 changed files with 1,300 additions and 56 deletions.
559 changes: 559 additions & 0 deletions .pylintrc

Large diffs are not rendered by default.

553 changes: 553 additions & 0 deletions .pylintrc.samples

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ services:

python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"

before_install:
- docker pull opendxl/opendxl-broker
Expand All @@ -15,15 +18,15 @@ before_install:

# command to install dependencies
install:
- pip install dxlclient
- pip install .
- pip install .[test]
# Install through setup.py should be redundant because of the preceding pip
# install. Just doing this to try to catch any high-level errors.
- python setup.py install

before_script:
- python -m dxlclient provisionconfig dxlclient/test 127.0.0.1 client -u admin -p password
- cp dxlclient/test/dxlclient.config dxlclient/test/client_config.cfg
- sed -i -e "s/external/unique_broker_id_1/g" -e "/local/d" dxlclient/test/client_config.cfg
- cat dxlclient/test/client_config.cfg
- python -m dxlclient provisionconfig sample 127.0.0.1 client -u admin -p password
- cat sample/dxlclient.config

# command to run tests
script:
- python setup.py install
- python setup.py ci
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For bugs, questions and discussions please use the
LICENSE
-------

Copyright 2017 McAfee LLC
Copyright 2018 McAfee LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ For bugs, questions and discussions please use the

## LICENSE

Copyright 2017 McAfee, Inc.
Copyright 2018 McAfee, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
Expand Down
30 changes: 19 additions & 11 deletions clean.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
from __future__ import absolute_import
from __future__ import print_function
import os
# pylint: disable=no-name-in-module, import-error
from distutils.dir_util import remove_tree
from shutil import copyfile


def clean_dir(directory):
def clean_dir(src_dir, directory):
if os.path.exists(directory):
print("Cleaning directory: " + directory + "\n")
for f in os.listdir(directory):
if not os.path.isdir(os.path.join(directory, f)) \
and not f.lower().endswith(".dist") and not f.lower().endswith(".py"):
target_file = os.path.join(directory, f)
if not os.path.isdir(target_file) and not f.lower().endswith(".py"):
os.remove(os.path.join(directory, f))
for f in os.listdir(directory):
if not os.path.isdir(f) and f.lower().endswith(".dist"):
copyfile(os.path.join(directory, f), os.path.join(directory, f[:-5]))

for f in os.listdir(src_dir):
src_file = os.path.join(src_dir, f)
if not os.path.isdir(src_file) and \
not(f.lower().endswith(".py") or f.lower().endswith(".pyc")):
copyfile(src_file, os.path.join(directory, f))

print("Starting clean.\n")

DIST_PY_FILE_LOCATION = os.path.dirname(os.path.realpath(__file__))
DIST_DIRECTORY = os.path.join(DIST_PY_FILE_LOCATION, "dist")
CONFIG_DIRECTORY = os.path.join(DIST_PY_FILE_LOCATION, "config")
SAMPLE_DIRECTORY = os.path.join(DIST_PY_FILE_LOCATION, "sample")
CONFIG_SRC_DIRECTORY = os.path.join(DIST_PY_FILE_LOCATION, "dxlciscopxgridclient",
"_config", "app")
SAMPLE_SRC_DIRECTORY = os.path.join(DIST_PY_FILE_LOCATION, "dxlciscopxgridclient",
"_config", "sample")

# Remove the dist directory if it exists
if os.path.exists(DIST_DIRECTORY):
print("Removing dist directory: " + DIST_DIRECTORY + "\n")
remove_tree(DIST_DIRECTORY, verbose=1)

# Clean the config directory
clean_dir(CONFIG_DIRECTORY)
clean_dir(CONFIG_SRC_DIRECTORY, CONFIG_DIRECTORY)

# Clean the samples directory
clean_dir(SAMPLE_DIRECTORY)
clean_dir(SAMPLE_SRC_DIRECTORY, SAMPLE_DIRECTORY)

# Clean .pyc files
print("Cleaning .pyc files")
for root, dirs, files in os.walk(DIST_PY_FILE_LOCATION):
for file in files:
full_path = os.path.join(root, file)
for source_file in files:
full_path = os.path.join(root, source_file)
if full_path.lower().endswith(".pyc"):
os.remove(full_path)
50 changes: 31 additions & 19 deletions dist.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import subprocess
from tempfile import mkstemp
from shutil import move

# pylint: disable=no-name-in-module, import-error
from distutils.dir_util import copy_tree, remove_tree
from distutils.file_util import copy_file, move_file
from distutils.core import run_setup
from distutils.archive_util import make_archive


# Run clean
import clean


def remove_dist_files(directory):
for f in os.listdir(directory):
if f.lower().endswith(".dist"):
os.remove(os.path.join(directory, f))
import clean # pylint: disable=unused-import

def replace(file_path, pattern, subst):
# Create temp file
fh, abs_path = mkstemp()
with open(abs_path, 'w') as new_file:
with open(file_path) as old_file:
for line in old_file:
new_file.write(line.replace(pattern, subst))
os.close(fh)
# Remove original file
os.remove(file_path)
# Move new file
move(abs_path, file_path)

print("Starting dist.\n")

Expand Down Expand Up @@ -44,12 +57,19 @@ def remove_dist_files(directory):
"--output-dir=" + DIST_DOCTMP_DIR,
os.path.join(DIST_PY_FILE_LOCATION, "dxlciscopxgridclient")])

print("\nCopying conf.py and sdk directory\n")
copy_file(os.path.join(DIST_PY_FILE_LOCATION, "doc", "conf.py"), os.path.join(DIST_DOCTMP_DIR, "conf.py"))
print("\nCopying conf.py, docutils.conf, and sdk directory\n")
copy_file(os.path.join(DIST_PY_FILE_LOCATION, "doc", "conf.py"),
os.path.join(DIST_DOCTMP_DIR, "conf.py"))
copy_file(os.path.join(DIST_PY_FILE_LOCATION, "doc", "docutils.conf"),
os.path.join(DIST_DOCTMP_DIR, "docutils.conf"))
copy_tree(os.path.join(DIST_PY_FILE_LOCATION, "doc", "sdk"), DIST_DOCTMP_DIR)

print("\nCalling sphinx-build\n")
subprocess.check_call(["sphinx-build", "-b", "html", DIST_DOCTMP_DIR, os.path.join(DIST_DIRECTORY, "doc")])
subprocess.check_call(["sphinx-build", "-b", "html", DIST_DOCTMP_DIR,
os.path.join(DIST_DIRECTORY, "doc")])

replace(os.path.join(DIST_DIRECTORY, "doc", "_static", "classic.css"),
"text-align: justify", "text-align: none")

# Delete .doctrees
remove_tree(os.path.join(os.path.join(DIST_DIRECTORY, "doc"), ".doctrees"), verbose=1)
Expand All @@ -70,23 +90,15 @@ def remove_dist_files(directory):
"--dist-dir",
DIST_LIB_DIRECTORY])

print("\nRunning setup.py bdist_egg\n")
run_setup(SETUP_PY,
["bdist_egg",
"--dist-dir",
DIST_LIB_DIRECTORY])

print("\nRunning setup.py bdist_wheel\n")
run_setup(SETUP_PY,
["bdist_wheel",
"--dist-dir",
DIST_LIB_DIRECTORY,
"--python-tag",
"py2.7"])
"--universal"])

print("\nCopying sample into dist directory\n")
copy_tree(os.path.join(DIST_PY_FILE_LOCATION, "sample"), SAMPLE_RELEASE_DIR)
remove_dist_files(SAMPLE_RELEASE_DIR)

print("\nCopying dist to " + DIST_RELEASE_DIR + "\n")
copy_tree(DIST_DIRECTORY, DIST_RELEASE_DIR)
Expand Down
4 changes: 3 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#

from __future__ import absolute_import
import sys
import os

Expand Down Expand Up @@ -30,7 +31,7 @@

# General information about the project.
project = "Cisco pxGrid DXL Client Library"
copyright = "2017 McAfee LLC"
copyright = "2018 McAfee LLC"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -62,3 +63,4 @@

modindex_common_prefix = ['dxlciscopxgridclient.']

html_use_smartypants = False
2 changes: 2 additions & 0 deletions doc/docutils.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[parsers]
smart_quotes = False
4 changes: 2 additions & 2 deletions doc/sdk/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>Cisco pxGrid DXL Client Library</h1>
This distribution contains following directories:
<ul>
<li><b>doc</b><ul><li>Cisco pxGrid DXL Client Library documentation</li></ul></li>
<li><b>lib</b><ul><li>Cisco pxGrid DXL Client Library libraries (.zip, .egg, .whl)</li></ul></li>
<li><b>lib</b><ul><li>Cisco pxGrid DXL Client Library libraries (.zip, .whl)</li></ul></li>
<li><b>sample</b><ul><li>Samples that demonstrate using the Cisco pxGrid DXL Client Library</li></ul></li>
</ul>
</p>
Expand All @@ -28,7 +28,7 @@ <h1>Cisco pxGrid DXL Client Library</h1>
<div class="clearer"></div>
</div>
<div class="footer">
&copy; Copyright 2017 McAfee LLC
&copy; Copyright 2018 McAfee LLC
</div>
</div>
</body>
5 changes: 4 additions & 1 deletion doc/sdk/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ Prerequisites
* The DXL fabric to which the client will connect has been bridged to Cisco
pxGrid.

* Python 2.7.9 or higher in the Python 2.x series or Python 3.4.0 or higher
in the Python 3.x series installed within a Windows or Linux environment.

Installation
************

Use ``pip`` to automatically install the library:

.. parsed-literal::
pip install dxlciscopxgridclient-\ |version|\-py2.7-none-any.whl
pip install dxlciscopxgridclient-\ |version|\-py2.py3-none-any.whl
Or with:

Expand Down
Empty file.
Empty file.
File renamed without changes.
2 changes: 1 addition & 1 deletion dxlciscopxgridclient/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.2"
__version__ = "0.2.0"
1 change: 1 addition & 0 deletions dxlciscopxgridclient/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from dxlbootstrap.util import MessageUtils
from dxlclient.callbacks import EventCallback

Expand Down
1 change: 1 addition & 0 deletions dxlciscopxgridclient/client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from dxlclient.message import Request
from dxlbootstrap.util import MessageUtils
from dxlbootstrap.client import Client
Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_apply_endpoint_policy_by_ip_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_clear_endpoint_policy_by_ip_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_create_policy_notification_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_delete_policy_notification_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_get_endpoint_by_ip_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_get_endpoint_by_mac_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_retrieve_all_policies_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_retrieve_policy_by_name_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_anc_update_policy_notification_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys

Expand Down
2 changes: 2 additions & 0 deletions sample/basic/basic_identity_session_notification_example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
import os
import sys
import time
Expand Down
1 change: 1 addition & 0 deletions sample/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
in addition to setting up the logger appropriately.
"""

from __future__ import absolute_import
import os
import logging

Expand Down
Loading

0 comments on commit b11afaf

Please sign in to comment.