Skip to content

Commit

Permalink
Merge branch 'release-v1.6.0' into master2
Browse files Browse the repository at this point in the history
  • Loading branch information
jathanism committed Mar 8, 2017
2 parents 9f4136d + 421f3a9 commit 7e023d6
Show file tree
Hide file tree
Showing 53 changed files with 2,280 additions and 930 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "2.6"
- "2.7"

install:
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Supported Platforms

Refer to the `official docs`_ for the full list.

.. _official docs: http://trigger.readthedocs.org/en/latest/#supported-platforms
.. _official docs: http://trigger.readthedocs.io/en/latest/#supported-platforms

Key Features
============
Expand Down Expand Up @@ -67,8 +67,8 @@ Getting Started
===============

The best way to get started is to read the documentation hosted by `Read the
Docs <http://readthedocs.org>`_ at `http://trigger.readthedocs.org
<http://trigger.readthedocs.org>`_. There you will find everything you need to
Docs <http://readthedocs.org>`_ at `http://trigger.readthedocs.io
<http://trigger.readthedocs.io>`_. There you will find everything you need to
get going including usage examples, installation and configuration
instructions, and more!

Expand All @@ -91,7 +91,7 @@ Get in touch!
-------------

If you run into any snags, have questions, feedback, or just want to talk shop:
`contact us <http://trigger.readthedocs.org/en/latest/#getting-help>`_!
`contact us <http://trigger.readthedocs.io/en/latest/#getting-help>`_!

**Pro tip**: Find us on IRC at ``#trigger`` on Freenode
(`irc://irc.freenode.net/trigger <irc://irc.freenode.net/trigger>`_).
4 changes: 3 additions & 1 deletion bin/check_access
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ from trigger.acl.tools import check_access, create_trigger_term

