moat-kv 0.70.24__py3-none-any.whl → 0.71.6__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.
Files changed (127) hide show
  1. moat/kv/__init__.py +6 -7
  2. moat/kv/_cfg.yaml +5 -8
  3. moat/kv/actor/__init__.py +2 -1
  4. moat/kv/actor/deletor.py +4 -1
  5. moat/kv/auth/__init__.py +12 -13
  6. moat/kv/auth/_test.py +4 -1
  7. moat/kv/auth/password.py +11 -7
  8. moat/kv/backend/mqtt.py +4 -8
  9. moat/kv/client.py +20 -39
  10. moat/kv/code.py +3 -3
  11. moat/kv/command/data.py +4 -3
  12. moat/kv/command/dump/__init__.py +29 -29
  13. moat/kv/command/internal.py +2 -3
  14. moat/kv/command/job.py +1 -2
  15. moat/kv/command/type.py +3 -6
  16. moat/kv/data.py +9 -8
  17. moat/kv/errors.py +16 -8
  18. moat/kv/mock/__init__.py +2 -12
  19. moat/kv/model.py +28 -32
  20. moat/kv/obj/__init__.py +3 -3
  21. moat/kv/obj/command.py +3 -3
  22. moat/kv/runner.py +4 -5
  23. moat/kv/server.py +106 -126
  24. moat/kv/types.py +8 -6
  25. {moat_kv-0.70.24.dist-info → moat_kv-0.71.6.dist-info}/METADATA +7 -6
  26. moat_kv-0.71.6.dist-info/RECORD +47 -0
  27. {moat_kv-0.70.24.dist-info → moat_kv-0.71.6.dist-info}/WHEEL +1 -1
  28. moat_kv-0.71.6.dist-info/licenses/LICENSE +3 -0
  29. moat_kv-0.71.6.dist-info/licenses/LICENSE.APACHE2 +202 -0
  30. moat_kv-0.71.6.dist-info/licenses/LICENSE.MIT +20 -0
  31. moat_kv-0.71.6.dist-info/top_level.txt +1 -0
  32. build/lib/docs/source/conf.py +0 -201
  33. build/lib/examples/pathify.py +0 -45
  34. build/lib/moat/kv/__init__.py +0 -19
  35. build/lib/moat/kv/_cfg.yaml +0 -97
  36. build/lib/moat/kv/_main.py +0 -91
  37. build/lib/moat/kv/actor/__init__.py +0 -98
  38. build/lib/moat/kv/actor/deletor.py +0 -139
  39. build/lib/moat/kv/auth/__init__.py +0 -444
  40. build/lib/moat/kv/auth/_test.py +0 -166
  41. build/lib/moat/kv/auth/password.py +0 -234
  42. build/lib/moat/kv/auth/root.py +0 -58
  43. build/lib/moat/kv/backend/__init__.py +0 -67
  44. build/lib/moat/kv/backend/mqtt.py +0 -74
  45. build/lib/moat/kv/backend/serf.py +0 -45
  46. build/lib/moat/kv/client.py +0 -1025
  47. build/lib/moat/kv/code.py +0 -236
  48. build/lib/moat/kv/codec.py +0 -11
  49. build/lib/moat/kv/command/__init__.py +0 -1
  50. build/lib/moat/kv/command/acl.py +0 -180
  51. build/lib/moat/kv/command/auth.py +0 -261
  52. build/lib/moat/kv/command/code.py +0 -293
  53. build/lib/moat/kv/command/codec.py +0 -186
  54. build/lib/moat/kv/command/data.py +0 -265
  55. build/lib/moat/kv/command/dump/__init__.py +0 -143
  56. build/lib/moat/kv/command/error.py +0 -149
  57. build/lib/moat/kv/command/internal.py +0 -248
  58. build/lib/moat/kv/command/job.py +0 -433
  59. build/lib/moat/kv/command/log.py +0 -53
  60. build/lib/moat/kv/command/server.py +0 -114
  61. build/lib/moat/kv/command/type.py +0 -201
  62. build/lib/moat/kv/config.py +0 -46
  63. build/lib/moat/kv/data.py +0 -216
  64. build/lib/moat/kv/errors.py +0 -561
  65. build/lib/moat/kv/exceptions.py +0 -126
  66. build/lib/moat/kv/mock/__init__.py +0 -101
  67. build/lib/moat/kv/mock/mqtt.py +0 -159
  68. build/lib/moat/kv/mock/serf.py +0 -250
  69. build/lib/moat/kv/mock/tracer.py +0 -63
  70. build/lib/moat/kv/model.py +0 -1069
  71. build/lib/moat/kv/obj/__init__.py +0 -646
  72. build/lib/moat/kv/obj/command.py +0 -241
  73. build/lib/moat/kv/runner.py +0 -1347
  74. build/lib/moat/kv/server.py +0 -2809
  75. build/lib/moat/kv/types.py +0 -513
  76. debian/moat-kv/usr/lib/python3/dist-packages/docs/source/conf.py +0 -201
  77. debian/moat-kv/usr/lib/python3/dist-packages/examples/pathify.py +0 -45
  78. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/__init__.py +0 -19
  79. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/_cfg.yaml +0 -97
  80. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/_main.py +0 -91
  81. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/actor/__init__.py +0 -98
  82. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/actor/deletor.py +0 -139
  83. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/__init__.py +0 -444
  84. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/_test.py +0 -166
  85. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/password.py +0 -234
  86. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/auth/root.py +0 -58
  87. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/backend/__init__.py +0 -67
  88. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/backend/mqtt.py +0 -74
  89. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/backend/serf.py +0 -45
  90. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/client.py +0 -1025
  91. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/code.py +0 -236
  92. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/codec.py +0 -11
  93. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/__init__.py +0 -1
  94. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/acl.py +0 -180
  95. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/auth.py +0 -261
  96. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/code.py +0 -293
  97. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/codec.py +0 -186
  98. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/data.py +0 -265
  99. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/dump/__init__.py +0 -143
  100. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/error.py +0 -149
  101. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/internal.py +0 -248
  102. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/job.py +0 -433
  103. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/log.py +0 -53
  104. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/server.py +0 -114
  105. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/command/type.py +0 -201
  106. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/config.py +0 -46
  107. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/data.py +0 -216
  108. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/errors.py +0 -561
  109. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/exceptions.py +0 -126
  110. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/__init__.py +0 -101
  111. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/mqtt.py +0 -159
  112. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/serf.py +0 -250
  113. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/mock/tracer.py +0 -63
  114. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/model.py +0 -1069
  115. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/obj/__init__.py +0 -646
  116. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/obj/command.py +0 -241
  117. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/runner.py +0 -1347
  118. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/server.py +0 -2809
  119. debian/moat-kv/usr/lib/python3/dist-packages/moat/kv/types.py +0 -513
  120. docs/source/conf.py +0 -201
  121. examples/pathify.py +0 -45
  122. moat/kv/backend/serf.py +0 -45
  123. moat/kv/codec.py +0 -11
  124. moat/kv/mock/serf.py +0 -250
  125. moat_kv-0.70.24.dist-info/RECORD +0 -137
  126. moat_kv-0.70.24.dist-info/top_level.txt +0 -9
  127. {moat_kv-0.70.24.dist-info → moat_kv-0.71.6.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,241 +0,0 @@
1
- # command line interface helpers for objects
2
- from __future__ import annotations
3
-
4
- import logging
5
- import sys
6
-
7
- import asyncclick as click
8
- from moat.util import NotGiven
9
-
10
- logger = logging.getLogger(__name__)
11
-
12
- __all__ = ["std_command"]
13
-
14
-
15
- class _InvSub:
16
- """
17
- This class is a helper for "std_command".
18
- """
19
-
20
- def __init__(
21
- self,
22
- name,
23
- id_name="name",
24
- id_typ=str,
25
- aux=(),
26
- name_cb=None,
27
- id_cb=None,
28
- postproc=None,
29
- apply=None,
30
- short_help=None,
31
- sub_base=None,
32
- sub_name=None,
33
- long_name=None,
34
- prepare=None,
35
- list_recursive=False,
36
- ):
37
- self.name = name
38
- self.id_name = id_name
39
- self.id_typ = id_typ
40
- self.id_cb = id_cb or (lambda _c, _k, x: x)
41
- self.apply = apply or (lambda _c, _t, _x: None)
42
- self.name_cb = name_cb or (lambda _c, _k, x: x)
43
- self.aux = aux
44
- self.short_help = short_help
45
- self.postproc = postproc or (lambda _c, _t, x: None)
46
- self.long_name = long_name or name
47
- self.sub_base = sub_base
48
- self.prepare = prepare
49
- self.list_recursive = list_recursive
50
- if sub_name is NotGiven:
51
- self.sub_name = None
52
- else:
53
- self.sub_name = sub_name or name
54
-
55
- def id_arg(self, proc):
56
- if self.id_name is None:
57
- return proc
58
- return click.argument(self.id_name, type=self.id_typ, callback=self.id_cb, nargs=1)(proc)
59
-
60
- def apply_aux(self, proc):
61
- for t in self.aux:
62
- proc = t(proc)
63
- return proc
64
-
65
-
66
- def std_command(cli, *a, **kw):
67
- """
68
- This procedure builds the interface for an inventory-ish thing.
69
-
70
- Usage::
71
-
72
- @click.group(short_help="Manage computer inventory.")
73
- @click.pass_obj
74
- async def cli(obj):
75
- "Inventorize your computers, networks, and their connections."
76
- obj.inv = await InventoryRoot.as_handler(obj.client)
77
-
78
- std_command(
79
- cli, # from above
80
- "vlan", # subcommand name
81
- "id", # item identifier
82
- int, # item identifier type
83
- aux=( # additional attributes
84
- click.option("-d", "--desc", type=str, default=None, help="Description"),
85
- click.option("-w", "--wlan", type=str, default=None, help="WLAN SSID"),
86
- ),
87
- short_help="Manage VLANs",
88
- )
89
- """
90
- tinv = _InvSub(*a, **kw)
91
- tname = tinv.name
92
- tnname = "n_" + tname
93
-
94
- def this(obj):
95
- # Delayed resolving of the actual thing subhierarchy
96
- if tinv.sub_base:
97
- data = getattr(obj, tinv.sub_base)
98
- else:
99
- data = obj.data
100
- if tinv.sub_name:
101
- return getattr(data, tinv.sub_name)
102
- return data
103
-
104
- @cli.group(
105
- name=tname,
106
- invoke_without_command=True,
107
- short_help=tinv.short_help,
108
- help=f"""\
109
- Manager for {tinv.long_name}s.
110
-
111
- \b
112
- Use '… {tname} -' to list all entries.
113
- Use '… {tname} NAME' to show details of a single entry.
114
- """,
115
- )
116
- @click.argument("name", type=str, nargs=1)
117
- @click.pass_context
118
- async def typ(ctx, name):
119
- obj = ctx.obj
120
- if tinv.prepare is not None:
121
- await tinv.prepare(obj)
122
-
123
- if name == "-":
124
- if ctx.invoked_subcommand is not None:
125
- raise click.BadParameter("The name '-' triggers a list and precludes subcommands.")
126
- cnt = 0
127
- for n in this(obj).all_children if tinv.list_recursive else this(obj):
128
- cnt += 1
129
- print(n, file=obj.stdout)
130
- if not cnt and ctx.obj.debug:
131
- print("no entries", file=sys.stderr)
132
- elif ctx.invoked_subcommand is None:
133
- # Show data from a single entry
134
- n = this(obj).by_name(name)
135
- if n is None:
136
- raise KeyError(name)
137
- cnt = 0
138
- for k in n.ATTRS + getattr(n, "AUX_ATTRS", ()):
139
- v = getattr(n, k, None)
140
- if v is not None:
141
- cnt += 1
142
- if isinstance(v, dict):
143
- v = v.items()
144
- if isinstance(v, type({}.items())): # pylint: disable=W1116
145
- for kk, vv in sorted(v):
146
- if isinstance(vv, (tuple, list)):
147
- if vv:
148
- vv = " ".join(str(x) for x in vv)
149
- else:
150
- vv = "-"
151
- elif isinstance(vv, dict):
152
- vv = " ".join("%s=%s" % (x, y) for x, y in sorted(vv.items()))
153
- print("%s %s %s" % (k, kk, vv), file=obj.stdout)
154
- else:
155
- print("%s %s" % (k, v), file=obj.stdout)
156
- if not cnt and ctx.obj.debug:
157
- print("exists, no data", file=sys.stderr)
158
- else:
159
- obj[tnname] = name
160
- try:
161
- obj[tname] = this(obj).by_name(name)
162
- except KeyError:
163
- obj[tname] = None
164
-
165
- def alloc(obj, name):
166
- # Allocate a new thing
167
- if isinstance(name, (tuple, list)):
168
- n = this(obj).follow(name, create=True)
169
- else:
170
- n = this(obj).allocate(name)
171
- return n
172
-
173
- # This is a hack for groups that take arguments. Doesn't work for
174
- # multiple arguments, but you shouldn't do that anyway.
175
- @typ.command("--help", hidden=True)
176
- @click.pass_context
177
- def help_(ctx): # pylint:disable=unused-variable # oh boy
178
- print(typ.get_help(ctx))
179
-
180
- @typ.command(short_help="Add a " + tinv.long_name)
181
- @tinv.id_arg
182
- @tinv.apply_aux
183
- @click.pass_obj
184
- async def add(obj, **kw):
185
- name = obj[tnname]
186
- if obj[tname] is not None:
187
- raise RuntimeError(f"{name} already exists")
188
- if tinv.id_name:
189
- kw["name"] = name
190
- n = alloc(obj, kw.pop(tinv.id_name))
191
- else:
192
- n = alloc(obj, name)
193
-
194
- await _v_mod(obj, n, **kw)
195
-
196
- add.__doc__ = f"""
197
- Add a {tinv.long_name}
198
- """
199
-
200
- @typ.command("set", short_help="Modify a " + tinv.long_name)
201
- @tinv.apply_aux
202
- @click.pass_obj
203
- async def set_(obj, **kw):
204
- n = obj[tname]
205
- if n is None:
206
- raise KeyError(tname)
207
-
208
- await _v_mod(obj, n, **kw)
209
-
210
- set_.__doc__ = f"""
211
- Modify a {tinv.long_name}
212
- """
213
-
214
- @typ.command(short_help="Delete a " + tinv.long_name)
215
- @click.pass_obj
216
- async def delete(obj, **kw): # pylint: disable=unused-argument,unused-variable
217
- name = obj[tnname]
218
- n = this(obj).by_name(name)
219
- if n is not None:
220
- await n.delete()
221
-
222
- delete.__doc__ = """
223
- Delete a {tinv.long_name}
224
- """
225
-
226
- async def _v_mod(obj, thing, **kw):
227
- tinv.apply(obj, thing, kw)
228
- for k, v in kw.items():
229
- if v:
230
- if v == "-":
231
- v = None
232
- try:
233
- setattr(thing, k, v)
234
- except AttributeError:
235
- if k != "name":
236
- raise AttributeError(k, v) from None
237
- tinv.postproc(obj, thing, kw)
238
- await thing.save()
239
-
240
- # Finally, return the CLI so the user can attach more stuff
241
- return typ