RacksDB 0.3.0__tar.gz → 0.4.0__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.
Files changed (64) hide show
  1. {RacksDB-0.3.0 → racksdb-0.4.0}/PKG-INFO +15 -5
  2. {RacksDB-0.3.0 → racksdb-0.4.0}/README.md +10 -3
  3. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/PKG-INFO +15 -5
  4. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/SOURCES.txt +6 -3
  5. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/requires.txt +5 -1
  6. {RacksDB-0.3.0 → racksdb-0.4.0}/pyproject.toml +6 -10
  7. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/__init__.py +15 -6
  8. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/bases.py +48 -9
  9. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/drawers/base.py +64 -5
  10. racksdb-0.4.0/racksdb/drawers/coordinates/__init__.py +17 -0
  11. racksdb-0.4.0/racksdb/drawers/coordinates/base.py +10 -0
  12. racksdb-0.4.0/racksdb/drawers/coordinates/json.py +19 -0
  13. racksdb-0.4.0/racksdb/drawers/coordinates/yaml.py +19 -0
  14. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/drawers/dtypes/hexcolor.py +5 -2
  15. racksdb-0.4.0/racksdb/drawers/infrastructure.py +586 -0
  16. racksdb-0.4.0/racksdb/drawers/room.py +238 -0
  17. racksdb-0.4.0/racksdb/errors.py +20 -0
  18. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/exec.py +34 -5
  19. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/db.py +70 -27
  20. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/dumpers/json.py +4 -18
  21. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/dumpers/yaml.py +7 -21
  22. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/openapi.py +1 -1
  23. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/schema.py +7 -1
  24. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/views.py +50 -12
  25. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/test_defined_type_hexcolor.py +4 -2
  26. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/test_drawer.py +7 -7
  27. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/views.py +36 -4
  28. racksdb-0.4.0/racksdb/web/__init__.py +0 -0
  29. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/web/app.py +102 -14
  30. RacksDB-0.3.0/racksdb/drawers/infrastructure.py +0 -282
  31. RacksDB-0.3.0/racksdb/drawers/room.py +0 -163
  32. RacksDB-0.3.0/racksdb/errors.py +0 -9
  33. RacksDB-0.3.0/racksdb/web/ui/node_modules/flatted/python/flatted.py +0 -149
  34. RacksDB-0.3.0/racksdb/web/ui/node_modules/flatted/python/test.py +0 -63
  35. {RacksDB-0.3.0 → racksdb-0.4.0}/LICENSE +0 -0
  36. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/dependency_links.txt +0 -0
  37. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/entry_points.txt +0 -0
  38. {RacksDB-0.3.0 → racksdb-0.4.0}/RacksDB.egg-info/top_level.txt +0 -0
  39. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/drawers/__init__.py +0 -0
  40. {RacksDB-0.3.0/racksdb → racksdb-0.4.0/racksdb/drawers}/dtypes/__init__.py +0 -0
  41. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/drawers/parameters.py +0 -0
  42. {RacksDB-0.3.0/racksdb/generic → racksdb-0.4.0/racksdb/dtypes}/__init__.py +0 -0
  43. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/angle.py +0 -0
  44. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/bits.py +0 -0
  45. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/bytes.py +0 -0
  46. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/dimension.py +0 -0
  47. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/netif_type.py +0 -0
  48. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/rack_height.py +0 -0
  49. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/rack_width.py +0 -0
  50. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/storage_type.py +0 -0
  51. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/dtypes/watts.py +0 -0
  52. {RacksDB-0.3.0/racksdb/tests → racksdb-0.4.0/racksdb/generic}/__init__.py +0 -0
  53. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/definedtype.py +0 -0
  54. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/dumpers/__init__.py +0 -0
  55. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/dumpers/_common.py +0 -0
  56. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/dumpers/console.py +0 -0
  57. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/generic/errors.py +0 -0
  58. {RacksDB-0.3.0/racksdb/web → racksdb-0.4.0/racksdb/tests}/__init__.py +0 -0
  59. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/test_defined_type_watts.py +0 -0
  60. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/test_schema.py +0 -0
  61. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/test_schema_defined_type_loader.py +0 -0
  62. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/tests/tests_db_load.py +0 -0
  63. {RacksDB-0.3.0 → racksdb-0.4.0}/racksdb/version.py +0 -0
  64. {RacksDB-0.3.0 → racksdb-0.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RacksDB
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Modelize your datacenters infrastructures in YAML database
5
5
  Author-email: Rémi Palancher <remi@rackslab.io>
6
6
  License: GPLv3+
@@ -20,9 +20,12 @@ License-File: LICENSE
20
20
  Requires-Dist: PyYAML
21
21
  Requires-Dist: ClusterShell
22
22
  Requires-Dist: pycairo
23
+ Requires-Dist: PyGObject
24
+ Provides-Extra: dev
25
+ Requires-Dist: Flask-Cors; extra == "dev"
23
26
  Provides-Extra: web
24
27
  Requires-Dist: Flask; extra == "web"
25
- Requires-Dist: Flask-Cors; extra == "web"
28
+ Requires-Dist: requests-toolbelt; extra == "web"
26
29
 
27
30
  <img
28
31
  src="assets/bitmaps/logo_full_white_medium.png"
@@ -53,9 +56,8 @@ source** for many purposes in IT management.
53
56
 
54
57
  <p align="center">
55
58
  <img
56
- src="docs/modules/overview/images/racksdb_overview.svg"
59
+ src="docs/modules/overview/images/racksdb_overview.png"
57
60
  alt="RacksDB Overview"
58
- width="600px"
59
61
  style="margin: 0 auto;">
60
62
  </p>
61
63
 
@@ -85,7 +87,15 @@ RacksDB provides multiple interfaces to request the database with its
85
87
  [CLI tool](https://docs.rackslab.io/racksdb/usage/racksdb.html), a
86
88
  [Python library](https://docs.rackslab.io/racksdb/usage/lib.html), a
87
89
  [REST API](https://docs.rackslab.io/racksdb/usage/rest.html) and a
88
- [Web UI](racksdb/web/ui/README.md) (in _beta_).
90
+ [Web UI](https://docs.rackslab.io/racksdb/usage/ui.html).
91
+
92
+ <p align="center">
93
+ <img
94
+ src="assets/screenshots/assemblies/bitmaps/screenshots-small.webp"
95
+ alt="RacksDB web UI"
96
+ width="600px"
97
+ style="margin: 0 auto;">
98
+ <p>
89
99
 
90
100
  For more details, read the
91
101
  [full description](https://docs.rackslab.io/racksdb/overview/overview.html)
@@ -27,9 +27,8 @@ source** for many purposes in IT management.
27
27
 
28
28
  <p align="center">
29
29
  <img
30
- src="docs/modules/overview/images/racksdb_overview.svg"
30
+ src="docs/modules/overview/images/racksdb_overview.png"
31
31
  alt="RacksDB Overview"
32
- width="600px"
33
32
  style="margin: 0 auto;">
34
33
  </p>
35
34
 
@@ -59,7 +58,15 @@ RacksDB provides multiple interfaces to request the database with its
59
58
  [CLI tool](https://docs.rackslab.io/racksdb/usage/racksdb.html), a
60
59
  [Python library](https://docs.rackslab.io/racksdb/usage/lib.html), a
61
60
  [REST API](https://docs.rackslab.io/racksdb/usage/rest.html) and a
62
- [Web UI](racksdb/web/ui/README.md) (in _beta_).
61
+ [Web UI](https://docs.rackslab.io/racksdb/usage/ui.html).
62
+
63
+ <p align="center">
64
+ <img
65
+ src="assets/screenshots/assemblies/bitmaps/screenshots-small.webp"
66
+ alt="RacksDB web UI"
67
+ width="600px"
68
+ style="margin: 0 auto;">
69
+ <p>
63
70
 
64
71
  For more details, read the
65
72
  [full description](https://docs.rackslab.io/racksdb/overview/overview.html)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RacksDB
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Modelize your datacenters infrastructures in YAML database
5
5
  Author-email: Rémi Palancher <remi@rackslab.io>
6
6
  License: GPLv3+
@@ -20,9 +20,12 @@ License-File: LICENSE
20
20
  Requires-Dist: PyYAML
21
21
  Requires-Dist: ClusterShell
22
22
  Requires-Dist: pycairo
23
+ Requires-Dist: PyGObject
24
+ Provides-Extra: dev
25
+ Requires-Dist: Flask-Cors; extra == "dev"
23
26
  Provides-Extra: web
24
27
  Requires-Dist: Flask; extra == "web"
25
- Requires-Dist: Flask-Cors; extra == "web"
28
+ Requires-Dist: requests-toolbelt; extra == "web"
26
29
 
27
30
  <img
28
31
  src="assets/bitmaps/logo_full_white_medium.png"
@@ -53,9 +56,8 @@ source** for many purposes in IT management.
53
56
 
54
57
  <p align="center">
55
58
  <img
56
- src="docs/modules/overview/images/racksdb_overview.svg"
59
+ src="docs/modules/overview/images/racksdb_overview.png"
57
60
  alt="RacksDB Overview"
58
- width="600px"
59
61
  style="margin: 0 auto;">
60
62
  </p>
61
63
 
@@ -85,7 +87,15 @@ RacksDB provides multiple interfaces to request the database with its
85
87
  [CLI tool](https://docs.rackslab.io/racksdb/usage/racksdb.html), a
86
88
  [Python library](https://docs.rackslab.io/racksdb/usage/lib.html), a
87
89
  [REST API](https://docs.rackslab.io/racksdb/usage/rest.html) and a
88
- [Web UI](racksdb/web/ui/README.md) (in _beta_).
90
+ [Web UI](https://docs.rackslab.io/racksdb/usage/ui.html).
91
+
92
+ <p align="center">
93
+ <img
94
+ src="assets/screenshots/assemblies/bitmaps/screenshots-small.webp"
95
+ alt="RacksDB web UI"
96
+ width="600px"
97
+ style="margin: 0 auto;">
98
+ <p>
89
99
 
90
100
  For more details, read the
91
101
  [full description](https://docs.rackslab.io/racksdb/overview/overview.html)
@@ -18,6 +18,11 @@ racksdb/drawers/base.py
18
18
  racksdb/drawers/infrastructure.py
19
19
  racksdb/drawers/parameters.py
20
20
  racksdb/drawers/room.py
21
+ racksdb/drawers/coordinates/__init__.py
22
+ racksdb/drawers/coordinates/base.py
23
+ racksdb/drawers/coordinates/json.py
24
+ racksdb/drawers/coordinates/yaml.py
25
+ racksdb/drawers/dtypes/__init__.py
21
26
  racksdb/drawers/dtypes/hexcolor.py
22
27
  racksdb/dtypes/__init__.py
23
28
  racksdb/dtypes/angle.py
@@ -49,6 +54,4 @@ racksdb/tests/test_schema.py
49
54
  racksdb/tests/test_schema_defined_type_loader.py
50
55
  racksdb/tests/tests_db_load.py
51
56
  racksdb/web/__init__.py
52
- racksdb/web/app.py
53
- racksdb/web/ui/node_modules/flatted/python/flatted.py
54
- racksdb/web/ui/node_modules/flatted/python/test.py
57
+ racksdb/web/app.py
@@ -1,7 +1,11 @@
1
1
  PyYAML
2
2
  ClusterShell
3
3
  pycairo
4
+ PyGObject
5
+
6
+ [dev]
7
+ Flask-Cors
4
8
 
5
9
  [web]
6
10
  Flask
7
- Flask-Cors
11
+ requests-toolbelt
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "RacksDB"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Modelize your datacenters infrastructures in YAML database"
9
9
  license = {text = "GPLv3+"}
10
10
  requires-python = ">=3.6"
@@ -16,6 +16,7 @@ dependencies = [
16
16
  "PyYAML",
17
17
  "ClusterShell",
18
18
  "pycairo",
19
+ "PyGObject",
19
20
  ]
20
21
  readme = "README.md"
21
22
  classifiers = [
@@ -29,9 +30,12 @@ classifiers = [
29
30
  ]
30
31
 
31
32
  [project.optional-dependencies]
33
+ dev = [
34
+ "Flask-Cors",
35
+ ]
32
36
  web = [
33
37
  "Flask",
34
- "Flask-Cors",
38
+ "requests-toolbelt",
35
39
  ]
36
40
 
37
41
  [project.scripts]
@@ -40,19 +44,11 @@ racksdb-web = "racksdb.web.app:RacksDBWebApp.run"
40
44
 
41
45
  [tool.setuptools.packages.find]
42
46
  include = ["racksdb*"]
43
- exclude = ["racksdb.web.ui*"]
44
47
 
45
48
  [project.urls]
46
49
  "Homepage" = "https://github.com/rackslab/RacksDB"
47
50
  "Bug Tracker" = "https://github.com/rackslab/RacksDB/issues"
48
51
 
49
- # Do not automatically install all files in package tree as data files. This is
50
- # especially required for files under UI folder that could be could considered
51
- # data files even though they are explicitely excluded from packages search
52
- # paths.
53
- [tool.setuptools]
54
- include-package-data = false
55
-
56
52
  [tool.black]
57
53
  target-version = ['py36']
58
54
  color = 1
@@ -9,6 +9,8 @@ from typing import Union
9
9
 
10
10
  from .generic.schema import Schema, SchemaFileLoader, SchemaDefinedTypeLoader
11
11
  from .generic.db import GenericDB, DBDict, DBList, DBSplittedFilesLoader
12
+ from .generic.errors import DBSchemaError, DBFormatError
13
+ from .errors import RacksDBFormatError, RacksDBSchemaError
12
14
  from . import bases
13
15
 
14
16
 
@@ -17,6 +19,7 @@ class RacksDB(GenericDB):
17
19
  DEFAULT_DB = "/var/lib/racksdb"
18
20
  DEFAULT_SCHEMA = "/usr/share/racksdb/schemas/racksdb.yml"
19
21
  DEFAULT_EXT = "/etc/racksdb/extensions.yml"
22
+ DEFAULT_UI = "/usr/share/racksdb/frontend"
20
23
  PREFIX = "RacksDB"
21
24
  DEFINED_TYPES_MODULE = "racksdb.dtypes"
22
25
 
@@ -65,10 +68,16 @@ class RacksDB(GenericDB):
65
68
  db = Path(cls.DEFAULT_DB)
66
69
  elif isinstance(db, str):
67
70
  db = Path(db)
68
- _schema = Schema(
69
- SchemaFileLoader(schema, ext),
70
- SchemaDefinedTypeLoader(cls.DEFINED_TYPES_MODULE),
71
- )
72
- _db = cls(_schema, DBSplittedFilesLoader(db))
73
- super(cls, _db).load(_db._loader)
71
+ try:
72
+ _schema = Schema(
73
+ SchemaFileLoader(schema, ext),
74
+ SchemaDefinedTypeLoader(cls.DEFINED_TYPES_MODULE),
75
+ )
76
+ except DBSchemaError as err:
77
+ raise RacksDBSchemaError(str(err)) from err
78
+ try:
79
+ _db = cls(_schema, DBSplittedFilesLoader(db))
80
+ super(cls, _db).load(_db._loader)
81
+ except DBFormatError as err:
82
+ raise RacksDBFormatError(str(err)) from err
74
83
  return _db
@@ -4,6 +4,20 @@
4
4
  #
5
5
  # SPDX-License-Identifier: GPL-3.0-or-later
6
6
 
7
+ import math
8
+
9
+ try:
10
+ from functools import cached_property
11
+ except ImportError:
12
+ # For Python 3.[6-7] compatibility. The dependency to cached_property
13
+ # external library is not declared in pyproject.toml, it is added
14
+ # explicitely in packages codes only for distributions stuck with these old
15
+ # versions of Python.
16
+ #
17
+ # This try/except block can be removed when support of Python < 3.8 is
18
+ # dropped in RacksDB.
19
+ from cached_property import cached_property
20
+
7
21
  from .generic.db import DBList, DBDict
8
22
 
9
23
 
@@ -43,18 +57,33 @@ class RacksDBInfrastructureBase:
43
57
  return True
44
58
 
45
59
 
46
- class RacksDBNodeBase:
60
+ class RacksDBGenericEquipment:
47
61
  @property
48
62
  def tags(self):
49
63
  result = DBList()
50
64
  for tag in getattr(self._parent, "tags", []):
51
65
  result.append(tag)
52
- # RacksDBNodeBase loaded tags are renamed with loaded prefix to avoid
53
- # conflict with this property.
66
+ # RacksDB{Node,StorageEquipment,NetworkEquipment,MiscEquipment} loaded tags are
67
+ # renamed with loaded prefix to avoid conflict with this property.
54
68
  for tag in getattr(self, f"{self.LOADED_PREFIX}tags", []):
55
- result.append(tag)
69
+ # Avoid duplicate tags that could be defined on both parent part and
70
+ # equipment.
71
+ if tag not in result:
72
+ result.append(tag)
56
73
  return result
57
74
 
75
+ @cached_property
76
+ def position(self):
77
+ obj = self._db.create_object_by_name("EquipmentPosition")
78
+ obj.height = (
79
+ self._first.slot
80
+ - self.rack.type.initial
81
+ + math.floor((self.slot - self._first.slot) * self.type.width)
82
+ * self.type.height
83
+ )
84
+ obj.width = (self.slot - self._first.slot) % int(1 / self.type.width)
85
+ return obj
86
+
58
87
  def _filter(self, infrastructure=None, name=None, tags=None):
59
88
  # filter by name
60
89
  if name is not None and name != self.name:
@@ -70,10 +99,23 @@ class RacksDBNodeBase:
70
99
  return True
71
100
 
72
101
 
73
- class RacksDBRackBase:
102
+ class RacksDBNodeBase(RacksDBGenericEquipment):
103
+ pass
104
+
105
+
106
+ class RacksDBStorageEquipmentBase(RacksDBGenericEquipment):
107
+ pass
108
+
74
109
 
75
- COMPUTED_PROPERTIES = ["nodes", "fillrate"]
110
+ class RacksDBNetworkEquipmentBase(RacksDBGenericEquipment):
111
+ pass
76
112
 
113
+
114
+ class RacksDBMiscEquipmentBase(RacksDBGenericEquipment):
115
+ pass
116
+
117
+
118
+ class RacksDBRackBase:
77
119
  def _filter(self, name=None):
78
120
  # filter by name
79
121
  if name is not None and name != self.name:
@@ -110,9 +152,6 @@ class RacksDBRackBase:
110
152
 
111
153
 
112
154
  class RacksDBRacksRowBase:
113
-
114
- COMPUTED_PROPERTIES = ["nbracks"]
115
-
116
155
  @property
117
156
  def nbracks(self):
118
157
  """Return the number of racks in the row."""
@@ -4,21 +4,36 @@
4
4
  #
5
5
  # SPDX-License-Identifier: GPL-3.0-or-later
6
6
 
7
+ from typing import Union
7
8
  import logging
8
9
 
9
10
  import cairo
11
+ import gi
12
+
13
+ from .coordinates import CoordinateDumperFactory
14
+
15
+ gi.require_version("Pango", "1.0")
16
+ gi.require_version("PangoCairo", "1.0")
17
+
18
+ # This import is not at the top of the file because gi requires the version to be
19
+ # specified with the calls above before importing the modules from repository, thus the
20
+ # ruff QA exception on E402.
21
+ from gi.repository import Pango, PangoCairo # noqa: E402
22
+
10
23
 
11
24
  logger = logging.getLogger(__name__)
12
25
 
13
26
 
14
27
  class DefaultRackColorSet:
15
- frame = (0.2, 0.2, 0.2) # aka. #333333 (dark gray)
16
- pane = (0, 0, 0) # aka. #000000 (black)
28
+ frame = (0.2, 0.2, 0.2, 1) # aka. #333333 (dark gray)
29
+ pane = (0, 0, 0, 1) # aka. #000000 (black)
17
30
 
18
31
 
19
32
  class DefaultEquipmentColorSet:
20
- background = (0.6, 0.6, 0.6) # aka. #999999 (light gray)
21
- border = (0.2, 0.2, 0.2) # aka. #333333 (dark gray)
33
+ background = (0.6, 0.6, 0.6, 1) # aka. #999999 (light gray)
34
+ ghost = (0.45, 0.45, 0.45, 1) # aka. #737373 (lighter gray)
35
+ chassis = (0.25, 0.25, 0.25, 1) # aka. #3F3F3F (medium gray)
36
+ border = (0.2, 0.2, 0.2, 1) # aka. #333333 (dark gray)
22
37
 
23
38
 
24
39
  class ImagePoint:
@@ -28,11 +43,16 @@ class ImagePoint:
28
43
 
29
44
 
30
45
  class Drawer:
31
- def __init__(self, db, file, output_format, parameters):
46
+ def __init__(
47
+ self, db, file, output_format, parameters, coordinates_fh, coordinates_format
48
+ ):
32
49
  self.db = db
33
50
  self.file = file
34
51
  self.output_format = output_format
35
52
  self.parameters = parameters
53
+ self.coordinates_fh = coordinates_fh
54
+ self.coordinates_format = coordinates_format
55
+ self.coordinates = {}
36
56
  self.surface = None
37
57
  self.ctx = None
38
58
 
@@ -51,6 +71,12 @@ class Drawer:
51
71
  elif self.output_format in ["svg", "pdf"]:
52
72
  self.surface.finish()
53
73
  self.surface.flush()
74
+ if self.coordinates_fh is not None:
75
+ self.coordinates_fh.write(
76
+ CoordinateDumperFactory.create(self.coordinates_format).dump(
77
+ self.coordinates
78
+ )
79
+ )
54
80
 
55
81
  def _find_rack_colorset(self, rack):
56
82
  """Return the rack matching coloring rule defined in drawing parameters or the
@@ -100,3 +126,36 @@ class Drawer:
100
126
  continue
101
127
  return rule
102
128
  return DefaultEquipmentColorSet
129
+
130
+ def _print_text(
131
+ self,
132
+ text: str,
133
+ max_width: Union[int, None] = None,
134
+ max_height: Union[int, None] = None,
135
+ shift_x: bool = False,
136
+ shift_y: bool = False,
137
+ ) -> None:
138
+ """Print text label in context. The text size can possibly be responsive to
139
+ maximum width and height. The boolean shift_x and shift_y can be set to True in
140
+ order to shift the position of the text label by its height vertically or
141
+ horizontally respectively."""
142
+ layout = PangoCairo.create_layout(self.ctx)
143
+ layout.set_alignment(Pango.Alignment.CENTER)
144
+ # Try multiple decreasing size until it fits into optional max width/height
145
+ for size in range(12, 4, -1):
146
+ layout.set_font_description(
147
+ Pango.font_description_from_string(f"Sans Serif Normal {size}")
148
+ )
149
+ layout.set_markup(text, -1)
150
+ _, extents = layout.get_pixel_extents()
151
+ tw, th = extents.width, extents.height
152
+ # If max_{width/height} is set, text label width/height must be smaller.
153
+ if (max_width is None or tw < max_width) and (
154
+ max_height is None or th < max_height
155
+ ):
156
+ break
157
+ if shift_x:
158
+ self.ctx.rel_move_to(-th, 0)
159
+ if shift_y:
160
+ self.ctx.rel_move_to(0, -th)
161
+ PangoCairo.show_layout(self.ctx, layout)
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2022-2024 Rackslab
2
+ #
3
+ # This file is part of RacksDB.
4
+ #
5
+ # SPDX-License-Identifier: GPL-3.0-or-later
6
+
7
+ from .json import CoordinatesDumperJson
8
+ from .yaml import CoordinatesDumperYaml
9
+
10
+
11
+ class CoordinateDumperFactory:
12
+ FORMATS = {"json": CoordinatesDumperJson, "yaml": CoordinatesDumperYaml}
13
+
14
+ @staticmethod
15
+ def create(format: str):
16
+ assert format in CoordinateDumperFactory.FORMATS.keys()
17
+ return CoordinateDumperFactory.FORMATS[format]()
@@ -0,0 +1,10 @@
1
+ # Copyright (c) 2022-2024 Rackslab
2
+ #
3
+ # This file is part of RacksDB.
4
+ #
5
+ # SPDX-License-Identifier: GPL-3.0-or-later
6
+
7
+
8
+ class CoordinatesDumper:
9
+ def dump(self, coordinates):
10
+ raise NotImplementedError
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2022-2024 Rackslab
2
+ #
3
+ # This file is part of RacksDB.
4
+ #
5
+ # SPDX-License-Identifier: GPL-3.0-or-later
6
+
7
+ import json
8
+
9
+ from .base import CoordinatesDumper
10
+
11
+
12
+ class CoordinatesDumperJson(CoordinatesDumper):
13
+ def __init__(self):
14
+ pass
15
+
16
+ def dump(self, coordinates):
17
+ return json.dumps(
18
+ {key: coordinate._serialized for key, coordinate in coordinates.items()}
19
+ )
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2022-2024 Rackslab
2
+ #
3
+ # This file is part of RacksDB.
4
+ #
5
+ # SPDX-License-Identifier: GPL-3.0-or-later
6
+
7
+ import yaml
8
+
9
+ from .base import CoordinatesDumper
10
+
11
+
12
+ class CoordinatesDumperYaml(CoordinatesDumper):
13
+ def __init__(self):
14
+ pass
15
+
16
+ def dump(self, coordinates):
17
+ return yaml.dump(
18
+ {key: coordinate._serialized for key, coordinate in coordinates.items()}
19
+ )
@@ -12,11 +12,14 @@ from racksdb.generic.definedtype import SchemaDefinedType
12
12
 
13
13
  class SchemaDefinedTypeHexcolor(SchemaDefinedType):
14
14
 
15
- pattern = r"#[0-9a-fA-F]{6}"
16
- native = Tuple[float, float, float]
15
+ pattern = r"^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"
16
+ native = Tuple[float, float, float, float]
17
17
 
18
18
  def parse(self, value):
19
19
  self._match(value)
20
20
  hexrgb = re.findall("[0-9a-fA-F]{2}", value)
21
+ # If optional alpha channel is not defined, set it to 255/ff (ie. fully opaque)
22
+ if len(hexrgb) == 3:
23
+ hexrgb.append("ff")
21
24
  rgb = tuple(int(f"0x{_hex}", 16) / 255 for _hex in hexrgb)
22
25
  return rgb