diff --git a/.gitignore b/.gitignore index 52e4e61..e52bb44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,55 @@ -*.pyc -*.pyo +*.py[cod] + +# C extensions +*.so + +# Packages +*.egg* +*.egg-info +dist +build +eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +lib +lib64 + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +cover/ +.coverage* +!.coveragerc +.tox +nosetests.xml +.testrepository +.venv + +# Translations +*.mo + +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + +# Complexity +output/*.html +output/*/index.html + +# Sphinx +doc/build + +# pbr generates these +AUTHORS +ChangeLog + +# Editors +*~ +.*.swp +.*sw? diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst new file mode 100644 index 0000000..1819743 --- /dev/null +++ b/CONTRIBUTING.rst @@ -0,0 +1,4 @@ +Bugs should be filed on Github: https://github.com/sileht/bird-lg/issues + +Contribution can be via Github pull requests: https://github.com/sileht/bird-lg/pulls + diff --git a/gpl-3.0.txt b/LICENSE similarity index 100% rename from gpl-3.0.txt rename to LICENSE diff --git a/README.mkd b/README.rst similarity index 88% rename from README.mkd rename to README.rst index b79e46c..f416441 100644 --- a/README.mkd +++ b/README.rst @@ -4,7 +4,7 @@ BIRD-LG This is a looking glass for the Internet Routing Daemon "Bird". -Software is split in two parts: +Software is split in two parts:: - lgproxy.py: @@ -23,11 +23,11 @@ Software is split in two parts: *************** +--> * lgproxy.py * | *************** - | + | ******** ******************* | *************** * USER * ----> * webserver/lg.py *--+--> * lgproxy.py * ******** ******************* | *************** - | + | | *************** +--> * lgproxy.py * *************** @@ -36,9 +36,9 @@ Software is split in two parts: bird-lg depends on : - - python-flask >= 0.8 - - python-dnspython - - python-pydot +* python-flask >= 0.9 +* python-dnspython +* python-pydot Each services can be embedded in any webserver by following regular python-flask configuration. diff --git a/bird_lg/__init__.py b/bird_lg/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bird.py b/bird_lg/bird.py similarity index 100% rename from bird.py rename to bird_lg/bird.py diff --git a/lg.py b/bird_lg/lg.py similarity index 99% rename from lg.py rename to bird_lg/lg.py index 657915d..4f73730 100644 --- a/lg.py +++ b/bird_lg/lg.py @@ -435,11 +435,11 @@ def show_bgpmap(): e = edges[edge_tuple] label_without_star = kwargs["label"].replace("*", "") - labels = e.get_label().split("\r") + labels = e.get_label().split("\r") if "%s*" % label_without_star not in labels: - labels = [ kwargs["label"] ] + [ l for l in labels if not l.startswith(label_without_star) ] + labels = [ kwargs["label"] ] + [ l for l in labels if not l.startswith(label_without_star) ] labels = sorted(labels, cmp=lambda x,y: x.endswith("*") and -1 or 1) - + label = escape("\r".join(labels)) e.set_label(label) return edges[edge_tuple] @@ -453,7 +453,7 @@ def show_bgpmap(): edge = add_edge(as_number, nodes[host]) edge.set_color("red") edge.set_style("bold") - + #colors = [ "#009e23", "#1a6ec1" , "#d05701", "#6f879f", "#939a0e", "#0e9a93", "#9a0e85", "#56d8e1" ] previous_as = None hosts = data.keys() @@ -473,14 +473,14 @@ def show_bgpmap(): if not hop: hop = True if _as not in hosts: - hop_label = _as + hop_label = _as if first: hop_label = hop_label + "*" continue else: hop_label = "" - + add_node(_as, fillcolor=(first and "#F5A9A9" or "white")) if hop_label: edge = add_edge(nodes[previous_as], nodes[_as], label=hop_label, fontsize="7") @@ -547,7 +547,7 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text): # ugly hack for good printing path = [ peer_protocol_name ] # path = ["%s\r%s" % (peer_protocol_name, get_as_name(get_as_number_from_protocol_name(host, proto, peer_protocol_name)))] - + expr2 = re.search(r'(.*)unreachable\s+\[(\w+)\s+', line) if expr2: if path: @@ -560,7 +560,7 @@ def build_as_tree_from_raw_bird_ouput(host, proto, text): if line.startswith("BGP.as_path:"): path.extend(line.replace("BGP.as_path:", "").strip().split(" ")) - + if path: path.append(net_dest) paths.append(path) diff --git a/lgproxy.py b/bird_lg/lgproxy.py similarity index 100% rename from lgproxy.py rename to bird_lg/lgproxy.py diff --git a/static/css/DT_bootstrap.css b/bird_lg/static/css/DT_bootstrap.css similarity index 100% rename from static/css/DT_bootstrap.css rename to bird_lg/static/css/DT_bootstrap.css diff --git a/static/css/bootstrap-responsive.css b/bird_lg/static/css/bootstrap-responsive.css similarity index 100% rename from static/css/bootstrap-responsive.css rename to bird_lg/static/css/bootstrap-responsive.css diff --git a/static/css/bootstrap-responsive.min.css b/bird_lg/static/css/bootstrap-responsive.min.css similarity index 100% rename from static/css/bootstrap-responsive.min.css rename to bird_lg/static/css/bootstrap-responsive.min.css diff --git a/static/css/bootstrap.css b/bird_lg/static/css/bootstrap.css similarity index 100% rename from static/css/bootstrap.css rename to bird_lg/static/css/bootstrap.css diff --git a/static/css/bootstrap.min.css b/bird_lg/static/css/bootstrap.min.css similarity index 100% rename from static/css/bootstrap.min.css rename to bird_lg/static/css/bootstrap.min.css diff --git a/static/css/docs.css b/bird_lg/static/css/docs.css similarity index 100% rename from static/css/docs.css rename to bird_lg/static/css/docs.css diff --git a/static/css/error.txt b/bird_lg/static/css/error.txt similarity index 100% rename from static/css/error.txt rename to bird_lg/static/css/error.txt diff --git a/static/img/glyphicons-halflings-white.png b/bird_lg/static/img/glyphicons-halflings-white.png similarity index 100% rename from static/img/glyphicons-halflings-white.png rename to bird_lg/static/img/glyphicons-halflings-white.png diff --git a/static/img/glyphicons-halflings.png b/bird_lg/static/img/glyphicons-halflings.png similarity index 100% rename from static/img/glyphicons-halflings.png rename to bird_lg/static/img/glyphicons-halflings.png diff --git a/static/img/sort_asc.png b/bird_lg/static/img/sort_asc.png similarity index 100% rename from static/img/sort_asc.png rename to bird_lg/static/img/sort_asc.png diff --git a/static/img/sort_asc_disabled.png b/bird_lg/static/img/sort_asc_disabled.png similarity index 100% rename from static/img/sort_asc_disabled.png rename to bird_lg/static/img/sort_asc_disabled.png diff --git a/static/img/sort_both.png b/bird_lg/static/img/sort_both.png similarity index 100% rename from static/img/sort_both.png rename to bird_lg/static/img/sort_both.png diff --git a/static/img/sort_desc.png b/bird_lg/static/img/sort_desc.png similarity index 100% rename from static/img/sort_desc.png rename to bird_lg/static/img/sort_desc.png diff --git a/static/img/sort_desc_disabled.png b/bird_lg/static/img/sort_desc_disabled.png similarity index 100% rename from static/img/sort_desc_disabled.png rename to bird_lg/static/img/sort_desc_disabled.png diff --git a/static/js/DT_bootstrap.js b/bird_lg/static/js/DT_bootstrap.js similarity index 100% rename from static/js/DT_bootstrap.js rename to bird_lg/static/js/DT_bootstrap.js diff --git a/static/js/bootstrap.js b/bird_lg/static/js/bootstrap.js similarity index 100% rename from static/js/bootstrap.js rename to bird_lg/static/js/bootstrap.js diff --git a/static/js/bootstrap.min.js b/bird_lg/static/js/bootstrap.min.js similarity index 100% rename from static/js/bootstrap.min.js rename to bird_lg/static/js/bootstrap.min.js diff --git a/static/js/jquery.dataTables.js b/bird_lg/static/js/jquery.dataTables.js similarity index 100% rename from static/js/jquery.dataTables.js rename to bird_lg/static/js/jquery.dataTables.js diff --git a/static/js/jquery.js b/bird_lg/static/js/jquery.js similarity index 100% rename from static/js/jquery.js rename to bird_lg/static/js/jquery.js diff --git a/static/js/lg.js b/bird_lg/static/js/lg.js similarity index 100% rename from static/js/lg.js rename to bird_lg/static/js/lg.js diff --git a/templates/bgpmap.html b/bird_lg/templates/bgpmap.html similarity index 100% rename from templates/bgpmap.html rename to bird_lg/templates/bgpmap.html diff --git a/templates/detail.html b/bird_lg/templates/detail.html similarity index 100% rename from templates/detail.html rename to bird_lg/templates/detail.html diff --git a/templates/error.html b/bird_lg/templates/error.html similarity index 100% rename from templates/error.html rename to bird_lg/templates/error.html diff --git a/templates/index.html b/bird_lg/templates/index.html similarity index 100% rename from templates/index.html rename to bird_lg/templates/index.html diff --git a/templates/layout.html b/bird_lg/templates/layout.html similarity index 100% rename from templates/layout.html rename to bird_lg/templates/layout.html diff --git a/templates/route.html b/bird_lg/templates/route.html similarity index 100% rename from templates/route.html rename to bird_lg/templates/route.html diff --git a/templates/summary.html b/bird_lg/templates/summary.html similarity index 100% rename from templates/summary.html rename to bird_lg/templates/summary.html diff --git a/templates/traceroute.html b/bird_lg/templates/traceroute.html similarity index 100% rename from templates/traceroute.html rename to bird_lg/templates/traceroute.html diff --git a/toolbox.py b/bird_lg/toolbox.py similarity index 100% rename from toolbox.py rename to bird_lg/toolbox.py diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100755 index 0000000..66110e5 --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +import os +import sys + +sys.path.insert(0, os.path.abspath('../..')) +# -- General configuration ---------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + 'sphinx.ext.autodoc', +] + +# autodoc generation is a bit aggressive and a nuisance when doing heavy +# text edit cycles. +# execute "export SPHINX_DEBUG=1" in your terminal to disable + +# The suffix of source filenames. +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'bird-lg' +copyright = u'2016, Mehdi Abaakouk' + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = True + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# -- Options for HTML output -------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +# html_theme_path = ["."] +# html_theme = '_theme' +# html_static_path = ['static'] + +# Output file base name for HTML help builder. +htmlhelp_basename = '%sdoc' % project + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', + '%s.tex' % project, + u'%s Documentation' % project, + u'Mehdi Abaakouk', 'manual'), +] + + +# Example configuration for intersphinx: refer to the Python standard library. +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/contributing.rst b/doc/source/contributing.rst new file mode 100644 index 0000000..1728a61 --- /dev/null +++ b/doc/source/contributing.rst @@ -0,0 +1,4 @@ +============ +Contributing +============ +.. include:: ../../CONTRIBUTING.rst diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..33727f7 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1,24 @@ +.. cotyledon documentation master file, created by + sphinx-quickstart on Tue Jul 9 22:26:36 2013. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to cotyledon's documentation! +======================================================== + +Contents: + +.. toctree:: + :maxdepth: 2 + + readme + installation + contributing + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/doc/source/installation.rst b/doc/source/installation.rst new file mode 100644 index 0000000..6808e9a --- /dev/null +++ b/doc/source/installation.rst @@ -0,0 +1,12 @@ +============ +Installation +============ + +At the command line:: + + $ pip install bird-lg + +Or, if you have virtualenvwrapper installed:: + + $ mkvirtualenv bird-lg + $ pip install bird-lg diff --git a/doc/source/readme.rst b/doc/source/readme.rst new file mode 100644 index 0000000..a6210d3 --- /dev/null +++ b/doc/source/readme.rst @@ -0,0 +1 @@ +.. include:: ../../README.rst diff --git a/lg.cfg b/etc/bird-lg/lg.cfg similarity index 100% rename from lg.cfg rename to etc/bird-lg/lg.cfg diff --git a/lgproxy.cfg b/etc/bird-lg/lgproxy.cfg similarity index 100% rename from lgproxy.cfg rename to etc/bird-lg/lgproxy.cfg diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3c254f0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pbr +flask>=0.8 +dnspython +pydot diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..85f3ba6 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,59 @@ +[metadata] +name = bird-lg +url = https://github.com/sileht/bird-lg +summary = bird looking glass +description-file = + README.rst +author = Mehdi Abaakouk +author-email = sileht@sileht.net +home-page = https://github.com/sileht/bird-lg +classifier = + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Operating System :: POSIX :: Linux + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3.5 + Topic :: System :: Monitoring + +[extras] +test = + gabbi>=1.21.0 + wsgi_intercept>=1.4.1 + hacking<0.11,>=0.10.0 + coverage>=3.6 + fixtures + mock + oslotest + python-subunit>=0.0.18 + os-testr + testrepository + testtools>=0.9.38 + sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 + oslosphinx>=2.5.0 # Apache-2.0 + +[global] +setup-hooks = + pbr.hooks.setup_hook + +[files] +packages = + bird_lg +data_files = + etc/bird-lg = etc/bird-lg/* + +[entry_points] +wsgi_scripts = + bird-lg-api = bird_lg.lg:app + bird-lg-proxy-api = bird_lg.lg_proxy:app + + +[build_sphinx] +all_files = 1 +build-dir = doc/build +source-dir = doc/source + +[wheel] +universal = 1 diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..c67e9f0 --- /dev/null +++ b/setup.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +import setuptools + +setuptools.setup(setup_requires=['pbr'], pbr=True) diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh new file mode 100755 index 0000000..799ac18 --- /dev/null +++ b/tools/pretty_tox.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -o pipefail + +TESTRARGS=$1 + +# --until-failure is not compatible with --subunit see: +# +# https://bugs.launchpad.net/testrepository/+bug/1411804 +# +# this work around exists until that is addressed +if [[ "$TESTARGS" =~ "until-failure" ]]; then + python setup.py testr --slowest --testr-args="$TESTRARGS" +else + python setup.py testr --slowest --testr-args="--subunit $TESTRARGS" | subunit-trace -f +fi diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..d9fa67c --- /dev/null +++ b/tox.ini @@ -0,0 +1,34 @@ +[tox] +minversion = 2.0 +skipsdist = True + +[testenv] +usedevelop = True +install_command = pip install -U {opts} {packages} +setenv = + VIRTUAL_ENV={envdir} +deps = .[test] +commands = {toxinidir}/tools/pretty_tox.sh + +[testenv:pep8] +deps = + flake8 + doc8 +commands = + doc8 --ignore-path doc/source/rest.rst doc/source + flake8 {posargs} + +[testenv:venv] +commands = {posargs} + +[testenv:cover] +commands = python setup.py test --coverage --testr-args='{posargs}' + +[testenv:docs] +commands = python setup.py build_sphinx + +[flake8] +show-source = True +builtins = _ +ignores = H103 +exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build