omlish 0.0.0.dev153__py3-none-any.whl → 0.0.0.dev155__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.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev153'
2
- __revision__ = '98ab8eed12f9cf5fa241294e648759c21741ad57'
1
+ __version__ = '0.0.0.dev155'
2
+ __revision__ = '7187ecad3907bd95f19a85608e9cbd7b9a103920'
3
3
 
4
4
 
5
5
  #
@@ -0,0 +1 @@
1
+ # @omlish-lite
@@ -2,6 +2,7 @@
2
2
  import asyncio.base_subprocess
3
3
  import asyncio.subprocess
4
4
  import contextlib
5
+ import dataclasses as dc
5
6
  import functools
6
7
  import logging
7
8
  import subprocess
@@ -177,6 +178,13 @@ async def asyncio_subprocess_communicate(
177
178
  return await AsyncioProcessCommunicator(proc).communicate(input, timeout) # noqa
178
179
 
179
180
 
181
+ @dc.dataclass(frozen=True)
182
+ class AsyncioSubprocessOutput:
183
+ proc: asyncio.subprocess.Process
184
+ stdout: ta.Optional[bytes]
185
+ stderr: ta.Optional[bytes]
186
+
187
+
180
188
  async def asyncio_subprocess_run(
181
189
  *args: str,
182
190
  input: ta.Any = None, # noqa
@@ -184,7 +192,7 @@ async def asyncio_subprocess_run(
184
192
  check: bool = False, # noqa
185
193
  capture_output: ta.Optional[bool] = None,
186
194
  **kwargs: ta.Any,
187
- ) -> ta.Tuple[ta.Optional[bytes], ta.Optional[bytes]]:
195
+ ) -> AsyncioSubprocessOutput:
188
196
  if capture_output:
189
197
  kwargs.setdefault('stdout', subprocess.PIPE)
190
198
  kwargs.setdefault('stderr', subprocess.PIPE)
@@ -203,7 +211,11 @@ async def asyncio_subprocess_run(
203
211
  stderr=stderr,
204
212
  )
205
213
 
206
- return stdout, stderr
214
+ return AsyncioSubprocessOutput(
215
+ proc,
216
+ stdout,
217
+ stderr,
218
+ )
207
219
 
208
220
 
209
221
  ##
@@ -216,7 +228,7 @@ async def asyncio_subprocess_check_call(
216
228
  timeout: ta.Optional[float] = None,
217
229
  **kwargs: ta.Any,
218
230
  ) -> None:
219
- _, _ = await asyncio_subprocess_run(
231
+ await asyncio_subprocess_run(
220
232
  *args,
221
233
  stdout=stdout,
222
234
  input=input,
@@ -232,7 +244,7 @@ async def asyncio_subprocess_check_output(
232
244
  timeout: ta.Optional[float] = None,
233
245
  **kwargs: ta.Any,
234
246
  ) -> bytes:
235
- stdout, stderr = await asyncio_subprocess_run(
247
+ out = await asyncio_subprocess_run(
236
248
  *args,
237
249
  stdout=asyncio.subprocess.PIPE,
238
250
  input=input,
@@ -241,7 +253,7 @@ async def asyncio_subprocess_check_output(
241
253
  **kwargs,
242
254
  )
243
255
 
244
- return check.not_none(stdout)
256
+ return check.not_none(out.stdout)
245
257
 
246
258
 
247
259
  async def asyncio_subprocess_check_output_str(*args: str, **kwargs: ta.Any) -> str:
omlish/lite/check.py CHANGED
@@ -2,8 +2,6 @@
2
2
  """
3
3
  TODO:
4
4
  - def maybe(v: lang.Maybe[T])
5
- - patch / override lite.check ?
6
- - checker interface?
7
5
  """
8
6
  import collections
9
7
  import threading
@@ -61,3 +61,17 @@ def attr_setting(obj, attr, val, *, default=None): # noqa
61
61
  delattr(obj, attr)
62
62
  else:
63
63
  setattr(obj, attr, orig)
64
+
65
+
66
+ ##
67
+
68
+
69
+ class aclosing(contextlib.AbstractAsyncContextManager): # noqa
70
+ def __init__(self, thing):
71
+ self.thing = thing
72
+
73
+ async def __aenter__(self):
74
+ return self.thing
75
+
76
+ async def __aexit__(self, *exc_info):
77
+ await self.thing.aclose()
omlish/lite/marshal.py CHANGED
@@ -1,7 +1,8 @@
1
1
  """
2
2
  TODO:
3
3
  - pickle stdlib objs? have to pin to 3.8 pickle protocol, will be cross-version
4
- - nonstrict toggle
4
+ - namedtuple
5
+ - literals
5
6
  """
6
7
  # ruff: noqa: UP006 UP007
7
8
  import abc
@@ -23,6 +24,7 @@ from .reflect import deep_subclasses
23
24
  from .reflect import get_optional_alias_arg
24
25
  from .reflect import is_generic_alias
25
26
  from .reflect import is_union_alias
27
+ from .strings import snake_case
26
28
 
27
29
 
28
30
  T = ta.TypeVar('T')
@@ -314,14 +316,18 @@ class ObjMarshalerManager:
314
316
  ) -> ObjMarshaler:
315
317
  if isinstance(ty, type):
316
318
  if abc.ABC in ty.__bases__:
317
- return PolymorphicObjMarshaler.of([ # type: ignore
319
+ impls = [ity for ity in deep_subclasses(ty) if abc.ABC not in ity.__bases__] # type: ignore
320
+ if all(ity.__qualname__.endswith(ty.__name__) for ity in impls):
321
+ ins = {ity: snake_case(ity.__qualname__[:-len(ty.__name__)]) for ity in impls}
322
+ else:
323
+ ins = {ity: ity.__qualname__ for ity in impls}
324
+ return PolymorphicObjMarshaler.of([
318
325
  PolymorphicObjMarshaler.Impl(
319
326
  ity,
320
- ity.__qualname__,
327
+ itn,
321
328
  rec(ity),
322
329
  )
323
- for ity in deep_subclasses(ty)
324
- if abc.ABC not in ity.__bases__
330
+ for ity, itn in ins.items()
325
331
  ])
326
332
 
327
333
  if issubclass(ty, enum.Enum):
omlish/os/linux.py ADDED
@@ -0,0 +1,484 @@
1
+ # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
3
+ """
4
+ ➜ ~ cat /etc/os-release
5
+ NAME="Amazon Linux"
6
+ VERSION="2"
7
+ ID="amzn"
8
+ ID_LIKE="centos rhel fedora"
9
+ VERSION_ID="2"
10
+ PRETTY_NAME="Amazon Linux 2"
11
+
12
+ ➜ ~ cat /etc/os-release
13
+ PRETTY_NAME="Ubuntu 22.04.5 LTS"
14
+ NAME="Ubuntu"
15
+ VERSION_ID="22.04"
16
+ VERSION="22.04.5 LTS (Jammy Jellyfish)"
17
+ VERSION_CODENAME=jammy
18
+ ID=ubuntu
19
+ ID_LIKE=debian
20
+ UBUNTU_CODENAME=jammy
21
+
22
+ ➜ omlish git:(master) docker run -i python:3.12 cat /etc/os-release
23
+ PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
24
+ NAME="Debian GNU/Linux"
25
+ VERSION_ID="12"
26
+ VERSION="12 (bookworm)"
27
+ VERSION_CODENAME=bookworm
28
+ ID=debian
29
+ """
30
+ import dataclasses as dc
31
+ import os.path
32
+ import typing as ta
33
+
34
+
35
+ @dc.dataclass(frozen=True)
36
+ class LinuxOsRelease:
37
+ """
38
+ https://man7.org/linux/man-pages/man5/os-release.5.html
39
+ """
40
+
41
+ raw: ta.Mapping[str, str]
42
+
43
+ # General information identifying the operating system
44
+
45
+ @property
46
+ def name(self) -> str:
47
+ """
48
+ A string identifying the operating system, without a version component, and suitable for presentation to the
49
+ user. If not set, a default of "NAME=Linux" may be used.
50
+
51
+ Examples: "NAME=Fedora", "NAME="Debian GNU/Linux"".
52
+ """
53
+
54
+ return self.raw['NAME']
55
+
56
+ @property
57
+ def id(self) -> str:
58
+ """
59
+ A lower-case string (no spaces or other characters outside of 0-9, a-z, ".", "_" and "-") identifying the
60
+ operating system, excluding any version information and suitable for processing by scripts or usage in generated
61
+ filenames. If not set, a default of "ID=linux" may be used. Note that even though this string may not include
62
+ characters that require shell quoting, quoting may nevertheless be used.
63
+
64
+ Examples: "ID=fedora", "ID=debian".
65
+ """
66
+
67
+ return self.raw['ID']
68
+
69
+ @property
70
+ def id_like(self) -> str:
71
+ """
72
+ A space-separated list of operating system identifiers in the same syntax as the ID= setting. It should list
73
+ identifiers of operating systems that are closely related to the local operating system in regards to packaging
74
+ and programming interfaces, for example listing one or more OS identifiers the local OS is a derivative from. An
75
+ OS should generally only list other OS identifiers it itself is a derivative of, and not any OSes that are
76
+ derived from it, though symmetric relationships are possible. Build scripts and similar should check this
77
+ variable if they need to identify the local operating system and the value of ID= is not recognized. Operating
78
+ systems should be listed in order of how closely the local operating system relates to the listed ones, starting
79
+ with the closest. This field is optional.
80
+
81
+ Examples: for an operating system with "ID=centos", an assignment of "ID_LIKE="rhel fedora"" would be
82
+ appropriate. For an operating system with "ID=ubuntu", an assignment of "ID_LIKE=debian" is appropriate.
83
+ """
84
+
85
+ return self.raw['ID_LIKE']
86
+
87
+ @property
88
+ def pretty_name(self) -> str:
89
+ """
90
+ A pretty operating system name in a format suitable for presentation to the user. May or may not contain a
91
+ release code name or OS version of some kind, as suitable. If not set, a default of "PRETTY_NAME="Linux"" may be
92
+ used
93
+
94
+ Example: "PRETTY_NAME="Fedora 17 (Beefy Miracle)"".
95
+ """
96
+
97
+ return self.raw['PRETTY_NAME']
98
+
99
+ @property
100
+ def cpe_name(self) -> str:
101
+ """
102
+ A CPE name for the operating system, in URI binding syntax, following the Common Platform Enumeration
103
+ Specification[4] as proposed by the NIST. This field is optional.
104
+
105
+ Example: "CPE_NAME="cpe:/o:fedoraproject:fedora:17""
106
+ """
107
+
108
+ return self.raw['CPE_NAME']
109
+
110
+ @property
111
+ def variant(self) -> str:
112
+ """
113
+ A string identifying a specific variant or edition of the operating system suitable for presentation to the
114
+ user. This field may be used to inform the user that the configuration of this system is subject to a specific
115
+ divergent set of rules or default configuration settings. This field is optional and may not be implemented on
116
+ all systems.
117
+
118
+ Examples: "VARIANT="Server Edition"", "VARIANT="Smart Refrigerator Edition"".
119
+
120
+ Note: this field is for display purposes only. The VARIANT_ID field should be used for making programmatic
121
+ decisions.
122
+
123
+ Added in version 220.
124
+ """
125
+
126
+ return self.raw['VARIANT']
127
+
128
+ @property
129
+ def variant_id(self) -> str:
130
+ """
131
+ A lower-case string (no spaces or other characters outside of 0-9, a-z, ".", "_" and "-"), identifying a
132
+ specific variant or edition of the operating system. This may be interpreted by other packages in order to
133
+ determine a divergent default configuration. This field is optional and may not be implemented on all systems.
134
+
135
+ Examples: "VARIANT_ID=server", "VARIANT_ID=embedded".
136
+
137
+ Added in version 220.
138
+ """
139
+
140
+ return self.raw['variant_id']
141
+
142
+ # Information about the version of the operating system
143
+
144
+ @property
145
+ def version(self) -> str:
146
+ """
147
+ A string identifying the operating system version, excluding any OS name information, possibly including a
148
+ release code name, and suitable for presentation to the user. This field is optional.
149
+
150
+ Examples: "VERSION=17", "VERSION="17 (Beefy Miracle)"".
151
+ """
152
+
153
+ return self.raw['VERSION']
154
+
155
+ @property
156
+ def version_id(self) -> str:
157
+ """
158
+ A lower-case string (mostly numeric, no spaces or other characters outside of 0-9, a-z, ".", "_" and "-")
159
+ identifying the operating system version, excluding any OS name information or release code name, and suitable
160
+ for processing by scripts or usage in generated filenames. This field is optional.
161
+
162
+ Examples: "VERSION_ID=17", "VERSION_ID=11.04".
163
+ """
164
+
165
+ return self.raw['VERSION_ID']
166
+
167
+ @property
168
+ def version_codename(self) -> str:
169
+ """
170
+ A lower-case string (no spaces or other characters outside of 0-9, a-z, ".", "_" and "-") identifying the
171
+ operating system release code name, excluding any OS name information or release version, and suitable for
172
+ processing by scripts or usage in generated filenames. This field is optional and may not be implemented on all
173
+ systems.
174
+
175
+ Examples: "VERSION_CODENAME=buster", "VERSION_CODENAME=xenial".
176
+
177
+ Added in version 231.
178
+ """
179
+
180
+ return self.raw['VERSION_CODENAME']
181
+
182
+ @property
183
+ def build_id(self) -> str:
184
+ """
185
+ A string uniquely identifying the system image originally used as the installation base. In most cases,
186
+ VERSION_ID or IMAGE_ID+IMAGE_VERSION are updated when the entire system image is replaced during an update.
187
+ BUILD_ID may be used in distributions where the original installation image version is important: VERSION_ID
188
+ would change during incremental system updates, but BUILD_ID would not. This field is optional.
189
+
190
+ Examples: "BUILD_ID="2013-03-20.3"", "BUILD_ID=201303203".
191
+
192
+ Added in version 200.
193
+ """
194
+
195
+ return self.raw['BUILD_ID']
196
+
197
+ @property
198
+ def image_id(self) -> str:
199
+ """
200
+ A lower-case string (no spaces or other characters outside of 0-9, a-z, ".", "_" and "-"), identifying a
201
+ specific image of the operating system. This is supposed to be used for environments where OS images are
202
+ prepared, built, shipped and updated as comprehensive, consistent OS images. This field is optional and may not
203
+ be implemented on all systems, in particularly not on those that are not managed via images but put together and
204
+ updated from individual packages and on the local system.
205
+
206
+ Examples: "IMAGE_ID=vendorx-cashier-system", "IMAGE_ID=netbook-image".
207
+
208
+ Added in version 249.
209
+ """
210
+
211
+ return self.raw['IMAGE_ID']
212
+
213
+ @property
214
+ def image_version(self) -> str:
215
+ """
216
+ A lower-case string (mostly numeric, no spaces or other characters outside of 0-9, a-z, ".", "_" and "-")
217
+ identifying the OS image version. This is supposed to be used together with IMAGE_ID described above, to discern
218
+ different versions of the same image.
219
+
220
+ Examples: "IMAGE_VERSION=33", "IMAGE_VERSION=47.1rc1".
221
+
222
+ Added in version 249.
223
+ """
224
+
225
+ return self.raw['IMAGE_VERSION']
226
+
227
+ # To summarize: if the image updates are built and shipped as comprehensive units, IMAGE_ID+IMAGE_VERSION is the
228
+ # best fit. Otherwise, if updates eventually completely replace previously installed contents, as in a typical
229
+ # binary distribution, VERSION_ID should be used to identify major releases of the operating system. BUILD_ID may
230
+ # be used instead or in addition to VERSION_ID when the original system image version is important.
231
+
232
+ #
233
+
234
+ # Presentation information and links
235
+
236
+ # Links to resources on the Internet related to the operating system. HOME_URL= should refer to the homepage of the
237
+ # operating system, or alternatively some homepage of the specific version of the operating system.
238
+ # DOCUMENTATION_URL= should refer to the main documentation page for this operating system. SUPPORT_URL= should
239
+ # refer to the main support page for the operating system, if there is any. This is primarily intended for operating
240
+ # systems which vendors provide support for. BUG_REPORT_URL= should refer to the main bug reporting page for the
241
+ # operating system, if there is any. This is primarily intended for operating systems that rely on community QA.
242
+ # PRIVACY_POLICY_URL= should refer to the main privacy policy page for the operating system, if there is any. These
243
+ # settings are optional, and providing only some of these settings is common. These URLs are intended to be exposed
244
+ # in "About this system" UIs behind links with captions such as "About this Operating System", "Obtain Support",
245
+ # "Report a Bug", or "Privacy Policy". The values should be in RFC3986 format[5], and should be "http:" or "https:"
246
+ # URLs, and possibly "mailto:" or "tel:". Only one URL shall be listed in each setting. If multiple resources need
247
+ # to be referenced, it is recommended to provide an online landing page linking all available resources.
248
+
249
+ # Examples: "HOME_URL="https://fedoraproject.org/"", "BUG_REPORT_URL="https://bugzilla.redhat.com/"".
250
+
251
+ @property
252
+ def home_url(self) -> str:
253
+ return self.raw['HOME_URL']
254
+
255
+ @property
256
+ def documentation_url(self) -> str:
257
+ return self.raw['DOCUMENTATION_URL']
258
+
259
+ @property
260
+ def support_url(self) -> str:
261
+ return self.raw['SUPPORT_URL']
262
+
263
+ @property
264
+ def bug_report_url(self) -> str:
265
+ return self.raw['BUG_REPORT_URL']
266
+
267
+ @property
268
+ def privacy_policy_url(self) -> str:
269
+ return self.raw['PRIVACY_POLICY_URL']
270
+
271
+ @property
272
+ def support_end(self) -> str:
273
+ """
274
+ The date at which support for this version of the OS ends. (What exactly "lack of support" means varies between
275
+ vendors, but generally users should assume that updates, including security fixes, will not be provided.) The
276
+ value is a date in the ISO 8601 format "YYYY-MM-DD", and specifies the first day on which support is not
277
+ provided.
278
+
279
+ For example, "SUPPORT_END=2001-01-01" means that the system was supported until the end of the last day of the
280
+ previous millennium.
281
+
282
+ Added in version 252.
283
+ """
284
+
285
+ return self.raw['SUPPORT_END']
286
+
287
+ @property
288
+ def logo(self) -> str:
289
+ """
290
+ A string, specifying the name of an icon as defined by freedesktop.org Icon Theme Specification[6]. This can be
291
+ used by graphical applications to display an operating system's or distributor's logo. This field is optional
292
+ and may not necessarily be implemented on all systems.
293
+
294
+ Examples: "LOGO=fedora-logo", "LOGO=distributor-logo-opensuse"
295
+
296
+ Added in version 240.
297
+ """
298
+
299
+ return self.raw['LOGO']
300
+
301
+ @property
302
+ def ansi_color(self) -> str:
303
+ """
304
+ A suggested presentation color when showing the OS name on the console. This should be specified as string
305
+ suitable for inclusion in the ESC [ m ANSI/ECMA-48 escape code for setting graphical rendition. This field is
306
+ optional.
307
+
308
+ Examples: "ANSI_COLOR="0;31"" for red, "ANSI_COLOR="1;34"" for light blue, or "ANSI_COLOR="0;38;2;60;110;180""
309
+ for Fedora blue.
310
+ """
311
+
312
+ return self.raw['ANSI_COLOR']
313
+
314
+ @property
315
+ def vendor_name(self) -> str:
316
+ """
317
+ The name of the OS vendor. This is the name of the organization or company which produces the OS. This field is
318
+ optional.
319
+
320
+ This name is intended to be exposed in "About this system" UIs or software update UIs when needed to distinguish
321
+ the OS vendor from the OS itself. It is intended to be human readable.
322
+
323
+ Examples: "VENDOR_NAME="Fedora Project"" for Fedora Linux, "VENDOR_NAME="Canonical"" for Ubuntu.
324
+
325
+ Added in version 254.
326
+ """
327
+
328
+ return self.raw['VENDOR_NAME']
329
+
330
+ @property
331
+ def vendor_url(self) -> str:
332
+ """
333
+ The homepage of the OS vendor. This field is optional. The VENDOR_NAME= field should be set if this one is,
334
+ although clients must be robust against either field not being set.
335
+
336
+ The value should be in RFC3986 format[5], and should be "http:" or "https:" URLs. Only one URL shall be listed
337
+ in the setting.
338
+
339
+ Examples: "VENDOR_URL="https://fedoraproject.org/"", "VENDOR_URL="https://canonical.com/"".
340
+
341
+ Added in version 254.
342
+ """
343
+
344
+ return self.raw['VENDOR_URL']
345
+
346
+ # Distribution-level defaults and metadata
347
+
348
+ @property
349
+ def default_hostname(self) -> str:
350
+ """
351
+ A string specifying the hostname if hostname(5) is not present and no other configuration source specifies the
352
+ hostname. Must be either a single DNS label (a string composed of 7-bit ASCII lower-case characters and no
353
+ spaces or dots, limited to the format allowed for DNS domain name labels), or a sequence of such labels
354
+ separated by single dots that forms a valid DNS FQDN. The hostname must be at most 64 characters, which is a
355
+ Linux limitation (DNS allows longer names).
356
+
357
+ See org.freedesktop.hostname1(5) for a description of how systemd-hostnamed.service(8) determines the fallback
358
+ hostname.
359
+
360
+ Added in version 248.
361
+ """
362
+
363
+ return self.raw['DEFAULT_HOSTNAME']
364
+
365
+ @property
366
+ def architecture(self) -> str:
367
+ """
368
+ A string that specifies which CPU architecture the userspace binaries require. The architecture identifiers are
369
+ the same as for ConditionArchitecture= described in systemd.unit(5). The field is optional and should only be
370
+ used when just single architecture is supported. It may provide redundant information when used in a GPT
371
+ partition with a GUID type that already encodes the architecture. If this is not the case, the architecture
372
+ should be specified in e.g., an extension image, to prevent an incompatible host from loading it.
373
+
374
+ Added in version 252.
375
+ """
376
+
377
+ return self.raw['ARCHITECTURE']
378
+
379
+ @property
380
+ def sysext_level(self) -> str:
381
+ """
382
+ A lower-case string (mostly numeric, no spaces or other characters outside of 0-9, a-z, ".", "_" and "-")
383
+ identifying the operating system extensions support level, to indicate which extension images are supported. See
384
+ /usr/lib/extension-release.d/extension-release.IMAGE, initrd[2] and systemd-sysext(8)) for more information.
385
+
386
+ Examples: "SYSEXT_LEVEL=2", "SYSEXT_LEVEL=15.14".
387
+
388
+ Added in version 248.
389
+ """
390
+
391
+ return self.raw['SYSEXT_LEVEL']
392
+
393
+ @property
394
+ def confext_level(self) -> str:
395
+ """
396
+ Semantically the same as SYSEXT_LEVEL= but for confext images. See
397
+ /etc/extension-release.d/extension-release.IMAGE for more information.
398
+
399
+ Examples: "CONFEXT_LEVEL=2", "CONFEXT_LEVEL=15.14".
400
+
401
+ Added in version 254.
402
+ """
403
+
404
+ return self.raw['CONFEXT_LEVEL']
405
+
406
+ @property
407
+ def sysext_scope(self) -> str:
408
+ """
409
+ Takes a space-separated list of one or more of the strings "system", "initrd" and "portable". This field is only
410
+ supported in extension-release.d/ files and indicates what environments the system extension is applicable to:
411
+ i.e. to regular systems, to initrds, or to portable service images. If unspecified, "SYSEXT_SCOPE=system
412
+ portable" is implied, i.e. any system extension without this field is applicable to regular systems and to
413
+ portable service environments, but not to initrd environments.
414
+
415
+ Added in version 250.
416
+ """
417
+
418
+ return self.raw['SYSEXT_SCOPE']
419
+
420
+ @property
421
+ def confext_scope(self) -> str:
422
+ """
423
+ Semantically the same as SYSEXT_SCOPE= but for confext images.
424
+
425
+ Added in version 254.
426
+ """
427
+
428
+ return self.raw['CONFEXT_SCOPE']
429
+
430
+ @property
431
+ def portable_prefixes(self) -> str:
432
+ """
433
+ Takes a space-separated list of one or more valid prefix match strings for the Portable Services[3] logic. This
434
+ field serves two purposes: it is informational, identifying portable service images as such (and thus allowing
435
+ them to be distinguished from other OS images, such as bootable system images). It is also used when a portable
436
+ service image is attached: the specified or implied portable service prefix is checked against the list
437
+ specified here, to enforce restrictions how images may be attached to a system.
438
+
439
+ Added in version 250.
440
+ """
441
+
442
+ return self.raw['PORTABLE_PREFIXES']
443
+
444
+ #
445
+
446
+ DEFAULT_PATHS: ta.ClassVar[ta.Sequence[str]] = [
447
+ '/etc/os-release',
448
+ '/usr/lib/os-release',
449
+ ]
450
+
451
+ @classmethod
452
+ def read(cls, *paths: str) -> ta.Optional['LinuxOsRelease']:
453
+ for fp in (paths or cls.DEFAULT_PATHS):
454
+ if not os.path.isfile(fp):
455
+ continue
456
+ with open(fp) as f:
457
+ src = f.read()
458
+ break
459
+ else:
460
+ return None
461
+
462
+ raw = cls._parse_os_release(src)
463
+
464
+ return cls(raw)
465
+
466
+ @classmethod
467
+ def _parse_os_release(cls, src: str) -> ta.Mapping[str, str]:
468
+ dct: ta.Dict[str, str] = {}
469
+
470
+ for l in src.splitlines():
471
+ if not (l := l.strip()):
472
+ continue
473
+ if l.startswith('#') or '=' not in l:
474
+ continue
475
+
476
+ k, _, v = l.partition('=')
477
+ if k.startswith('"'):
478
+ k = k[1:-1]
479
+ if v.startswith('"'):
480
+ v = v[1:-1]
481
+
482
+ dct[k] = v
483
+
484
+ return dct
omlish/term.py CHANGED
@@ -172,48 +172,63 @@ def _clamp_ofs(v: int, hi: int, ofs: int) -> str:
172
172
 
173
173
  FG8 = ControlSequence(
174
174
  lambda n: CSI + '38;5;' + str(n) + 'm',
175
- '8-Bit Foreground Color')
175
+ '8-Bit Foreground Color',
176
+ )
176
177
  FG8_STANDARD = ControlSequence(
177
178
  lambda n: CSI + '38;5;' + _clamp_ofs(n, 8, 0) + 'm',
178
- '8-Bit Foreground Color (Standard)')
179
+ '8-Bit Foreground Color (Standard)',
180
+ )
179
181
  FG8_HIGH_INTENSITY = ControlSequence(
180
182
  lambda n: CSI + '38;5;' + _clamp_ofs(n, 8, 8) + 'm',
181
- '8-Bit Foreground Color (High Intensity)')
183
+ '8-Bit Foreground Color (High Intensity)',
184
+ )
182
185
  FG8_216 = ControlSequence(
183
186
  lambda n: CSI + '38;5;' + _clamp_ofs(n, 216, 16) + 'm',
184
- '8-Bit Foreground Color (High Intensity)')
187
+ '8-Bit Foreground Color (High Intensity)',
188
+ )
185
189
  FG8_GRAYSCALE = ControlSequence(
186
190
  lambda n: CSI + '38;5;' + _clamp_ofs(n, 24, 232) + 'm',
187
- '8-Bit Foreground Color (Grayscale)')
191
+ '8-Bit Foreground Color (Grayscale)',
192
+ )
188
193
  FG8_RGB = ControlSequence(
189
194
  lambda r, g, b: CSI + '38;5;' + str(36 * r + 6 * g + b) + 'm',
190
- '8-Bit Foreground Color (RGB)')
195
+ '8-Bit Foreground Color (RGB)',
196
+ )
191
197
 
