omdev 0.0.0.dev80__py3-none-any.whl → 0.0.0.dev82__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 omdev might be problematic. Click here for more details.

omdev/.manifests.json CHANGED
@@ -167,6 +167,18 @@
167
167
  }
168
168
  }
169
169
  },
170
+ {
171
+ "module": ".scripts.slowcat",
172
+ "attr": "_CLI_MODULE",
173
+ "file": "omdev/scripts/slowcat.py",
174
+ "line": 113,
175
+ "value": {
176
+ "$.cli.types.CliModule": {
177
+ "cmd_name": "slowcat",
178
+ "mod_name": "omdev.scripts.slowcat"
179
+ }
180
+ }
181
+ },
170
182
  {
171
183
  "module": ".tools.dockertools",
172
184
  "attr": "_CLI_MODULE",
File without changes
@@ -0,0 +1,23 @@
1
+ """
2
+ https://askubuntu.com/questions/11925/a-command-line-clipboard-copy-and-paste-utility
3
+ """
4
+ import abc
5
+ import subprocess
6
+
7
+
8
+ class Clipboard(abc.ABC):
9
+ @abc.abstractmethod
10
+ def get(self) -> str:
11
+ raise NotImplementedError
12
+
13
+ @abc.abstractmethod
14
+ def put(self, s: str) -> None:
15
+ raise NotImplementedError
16
+
17
+
18
+ class DarwinClipboard(Clipboard):
19
+ def get(self) -> str:
20
+ return subprocess.check_output(['pbpaste']).decode('utf-8')
21
+
22
+ def put(self, s: str) -> None:
23
+ subprocess.run(['pbcopy'], input=s.encode('utf-8'), check=True)
@@ -0,0 +1,229 @@
1
+ # ruff: noqa: N802 N816
2
+ import ctypes as ct
3
+ import ctypes.util
4
+ import dataclasses as dc
5
+ import sys
6
+ import typing as ta
7
+
8
+ from omlish import check
9
+
10
+
11
+ ##
12
+
13
+
14
+ if getattr(sys, 'platform') != 'darwin':
15
+ raise OSError(sys.platform)
16
+
17
+
18
+ ##
19
+ # CoreFoundation
20
+
21
+ cf = ct.cdll.LoadLibrary(check.not_none(ct.util.find_library('CoreFoundation')))
22
+
23
+ #
24
+
25
+ CFArrayRef = ct.c_void_p
26
+ CFDataRef = ct.c_void_p
27
+ CFIndex = ct.c_long
28
+ CFStringEncoding = ct.c_uint32
29
+ CFStringRef = ct.c_void_p
30
+ CFTypeID = ct.c_ulong
31
+
32
+ #
33
+
34
+ cf.CFArrayGetCount.argtypes = [CFArrayRef]
35
+ cf.CFArrayGetCount.restype = CFIndex
36
+
37
+ cf.CFArrayGetValueAtIndex.argtypes = [CFArrayRef, CFIndex]
38
+ cf.CFArrayGetValueAtIndex.restype = CFStringRef
39
+
40
+ cf.CFDataGetBytePtr.argtypes = [CFDataRef]
41
+ cf.CFDataGetBytePtr.restype = ct.POINTER(ct.c_uint8)
42
+
43
+ cf.CFDataGetLength.argtypes = [CFDataRef]
44
+ cf.CFDataGetLength.restype = CFIndex
45
+
46
+ cf.CFGetTypeID.argtypes = [ct.c_void_p]
47
+ cf.CFGetTypeID.restype = CFTypeID
48
+
49
+ cf.CFRelease.argtypes = [ct.c_void_p]
50
+ cf.CFRelease.restype = None
51
+
52
+ cf.CFStringCreateWithCString.argtypes = [ct.c_void_p, ct.c_char_p, ct.c_int32]
53
+ cf.CFStringCreateWithCString.restype = CFStringRef
54
+
55
+ cf.CFStringGetCString.argtypes = [CFStringRef, ct.c_char_p, ct.c_long, ct.c_uint32]
56
+ cf.CFStringGetCString.restype = ct.c_bool
57
+
58
+ cf.CFStringGetLength.argtypes = [CFStringRef]
59
+ cf.CFStringGetLength.restype = CFIndex
60
+
61
+ cf.CFStringGetMaximumSizeForEncoding.argtypes = [CFIndex, CFStringEncoding]
62
+ cf.CFStringGetMaximumSizeForEncoding.restype = CFIndex
63
+
64
+ cf.CFStringGetTypeID.argtypes = []
65
+ cf.CFStringGetTypeID.restype = CFTypeID
66
+
67
+
68
+ ##
69
+ # ApplicationServices
70
+
71
+ aps = ct.cdll.LoadLibrary(check.not_none(ct.util.find_library('ApplicationServices')))
72
+
73
+ #
74
+
75
+ OSStatus = ct.c_int32
76
+
77
+ PasteboardItemID = ct.c_ulong
78
+ PasteboardRef = ct.c_void_p
79
+
80
+ #
81
+
82
+ aps.PasteboardCopyItemFlavorData.argtypes = [PasteboardRef, PasteboardItemID, CFStringRef, ct.POINTER(CFDataRef)]
83
+ aps.PasteboardCopyItemFlavorData.restype = OSStatus
84
+
85
+ aps.PasteboardCopyItemFlavors.argtypes = [PasteboardRef, PasteboardItemID, ct.POINTER(CFArrayRef)]
86
+ aps.PasteboardCopyItemFlavors.restype = OSStatus
87
+
88
+ aps.PasteboardCreate.argtypes = [CFStringRef, ct.POINTER(PasteboardRef)]
89
+ aps.PasteboardCreate.restype = OSStatus
90
+
91
+ aps.PasteboardGetItemCount.argtypes = [PasteboardRef, ct.POINTER(ct.c_ulong)]
92
+ aps.PasteboardGetItemCount.restype = OSStatus
93
+
94
+ aps.PasteboardGetItemIdentifier.argtypes = [PasteboardRef, ct.c_ulong, ct.POINTER(PasteboardItemID)]
95
+ aps.PasteboardGetItemIdentifier.restype = OSStatus
96
+
97
+
98
+ ##
99
+
100
+
101
+ def CFSTR(string):
102
+ return cf.CFStringCreateWithCString(None, string.encode('utf-8'), 0)
103
+
104
+
105
+ kCFStringEncodingUTF8 = 0x08000100
106
+ kPasteboardClipboard = CFSTR('com.apple.pasteboard.clipboard')
107
+
108
+
109
+ def cfstring_to_string(cf_string: CFStringRef) -> str:
110
+ if not cf_string:
111
+ return ''
112
+
113
+ length = cf.CFStringGetLength(cf_string)
114
+ max_size = cf.CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8) + 1
115
+ buffer = ct.create_string_buffer(max_size)
116
+
117
+ if success := cf.CFStringGetCString(cf_string, buffer, max_size, kCFStringEncodingUTF8): # noqa
118
+ return ''
119
+
120
+ return buffer.value.decode('utf-8')
121
+
122
+
123
+ ##
124
+
125
+
126
+ class OsxClipboardError(Exception):
127
+ pass
128
+
129
+
130
+ @dc.dataclass(frozen=True)
131
+ class StatusOsxClipboardError(OsxClipboardError):
132
+ fn: str
133
+ status: int
134
+
135
+
136
+ @dc.dataclass(frozen=True)
137
+ class OsxClipboardItem:
138
+ type: str | None
139
+ data: bytes | None
140
+
141
+
142
+ def get_osx_clipboard_data(
143
+ *,
144
+ types: ta.Container[str | None] | None = None,
145
+ strict: bool = False,
146
+ types_only: bool = False,
147
+ ) -> list[OsxClipboardItem]:
148
+ lst: list[OsxClipboardItem] = []
149
+
150
+ pasteboard = PasteboardRef()
151
+ if status := aps.PasteboardCreate(kPasteboardClipboard, ct.byref(pasteboard)):
152
+ raise StatusOsxClipboardError('PasteboardCreate', status)
153
+
154
+ try:
155
+ item_count = ct.c_ulong(0)
156
+ if status := aps.PasteboardGetItemCount(pasteboard, ct.byref(item_count)):
157
+ raise StatusOsxClipboardError('PasteboardGetItemCount', status)
158
+
159
+ for i in range(1, item_count.value + 1):
160
+ item_id = PasteboardItemID()
161
+ if status := aps.PasteboardGetItemIdentifier(pasteboard, i, ct.byref(item_id)):
162
+ raise StatusOsxClipboardError('PasteboardGetItemIdentifier', status)
163
+
164
+ data_types = CFArrayRef()
165
+ if status := aps.PasteboardCopyItemFlavors(pasteboard, item_id, ct.byref(data_types)):
166
+ raise StatusOsxClipboardError('PasteboardCopyItemFlavors', status)
167
+ if not data_types:
168
+ continue
169
+
170
+ try:
171
+ type_count = cf.CFArrayGetCount(data_types)
172
+ for j in range(type_count):
173
+ data_type = cf.CFArrayGetValueAtIndex(data_types, j)
174
+
175
+ if cf.CFGetTypeID(data_type) == cf.CFStringGetTypeID():
176
+ data_type_str = cfstring_to_string(data_type)
177
+ else:
178
+ data_type_str = None
179
+
180
+ if types is not None and data_type_str not in types:
181
+ continue
182
+
183
+ if types_only:
184
+ lst.append(OsxClipboardItem(
185
+ type=data_type_str,
186
+ data=None,
187
+ ))
188
+ continue
189
+
190
+ data = CFDataRef()
191
+ if status := aps.PasteboardCopyItemFlavorData(pasteboard, item_id, data_type, ct.byref(data)):
192
+ if not strict:
193
+ continue
194
+ raise StatusOsxClipboardError('PasteboardCopyItemFlavorData', status)
195
+ if not data:
196
+ continue
197
+
198
+ try:
199
+ data_size = cf.CFDataGetLength(data)
200
+ data_ptr = cf.CFDataGetBytePtr(data)
201
+ data_bytes = ct.string_at(data_ptr, data_size)
202
+
203
+ lst.append(OsxClipboardItem(
204
+ type=data_type_str,
205
+ data=data_bytes,
206
+ ))
207
+
208
+ finally:
209
+ cf.CFRelease(data)
210
+
211
+ finally:
212
+ cf.CFRelease(data_types)
213
+
214
+ finally:
215
+ cf.CFRelease(pasteboard)
216
+
217
+ return lst
218
+
219
+
220
+ ##
221
+
222
+
223
+ def _main() -> None:
224
+ for i in get_osx_clipboard_data():
225
+ print(i)
226
+
227
+
228
+ if __name__ == '__main__':
229
+ _main()
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/env python3
2
+ # @omlish-script
3
+ import argparse
4
+ import contextlib
5
+ import os
6
+ import random
7
+ import sys
8
+ import time
9
+ import typing as ta
10
+
11
+
12
+ T = ta.TypeVar('T')
13
+
14
+
15
+ DEFAULT_SLEEP_N = 128
16
+ DEFAULT_SLEEP_S = .5
17
+
18
+
19
+ def _main() -> None:
20
+ parser = argparse.ArgumentParser()
21
+
22
+ parser.add_argument('files', nargs='*')
23
+
24
+ parser.add_argument('-b', '--buffer-size', type=int, default=0x4000)
25
+
26
+ parser.add_argument('--initial-sleep')
27
+
28
+ parser.add_argument('--sleep-n')
29
+ parser.add_argument('--sleep-s')
30
+
31
+ args = parser.parse_args()
32
+
33
+ #
34
+
35
+ def parse_range(s: str, d: T) -> tuple[T, T]:
36
+ if not s:
37
+ return d, d
38
+ elif '-' in s:
39
+ l, r = map(type(d), s.split('-'))
40
+ return l, r
41
+ else:
42
+ l = r = type(d)(s) # type: ignore
43
+ return l, r
44
+
45
+ sleep_s_min, sleep_s_max = parse_range(args.sleep_s, DEFAULT_SLEEP_S)
46
+ sleep_n_min, sleep_n_max = parse_range(args.sleep_n, DEFAULT_SLEEP_N)
47
+
48
+ #
49
+
50
+ in_files: list
51
+ if args.files:
52
+ in_files = args.files
53
+ else:
54
+ in_files = [sys.stdin.buffer]
55
+
56
+ #
57
+
58
+ of = sys.stdout.buffer
59
+
60
+ #
61
+
62
+ def next_sleep() -> int:
63
+ if sleep_n_min != sleep_n_max:
64
+ o = random.randint(sleep_n_min, sleep_n_max)
65
+ else:
66
+ o = sleep_n_min
67
+ return n + o
68
+
69
+ def do_sleep() -> None:
70
+ if sleep_s_min != sleep_s_max:
71
+ s = random.uniform(sleep_s_min, sleep_s_max)
72
+ else:
73
+ s = sleep_s_min
74
+ time.sleep(s)
75
+
76
+ #
77
+
78
+ if args.initial_sleep:
79
+ do_sleep()
80
+
81
+ n = 0
82
+ ns = next_sleep()
83
+
84
+ for in_file in in_files:
85
+ with contextlib.ExitStack() as es:
86
+ if isinstance(in_file, str):
87
+ fo = es.enter_context(open(in_file, 'rb'))
88
+ else:
89
+ fo = in_file
90
+
91
+ fd = fo.fileno()
92
+ while buf := os.read(fd, args.buffer_size):
93
+ p = 0
94
+ while p < len(buf):
95
+ c = ns - n
96
+ r = len(buf) - p
97
+ if r >= c:
98
+ r = c
99
+ sleep = True
100
+ else:
101
+ sleep = False
102
+
103
+ of.write(buf[p:p + r])
104
+ of.flush()
105
+
106
+ n += len(buf)
107
+ p += r
108
+ if sleep:
109
+ do_sleep()
110
+ ns = next_sleep()
111
+
112
+
113
+ # @omlish-manifest
114
+ _CLI_MODULE = {'$omdev.cli.types.CliModule': {
115
+ 'cmd_name': 'slowcat',
116
+ 'mod_name': __name__,
117
+ }}
118
+
119
+
120
+ if __name__ == '__main__':
121
+ _main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omdev
3
- Version: 0.0.0.dev80
3
+ Version: 0.0.0.dev82
4
4
  Summary: omdev
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -12,7 +12,7 @@ Classifier: Operating System :: OS Independent
12
12
  Classifier: Operating System :: POSIX