optp = optparse.OptionParser(description='''\
Determine whether access is permitted by a given ACL. Exits 0 if permitted,
1 if edits are needed. Lists the terms that apply and what edits are needed.''',
1 if edits are needed. Lists the terms that apply and what edits are needed.
Note that in order for the suggested edits feature to work, your policy must
end with an explicit deny.''',
usage='%prog [opts] file source dest [protocol [port]]')
optp.add_option('-q', '--quiet', action='store_true', help='suppress output')
(opts, args) = optp.parse_args()
Expand Down
10 changes: 8 additions & 2 deletions bin/check_syntax
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ def main():
opts, args = parse_args(sys.argv)

for file in args[1:]:
fd = open(file, 'r')
file_contents = fd.read()
if not os.path.exists(file):
print 'Moving on. File does not exist: {}'.format(file)
continue
if not os.path.isfile(file):
print 'Moving on. Not a normal file: {}'.format(file)
continue
# Calling `read()` on the fd immediately closes it
file_contents = open(file, 'r').read()

try:
acl_parse(file_contents)
Expand Down
102 changes: 16 additions & 86 deletions bin/gnng
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import os
import re
from sqlite3 import dbapi2 as sqlite
import sys
import prettytable
from twisted.python import log
from trigger.cmds import NetACLInfo
from trigger.netdevices import device_match, NetDevices
Expand All @@ -39,8 +40,8 @@ settings.WITH_ACLS = False
# Constants
DEBUG = os.getenv('DEBUG')
MAX_CONNS = 10
ROW_LABELS = ('Interface', 'Addresses', 'Subnets', 'ACLs IN', 'ACLs OUT',
'Description')
ROW_LABELS = ['Interface', 'Addresses', 'Subnets', 'ACLs IN', 'ACLs OUT',
'Description']

# Namedtuples
RowData = namedtuple('RowData', 'all_rows subnet_table')
Expand Down Expand Up @@ -119,83 +120,6 @@ def pass_filters(device):

return True

def indent(rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
separateRows=False, prefix='', postfix='', wrapfunc=lambda x:x, wraplast=True):
"""Indents a table by column.
- rows: A sequence of sequences of items, one sequence per row.
- hasHeader: True if the first row consists of the columns' names.
- headerChar: Character to be used for the row separator line
(if hasHeader==True or separateRows==True).
- delim: The column delimiter.
- justify: Determines how are data justified in their column.
Valid values are 'left','right' and 'center'.
- separateRows: True if rows are to be separated by a line
of 'headerChar's.
- prefix: A string prepended to each printed row.
- postfix: A string appended to each printed row.
- wrapfunc: A function f(text) for wrapping text; each element in
the table is first wrapped by this function."""
# closure for breaking logical rows to physical, using wrapfunc
def rowWrapper(row):
if not wraplast:
lastcolumn = row[-1]
newRows = [wrapfunc(item).split('\n') for item in row[0:-1]]
newRows.append([lastcolumn])
else:
newRows = [wrapfunc(item).split('\n') for item in row]

return [[substr or '' for substr in item] for item in map(None,*newRows)]
# break each logical row into one or more physical ones
logicalRows = [rowWrapper(row) for row in rows]
# columns of physical rows
columns = map(None,*reduce(operator.add,logicalRows))
# get the maximum of each column by the string length of its items
maxWidths = [max([len(str(item)) for item in column]) for column in columns]
rowSeparator = headerChar * (len(prefix) + len(postfix) + sum(maxWidths) + \
len(delim)*(len(maxWidths)-1))
# select the appropriate justify method
justify = {'center':str.center, 'right':str.rjust, 'left':str.ljust}[justify.lower()]
output=cStringIO.StringIO()
if separateRows: print >> output, rowSeparator
for physicalRows in logicalRows:
for row in physicalRows:
print >> output, \
prefix \
+ delim.join([justify(str(item),width) for (item,width) in zip(row,maxWidths)]) \
+ postfix
if separateRows or hasHeader: print >> output, rowSeparator; hasHeader=False
return output.getvalue()

def wrap_onspace(text, width):
"""
A word-wrap function that preserves existing line breaks
and most spaces in the text. Expects that existing line
breaks are posix newlines (\n).
Written by Mike Brown
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/148061
"""
return reduce(lambda line, word, width=width: '%s%s%s' %
(line,
' \n'[(len(line[line.rfind('\n')+1:])
+ len(word.split('\n',1)[0]
) >= width)],
word),
text.split(' ')
)

def wrap_onspace_strict(text, width):
"""Similar to wrap_onspace, but enforces the width constraint:
words longer than width are split."""
wordRegex = re.compile(r'\S{'+str(width)+r',}')
return wrap_onspace(wordRegex.sub(lambda m: wrap_always(m.group(),width),text),width)

def wrap_always(text, width):
"""A simple word-wrap function that wraps text on exactly width characters.
It doesn't split the text in words."""
return '\n'.join([ text[width*i:width*(i+1)] \
for i in xrange(int(math.ceil(1.*len(text)/width))) ])

def write_sqldb(sqlfile, dev, rows):
"""Write device fields to sqlite db"""
create_table = False
Expand Down Expand Up @@ -369,19 +293,25 @@ def handle_output(all_rows, opts):
print 'DEVICE: {}'.format(dev)
print_table(rows)

def print_table(rows, labels=None, has_header=True, separate_rows=False,
wrapfunc=None, delim=' | ', wrap_last=False):
def print_table(rows, labels=None):
"""
Print the interface table for a device
"""
if labels is None:
labels = ROW_LABELS
if wrapfunc is None:
wrapfunc = lambda x: wrap_onspace(x, 20)

print indent([labels] + rows, hasHeader=has_header,
separateRows=separate_rows, wrapfunc=wrapfunc, delim=delim,
wraplast=wrap_last)
output_table = prettytable.PrettyTable()
output_table.field_names = labels
output_table.align = 'l'
output_table.vrules = prettytable.prettytable.ALL
output_table.hrules = prettytable.prettytable.HEADER

for row in rows:
row = [x.strip() for x in row]
output_table.add_row(row)

print output_table
print ''

def output_dotty(subnet_table, display=True):
"""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7e023d6

Please sign in to comment.