192
198
  BG8 = ControlSequence(
193
199
  lambda n: CSI + '48;5;' + str(n) + 'm',
194
- '8-Bit Background Color')
200
+ '8-Bit Background Color',
201
+ )
195
202
  BG8_STANDARD = ControlSequence(
196
203
  lambda n: CSI + '48;5;' + _clamp_ofs(n, 8, 0) + 'm',
197
- '8-Bit Background Color (Standard)')
204
+ '8-Bit Background Color (Standard)',
205
+ )
198
206
  BG8_HIGH_INTENSITY = ControlSequence(
199
207
  lambda n: CSI + '48;5;' + _clamp_ofs(n, 8, 8) + 'm',
200
- '8-Bit Background Color (High Intensity)')
208
+ '8-Bit Background Color (High Intensity)',
209
+ )
201
210
  BG8_216 = ControlSequence(
202
211
  lambda n: CSI + '48;5;' + _clamp_ofs(n, 216, 16) + 'm',
203
- '8-Bit Background Color (High Intensity)')
212
+ '8-Bit Background Color (High Intensity)',
213
+ )
204
214
  BG8_GRAYSCALE = ControlSequence(
205
215
  lambda n: CSI + '48;5;' + _clamp_ofs(n, 24, 232) + 'm',
206
- '8-Bit Background Color (Grayscale)')
216
+ '8-Bit Background Color (Grayscale)',
217
+ )
207
218
  BG8_RGB = ControlSequence(
208
219
  lambda r, g, b: CSI + '48;5;' + str(36 * r + 6 * g + b) + 'm',
209
- '8-Bit Background Color (RGB)')
220
+ '8-Bit Background Color (RGB)',
221
+ )
210
222
 