13
13
  Requires-Python: ~=3.12
14
14
  License-File: LICENSE
15
- Requires-Dist: omlish ==0.0.0.dev80
15
+ Requires-Dist: omlish ==0.0.0.dev82
16
16
  Provides-Extra: all
17
17
  Requires-Dist: black ~=24.10 ; extra == 'all'
18
18
  Requires-Dist: pycparser ~=2.22 ; extra == 'all'
@@ -1,4 +1,4 @@
1
- omdev/.manifests.json,sha256=TmB_ctSLXsOq5UGeoiGLy5FoI490OCjT2Q2kRWyWG9g,5993
1
+ omdev/.manifests.json,sha256=eAMErpBPPY0YM3fBzmtDzhtOO1SEvG3iYBf2jZi3LNU,6257
2
2
  omdev/__about__.py,sha256=do_MjpnIpB_DX4GL4VV9gFQzs6bkoyDIYu29yB3rYxw,1131
3
3
  omdev/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omdev/bracepy.py,sha256=I8EdqtDvxzAi3I8TuMEW-RBfwXfqKbwp06CfOdj3L1o,2743
@@ -66,6 +66,9 @@ omdev/cli/install.py,sha256=C-W171YlIHt4Cfok-nWSMbHwWhqF_PFqq2HixFttYx8,4460
66
66
  omdev/cli/main.py,sha256=nD3bW3MkI0KuDSLpX_PTnl-lBnm4hIxVqczvvMHtupo,7058
