python3-cyberfusion-ferm-support 1.1.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.1
2
+ Name: python3-cyberfusion-ferm-support
3
+ Version: 1.1.2.1
4
+ Summary: Library for ferm.
5
+ Home-page: https://vcs.cyberfusion.nl/shared/python3-cyberfusion-ferm-support
6
+ Author: Cyberfusion
7
+ Author-email: support@cyberfusion.io
8
+ Platform: linux
9
+ Description-Content-Type: text/markdown
10
+
11
+ # python3-cyberfusion-ferm-support
12
+
13
+ Library for [ferm](http://ferm.foo-projects.org/).
14
+
15
+ # Install
16
+
17
+ ## PyPI
18
+
19
+ Run the following command to install the package from PyPI:
20
+
21
+ pip3 install python3-cyberfusion-ferm-support
22
+
23
+ ## Generic
24
+
25
+ Run the following command to create a source distribution:
26
+
27
+ python3 setup.py sdist
28
+
29
+ ## Debian
30
+
31
+ Run the following commands to build a Debian package:
32
+
33
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
34
+ dpkg-buildpackage -us -uc
35
+
36
+ # Configure
37
+
38
+ No configuration is supported.
39
+
40
+ # Usage
41
+
42
+ ## Example
43
+
44
+ ```python
45
+ from cyberfusion.FermSupport.configuration import Configuration
46
+
47
+ c = Configuration(path="/etc/ferm/vars.d/example.conf")
48
+
49
+ c.add_variable(
50
+ name="EXAMPLE",
51
+ values=["2001:0db8::/32"]
52
+ )
53
+
54
+ c.save()
55
+ ```
@@ -0,0 +1,45 @@
1
+ # python3-cyberfusion-ferm-support
2
+
3
+ Library for [ferm](http://ferm.foo-projects.org/).
4
+
5
+ # Install
6
+
7
+ ## PyPI
8
+
9
+ Run the following command to install the package from PyPI:
10
+
11
+ pip3 install python3-cyberfusion-ferm-support
12
+
13
+ ## Generic
14
+
15
+ Run the following command to create a source distribution:
16
+
17
+ python3 setup.py sdist
18
+
19
+ ## Debian
20
+
21
+ Run the following commands to build a Debian package:
22
+
23
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
24
+ dpkg-buildpackage -us -uc
25
+
26
+ # Configure
27
+
28
+ No configuration is supported.
29
+
30
+ # Usage
31
+
32
+ ## Example
33
+
34
+ ```python
35
+ from cyberfusion.FermSupport.configuration import Configuration
36
+
37
+ c = Configuration(path="/etc/ferm/vars.d/example.conf")
38
+
39
+ c.add_variable(
40
+ name="EXAMPLE",
41
+ values=["2001:0db8::/32"]
42
+ )
43
+
44
+ c.save()
45
+ ```
@@ -0,0 +1,21 @@
1
+ [tool.isort]
2
+ profile = "black"
3
+ line_length = 79
4
+ known_first_party = ["cyberfusion"]
5
+ default_section = "THIRDPARTY"
6
+
7
+ [tool.black]
8
+ line-length = 79
9
+ exclude = '''
10
+ (
11
+ /(
12
+ \.eggs # exclude a few common directories in the
13
+ | \.git # root of the project
14
+ | \.hg
15
+ | \.mypy_cache
16
+ | \.tox
17
+ | \.venv
18
+ | venv
19
+ )/
20
+ )
21
+ '''
@@ -0,0 +1,12 @@
1
+ [aliases]
2
+ test = pytest
3
+
4
+ [tool:pytest]
5
+ norecursedirs = .git build dist *.egg __pycache__ .cache
6
+ testpaths = tests
7
+ junit_suite_name = python3-cyberfusion-ferm-support
8
+
9
+ [egg_info]
10
+ tag_build =
11
+ tag_date = 0
12
+
@@ -0,0 +1,25 @@
1
+ """A setuptools based setup module."""
2
+
3
+ from setuptools import setup
4
+
5
+ with open("README.md", "r", encoding="utf-8") as fh:
6
+ long_description = fh.read()
7
+
8
+ setup(
9
+ name="python3-cyberfusion-ferm-support",
10
+ version="1.1.2.1",
11
+ description="Library for ferm.",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ author="Cyberfusion",
15
+ author_email="support@cyberfusion.io",
16
+ url="https://vcs.cyberfusion.nl/shared/python3-cyberfusion-ferm-support",
17
+ platforms=["linux"],
18
+ packages=[
19
+ "cyberfusion.FermSupport",
20
+ "cyberfusion.FermSupport.configuration",
21
+ "cyberfusion.FermSupport.exceptions",
22
+ ],
23
+ package_dir={"": "src"},
24
+ data_files=[],
25
+ )
@@ -0,0 +1 @@
1
+ """Empty file to turn this into a package."""
@@ -0,0 +1,80 @@
1
+ """Helpers for ferm configuration."""
2
+
3
+ import os
4
+ import subprocess
5
+ from typing import List
6
+
7
+ from cyberfusion.Common import find_executable
8
+ from cyberfusion.FermSupport.configuration.custom_lines import CustomLine
9
+ from cyberfusion.FermSupport.configuration.variables import (
10
+ Variable,
11
+ VariableValue,
12
+ )
13
+ from cyberfusion.FermSupport.exceptions import ConfigInvalidError
14
+ from cyberfusion.SystemdSupport.units import Unit
15
+
16
+
17
+ class Configuration:
18
+ """Represents configuration."""
19
+
20
+ def __init__(self, *, path: str) -> None:
21
+ """Set attributes."""
22
+ self.path = path
23
+
24
+ self.variables: List[Variable] = []
25
+ self.custom_lines: List[CustomLine] = []
26
+
27
+ def add_variable(self, *, name: str, values: List[str]) -> None:
28
+ """Add variable."""
29
+ self.variables.append(
30
+ Variable(
31
+ name=name,
32
+ values=[VariableValue(content=value) for value in values],
33
+ )
34
+ )
35
+
36
+ def add_custom_line(self, *, contents: str) -> None:
37
+ """Add custom line."""
38
+ self.custom_lines.append(CustomLine(contents=contents))
39
+
40
+ def __str__(self) -> str:
41
+ """Get string representation."""
42
+ return (
43
+ "\n".join(
44
+ [str(line) for line in self.variables + self.custom_lines]
45
+ )
46
+ + "\n"
47
+ )
48
+
49
+ @property
50
+ def is_valid(self) -> bool:
51
+ """Get if config is valid."""
52
+ try:
53
+ subprocess.run(
54
+ [find_executable("ferm"), "--noexec", self.path], check=True
55
+ )
56
+ except subprocess.CalledProcessError:
57
+ return False
58
+
59
+ return True
60
+
61
+ def save(self) -> bool:
62
+ """Get file object."""
63
+ if not os.path.exists(self.path):
64
+ with open(self.path, "w") as f:
65
+ pass
66
+
67
+ original_contents = open(self.path, "r").read()
68
+
69
+ with open(self.path, "w") as f:
70
+ f.write(str(self))
71
+
72
+ changed = original_contents != open(self.path, "r").read()
73
+
74
+ if changed:
75
+ if not self.is_valid:
76
+ raise ConfigInvalidError
77
+
78
+ Unit(f"ferm.{Unit.SUFFIX_SERVICE}").restart()
79
+
80
+ return changed
@@ -0,0 +1,13 @@
1
+ """Helpers for ferm custom lines."""
2
+
3
+
4
+ class CustomLine:
5
+ """Represents custom line."""
6
+
7
+ def __init__(self, *, contents: str) -> None:
8
+ """Set attributes."""
9
+ self.contents = contents
10
+
11
+ def __str__(self) -> str:
12
+ """Get string representation."""
13
+ return self.contents
@@ -0,0 +1,42 @@
1
+ """Helpers for ferm variables."""
2
+
3
+ from typing import List
4
+
5
+
6
+ class Variable:
7
+ """Represents variable."""
8
+
9
+ def __init__(self, *, name: str, values: List["VariableValue"]) -> None:
10
+ """Set attributes."""
11
+ self._name = name
12
+ self.values = values
13
+
14
+ @property
15
+ def name(self) -> str:
16
+ """Get name."""
17
+ return self._name.upper()
18
+
19
+ def __str__(self) -> str:
20
+ """Get string representation."""
21
+ lines = []
22
+
23
+ lines.append(f"@def ${self.name} = (")
24
+
25
+ for value in self.values:
26
+ lines.append(" " + str(value))
27
+
28
+ lines.append(");")
29
+
30
+ return "\n".join(lines)
31
+
32
+
33
+ class VariableValue:
34
+ """Represents variable value."""
35
+
36
+ def __init__(self, *, content: str) -> None:
37
+ """Set attributes."""
38
+ self.content = content
39
+
40
+ def __str__(self) -> str:
41
+ """Get string representation."""
42
+ return self.content
@@ -0,0 +1,7 @@
1
+ """Exceptions."""
2
+
3
+
4
+ class ConfigInvalidError(Exception):
5
+ """Config is invalid."""
6
+
7
+ pass
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.1
2
+ Name: python3-cyberfusion-ferm-support
3
+ Version: 1.1.2.1
4
+ Summary: Library for ferm.
5
+ Home-page: https://vcs.cyberfusion.nl/shared/python3-cyberfusion-ferm-support
6
+ Author: Cyberfusion
7
+ Author-email: support@cyberfusion.io
8
+ Platform: linux
9
+ Description-Content-Type: text/markdown
10
+
11
+ # python3-cyberfusion-ferm-support
12
+
13
+ Library for [ferm](http://ferm.foo-projects.org/).
14
+
15
+ # Install
16
+
17
+ ## PyPI
18
+
19
+ Run the following command to install the package from PyPI:
20
+
21
+ pip3 install python3-cyberfusion-ferm-support
22
+
23
+ ## Generic
24
+
25
+ Run the following command to create a source distribution:
26
+
27
+ python3 setup.py sdist
28
+
29
+ ## Debian
30
+
31
+ Run the following commands to build a Debian package:
32
+
33
+ mk-build-deps -i -t 'apt -o Debug::pkgProblemResolver=yes --no-install-recommends -y'
34
+ dpkg-buildpackage -us -uc
35
+
36
+ # Configure
37
+
38
+ No configuration is supported.
39
+
40
+ # Usage
41
+
42
+ ## Example
43
+
44
+ ```python
45
+ from cyberfusion.FermSupport.configuration import Configuration
46
+
47
+ c = Configuration(path="/etc/ferm/vars.d/example.conf")
48
+
49
+ c.add_variable(
50
+ name="EXAMPLE",
51
+ values=["2001:0db8::/32"]
52
+ )
53
+
54
+ c.save()
55
+ ```
@@ -0,0 +1,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ setup.cfg
4
+ setup.py
5
+ src/cyberfusion/FermSupport/__init__.py
6
+ src/cyberfusion/FermSupport/configuration/__init__.py
7
+ src/cyberfusion/FermSupport/configuration/custom_lines.py
8
+ src/cyberfusion/FermSupport/configuration/variables.py
9
+ src/cyberfusion/FermSupport/exceptions/__init__.py
10
+ src/python3_cyberfusion_ferm_support.egg-info/PKG-INFO
11
+ src/python3_cyberfusion_ferm_support.egg-info/SOURCES.txt
12
+ src/python3_cyberfusion_ferm_support.egg-info/dependency_links.txt
13
+ src/python3_cyberfusion_ferm_support.egg-info/top_level.txt