211
223
  FG24_RGB = ControlSequence(
212
224
  lambda r, g, b: CSI + '38;2;' + str(r) + ';' + str(g) + ';' + str(b) + 'm',
213
- '24-Bit Foreground Color (RGB)')
225
+ '24-Bit Foreground Color (RGB)',
226
+ )
214
227
  BG24_RGB = ControlSequence(
215
228
  lambda r, g, b: CSI + '48;2;' + str(r) + ';' + str(g) + ';' + str(b) + 'm',
216
- '24-Bit Background Color (RGB)')
229
+ '24-Bit Background Color (RGB)',
230
+ )
231
+
217
232
 
218
233
  ##
219
234
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omlish
3
- Version: 0.0.0.dev153
3
+ Version: 0.0.0.dev155
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=RX24SRc6DCEg77PUVnaXOKCWa5TF_c9RQJdGIf7gl9c,1135
2
- omlish/__about__.py,sha256=b3YvnZv7CD-eAnC8X8P0BTKSk3UmrhaMttytZs3utcs,3409
2
+ omlish/__about__.py,sha256=TTGSgQiaw8RlS3TEaNm9PX3osMhDFRCTCzGdQmtU5dQ,3409
3
3
  omlish/__init__.py,sha256=SsyiITTuK0v74XpKV8dqNaCmjOlan1JZKrHQv5rWKPA,253