67
67
  omdev/cli/managers.py,sha256=BV98_n30Jj63OJrFgRoVZRfICxMLXEZKoEn4rMj9LV4,1160
68
68
  omdev/cli/types.py,sha256=bqKw9SbtBtAip2vF9v4khh0CqKG6LBr6n9VzWBz7AJE,474
69
+ omdev/clipboard/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
70
+ omdev/clipboard/clipboard.py,sha256=CmnozkRljJ9UQDHLfCS8wKU0Xg-HfbsAkagAfMEias0,567
71
+ omdev/clipboard/darwin.py,sha256=AE4oYrDXTV0uBgZ-8pWxtqXes3k0IL2pxrJN8WjK1C4,6370
69
72
  omdev/interp/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
70
73
  omdev/interp/__main__.py,sha256=GMCqeGYltgt5dlJzHxY9gqisa8cRkrPfmZYuZnjg4WI,162
71
74
  omdev/interp/cli.py,sha256=sh7PZQoLletUViw1Y9OXNr9ekyNZ6YyxYuOQ_n9hyqU,2072
@@ -109,6 +112,7 @@ omdev/scripts/exectime.py,sha256=dBdn3KV2jR6tCrzGvb9dTl2uGe2vNpLxmHMtExmnaiM,410
109
112
  omdev/scripts/importtrace.py,sha256=Jbo3Yk2RAbE8_tJ97iTcVNpoxCJxrRb2tl1W_CV3NG0,14067
