[~] Refactor
This commit is contained in:
parent
1cfc6c52f3
commit
8656b3b985
@ -24,7 +24,10 @@ import tempfile
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from typing import (Literal, Optional, TypedDict, Callable, Generator, TypeAlias, Any,)
|
from typing import (
|
||||||
|
Literal, Optional, TypedDict, Callable, Generator, TypeAlias, Any,
|
||||||
|
cast,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -155,8 +158,8 @@ def intercept_output(
|
|||||||
buffer.clear()
|
buffer.clear()
|
||||||
buffer.append(t3[t3_pos + 1:])
|
buffer.append(t3[t3_pos + 1:])
|
||||||
while len(buffer_lines) > 0:
|
while len(buffer_lines) > 0:
|
||||||
yield dict(
|
yield intercept_output_t.line_res_t(
|
||||||
aggegated=False,
|
aggregated=False,
|
||||||
line=buffer_lines.popleft(),
|
line=buffer_lines.popleft(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -293,6 +296,9 @@ def chrome(
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def raise_not_implemented() -> None:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
def eternal_oom(argv: list[str]) -> None:
|
def eternal_oom(argv: list[str]) -> None:
|
||||||
import signal
|
import signal
|
||||||
import re
|
import re
|
||||||
@ -485,14 +491,24 @@ def eternal_oom(argv: list[str]) -> None:
|
|||||||
|
|
||||||
return columns
|
return columns
|
||||||
|
|
||||||
def pandas_merge(left, right, on):
|
def pandas_merge(
|
||||||
index = {}
|
left: dict[str, list[Any]],
|
||||||
input_data_frames = [
|
right: dict[str, list[Any]],
|
||||||
|
on: str,
|
||||||
|
) -> dict[str, list[Any]]:
|
||||||
|
index : dict[str, dict[Any, list[int]]] = {}
|
||||||
|
|
||||||
|
input_data_frames : list[
|
||||||
|
tuple[
|
||||||
|
str,
|
||||||
|
dict[str, list[Any]]
|
||||||
|
]
|
||||||
|
] = [
|
||||||
('left', left),
|
('left', left),
|
||||||
('right', right),
|
('right', right),
|
||||||
]
|
]
|
||||||
for index_name, data_frame in input_data_frames:
|
for index_name, data_frame in input_data_frames:
|
||||||
current_index = {}
|
current_index: dict[Any, list[int]] = {}
|
||||||
for row_index, value in enumerate(data_frame[on]):
|
for row_index, value in enumerate(data_frame[on]):
|
||||||
if not value in current_index:
|
if not value in current_index:
|
||||||
current_index[value] = []
|
current_index[value] = []
|
||||||
@ -500,7 +516,11 @@ def eternal_oom(argv: list[str]) -> None:
|
|||||||
|
|
||||||
index[index_name] = current_index
|
index[index_name] = current_index
|
||||||
|
|
||||||
merged_data_frame = dict(
|
class MergedDataFrame(TypedDict):
|
||||||
|
header: list[str]
|
||||||
|
columns: dict[str, list[Any]]
|
||||||
|
|
||||||
|
merged_data_frame: MergedDataFrame = dict(
|
||||||
header=[
|
header=[
|
||||||
column + '_x'
|
column + '_x'
|
||||||
for column in left
|
for column in left
|
||||||
@ -514,12 +534,16 @@ def eternal_oom(argv: list[str]) -> None:
|
|||||||
for column in merged_data_frame['header']:
|
for column in merged_data_frame['header']:
|
||||||
merged_data_frame['columns'][column] = []
|
merged_data_frame['columns'][column] = []
|
||||||
|
|
||||||
common_values = {
|
common_values: set[Any] = {
|
||||||
left_value
|
left_value
|
||||||
for left_value in index['left']
|
for left_value in index['left']
|
||||||
if left_value in index['right']
|
if left_value in index['right']
|
||||||
}
|
}
|
||||||
common_rows = sorted(
|
class RowMatch(TypedDict):
|
||||||
|
left_row_index: int
|
||||||
|
right_row_index: int
|
||||||
|
|
||||||
|
common_rows: list[RowMatch] = sorted(
|
||||||
[
|
[
|
||||||
dict(
|
dict(
|
||||||
left_row_index=index['left'][value][0],
|
left_row_index=index['left'][value][0],
|
||||||
@ -533,7 +557,17 @@ def eternal_oom(argv: list[str]) -> None:
|
|||||||
row = sum([
|
row = sum([
|
||||||
[
|
[
|
||||||
values[
|
values[
|
||||||
common_row['%s_row_index' % index_name]
|
common_row[
|
||||||
|
cast(
|
||||||
|
Literal['left_row_index' | 'right_row_index'],
|
||||||
|
'left_row_index'
|
||||||
|
if index_name == 'left'
|
||||||
|
else
|
||||||
|
'right_row_index'
|
||||||
|
if index_name == 'right'
|
||||||
|
else raise_not_implemented()
|
||||||
|
)
|
||||||
|
]
|
||||||
]
|
]
|
||||||
for column, values in data_frame.items()
|
for column, values in data_frame.items()
|
||||||
]
|
]
|
||||||
@ -3794,7 +3828,12 @@ class Command(enum.StrEnum):
|
|||||||
vpn = 'vpn'
|
vpn = 'vpn'
|
||||||
backup = 'backup'
|
backup = 'backup'
|
||||||
|
|
||||||
def commands_cli() -> None:
|
def commands_cli(
|
||||||
|
argv: Optional[list[str]] = None
|
||||||
|
) -> None:
|
||||||
|
if argv is None:
|
||||||
|
argv = sys.argv[1:]
|
||||||
|
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
handler = logging.StreamHandler(sys.stderr)
|
handler = logging.StreamHandler(sys.stderr)
|
||||||
@ -3802,9 +3841,13 @@ def commands_cli() -> None:
|
|||||||
|
|
||||||
msg : Optional[str] = None
|
msg : Optional[str] = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
if len(argv) > 0 and argv[0].startswith('media'):
|
||||||
|
msg = media_keys(argv).get('msg')
|
||||||
|
else:
|
||||||
parser = argparse.ArgumentParser('online_fxreader.commands')
|
parser = argparse.ArgumentParser('online_fxreader.commands')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'command',
|
'_command',
|
||||||
choices=[
|
choices=[
|
||||||
o.value
|
o.value
|
||||||
for o in Command
|
for o in Command
|
||||||
@ -3812,13 +3855,10 @@ def commands_cli() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
options, args = parser.parse_known_args()
|
options, args = parser.parse_known_args()
|
||||||
|
options.command = Command(options._command)
|
||||||
|
|
||||||
options.command = Command(options.command)
|
|
||||||
|
|
||||||
try:
|
if options.command is Command.status:
|
||||||
if len(args) > 0 and args[0].startswith('media'):
|
|
||||||
msg = media_keys(args).get('msg')
|
|
||||||
elif options.command is Command.status:
|
|
||||||
status(args)
|
status(args)
|
||||||
elif options.command is Command.http_server:
|
elif options.command is Command.http_server:
|
||||||
http_server(args)
|
http_server(args)
|
||||||
|
Loading…
Reference in New Issue
Block a user