4
4
  omlish/c3.py,sha256=ubu7lHwss5V4UznbejAI0qXhXahrU01MysuHOZI9C4U,8116
5
5
  omlish/cached.py,sha256=UI-XTFBwA6YXWJJJeBn-WkwBkfzDjLBBaZf4nIJA9y0,510
@@ -12,7 +12,7 @@ omlish/libc.py,sha256=8r7Ejyhttk9ruCfBkxNTrlzir5WPbDE2vmY7VPlceMA,15362
12
12
  omlish/multiprocessing.py,sha256=QZT4C7I-uThCAjaEY3xgUYb-5GagUlnE4etN01LDyU4,5186
13
13
  omlish/runmodule.py,sha256=PWvuAaJ9wQQn6bx9ftEL3_d04DyotNn8dR_twm2pgw0,700
14
14
  omlish/sync.py,sha256=QJ79kxmIqDP9SeHDoZAf--DpFIhDQe1jACy8H4N0yZI,2928
15
- omlish/term.py,sha256=BXJSE9gfM461bh4z_gysx0oavZSafqcQs5ayZK-kTUo,9284
15
+ omlish/term.py,sha256=EVHm3lEEIc9hT4f8BPmzbNUwlqZ8nrRpCwyQMN7LBm0,9313
16
16
  omlish/antlr/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  omlish/antlr/_runtime/BufferedTokenStream.py,sha256=1Rnhm62MZCWSuQeRs7lRUbdtdyo7Gyg8r4gAETjv-cE,10793