110
113
  omdev/scripts/interp.py,sha256=2poCQ_45tO0-X16KeoxiAyuTfltSjnPETejlYEm9VY4,71527
111
114
  omdev/scripts/pyproject.py,sha256=wtmF5ji8fHw2qzc1aEve09Ozv0ncuZmTQ8IbKCJVAQ0,158223
115
+ omdev/scripts/slowcat.py,sha256=Rglbg0TZ6GmcJgePxN2Bq9JQChZyvQK_qExOYWajaYE,2601
112
116
  omdev/toml/__init__.py,sha256=Y3l4WY4JRi2uLG6kgbGp93fuGfkxkKwZDvhsa0Rwgtk,15
113
117
  omdev/toml/parser.py,sha256=84bn09uhYHwQGyfww6Rw6y1RxPAE_HDltODOSakcqDM,29186
114
118
  omdev/toml/writer.py,sha256=lk3on3YXVbWuLJa-xsOzOhs1bBAT1vXqw4mBbluZl_w,3040
@@ -122,9 +126,9 @@ omdev/tools/piptools.py,sha256=-jR5q3w4sHqntxCLExFCBNIARB788FUsAbJ62PK2sBU,2774
122
126
  omdev/tools/proftools.py,sha256=8ZU9x_Dq8eT2ZFwU9sJpDIvxcIn9qBc8y2ELKPb5e5M,1382
