Skip to content

Commit 1a59f09

Browse files
committed
Documentation
- Add inline code documentation
1 parent 35ad031 commit 1a59f09

File tree

10 files changed

+171
-52
lines changed

10 files changed

+171
-52
lines changed

dsc_datatool/__init__.py

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
4-
5-
DSC datatool
6-
7-
:copyright: 2020 OARC, Inc.
1+
"""dsc_datatool
2+
3+
The main Python module for the command line tool `dsc-datatool`, see
4+
`man dsc-datatool` on how to run it.
5+
6+
On runtime it will load all plugins under the following module path:
7+
- dsc_datatool.input
8+
- dsc_datatool.output
9+
- dsc_datatool.generator
10+
- dsc_datatool.transformer
11+
12+
Each plugin category should base it class on one of the follow superclasses:
13+
- dsc_datatool.Input
14+
- dsc_datatool.Output
15+
- dsc_datatool.Generator
16+
- dsc_datatool.Transformer
17+
18+
Doing so it will be automatically registered as available and indexed in
19+
the following public dicts using the class name:
20+
- inputs
21+
- outputs
22+
- generators
23+
- transformers
24+
25+
Example of an output:
26+
27+
from dsc_datatool import Output
28+
class ExampleOutput(Output):
29+
def process(self, datasets)
30+
...
31+
32+
:copyright: 2020 OARC, Inc.
833
"""
934

1035
__version__ = '1.0.0'
@@ -27,87 +52,181 @@
2752

2853

2954
class Dataset(object):
55+
"""A representation of a DSC dataset
56+
57+
A DSC dataset is one to two dimensional structure where the last
58+
dimension holds an array of values and counters.
59+
60+
It is based on the XML structure of DSC:
61+
62+
<array name="pcap_stats" dimensions="2" start_time="1563520560" stop_time="1563520620">
63+
<dimension number="1" type="ifname"/>
64+
<dimension number="2" type="pcap_stat"/>
65+
<data>
66+
<ifname val="eth0">
67+
<pcap_stat val="filter_received" count="5625"/>
68+
<pcap_stat val="pkts_captured" count="4894"/>
69+
<pcap_stat val="kernel_dropped" count="731"/>
70+
</ifname>
71+
</data>
72+
</array>
73+
74+
Attributes:
75+
- name: The name of the dataset
76+
- start_time: The start time of the dataset in seconds
77+
- stop_time: The stop time of the dataset in seconds
78+
- dimensions: An array with `Dimension`, the first dimension
79+
"""
3080
name = None
3181
start_time = None
3282
stop_time = None
3383
dimensions = None
3484

85+
3586
def __init__(self):
3687
self.dimensions = []
3788

89+
3890
def __repr__(self):
3991
return '<Dataset name=%r dimension=%r>' % (self.name, self.dimensions)
4092

4193

4294
class Dimension(object):
95+
"""A representation of a DSC dimension
96+
97+
A DSC dataset dimension which can be the first or second dimension,
98+
see `Dataset` for more information.
99+
100+
Attributes:
101+
- name: The name of the dimension
102+
- value: Is set to the value of the dimension if it's the first dimension
103+
- values: A dict of values with corresponding counters if it's the second dimension
104+
"""
43105
name = None
44106
value = None
45107
values = None
46108
dimensions = None
47109

110+
48111
def __init__(self, name):
49112
self.name = name
50113
self.values = {}
51114
self.dimensions = []
52115

116+
53117
def __repr__(self):
54118
return '<Dimension name=%r value=%r dimension=%r>' % (self.name, self.values or self.value, self.dimensions)
55119

56120

57121
class Input(object):
122+
"""Base class of an input plugin"""
123+
124+
58125
def process(self, file):
126+
"""Input.process(...) -> [ Dataset, ... ]
127+
128+
Called to process a file and return an array of `Dataset`'s found in it.
129+
"""
59130
raise Exception('process() not overloaded')
60131

132+
61133
def __init_subclass__(cls):
134+
"""This method is called when a class is subclassed and it will
135+
register the input plugin in `inputs`."""
62136
global inputs
63137
if cls.__name__ in inputs:
64138
raise Exception('Duplicate input module: %s already exists' % cls.__name__)
65139
inputs[cls.__name__] = cls
66140

67141