18
18
  omlish/antlr/_runtime/CommonTokenFactory.py,sha256=QrSSTH0gYhOpPeOHqrs6-2g1PGcgYvjhR6J6pynKLOc,2147
@@ -288,7 +288,7 @@ omlish/io/compress/lzma.py,sha256=8qxi7TniLN00LyJIJLyp6W7UUU50JBaPxxoXYg2j2XQ,22
288
288
  omlish/io/compress/snappy.py,sha256=kCPgZ7PTBAxAnmYzpQCq4HKUIJ4APeAEXsU3Vg2CaDU,411
289
289
  omlish/io/compress/zlib.py,sha256=MtnVGfzDlRU1LPl2J8Sa3wwgqnTVBx2uclZygWpH9xI,2115
290
290
  omlish/io/compress/zstd.py,sha256=LrYWVHzk-TqWJA_Bnci2i8QOtrqnFFpppLQhLqanDWM,668
291
- omlish/io/fdio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
291
+ omlish/io/fdio/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
292
292
  omlish/io/fdio/corohttp.py,sha256=AdsGyaTT4c0V4eUyhxob8Zm4Ixj936DfpwyyJO2-R8k,3995
293
293
  omlish/io/fdio/handlers.py,sha256=OOQhiazbhNMwxLwyzf8KUQrBQSuHIm-UqAMpXmmHGFQ,1344
