annet 1.1.1__py3-none-any.whl → 1.1.2__py3-none-any.whl

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.

Potentially problematic release.


This version of annet might be problematic. Click here for more details.

annet/annlib/lib.py CHANGED
@@ -18,7 +18,6 @@ from functools import lru_cache
18
18
  from typing import List, NamedTuple, Optional, Tuple, Union
19
19
 
20
20
  import contextlog
21
- import jinja2
22
21
  import mako.template
23
22
 
24
23
  _logger = contextlog.get_logger()
@@ -292,19 +291,6 @@ def mako_render(template, dedent=False, **kwargs):
292
291
  return ret
293
292
 
294
293
 
295
- def jinja_render(template, dedent=False, **kwargs):
296
- @lru_cache(None)
297
- def _compile_jinja(template, dedent):
298
- if dedent:
299
- template = textwrap.dedent(template).strip()
300
- return jinja2.Template(template)
301
-
302
- ret = _compile_jinja(template, dedent).render(**kwargs)
303
- if dedent:
304
- ret = ret.strip()
305
- return ret
306
-
307
-
308
294
  # =====
309
295
  def find_exc_in_stack(
310
296
  container_exc: Exception,
@@ -25,7 +25,7 @@ VENDOR_DIFF = {
25
25
  "routeros": "common.default_diff",
26
26
  "aruba": "aruba.default_diff",
27
27
  "pc": "common.default_diff",
28
- "ribbon": "common.default_diff",
28
+ "ribbon": "juniper.default_diff",
29
29
  "b4com": "common.default_diff",
30
30
  }
31
31
 
@@ -40,7 +40,7 @@ VENDOR_DIFF_ORDERED = {
40
40
  "routeros": "common.ordered_diff",
41
41
  "aruba": "common.ordered_diff",
42
42
  "pc": "common.ordered_diff",
43
- "ribbon": "common.ordered_diff",
43
+ "ribbon": "juniper.ordered_diff",
44
44
  "b4com": "common.ordered_diff",
45
45
  }
46
46
 
annet/annlib/tabparser.py CHANGED
@@ -387,6 +387,24 @@ class AsrFormatter(BlockExitFormatter):
387
387
  yield from super().block_exit(context)
388
388
 
389
389
 
390
+ class JuniperPatch:
391
+ def __init__(self):
392
+ """In the case of comments, odict is not suitable: there may be several identical edit and exit"""
393
+ self._items = []
394
+
395
+ def __setitem__(self, key, value):
396
+ self._items.append((key, value))
397
+
398
+ def keys(self):
399
+ return list(self)
400
+
401
+ def items(self):
402
+ return self._items
403
+
404
+ def __iter__(self):
405
+ return iter(item[0] for item in self._items)
406
+
407
+
390
408
  class JuniperFormatter(CommonFormatter):
391
409
  patch_set_prefix = "set"
392
410
 
@@ -399,7 +417,7 @@ class JuniperFormatter(CommonFormatter):
399
417
  comment: str
400
418
 
401
419
  def __post_init__(self):
402
- self.row = self.row.strip()
420
+ self.row = " ".join(map(lambda x: x.strip("\"'"), self.row.strip().split(" ")))
403
421
  self.comment = self.comment.strip()
404
422
 
405
423
  @classmethod
@@ -485,7 +503,8 @@ class JuniperFormatter(CommonFormatter):
485
503
  yield line + self._statement_end
486
504
 
487
505
  def cmd_paths(self, patch, _prev=tuple()):
488
- commands = odict()
506
+ commands = JuniperPatch()
507
+
489
508
  for item in patch.itms:
490
509
  key, childs, context = item.row, item.child, item.context
491
510
 
@@ -497,33 +516,39 @@ class JuniperFormatter(CommonFormatter):
497
516
  value = (
498
517
  ""
499
518
  if key.startswith("delete")
500
- else context["comment"]
519
+ else key.removeprefix(self.Comment.begin).removesuffix(self.Comment.end).strip()
501
520
  )
502
-
503
- cmd = "\n".join(
504
- (
505
- "edit " + " ".join(_prev),
506
- " ".join(("annotate", context["row"].split(" ")[0], f'"{value}"')),
507
- "exit"
508
- )
521
+ cmds = (
522
+ f"edit {' '.join(_prev)}",
523
+ " ".join(("annotate", context["row"].split(" ")[0], f'"{value}"')),
524
+ "exit"
509
525
  )
510
526
  elif key.startswith("delete"):
511
- cmd = " ".join(("delete", *_prev, key.replace("delete", "", 1).strip()))
527
+ cmds = (
528
+ " ".join(("delete", *_prev, key.replace("delete", "", 1).strip())),
529
+ )
512
530
  elif key.startswith("activate"):
513
- cmd = " ".join(("activate", *_prev, key.replace("activate", "", 1).strip()))
531
+ cmds = (
532
+ " ".join(("activate", *_prev, key.replace("activate", "", 1).strip())),
533
+ )
514
534
  elif key.startswith("deactivate"):
515
- cmd = " ".join(("deactivate", *_prev, key.replace("deactivate", "", 1).strip()))
535
+ cmds = (
536
+ " ".join(("deactivate", *_prev, key.replace("deactivate", "", 1).strip())),
537
+ )
516
538
  else:
517
- cmd = " ".join((self.patch_set_prefix, *_prev, key.strip()))
539
+ cmds = (
540
+ " ".join((self.patch_set_prefix, *_prev, key.strip())),
541
+ )
518
542
 
519
543
  # Expanding [ a b c ] junipers list of arguments
520
- if matches := re.search(r"^(.*)\s+\[(.+)\]$", cmd):
521
- for c in matches.group(2).split(" "):
522
- if c.strip():
523
- cmd = " ".join([matches.group(1), c])
524
- commands[(cmd,)] = context
525
- else:
526
- commands[(cmd,)] = context
544
+ for cmd in cmds:
545
+ if matches := re.search(r"^(.*)\s+\[(.+)\]$", cmd):
546
+ for c in matches.group(2).split(" "):
547
+ if c.strip():
548
+ items = " ".join([matches.group(1), c])
549
+ commands[(items,)] = context
550
+ else:
551
+ commands[(cmd,)] = context
527
552
 
528
553
  return commands
529
554
 
annet/api/__init__.py CHANGED
@@ -700,7 +700,7 @@ async def adeploy(
700
700
  ans = deployer.ask_deploy()
701
701
  if ans != "y":
702
702
  return 2 ** 2
703
- progress_bar = None
703
+
704
704
  if sys.stdout.isatty() and not args.no_progress:
705
705
  progress_bar = annet.deploy_ui.ProgressBars(odict([(device.fqdn, {}) for device in deploy_cmds]))
706
706
  progress_bar.init()
@@ -14,7 +14,6 @@ from typing import (
14
14
 
15
15
  from annet.lib import (
16
16
  flatten,
17
- jinja_render,
18
17
  mako_render,
19
18
  )
20
19
  from .base import BaseGenerator, _filter_str
@@ -70,9 +69,6 @@ class Entire(BaseGenerator):
70
69
  def mako(self, text, **kwargs) -> str:
71
70
  return mako_render(text, dedent=True, device=self.__device, **kwargs)
72
71
 
73
- def jinja(self, text, **kwargs) -> str:
74
- return jinja_render(text, dedent=True, device=self.__device, **kwargs)
75
-
76
72
  # =====
77
73
 
78
74
  @classmethod
annet/lib.py CHANGED
@@ -24,7 +24,6 @@ from annet.annlib.lib import ( # pylint: disable=unused-import
24
24
  huawei_expand_vlandb,
25
25
  huawei_iface_ranges,
26
26
  is_relative,
27
- jinja_render,
28
27
  jun_activate,
29
28
  jun_is_inactive,
30
29
  juniper_fmt_prefix_lists_acl,
@@ -151,10 +150,15 @@ def do_async(coro: Awaitable[ReturnType], new_thread=False) -> ReturnType:
151
150
 
152
151
  def wrapper(main):
153
152
  nonlocal res
154
- res = asyncio.run(main)
153
+ try:
154
+ res = asyncio.run(main)
155
+ except BaseException as e:
156
+ res = e
155
157
  thread = threading.Thread(target=wrapper, args=(coro,))
156
158
  thread.start()
157
159
  thread.join()
160
+ if isinstance(res, BaseException):
161
+ raise res
158
162
  return res
159
163
  else:
160
164
  return asyncio.run(coro)
@@ -12,8 +12,8 @@ def comment_processor(item: common.DiffItem):
12
12
  if item.op in (Op.REMOVED, Op.ADDED) and item.row.startswith(JuniperFormatter.Comment.begin):
13
13
  comment = JuniperFormatter.Comment.loads(item.row)
14
14
 
15
+ item.diff_pre["attrs"]["context"]["comment"] = True
15
16
  item.diff_pre["attrs"]["context"]["row"] = comment.row
16
- item.diff_pre["attrs"]["context"]["comment"] = comment.comment
17
17
  item.diff_pre["key"] = item.diff_pre["raw_rule"] = (
18
18
  f"{JuniperFormatter.Comment.begin} {comment.row} {JuniperFormatter.Comment.end}"
19
19
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: annet
3
- Version: 1.1.1
3
+ Version: 1.1.2
4
4
  Summary: annet
5
5
  Home-page: https://github.com/annetutil/annet
6
6
  License: MIT
@@ -14,7 +14,6 @@ Requires-Dist: jsonpointer>=2.4
14
14
  Requires-Dist: PyYAML>=6.0.1
15
15
  Requires-Dist: Pygments>=2.14.0
16
16
  Requires-Dist: Mako>=1.2.4
17
- Requires-Dist: Jinja2>=3.1.2
18
17
  Requires-Dist: packaging>=23.2
19
18
  Requires-Dist: contextlog>=1.1
20
19
  Requires-Dist: valkit>=0.1.4
@@ -13,7 +13,7 @@ annet/filtering.py,sha256=ZtqxPsKdV9reZoRxtQyBg22BqyMqd-2SotYcxZ-68AQ,903
13
13
  annet/gen.py,sha256=A718tYqIcxAa8tQEdjR6PjQ2ovWBnwPH7STKh38lmFY,33567
14
14
  annet/hardware.py,sha256=_iR28dWiPtt6ZYdk-qg1sxazkSRJE3ukqKB-fFFfQak,1141
15
15
  annet/implicit.py,sha256=G6EwZbrtUp089qRAwh96hminp236-1pJbeKAedoEafg,6056
16
- annet/lib.py,sha256=9DI_uuqREILcLqV7XWPPxiCigMe5QkBRkoOM22e3IR0,4681
16
+ annet/lib.py,sha256=4N4X6jCCrig5rk7Ua4AofrV9zK9jhzkBq57fLsfBJjw,4812
17
17
  annet/output.py,sha256=FYMcWCc43-b51KsCiKnXPZHawhgWNoVtY9gRqw__Ce0,7473
18
18
  annet/parallel.py,sha256=hLkzEht0KhzmzUWDdO4QFYQHzhxs3wPlTA8DxbB2ziw,17160
19
19
  annet/patching.py,sha256=nILbY5oJajN0b1j3f0HEJm05H3HVThnWvB7vDVh7UQw,559
@@ -48,10 +48,10 @@ annet/annlib/diff.py,sha256=MZ6eQAU3cadQp8KaSE6uAYFtcfMDCIe_eNuVROnYkCk,4496
48
48
  annet/annlib/errors.py,sha256=jBcSFzY6Vj-FxR__vqjFm-87AwYQ0xHuAopTirii5AU,287
49
49
  annet/annlib/filter_acl.py,sha256=0w1VF6WcONiTYTQh0yWi6_j9rCTc_kMLAUMr0hbdkNU,7203
50
50
  annet/annlib/jsontools.py,sha256=BS7s4rI8R9c_y3zz0zYl1l6con65oQ0MvfsC1dsXZts,5535
51
- annet/annlib/lib.py,sha256=eJ4hcVuQ6pdYBzLs4YKCHFtq45idOfZCYp92XfF7_QI,15317
51
+ annet/annlib/lib.py,sha256=lxmYrbeablFMhFtvFmADVpVShSFi9TN4gNWaBs_Ygm0,14952
52
52
  annet/annlib/output.py,sha256=_SjJ6G6bejvnTKqNHw6xeio0FT9oO3OIkLaOC3cEga4,7569
53
53
  annet/annlib/patching.py,sha256=IZYW4kydEzBmRi_PZ8Lk0g7hx-sSYl2wjd6lDaI0D4k,21435
54
- annet/annlib/tabparser.py,sha256=dLH6idK7zr6ZDhdIugjdohTHURcEIXQVN7vPIv5qsjA,31208
54
+ annet/annlib/tabparser.py,sha256=9oDBdmZg2St7n7N8LFyXH-y8G3gxZ8FUiJkfDsYmY9U,31950
55
55
  annet/annlib/types.py,sha256=VHU0CBADfYmO0xzB_c5f-mcuU3dUumuJczQnqGlib9M,852
56
56
  annet/annlib/netdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  annet/annlib/netdev/db.py,sha256=fI_u5aya4l61mbYSjj4JwlVfi3s7obt2jqERSuXGRUI,1634
@@ -64,16 +64,16 @@ annet/annlib/rbparser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3h
64
64
  annet/annlib/rbparser/acl.py,sha256=RR8yPt6t96_IiyuKVbeZ-3x32cyhBAT2wC1y99oWBO8,3931
65
65
  annet/annlib/rbparser/deploying.py,sha256=ACT8QNhDAhJx3ZKuGh2nYBOrpdka2qEKuLDxvQAGKLk,1649
66
66
  annet/annlib/rbparser/ordering.py,sha256=SmN_22pIJSIkmyT1-HSjWsqid7UJ0DgkqyQu7IO3bS4,2142
67
- annet/annlib/rbparser/platform.py,sha256=Q9HtqmhyzV3JK_236_4LjC2wgp5fgxY6seDfWYl1oHU,1558
67
+ annet/annlib/rbparser/platform.py,sha256=65-r9mboRA3gaz9DRkSwPCdCRQneItqxppdMB6zf7pI,1560
68
68
  annet/annlib/rbparser/syntax.py,sha256=iZ7Y-4QQBw4L3UtjEh54qisiRDhobl7HZxFNdP8mi54,3577
69
69
  annet/annlib/rulebook/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
70
70
  annet/annlib/rulebook/common.py,sha256=hqwmmNofm5q2f-hV2usMY-IPMeiANLth28tZcRBYJTw,16640
71
- annet/api/__init__.py,sha256=gYkfSZRFo9ahkYwbyjOekS98QWEClvggM7ZoGSD0LGY,35081
71
+ annet/api/__init__.py,sha256=oj6n0hwdxEbv7EoqAQUA56413BddSlIXNR_pUDTb8fY,35054
72
72
  annet/configs/context.yml,sha256=RVLrKLIHpCty7AGwOnmqf7Uu0iZQCn-AjYhophDJer8,259
73
73
  annet/configs/logging.yaml,sha256=EUagfir99QqA73Scc3k7sfQccbU3E1SvEQdyhLFtCl4,997
74
74
  annet/generators/__init__.py,sha256=rVHHDTPKHPZsml1eNEAj3o-8RweFTN8J7LX3tKMXdIY,16402
75
75
  annet/generators/base.py,sha256=rgQLcQBPZm4ecbKmRhVOpBR-GFJAiVfdb_y5f2-LUR8,3670
76
- annet/generators/entire.py,sha256=7WySkVaXNT3ZAiHcQ0JUKdlhGJAN8cNUxF6c7ilYnO8,2928
76
+ annet/generators/entire.py,sha256=Oe7d0VuIn2sLcOKuRVQW9uR8Vuirg0edekFMSZCMnI4,2786
77
77
  annet/generators/exceptions.py,sha256=GPXTBgn2xZ3Ev_bdOPlfCLGRC1kQHe_dEq88S-uyi5s,151
78
78
  annet/generators/jsonfragment.py,sha256=s7zOjX6JR43sIA9wse13GEPU06aeOa75uiA8WBOVDa8,4207
79
79
  annet/generators/partial.py,sha256=XI01KDA--XwjSEU33SOQCCJZRXFq5boRz1uJA8lVA1g,3502
@@ -131,7 +131,7 @@ annet/rulebook/huawei/bgp.py,sha256=dN8T3-44ggGEapt4u4sT3bTn_dsoCbS5qdNeSQ8LSTs,
131
131
  annet/rulebook/huawei/iface.py,sha256=DvLtQ7tfbDQWFmIYV4lxfih13Tdrt24L4-ZS29mCkuc,1126
132
132
  annet/rulebook/huawei/misc.py,sha256=Rpwhtm42IgcueDq4K6VOzN2qORoIDYh42Jb7iWL8AII,14424
133
133
  annet/rulebook/huawei/vlandb.py,sha256=B4BEUhZetjsNNhIJOp9cXtJSAYKMOgQucO8oAxSkRI0,4658
134
- annet/rulebook/juniper/__init__.py,sha256=FnVaO7FHYz7O1ExRE6igYX7OKMUgx5_siC-aoHOLx1s,5380
134
+ annet/rulebook/juniper/__init__.py,sha256=Wl1pb-Ncsmmw1wF_QVf9tq5SbAxhnLmmmkzXCs-rX_o,5369
135
135
  annet/rulebook/nexus/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
136
136
  annet/rulebook/nexus/iface.py,sha256=aeog9iSGT2zZ78tsGlrRcfgfOv7yW3jLwryXqdeplRw,2923
137
137
  annet/rulebook/routeros/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -178,10 +178,10 @@ annet_generators/rpl_example/generator.py,sha256=zndIGfV4ZlTxPgAGYs7bMQvTc_tYScO
178
178
  annet_generators/rpl_example/items.py,sha256=Ez1RF5YhcXNCusBmeApIjRL3rBlMazNZd29Gpw1_IsA,766
179
179
  annet_generators/rpl_example/mesh.py,sha256=z_WgfDZZ4xnyh3cSf75igyH09hGvtexEVwy1gCD_DzA,288
180
180
  annet_generators/rpl_example/route_policy.py,sha256=z6nPb0VDeQtKD1NIg9sFvmUxBD5tVs2frfNIuKdM-5c,2318
181
- annet-1.1.1.dist-info/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
182
- annet-1.1.1.dist-info/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
183
- annet-1.1.1.dist-info/METADATA,sha256=M6zpUiTyWxk5rg5WDIdJBv1XGl86GYa8v9_-4HlG26I,822
184
- annet-1.1.1.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
185
- annet-1.1.1.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
186
- annet-1.1.1.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
187
- annet-1.1.1.dist-info/RECORD,,
181
+ annet-1.1.2.dist-info/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
182
+ annet-1.1.2.dist-info/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
183
+ annet-1.1.2.dist-info/METADATA,sha256=Ngyf7Hi193Mgaifi37xaep8v7fjSM9-KWlIveKaXiEg,793
184
+ annet-1.1.2.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
185
+ annet-1.1.2.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
186
+ annet-1.1.2.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
187
+ annet-1.1.2.dist-info/RECORD,,
File without changes
File without changes
File without changes