68142
class Output(object):
143+
"""Base class of an output plugin"""
144+
145+
69146
def process(self, datasets):
147+
"""Output.process([ Dataset, ... ])
148+
149+
Called to output the `Dataset`'s in the given array."""
70150
raise Exception('process() not overloaded')
71151

152+
72153
def __init__(self, opts):
154+
"""instance = Output({ 'opt': value, ... })
155+
156+
Called to create an instance of the output plugin, will get a dict
157+
with options provided on command line."""
73158
pass
74159

160+
75161
def __init_subclass__(cls):
162+
"""This method is called when a class is subclassed and it will
163+
register the output plugin in `outputs`."""
76164
global outputs
77165
if cls.__name__ in outputs:
78166
raise Exception('Duplicate output module: %s already exists' % cls.__name__)
79167
outputs[cls.__name__] = cls
80168

81169

82170
class Generator(object):
171+
"""Base class of a generator plugin"""
172+
173+
83174
def process(self, datasets):
175+
"""Generator.process([ Dataset, ... ]) -> [ Dataset, ... ]
176+
177+
Called to generate additional `Dataset`'s based on the given array
178+
of `Dataset`'s."""
84179
raise Exception('process() not overloaded')
85180

181+
86182
def __init__(self, opts):
183+
"""instance = Generator({ 'opt': value, ... })
184+
185+
Called to create an instance of the generator plugin, will get a dict
186+
with options provided on command line."""
87187
pass
88188

189+
89190
def __init_subclass__(cls):
191+
"""This method is called when a class is subclassed and it will
192+
register the generator plugin in `generators`."""
90193
global generators
91194
if cls.__name__ in generators:
92195
raise Exception('Duplicate generator module: %s already exists' % cls.__name__)
93196
generators[cls.__name__] = cls
94197

95198

96199
class Transformer(object):
200+
"""Base class of a transformer plugin"""
201+
202+
97203
def process(self, datasets):
204+
"""Transformer.process([ Dataset, ... ])
205+
206+
Called to do transformation of the given `Dataset`'s, as in modifying
207+
them directly."""
98208
raise Exception('process() not overloaded')
99209

210+
100211
def __init__(self, opts):
212+
"""instance = Transformer({ 'opt': value, ... })
213+
214+
Called to create an instance of the transformer plugin, will get a dict
215+
with options provided on command line."""
101216
pass
102217

218+
103219
def __init_subclass__(cls):
220+
"""This method is called when a class is subclassed and it will
221+
register the transformer plugin in `transformers`."""
104222
global transformers
105223
if cls.__name__ in transformers:
106224
raise Exception('Duplicate transformer module: %s already exists' % cls.__name__)
107225
transformers[cls.__name__] = cls
108226

109227

110228
def main():
229+
"""Called when running `dsc-datatool`."""
111230
def iter_namespace(ns_pkg):
112231
return pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + ".")
113232

dsc_datatool/generator/client_ports_count.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.generator.client_ports_count
2+
3+
Not implemented.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
from dsc_datatool import Generator

dsc_datatool/generator/client_subnet_authority.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.generator.client_subnet_authority
2+
3+
See `man dsc-datatool-generator client_subnet_authority`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import csv

dsc_datatool/generator/client_subnet_country.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.generator.client_subnet_country
2+
3+
See `man dsc-datatool-generator client_subnet_country`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import maxminddb

dsc_datatool/input/dat.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.input.dat
2+
3+
Input plugin to generate `Dataset`'s from DSC DAT files.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import re

dsc_datatool/input/xml.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.input.xml
2+
3+
Input plugin to generate `Dataset`'s from DSC XML files.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import logging

dsc_datatool/output/influxdb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.output.influxdb
2+
3+
See `man dsc-datatool-output influxdb`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import re

dsc_datatool/transformer/labler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.transformer.labler
2+
3+
See `man dsc-datatool-transformer labler`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import yaml

dsc_datatool/transformer/net_remap.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.transformer.net_remap
2+
3+
See `man dsc-datatool-transformer netremap`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import ipaddress

dsc_datatool/transformer/re_ranger.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
"""
2-
dsc_datatool
3-
~~~~~~~~~~~~
1+
"""dsc_datatool.transformer.re_ranger
2+
3+
See `man dsc-datatool-transformer reranger`.
44
5-
DSC datatool
5+
Part of dsc_datatool.
66
7-
:copyright: 2020 OARC, Inc.
7+
:copyright: 2020 OARC, Inc.
88
"""
99

1010
import re

0 commit comments

Comments
 (0)