294
294
  omlish/io/fdio/kqueue.py,sha256=YgGBQibkAUYODYDiGl7Enjtx1oQsJXuDsBLBXgqlLQw,3832
@@ -334,12 +334,12 @@ omlish/lifecycles/states.py,sha256=zqMOU2ZU-MDNnWuwauM3_anIAiXM8LoBDElDEraptFg,1
334
334
  omlish/lifecycles/transitions.py,sha256=qQtFby-h4VzbvgaUqT2NnbNumlcOx9FVVADP9t83xj4,1939
335
335
  omlish/lite/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
336
336
  omlish/lite/cached.py,sha256=hBW77-F7ZLtFqbLwVrlqaJ4-iFHMQleMWZXaZN1IubA,1308
337
- omlish/lite/check.py,sha256=tAKB99X_oHG3JADUgZXMdPzgN8aNF9UBuJv4WeSgM_A,12877
338
- omlish/lite/contextmanagers.py,sha256=4tKuBYyxn-aI31QowIuClHgpML8JsdzCW3j5ms_-uuY,1418
337
+ omlish/lite/check.py,sha256=KvcO86LqWlh2j4ORaZXRR4FM8fFb7kUkNqq3lTs0Ta0,12821
338
+ omlish/lite/contextmanagers.py,sha256=m9JO--p7L7mSl4cycXysH-1AO27weDKjP3DZG61cwwM,1683
339
339
  omlish/lite/inject.py,sha256=729Qi0TLbQgBtkvx97q1EUMe73VFYA1hu4woXkOTcwM,23572
