kaqing 2.0.172__py3-none-any.whl → 2.0.186__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 kaqing might be problematic. Click here for more details.
- adam/app_session.py +2 -2
- adam/apps.py +18 -4
- adam/batch.py +1 -1
- adam/checks/check_utils.py +3 -1
- adam/commands/__init__.py +8 -2
- adam/commands/alter_tables.py +24 -35
- adam/commands/app/__init__.py +0 -0
- adam/commands/app/app.py +38 -0
- adam/commands/app/app_ping.py +38 -0
- adam/commands/app/show_app_actions.py +49 -0
- adam/commands/app/show_app_id.py +44 -0
- adam/commands/app/show_app_queues.py +38 -0
- adam/commands/app/utils_app.py +106 -0
- adam/commands/audit/audit.py +9 -27
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +14 -1
- adam/commands/bash/bash.py +1 -1
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +6 -8
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +94 -10
- adam/commands/commands_utils.py +19 -12
- adam/commands/cql/completions_c.py +28 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +22 -60
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +39 -8
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +93 -21
- adam/commands/export/export_select.py +8 -68
- adam/commands/export/export_sessions.py +209 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +108 -129
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +19 -5
- adam/commands/export/importer_athena.py +112 -41
- adam/commands/export/importer_sqlite.py +47 -19
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +46 -16
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/ls.py +1 -1
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +39 -32
- adam/commands/medusa/medusa_show_backupjobs.py +6 -4
- adam/commands/medusa/medusa_show_restorejobs.py +5 -3
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +270 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +3 -3
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_scan.py +0 -2
- adam/commands/repair/repair_stop.py +0 -1
- adam/commands/shell.py +7 -5
- adam/commands/show/show.py +1 -1
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -3
- adam/commands/show/show_cassandra_status.py +27 -20
- adam/commands/show/{show_commands.py → show_cli_commands.py} +2 -2
- adam/commands/show/show_login.py +2 -2
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -14
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +1 -0
- adam/embedded_params.py +1 -1
- adam/repl.py +20 -11
- adam/repl_commands.py +16 -9
- adam/repl_session.py +8 -1
- adam/repl_state.py +33 -10
- adam/sql/lark_completer.py +280 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/sql_state_machine.py +8 -2
- adam/utils.py +116 -29
- adam/utils_athena.py +7 -8
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +2 -2
- adam/utils_k8s/app_pods.py +5 -2
- adam/utils_k8s/cassandra_clusters.py +11 -3
- adam/utils_k8s/cassandra_nodes.py +2 -2
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +2 -2
- adam/utils_k8s/pods.py +23 -5
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +4 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +128 -2
- adam/utils_sqlite.py +14 -14
- adam/version.py +1 -1
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/METADATA +1 -1
- kaqing-2.0.186.dist-info/RECORD +250 -0
- adam/commands/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/postgres/postgres_context.py +0 -272
- adam/commands/postgres/psql_completions.py +0 -10
- kaqing-2.0.172.dist-info/RECORD +0 -230
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/WHEEL +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/entry_points.txt +0 -0
- {kaqing-2.0.172.dist-info → kaqing-2.0.186.dist-info}/top_level.txt +0 -0
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
from adam.commands import extract_trailing_options
|
|
3
1
|
from adam.commands.command import Command
|
|
4
|
-
from adam.commands.export.
|
|
5
|
-
from adam.config import Config
|
|
2
|
+
from adam.commands.export.completions_x import completions_x
|
|
6
3
|
from adam.repl_state import ReplState, RequiredState
|
|
7
|
-
from adam.sql.sql_completer import SqlCompleter, SqlVariant
|
|
8
|
-
from adam.utils import log2
|
|
9
|
-
from adam.utils_athena import Athena
|
|
10
4
|
|
|
5
|
+
# No action body, only for a help entry and auto-completion
|
|
11
6
|
class ExportSelect(Command):
|
|
12
|
-
COMMAND = '
|
|
7
|
+
COMMAND = 'select_on_x'
|
|
13
8
|
|
|
14
9
|
# the singleton pattern
|
|
15
10
|
def __new__(cls, *args, **kwargs):
|
|
@@ -26,69 +21,14 @@ class ExportSelect(Command):
|
|
|
26
21
|
def required(self):
|
|
27
22
|
return RequiredState.EXPORT_DB
|
|
28
23
|
|
|
29
|
-
def run(self, cmd: str, state: ReplState):
|
|
30
|
-
if not(args := self.args(cmd)):
|
|
31
|
-
return super().run(cmd, state)
|
|
32
|
-
|
|
33
|
-
with self.validate(args, state) as (args, state):
|
|
34
|
-
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
35
|
-
if not state.export_session:
|
|
36
|
-
if state.in_repl:
|
|
37
|
-
if state.device == ReplState.C:
|
|
38
|
-
log2("Select an export database first with 'use' command.")
|
|
39
|
-
else:
|
|
40
|
-
log2('cd to an export database first.')
|
|
41
|
-
else:
|
|
42
|
-
log2('* export database is missing.')
|
|
43
|
-
|
|
44
|
-
Command.display_help()
|
|
45
|
-
|
|
46
|
-
return 'command-missing'
|
|
47
|
-
|
|
48
|
-
if not args:
|
|
49
|
-
if state.in_repl:
|
|
50
|
-
log2('Use a SQL statement.')
|
|
51
|
-
else:
|
|
52
|
-
log2('* SQL statement is missing.')
|
|
53
|
-
|
|
54
|
-
Command.display_help()
|
|
55
|
-
|
|
56
|
-
return 'command-missing'
|
|
57
|
-
|
|
58
|
-
query = ' '.join(args)
|
|
59
|
-
|
|
60
|
-
def output(out: str):
|
|
61
|
-
log_prefix = Config().get('export.log-prefix', '/tmp/qing')
|
|
62
|
-
log_file = f'{log_prefix}-{datetime.now().strftime("%d%H%M%S")}-sqlite.log'
|
|
63
|
-
|
|
64
|
-
with open(log_file, 'w') as f:
|
|
65
|
-
f.write(out)
|
|
66
|
-
|
|
67
|
-
return log_file
|
|
68
|
-
|
|
69
|
-
ExportDatabases.run_query(f'select {query}', database=state.export_session, output=output if backgrounded else None)
|
|
70
|
-
|
|
71
|
-
return state
|
|
72
|
-
|
|
73
24
|
def completion(self, state: ReplState):
|
|
74
|
-
if
|
|
25
|
+
if state.device != ReplState.X:
|
|
75
26
|
return {}
|
|
76
27
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# warm up the caches first time when x: drive is accessed
|
|
80
|
-
ExportDatabases.table_names(db)
|
|
81
|
-
Athena.column_names(database=db, function='export')
|
|
82
|
-
Athena.column_names(partition_cols_only=True, database=db, function='export')
|
|
28
|
+
if state.export_session:
|
|
29
|
+
return completions_x(state)
|
|
83
30
|
|
|
84
|
-
return {
|
|
85
|
-
lambda: ExportDatabases.table_names(db),
|
|
86
|
-
dml='select',
|
|
87
|
-
expandables={
|
|
88
|
-
'columns':lambda table: Athena.column_names(database=db, function='export'),
|
|
89
|
-
},
|
|
90
|
-
variant=SqlVariant.ATHENA
|
|
91
|
-
)}
|
|
31
|
+
return {}
|
|
92
32
|
|
|
93
33
|
def help(self, _: ReplState):
|
|
94
|
-
return f'
|
|
34
|
+
return f'<sql-select-statements>\t run queries on export database'
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import os
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from adam.commands.export.importer import Importer
|
|
6
|
+
from adam.commands.export.utils_export import ExportTableStatus, csv_dir, find_files
|
|
7
|
+
from adam.config import Config
|
|
8
|
+
from adam.repl_state import ReplState
|
|
9
|
+
from adam.utils import log2, tabulize, log, parallelize
|
|
10
|
+
from adam.utils_k8s.cassandra_nodes import CassandraNodes
|
|
11
|
+
from adam.utils_k8s.pods import Pods, log_prefix
|
|
12
|
+
from adam.utils_k8s.statefulsets import StatefulSets
|
|
13
|
+
from adam.utils_local import local_tmp_dir
|
|
14
|
+
|
|
15
|
+
class ExportSessions:
|
|
16
|
+
def clear_export_session_cache():
|
|
17
|
+
ExportSessions.find_export_sessions.cache_clear()
|
|
18
|
+
ExportSessions.export_session_names.cache_clear()
|
|
19
|
+
|
|
20
|
+
@functools.lru_cache()
|
|
21
|
+
def export_session_names(sts: str, pod: str, namespace: str, importer: str = None, export_state = None):
|
|
22
|
+
if not sts or not namespace:
|
|
23
|
+
return []
|
|
24
|
+
|
|
25
|
+
if not pod:
|
|
26
|
+
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
27
|
+
|
|
28
|
+
if not pod:
|
|
29
|
+
return []
|
|
30
|
+
|
|
31
|
+
return [session for session, state in ExportSessions.find_export_sessions(pod, namespace, importer).items() if not export_state or state == export_state]
|
|
32
|
+
|
|
33
|
+
@functools.lru_cache()
|
|
34
|
+
def find_export_sessions(pod: str, namespace: str, importer: str = None, limit = 100):
|
|
35
|
+
sessions: dict[str, str] = {}
|
|
36
|
+
|
|
37
|
+
prefix = Importer.prefix_from_importer(importer)
|
|
38
|
+
|
|
39
|
+
log_files: list[str] = find_files(pod, namespace, f'{log_prefix()}-{prefix}*_*.log*')
|
|
40
|
+
|
|
41
|
+
if not log_files:
|
|
42
|
+
return {}
|
|
43
|
+
|
|
44
|
+
for log_file in log_files[:limit]:
|
|
45
|
+
m = re.match(f'{log_prefix()}-(.*?)_.*\.log?(.*)', log_file)
|
|
46
|
+
if m:
|
|
47
|
+
s = m.group(1)
|
|
48
|
+
state = m.group(2) # '', '.pending_import', '.done'
|
|
49
|
+
if state:
|
|
50
|
+
state = state.strip('.')
|
|
51
|
+
else:
|
|
52
|
+
state = 'in_export'
|
|
53
|
+
|
|
54
|
+
if s not in sessions:
|
|
55
|
+
sessions[s] = state
|
|
56
|
+
elif sessions[s] == 'done' and state != 'done':
|
|
57
|
+
sessions[s] = state
|
|
58
|
+
|
|
59
|
+
return sessions
|
|
60
|
+
|
|
61
|
+
def clean_up_all_sessions(sts: str, pod: str, namespace: str):
|
|
62
|
+
if not sts or not namespace:
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
if not pod:
|
|
66
|
+
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
67
|
+
|
|
68
|
+
CassandraNodes.exec(pod, namespace, f'rm -rf {csv_dir()}/*', show_out=Config().is_debug(), shell='bash')
|
|
69
|
+
CassandraNodes.exec(pod, namespace, f'rm -rf {log_prefix()}-*.log*', show_out=Config().is_debug(), shell='bash')
|
|
70
|
+
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
def clean_up_sessions(sts: str, pod: str, namespace: str, sessions: list[str], max_workers = 0):
|
|
74
|
+
if not sessions:
|
|
75
|
+
return []
|
|
76
|
+
|
|
77
|
+
if not max_workers:
|
|
78
|
+
max_workers = Config().action_workers('export', 8)
|
|
79
|
+
|
|
80
|
+
with parallelize(sessions,
|
|
81
|
+
max_workers,
|
|
82
|
+
msg='Cleaning|Cleaned up {size} export sessions') as exec:
|
|
83
|
+
cnt_tuples = exec.map(lambda session: ExportSessions.clean_up_session(sts, pod, namespace, session, True))
|
|
84
|
+
csv_cnt = 0
|
|
85
|
+
log_cnt = 0
|
|
86
|
+
for (csv, log) in cnt_tuples:
|
|
87
|
+
csv_cnt += csv
|
|
88
|
+
log_cnt += log
|
|
89
|
+
|
|
90
|
+
return csv_cnt, log_cnt
|
|
91
|
+
|
|
92
|
+
def clean_up_session(sts: str, pod: str, namespace: str, session: str, multi_tables = True):
|
|
93
|
+
if not sts or not namespace:
|
|
94
|
+
return 0, 0
|
|
95
|
+
|
|
96
|
+
if not pod:
|
|
97
|
+
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
98
|
+
|
|
99
|
+
if not pod:
|
|
100
|
+
return 0, 0
|
|
101
|
+
|
|
102
|
+
csv_cnt = 0
|
|
103
|
+
log_cnt = 0
|
|
104
|
+
|
|
105
|
+
log_files: list[str] = find_files(pod, namespace, f'{log_prefix()}-{session}_*.log*')
|
|
106
|
+
|
|
107
|
+
for log_file in log_files:
|
|
108
|
+
m = re.match(f'{log_prefix()}-{session}_(.*?)\.(.*?)\.log.*', log_file)
|
|
109
|
+
if m:
|
|
110
|
+
table = m.group(2)
|
|
111
|
+
|
|
112
|
+
CassandraNodes.exec(pod, namespace, f'rm -rf {csv_dir()}/{session}_{table}', show_out=not multi_tables, shell='bash')
|
|
113
|
+
csv_cnt += 1
|
|
114
|
+
|
|
115
|
+
CassandraNodes.exec(pod, namespace, f'rm -rf {log_file}', show_out=not multi_tables, shell='bash')
|
|
116
|
+
log_cnt += 1
|
|
117
|
+
|
|
118
|
+
return csv_cnt, log_cnt
|
|
119
|
+
|
|
120
|
+
def show_session(sts: str, pod: str, namespace: str, session: str):
|
|
121
|
+
if not pod:
|
|
122
|
+
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
123
|
+
|
|
124
|
+
if not pod:
|
|
125
|
+
return
|
|
126
|
+
|
|
127
|
+
tables, _ = ExportTableStatus.from_session(sts, pod, namespace, session)
|
|
128
|
+
log()
|
|
129
|
+
tabulize(tables,
|
|
130
|
+
lambda t: f'{t.keyspace}\t{t.target_table}\t{"export_completed_pending_import" if t.status == "pending_import" else t.status}\t{t.csv_file}',
|
|
131
|
+
header='KEYSPACE\tTARGET_TABLE\tSTATUS\tCSV_FILES',
|
|
132
|
+
separator='\t')
|
|
133
|
+
|
|
134
|
+
def download_session(sts: str, pod: str, namespace: str, session: str):
|
|
135
|
+
if not pod:
|
|
136
|
+
pod = StatefulSets.pod_names(sts, namespace)[0]
|
|
137
|
+
|
|
138
|
+
if not pod:
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
tables, _ = ExportTableStatus.from_session(sts, pod, namespace, session)
|
|
142
|
+
def download_csv(table):
|
|
143
|
+
from_path: str = table.csv_file
|
|
144
|
+
|
|
145
|
+
to_path = from_path.replace(csv_dir(), local_tmp_dir())
|
|
146
|
+
os.makedirs(os.path.dirname(to_path), exist_ok=True)
|
|
147
|
+
Pods.download_file(pod, 'cassandra', namespace, from_path, to_path)
|
|
148
|
+
|
|
149
|
+
log2(f'[{session}] Downloaded to {to_path}.')
|
|
150
|
+
|
|
151
|
+
with parallelize(tables,
|
|
152
|
+
workers=Config().get('download.workers', 8),
|
|
153
|
+
msg='Downloading|Downloaded {size} csv files') as exec:
|
|
154
|
+
exec.map(download_csv)
|
|
155
|
+
|
|
156
|
+
class ExportSessionService:
|
|
157
|
+
def __init__(self, handler: 'ExportSessionHandler'):
|
|
158
|
+
self.handler = handler
|
|
159
|
+
|
|
160
|
+
def clean_up(self, sessions: list[str]):
|
|
161
|
+
state = self.handler.state
|
|
162
|
+
|
|
163
|
+
csv_cnt, log_cnt = ExportSessions.clean_up_sessions(state.sts, self.pod(), state.namespace, sessions)
|
|
164
|
+
|
|
165
|
+
log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
|
|
166
|
+
|
|
167
|
+
ExportSessions.clear_export_session_cache()
|
|
168
|
+
|
|
169
|
+
def clean_up_all(self):
|
|
170
|
+
state = self.handler.state
|
|
171
|
+
|
|
172
|
+
if ExportSessions.clean_up_all_sessions(state.sts, self.pod(), state.namespace):
|
|
173
|
+
ExportSessions.clear_export_session_cache()
|
|
174
|
+
|
|
175
|
+
def show_all_sessions(self):
|
|
176
|
+
state = self.handler.state
|
|
177
|
+
|
|
178
|
+
sessions = sorted(ExportSessions.find_export_sessions(self.pod(), state.namespace).items(), reverse=True)
|
|
179
|
+
tabulize(sessions, lambda args: f'{args[0]}\t{args[1]}', header='EXPORT_SESSION\tSTATUS', separator='\t')
|
|
180
|
+
|
|
181
|
+
def show_session(self, session: str):
|
|
182
|
+
state = self.handler.state
|
|
183
|
+
ExportSessions.show_session(state.sts, self.pod(), state.namespace, session)
|
|
184
|
+
|
|
185
|
+
def download_session(self, session: str):
|
|
186
|
+
state = self.handler.state
|
|
187
|
+
ExportSessions.download_session(state.sts, self.pod(), state.namespace, session)
|
|
188
|
+
|
|
189
|
+
def pod(self):
|
|
190
|
+
state = self.handler.state
|
|
191
|
+
|
|
192
|
+
pod = state.pod
|
|
193
|
+
if not pod:
|
|
194
|
+
pod = StatefulSets.pod_names(state.sts, state.namespace)[0]
|
|
195
|
+
|
|
196
|
+
return pod
|
|
197
|
+
|
|
198
|
+
class ExportSessionHandler:
|
|
199
|
+
def __init__(self, state: ReplState = None):
|
|
200
|
+
self.state = state
|
|
201
|
+
|
|
202
|
+
def __enter__(self):
|
|
203
|
+
return ExportSessionService(self)
|
|
204
|
+
|
|
205
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
206
|
+
return False
|
|
207
|
+
|
|
208
|
+
def export_session(state: ReplState = None):
|
|
209
|
+
return ExportSessionHandler(state)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
from adam.commands import validate_args
|
|
1
2
|
from adam.commands.command import Command
|
|
2
|
-
from adam.commands.export.export_databases import
|
|
3
|
+
from adam.commands.export.export_databases import export_db
|
|
3
4
|
from adam.repl_state import ReplState
|
|
4
5
|
from adam.utils import log2
|
|
5
|
-
from adam.utils_athena import Athena
|
|
6
|
-
from adam.utils_sqlite import SQLite
|
|
7
6
|
|
|
8
7
|
class ExportUse(Command):
|
|
9
8
|
COMMAND = 'use'
|
|
@@ -21,32 +20,30 @@ class ExportUse(Command):
|
|
|
21
20
|
return ExportUse.COMMAND
|
|
22
21
|
|
|
23
22
|
def required(self):
|
|
24
|
-
return [ReplState.C
|
|
23
|
+
return [ReplState.C]
|
|
25
24
|
|
|
26
25
|
def run(self, cmd: str, state: ReplState):
|
|
27
26
|
if not(args := self.args(cmd)):
|
|
28
27
|
return super().run(cmd, state)
|
|
29
28
|
|
|
30
29
|
with self.validate(args, state) as (args, state):
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
with validate_args(args, state, at_least=0) as session:
|
|
31
|
+
if not session:
|
|
32
|
+
state.export_session = None
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
log2('Export database is unset.')
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
return state
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
if state.export_session.startswith('e'):
|
|
40
|
-
Athena.clear_cache()
|
|
41
|
-
else:
|
|
42
|
-
SQLite.clear_cache()
|
|
38
|
+
state.export_session = session
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
with export_db(state) as dbs:
|
|
41
|
+
dbs.show_database()
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
return state
|
|
47
44
|
|
|
48
45
|
def completion(self, state: ReplState):
|
|
49
|
-
return
|
|
46
|
+
return {}
|
|
50
47
|
|
|
51
48
|
def help(self, _: ReplState):
|
|
52
49
|
return f'{ExportUse.COMMAND} <export-database-name>\t use export database'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from adam.commands import extract_trailing_options, validate_args
|
|
2
|
+
from adam.commands.command import Command
|
|
3
|
+
from adam.commands.export.completions_x import completions_x
|
|
4
|
+
from adam.commands.export.export_databases import export_db
|
|
5
|
+
from adam.repl_state import ReplState, RequiredState
|
|
6
|
+
|
|
7
|
+
class ExportXSelect(Command):
|
|
8
|
+
COMMAND = 'xelect'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(ExportXSelect, cls).__new__(cls)
|
|
13
|
+
|
|
14
|
+
return cls.instance
|
|
15
|
+
|
|
16
|
+
def __init__(self, successor: Command=None):
|
|
17
|
+
super().__init__(successor)
|
|
18
|
+
|
|
19
|
+
def command(self):
|
|
20
|
+
return ExportXSelect.COMMAND
|
|
21
|
+
|
|
22
|
+
def required(self):
|
|
23
|
+
return RequiredState.EXPORT_DB
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
30
|
+
with extract_trailing_options(args, '&') as (args, backgrounded):
|
|
31
|
+
with validate_args(args, state, name='SQL statement') as query:
|
|
32
|
+
with export_db(state) as dbs:
|
|
33
|
+
dbs.sql(f'select {query}', backgrounded=backgrounded)
|
|
34
|
+
|
|
35
|
+
return state
|
|
36
|
+
|
|
37
|
+
def completion(self, state: ReplState):
|
|
38
|
+
if state.device != ReplState.C:
|
|
39
|
+
return {}
|
|
40
|
+
|
|
41
|
+
if not state.export_session:
|
|
42
|
+
return {}
|
|
43
|
+
|
|
44
|
+
# add only xelect completions to c: drive from lark
|
|
45
|
+
return {ExportXSelect.COMMAND: completions_x(state)[ExportXSelect.COMMAND]}
|
|
46
|
+
|
|
47
|
+
def help(self, _: ReplState):
|
|
48
|
+
return f'xelect...\t run queries on export database'
|