2020-04-10 12:08:25 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import textwrap
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
print("""
|
|
|
|
---
|
|
|
|
title: "Examples"
|
|
|
|
menu:
|
|
|
|
addons:
|
|
|
|
weight: 6
|
|
|
|
---
|
|
|
|
|
|
|
|
# Examples of Addons and Scripts
|
|
|
|
|
2020-04-11 10:25:56 +00:00
|
|
|
The most recent set of examples is also available [on our GitHub project](https://github.com/mitmproxy/mitmproxy/tree/master/examples).
|
|
|
|
|
2020-04-10 12:08:25 +00:00
|
|
|
""")
|
|
|
|
|
|
|
|
base = os.path.dirname(os.path.realpath(__file__))
|
2020-04-11 10:25:56 +00:00
|
|
|
examples_path = os.path.join(base, 'src/examples/')
|
2020-04-10 12:08:25 +00:00
|
|
|
pathlist = Path(examples_path).glob('**/*.py')
|
|
|
|
|
|
|
|
examples = [os.path.relpath(str(p), examples_path) for p in sorted(pathlist)]
|
|
|
|
examples = [p for p in examples if not os.path.basename(p) == '__init__.py']
|
|
|
|
examples = [p for p in examples if not os.path.basename(p).startswith('test_')]
|
|
|
|
|
|
|
|
current_dir = None
|
|
|
|
current_level = 2
|
|
|
|
for ex in examples:
|
|
|
|
if os.path.dirname(ex) != current_dir:
|
|
|
|
current_dir = os.path.dirname(ex)
|
|
|
|
sanitized = current_dir.replace('/', '').replace('.', '')
|
|
|
|
print(" * [Examples: {}]({{{{< relref \"addons-examples#{}\">}}}})".format(current_dir, sanitized))
|
|
|
|
|
|
|
|
sanitized = ex.replace('/', '').replace('.', '')
|
2020-04-11 10:25:56 +00:00
|
|
|
print(" * [{}]({{{{< relref \"addons-examples#example-{}\">}}}})".format(os.path.basename(ex), sanitized))
|
2020-04-10 12:08:25 +00:00
|
|
|
|
|
|
|
current_dir = None
|
|
|
|
current_level = 2
|
|
|
|
for ex in examples:
|
|
|
|
if os.path.dirname(ex) != current_dir:
|
|
|
|
current_dir = os.path.dirname(ex)
|
2020-04-10 12:08:40 +00:00
|
|
|
print("#" * current_level, current_dir)
|
2020-04-10 12:08:25 +00:00
|
|
|
|
|
|
|
print(textwrap.dedent("""
|
2020-04-11 10:25:56 +00:00
|
|
|
{} Example: {}
|
2020-04-10 12:08:25 +00:00
|
|
|
{{{{< example src="{}" lang="py" >}}}}
|
2020-04-11 10:25:56 +00:00
|
|
|
""".format("#" * (current_level + 1), ex, "examples/" + ex)))
|