340
340
  omlish/lite/json.py,sha256=7-02Ny4fq-6YAu5ynvqoijhuYXWpLmfCI19GUeZnb1c,740
341
341
  omlish/lite/logs.py,sha256=1pcGu0ekhVCcLUckLSP16VccnAoprjtl5Vkdfm7y1Wg,6184
342
- omlish/lite/marshal.py,sha256=6dCv_H4MF0BgzQ1XfIn30eE5jr4S96IfDi7anbBFl2c,13485
342
+ omlish/lite/marshal.py,sha256=jbdKjTeumReSKUNNEn-oAyd5Bdy6NK_9_LsPSHpvqRU,13817
343
343
  omlish/lite/maybes.py,sha256=7OlHJ8Q2r4wQ-aRbZSlJY7x0e8gDvufFdlohGEIJ3P4,833
344
344
  omlish/lite/pycharm.py,sha256=pUOJevrPClSqTCEOkQBO11LKX2003tfDcp18a03QFrc,1163
345
345
  omlish/lite/reflect.py,sha256=ad_ya_zZJOQB8HoNjs9yc66R54zgflwJVPJqiBXMzqA,1681
@@ -352,7 +352,7 @@ omlish/lite/strings.py,sha256=QURcE4-1pKVW8eT_5VCJpXaHDWR2dW2pYOChTJnZDiQ,1504
352
352
  omlish/lite/subprocesses.py,sha256=iN-HX44g9uxkZ7HII2Upvkfjp7YK6qQuhPrBqM4Hnp0,4934