123
127
  omdev/tools/rsttool.py,sha256=suwsfseUf8GH8rYmYygTUdif-Jk_bX1g9fYRLXaKkmM,1340
124
128
  omdev/tools/sqlrepl.py,sha256=tmFZh80-xsGM62dyQ7_UGLebChrj7IHbIPYBWDJMgVk,5741
125
- omdev-0.0.0.dev80.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
126
- omdev-0.0.0.dev80.dist-info/METADATA,sha256=68sUTkl9Uc5f4dvq8nA5q3OQ7eDcDDh0MPClMBFBAps,1492
127
- omdev-0.0.0.dev80.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
128
- omdev-0.0.0.dev80.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
129
- omdev-0.0.0.dev80.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
130
- omdev-0.0.0.dev80.dist-info/RECORD,,
129
+ omdev-0.0.0.dev82.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
130
+ omdev-0.0.0.dev82.dist-info/METADATA,sha256=D6gJ4sHSoH-ucg-IsG2pk8Ft_XYv1bhTxObxFAdrLIU,1492
131
+ omdev-0.0.0.dev82.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
132
+ omdev-0.0.0.dev82.dist-info/entry_points.txt,sha256=dHLXFmq5D9B8qUyhRtFqTGWGxlbx3t5ejedjrnXNYLU,33
133
+ omdev-0.0.0.dev82.dist-info/top_level.txt,sha256=1nr7j30fEWgLYHW3lGR9pkdHkb7knv1U1ES1XRNVQ6k,6
134
+ omdev-0.0.0.dev82.dist-info/RECORD,,