353
353
  omlish/lite/typing.py,sha256=U3-JaEnkDSYxK4tsu_MzUn3RP6qALBe5FXQXpD-licE,1090
354
354
  omlish/lite/asyncio/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
355
- omlish/lite/asyncio/subprocesses.py,sha256=FB9PbS17MCE2fvgbSUb30KOg8kiJe37DNioD51T8HOk,8427
355
+ omlish/lite/asyncio/subprocesses.py,sha256=luHARTCKB5qoxwUln1LH_v-z8k7YTkf32b2rgV_qkMg,8634
356
356
  omlish/logs/__init__.py,sha256=FbOyAW-lGH8gyBlSVArwljdYAU6RnwZLI5LwAfuNnrk,438
357
357
  omlish/logs/abc.py,sha256=ho4ABKYMKX-V7g4sp1BByuOLzslYzLlQ0MESmjEpT-o,8005
358
358
  omlish/logs/configs.py,sha256=EE0jlNaXJbGnM7V-y4xS5VwyTBSTzFzc0BYaVjg0JmA,1283
@@ -401,6 +401,7 @@ omlish/os/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
401
401
  omlish/os/deathsig.py,sha256=hk9Yq2kyDdI-cI7OQH7mOfpRbOKzY_TfPKEqgrjVYbA,641
402
402
  omlish/os/files.py,sha256=1tNy1z5I_CgYKA5c6lOfsXc-hknP4tQDbSShdz8HArw,1308
403
403
  omlish/os/journald.py,sha256=2nI8Res1poXkbLc31--MPUlzYMESnCcPUkIxDOCjZW0,3903
404
+ omlish/os/linux.py,sha256=whJ6scwMKSFBdXiVhJW0BCpJV4jOGMr-a_a3Bhwz6Ls,18938
404
405
  omlish/os/pidfile.py,sha256=S4Nbe00oSxckY0qCC9AeTEZe7NSw4eJudnQX7wCXzks,1738
405
406
  omlish/os/sizes.py,sha256=ohkALLvqSqBX4iR-7DMKJ4pfOCRdZXV8htH4QywUNM0,152
406
407
  omlish/reflect/__init__.py,sha256=4-EuCSX1qpEWfScCFzAJv_XghHFu4cXxpxKeBKrosQ4,720
@@ -519,9 +520,9 @@ omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,329
519
520
  omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
520
521
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
521
522
  omlish/text/random.py,sha256=jNWpqiaKjKyTdMXC-pWAsSC10AAP-cmRRPVhm59ZWLk,194
522
- omlish-0.0.0.dev153.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
523
- omlish-0.0.0.dev153.dist-info/METADATA,sha256=NANx-xsYundThAIFYybGp0wnUqq1fd7AhbGDyQ4CJxQ,4264
524
- omlish-0.0.0.dev153.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
525
- omlish-0.0.0.dev153.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
526
- omlish-0.0.0.dev153.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
527
- omlish-0.0.0.dev153.dist-info/RECORD,,
523
+ omlish-0.0.0.dev155.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
524
+ omlish-0.0.0.dev155.dist-info/METADATA,sha256=EZnz0auK1L6Br8TpcHXEE4T5zN79d2pJpORfJEZeFss,4264
525
+ omlish-0.0.0.dev155.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
526
+ omlish-0.0.0.dev155.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
527
+ omlish-0.0.0.dev155.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
528
+ omlish-0.0.0.dev155.dist-info/RECORD,,