kaqing 2.0.172__py3-none-any.whl → 2.0.174__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.

Files changed (54) hide show
  1. adam/commands/__init__.py +6 -2
  2. adam/commands/alter_tables.py +24 -35
  3. adam/commands/cat.py +3 -13
  4. adam/commands/cd.py +6 -8
  5. adam/commands/check.py +9 -17
  6. adam/commands/command.py +39 -5
  7. adam/commands/cp.py +24 -32
  8. adam/commands/cql/cql_completions.py +3 -4
  9. adam/commands/cql/utils_cql.py +0 -2
  10. adam/commands/devices/device_app.py +2 -2
  11. adam/commands/devices/device_cass.py +2 -2
  12. adam/commands/devices/device_export.py +7 -9
  13. adam/commands/devices/device_postgres.py +2 -2
  14. adam/commands/export/clean_up_all_export_sessions.py +3 -3
  15. adam/commands/export/clean_up_export_sessions.py +8 -15
  16. adam/commands/export/drop_export_database.py +6 -22
  17. adam/commands/export/drop_export_databases.py +3 -9
  18. adam/commands/export/export.py +1 -1
  19. adam/commands/export/export_databases.py +70 -15
  20. adam/commands/export/export_select.py +12 -23
  21. adam/commands/export/export_select_x.py +3 -3
  22. adam/commands/export/export_sessions.py +124 -0
  23. adam/commands/export/export_use.py +0 -6
  24. adam/commands/export/exporter.py +61 -120
  25. adam/commands/export/import_session.py +4 -4
  26. adam/commands/export/importer.py +12 -5
  27. adam/commands/export/importer_athena.py +17 -13
  28. adam/commands/export/importer_sqlite.py +20 -17
  29. adam/commands/export/show_column_counts.py +5 -14
  30. adam/commands/export/show_export_databases.py +2 -1
  31. adam/commands/export/show_export_session.py +5 -13
  32. adam/commands/export/show_export_sessions.py +2 -2
  33. adam/commands/export/utils_export.py +5 -3
  34. adam/commands/medusa/medusa_backup.py +1 -2
  35. adam/commands/medusa/medusa_restore.py +21 -19
  36. adam/commands/param_get.py +8 -9
  37. adam/commands/param_set.py +7 -10
  38. adam/commands/postgres/postgres.py +13 -21
  39. adam/commands/postgres/utils_postgres.py +5 -1
  40. adam/commands/preview_table.py +1 -1
  41. adam/commands/reaper/reaper_run_abort.py +4 -10
  42. adam/commands/reaper/reaper_schedule_activate.py +6 -10
  43. adam/commands/reaper/reaper_schedule_start.py +6 -10
  44. adam/commands/reaper/reaper_schedule_stop.py +6 -10
  45. adam/repl.py +5 -3
  46. adam/utils_k8s/k8s.py +5 -5
  47. adam/utils_sqlite.py +13 -13
  48. adam/version.py +1 -1
  49. {kaqing-2.0.172.dist-info → kaqing-2.0.174.dist-info}/METADATA +1 -1
  50. {kaqing-2.0.172.dist-info → kaqing-2.0.174.dist-info}/RECORD +53 -53
  51. adam/commands/export/export_handlers.py +0 -71
  52. {kaqing-2.0.172.dist-info → kaqing-2.0.174.dist-info}/WHEEL +0 -0
  53. {kaqing-2.0.172.dist-info → kaqing-2.0.174.dist-info}/entry_points.txt +0 -0
  54. {kaqing-2.0.172.dist-info → kaqing-2.0.174.dist-info}/top_level.txt +0 -0
adam/commands/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
- from adam.commands.command import ExtractAllOptionsHandler, ExtractOptionsHandler, ExtractSequenceOptionsHandler, ExtractTrailingOptionsHandler
1
+ from collections.abc import Callable
2
+ from adam.commands.command import ExtractAllOptionsHandler, ExtractOptionsHandler, ExtractSequenceOptionsHandler, ExtractTrailingOptionsHandler, ValidateArgCountHandler
2
3
  from adam.repl_state import ReplState
3
4
  from adam.commands.app.utils_app import AppHandler
4
5
 
@@ -15,4 +16,7 @@ def extract_all_options(args: list[str], trailing = None, sequence = None, optio
15
16
  return ExtractAllOptionsHandler(args, trailing = trailing, sequence = sequence, options = options)
16
17
 
17
18
  def extract_sequence(args: list[str], sequence: list[str]):
18
- return ExtractSequenceOptionsHandler(args, sequence = sequence)
19
+ return ExtractSequenceOptionsHandler(args, sequence = sequence)
20
+
21
+ def validate_args(args: list[str], state: ReplState, count_at_least: int = 1, name: str = None, msg: Callable[[], None] = None):
22
+ return ValidateArgCountHandler(args, state, count_at_least=count_at_least, name=name, msg=msg)
@@ -1,4 +1,4 @@
1
- from adam.commands import extract_options
1
+ from adam.commands import extract_options, validate_args
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.cql.utils_cql import cassandra, cassandra_tables as get_tables
4
4
  from adam.config import Config
@@ -29,45 +29,34 @@ class AlterTables(Command):
29
29
 
30
30
  with self.validate(args, state) as (args, state):
31
31
  with extract_options(args, '--include-reaper') as (args, include_reaper):
32
- if not args:
33
- if state.in_repl:
34
- log2('Please enter gc grace in seconds. e.g. alter gc-grace-seconds 3600')
35
- else:
36
- log2('* gc grace second is missing.')
37
- log2()
38
- Command.display_help()
39
-
40
- return 'missing-arg'
41
-
42
- arg_str = ' '.join(args)
43
-
44
- excludes = [e.strip(' \r\n') for e in Config().get(
45
- 'cql.alter-tables.excludes',
46
- 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
47
- batching = Config().get('cql.alter-tables.batching', True)
48
- tables = get_tables(state, on_any=True)
49
- for k, v in tables.items():
50
- if k not in excludes or k == 'reaper_db' and include_reaper:
51
- if batching:
52
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
53
- cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
54
- with log_exc(True):
55
- with cassandra(state) as pods:
56
- pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
57
- continue
58
- else:
59
- for t in v:
32
+ with validate_args(args, state, name='gc grace in seconds') as arg_str:
33
+ excludes = [e.strip(' \r\n') for e in Config().get(
34
+ 'cql.alter-tables.excludes',
35
+ 'system_auth,system_traces,reaper_db,system_distributed,system_views,system,system_schema,system_virtual_schema').split(',')]
36
+ batching = Config().get('cql.alter-tables.batching', True)
37
+ tables = get_tables(state, on_any=True)
38
+ for k, v in tables.items():
39
+ if k not in excludes or k == 'reaper_db' and include_reaper:
40
+ if batching:
41
+ # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
42
+ cql = ';\n'.join([f'alter table {k}.{t} with {arg_str}' for t in v])
60
43
  with log_exc(True):
61
- # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
62
- cql = f'alter table {k}.{t} with {arg_str}'
63
44
  with cassandra(state) as pods:
64
- pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
45
+ pods.cql(cql, show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
65
46
  continue
47
+ else:
48
+ for t in v:
49
+ with log_exc(True):
50
+ # alter table <table_name> with GC_GRACE_SECONDS = <timeout>;
51
+ cql = f'alter table {k}.{t} with {arg_str}'
52
+ with cassandra(state) as pods:
53
+ pods.cql(show_out=Config().is_debug(), show_query=not Config().is_debug(), on_any=True)
54
+ continue
66
55
 
67
- log2(f'{len(v)} tables altered in {k}.')
56
+ log2(f'{len(v)} tables altered in {k}.')
68
57
 
69
- # do not continue to cql route
70
- return state
58
+ # do not continue to cql route
59
+ return state
71
60
 
72
61
  def completion(self, _: ReplState) -> dict[str, any]:
73
62
  # auto completion is taken care of by sql completer
adam/commands/cat.py CHANGED
@@ -1,9 +1,8 @@
1
+ from adam.commands import validate_args
1
2
  from adam.commands.command import Command
2
3
  from adam.commands.devices.devices import Devices
3
4
  from adam.repl_state import ReplState, RequiredState
4
5
  from adam.utils import log2
5
- from adam.utils_k8s.app_pods import AppPods
6
- from adam.utils_k8s.statefulsets import StatefulSets
7
6
 
8
7
  class Cat(Command):
9
8
  COMMAND = 'cat'
@@ -28,17 +27,8 @@ class Cat(Command):
28
27
  return super().run(cmd, state)
29
28
 
30
29
  with self.validate(args, state) as (args, state):
31
- if len(args) < 1:
32
- if state.in_repl:
33
- log2('File is required.')
34
- log2()
35
- else:
36
- log2('* File is missing.')
37
- Command.display_help()
38
-
39
- return 'command-missing'
40
-
41
- return Devices.device(state).cat(cmd, state)
30
+ with validate_args(args, state, name='file'):
31
+ return Devices.device(state).cat(cmd, state)
42
32
 
43
33
  def completion(self, state: ReplState):
44
34
  if super().completion(state):
adam/commands/cd.py CHANGED
@@ -1,3 +1,4 @@
1
+ from adam.commands import validate_args
1
2
  from adam.commands.command import Command
2
3
  from adam.commands.devices.device import Device
3
4
  from adam.commands.devices.devices import Devices
@@ -26,15 +27,12 @@ class Cd(Command):
26
27
  return super().run(cmd, state)
27
28
 
28
29
  with self.validate(args, state, apply=False) as (args, state):
29
- if len(args) < 2:
30
- return state
31
-
32
- device: Device = Devices.device(state)
33
- arg = args[1]
34
- for dir in arg.split('/'):
35
- device.cd(dir, state)
30
+ with validate_args(args, state, name='directory') as arg_str:
31
+ device: Device = Devices.device(state)
32
+ for dir in arg_str.split('/'):
33
+ device.cd(dir, state)
36
34
 
37
- return state
35
+ return state
38
36
 
39
37
  def completion(self, state: ReplState):
40
38
  return Devices.device(state).cd_completion(Cd.COMMAND, state, default = {})
adam/commands/check.py CHANGED
@@ -2,7 +2,7 @@ import click
2
2
 
3
3
  from adam.checks.check_result import CheckResult
4
4
  from adam.checks.check_utils import all_checks, checks_from_csv, run_checks
5
- from adam.commands import extract_options
5
+ from adam.commands import extract_options, validate_args
6
6
  from adam.commands.command import Command
7
7
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
8
8
  from adam.commands.issues import Issues
@@ -34,25 +34,17 @@ class Check(Issues):
34
34
 
35
35
  with self.validate(args, state) as (args, state):
36
36
  with extract_options(args, ['-s', '--show']) as (args, show_out):
37
- if not args:
38
- if state.in_repl:
39
- log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))
40
- else:
41
- log('* Check name is missing.')
42
- Command.display_help()
37
+ with validate_args(args, state, name='check name', msg=lambda:log(lines_to_tabular([check.help() for check in all_checks()], separator=':'))) as arg:
38
+ checks = checks_from_csv(args[0])
39
+ if not checks:
40
+ return 'invalid check name'
43
41
 
44
- return 'arg missing'
42
+ results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
45
43
 
46
- checks = checks_from_csv(args[0])
47
- if not checks:
48
- return 'invalid check name'
44
+ issues = CheckResult.collect_issues(results)
45
+ IssuesUtils.show_issues(issues, in_repl=state.in_repl)
49
46
 
50
- results = run_checks(state.sts, state.namespace, state.pod, checks=checks, show_out=show_out)
51
-
52
- issues = CheckResult.collect_issues(results)
53
- IssuesUtils.show_issues(issues, in_repl=state.in_repl)
54
-
55
- return issues if issues else 'no issues found'
47
+ return issues if issues else 'no issues found'
56
48
 
57
49
  def completion(self, _: ReplState):
58
50
  return {Check.COMMAND: {check.name(): {'-s': None} for check in all_checks()}}
adam/commands/command.py CHANGED
@@ -1,11 +1,12 @@
1
1
  from abc import abstractmethod
2
+ from collections.abc import Callable
2
3
  import copy
3
4
  import subprocess
4
5
  import sys
5
6
  from typing import Union
6
7
 
7
8
  from adam.repl_state import ReplState, RequiredState
8
- from adam.utils import is_lambda
9
+ from adam.utils import is_lambda, log2
9
10
 
10
11
  repl_cmds: list['Command'] = []
11
12
 
@@ -45,7 +46,7 @@ class Command:
45
46
  return None
46
47
 
47
48
  def validate(self, args: list[str], state: ReplState, apply = True):
48
- return ValidateHandler(self, args, state, apply = apply)
49
+ return ValidateStateHandler(self, args, state, apply = apply)
49
50
 
50
51
  def validate_state(self, state: ReplState, show_err = True):
51
52
  return state.validate(self.required(), show_err=show_err)
@@ -148,11 +149,11 @@ class Command:
148
149
  cmd = s
149
150
  print()
150
151
 
151
- class InvalidState(Exception):
152
+ class InvalidStateException(Exception):
152
153
  def __init__(self, state: ReplState):
153
154
  super().__init__(f'Invalid state')
154
155
 
155
- class ValidateHandler:
156
+ class ValidateStateHandler:
156
157
  def __init__(self, cmd: Command, args: list[str], state: ReplState, apply = True):
157
158
  self.cmd = cmd
158
159
  self.args = args
@@ -164,15 +165,48 @@ class ValidateHandler:
164
165
  args = self.args
165
166
  if self.apply:
166
167
  state, args = self.cmd.apply_state(args, state)
168
+ else:
169
+ args = args[len(self.cmd.command_tokens()):]
167
170
 
168
171
  if not self.cmd.validate_state(state):
169
- raise InvalidState(state)
172
+ raise InvalidStateException(state)
170
173
 
171
174
  return args, state
172
175
 
173
176
  def __exit__(self, exc_type, exc_val, exc_tb):
174
177
  return False
175
178
 
179
+ class InvalidArgumentsException(Exception):
180
+ def __init__(self):
181
+ super().__init__(f'Invalid arguments')
182
+
183
+ class ValidateArgCountHandler:
184
+ def __init__(self, args: list[str], state: ReplState, count_at_least: int = 1, name: str = None, msg: Callable[[], None] = None):
185
+ self.args = args
186
+ self.state = state
187
+ self.count_at_least = count_at_least
188
+ self.name = name
189
+ self.msg = msg
190
+
191
+ def __enter__(self) -> tuple[list[str], ReplState]:
192
+ if len(self.args) < self.count_at_least:
193
+ if self.state.in_repl:
194
+ if self.msg:
195
+ self.msg()
196
+ elif self.name:
197
+ log2(f'{self.name} is required.')
198
+ elif self.name:
199
+ log2(f'* {self.name} is missing.')
200
+
201
+ Command.display_help()
202
+
203
+ raise InvalidArgumentsException()
204
+
205
+ return ' '.join(self.args)
206
+
207
+ def __exit__(self, exc_type, exc_val, exc_tb):
208
+ return False
209
+
176
210
  class ExtractOptionsHandler:
177
211
  def __init__(self, args: list[str], options: list[str] = None):
178
212
  self.args = args
adam/commands/cp.py CHANGED
@@ -1,7 +1,8 @@
1
1
  import click
2
2
  import pyperclip
3
3
 
4
- from adam.commands.command import Command
4
+ from adam.commands import validate_args
5
+ from adam.commands.command import Command, InvalidArgumentsException
5
6
  from adam.commands.command_helpers import ClusterOrPodCommandHelper
6
7
  from adam.commands.cli_commands import CliCommands
7
8
  from adam.repl_state import ReplState, RequiredState
@@ -30,37 +31,28 @@ class ClipboardCopy(Command):
30
31
  return super().run(cmd, state)
31
32
 
32
33
  with self.validate(args, state) as (args, state):
33
- if len(args) < 1:
34
- if state.in_repl:
35
- log2('Key is required.')
36
- log2()
37
- log2('Keys:')
38
- log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
39
- else:
40
- log2('* Key is missing.')
41
- Command.display_help()
42
-
43
- return 'command-missing'
44
-
45
- key = args[0]
46
- if not key in CliCommands.values(state):
47
- if state.in_repl:
48
- log2('Key is required.')
49
- log2()
50
- log2('Keys:')
51
- log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
52
- else:
53
- log2('* Invalid key')
54
- Command.display_help()
55
-
56
- return 'command-invalid'
57
-
58
- value = CliCommands.values(state)[key]
59
- pyperclip.copy(value)
60
- log2('The following line has been copied to clipboard. Use <Ctrl-V> to use it.')
61
- log2(f' {value}')
62
-
63
- return 'value-copied'
34
+ def display_keys():
35
+ log2('Key is required.')
36
+ log2()
37
+ log2('Keys:')
38
+ log2(lines_to_tabular([f'{k},{v}' for k, v in CliCommands.values(state, collapse=True).items()], separator=','))
39
+
40
+ with validate_args(args, state, name='key', msg=display_keys) as key:
41
+ if not key in CliCommands.values(state):
42
+ if state.in_repl:
43
+ display_keys()
44
+ else:
45
+ log2('* Invalid key')
46
+ Command.display_help()
47
+
48
+ raise InvalidArgumentsException()
49
+
50
+ value = CliCommands.values(state)[key]
51
+ pyperclip.copy(value)
52
+ log2('The following line has been copied to clipboard. Use <Ctrl-V> to use it.')
53
+ log2(f' {value}')
54
+
55
+ return state
64
56
 
65
57
  def completion(self, state: ReplState):
66
58
  return super().completion(state, lambda: {key: None for key in CliCommands.values(state).keys()})
@@ -1,6 +1,5 @@
1
- import time
2
1
  from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
3
- from adam.commands.export.exporter import Exporter
2
+ from adam.commands.export.export_sessions import ExportSessions
4
3
  from adam.commands.export.export_databases import ExportDatabases
5
4
  from adam.config import Config
6
5
  from adam.repl_state import ReplState
@@ -23,8 +22,8 @@ def cql_completions(state: ReplState) -> dict[str, any]:
23
22
  'GC_GRACE_SECONDS': ps
24
23
  },
25
24
  'export-dbs': lambda: ExportDatabases.database_names(),
26
- 'export-sessions': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace),
27
- 'export-sessions-incomplete': lambda: Exporter.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
25
+ 'export-sessions': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace),
26
+ 'export-sessions-incomplete': lambda: ExportSessions.export_session_names(state.sts, state.pod, state.namespace, export_state='pending_import'),
28
27
  }
29
28
 
30
29
  return SqlCompleter(
@@ -242,8 +242,6 @@ class CqlShHandler:
242
242
  for index, arg in enumerate(args):
243
243
  if arg.startswith('--'):
244
244
  opts.append(arg)
245
- # elif index == len(args) -1 and arg == '&':
246
- # background = True
247
245
  elif arg != '-e':
248
246
  cqls.append(arg)
249
247
  if not cqls:
@@ -1,7 +1,7 @@
1
1
  from adam.apps import Apps
2
2
  from adam.commands import app
3
3
  from adam.commands.bash.bash_completer import BashCompleter
4
- from adam.commands.command import Command, InvalidState
4
+ from adam.commands.command import Command, InvalidStateException
5
5
  from adam.commands.devices.device import Device
6
6
  from adam.config import Config
7
7
  from adam.repl_state import ReplState
@@ -78,7 +78,7 @@ class DeviceApp(Command, Device):
78
78
  if state.app_pod:
79
79
  return self.bash(state, state, cmd.split(' '))
80
80
 
81
- return InvalidState()
81
+ raise InvalidStateException()
82
82
 
83
83
  def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
84
84
  if state.app_app:
@@ -1,5 +1,5 @@
1
1
  from adam.commands.bash.bash_completer import BashCompleter
2
- from adam.commands.command import Command, InvalidState
2
+ from adam.commands.command import Command, InvalidStateException
3
3
  from adam.commands.commands_utils import show_pods, show_rollout
4
4
  from adam.commands.cql.utils_cql import cassandra, cassandra_table_names
5
5
  from adam.commands.devices.device import Device
@@ -62,7 +62,7 @@ class DeviceCass(Command, Device):
62
62
  if state.pod:
63
63
  return self.bash(state, state, cmd.split(' '))
64
64
 
65
- return InvalidState()
65
+ raise InvalidStateException()
66
66
 
67
67
  def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
68
68
  if state.sts:
@@ -1,6 +1,6 @@
1
1
  from adam.commands.command import Command
2
2
  from adam.commands.devices.device import Device
3
- from adam.commands.export.export_databases import ExportDatabases
3
+ from adam.commands.export.export_databases import ExportDatabases, export_db
4
4
  from adam.config import Config
5
5
  from adam.repl_state import ReplState
6
6
  from adam.utils import lines_to_tabular, log, log2, wait_log
@@ -36,16 +36,14 @@ class DeviceExport(Command, Device):
36
36
 
37
37
  def ls(self, cmd: str, state: ReplState):
38
38
  if state.export_session:
39
- self.show_export_tables(state.export_session)
39
+ log(lines_to_tabular(ExportDatabases.table_names(state.export_session), 'NAME', separator=','))
40
40
  else:
41
- self.show_export_databases()
41
+ ExportDatabases.show_databases()
42
42
 
43
- def show_export_databases(self, importer: str = None):
44
- lines = [f'{k}\t{v}' for k, v in ExportDatabases.database_names_with_keyspace_cnt(importer).items()]
45
- log(lines_to_tabular(lines, 'NAME\tKEYSPACES', separator='\t'))
46
-
47
- def show_export_tables(self, export_session: str):
48
- log(lines_to_tabular(ExportDatabases.table_names(export_session), 'NAME', separator=','))
43
+ def show_table_preview(self, state: ReplState, table: str, rows: int):
44
+ if state.export_session:
45
+ with export_db(state) as dbs:
46
+ dbs.sql(f'select * from {table} limit {rows}')
49
47
 
50
48
  def cd(self, dir: str, state: ReplState):
51
49
  if dir in ['', '..']:
@@ -1,5 +1,5 @@
1
1
  from adam.commands.bash.bash_completer import BashCompleter
2
- from adam.commands.command import Command, InvalidState
2
+ from adam.commands.command import Command, InvalidStateException
3
3
  from adam.commands.devices.device import Device
4
4
  from adam.commands.postgres.postgres_context import PostgresContext
5
5
  from adam.commands.postgres.utils_postgres import pg_database_names, pg_table_names, postgres
@@ -50,7 +50,7 @@ class DevicePostgres(Command, Device):
50
50
  if state.pod:
51
51
  return self.bash(state, state, cmd.split(' '))
52
52
 
53
- return InvalidState()
53
+ raise InvalidStateException()
54
54
 
55
55
  def show_pg_hosts(self, state: ReplState):
56
56
  if state.namespace:
@@ -1,5 +1,5 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.export.exporter import Exporter
2
+ from adam.commands.export.export_sessions import ExportSessions
3
3
  from adam.repl_state import ReplState, RequiredState
4
4
 
5
5
  class CleanUpAllExportSessions(Command):
@@ -25,8 +25,8 @@ class CleanUpAllExportSessions(Command):
25
25
  return super().run(cmd, state)
26
26
 
27
27
  with self.validate(args, state) as (args, state):
28
- if Exporter.clean_up_all_sessions(state.sts, state.pod, state.namespace):
29
- Exporter.clear_export_session_cache()
28
+ if ExportSessions.clean_up_all_sessions(state.sts, state.pod, state.namespace):
29
+ ExportSessions.clear_export_session_cache()
30
30
 
31
31
  return state
32
32
 
@@ -1,4 +1,6 @@
1
+ from adam.commands import validate_args
1
2
  from adam.commands.command import Command
3
+ from adam.commands.export.export_sessions import ExportSessions
2
4
  from adam.commands.export.exporter import Exporter
3
5
  from adam.repl_state import ReplState, RequiredState
4
6
  from adam.utils import log, log2
@@ -26,23 +28,14 @@ class CleanUpExportSessions(Command):
26
28
  return super().run(cmd, state)
27
29
 
28
30
  with self.validate(args, state) as (args, state):
29
- if not args:
30
- if state.in_repl:
31
- log2('Specify export session name.')
32
- else:
33
- log2('* Session name is missing.')
31
+ with validate_args(args, state, name='export session') as arg_str:
32
+ sessions = [arg.strip(' ') for arg in arg_str.split(',')]
33
+ csv_cnt, log_cnt = ExportSessions.clean_up_sessions(state.sts, state.pod, state.namespace, sessions)
34
+ log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
34
35
 
35
- Command.display_help()
36
+ ExportSessions.clear_export_session_cache()
36
37
 
37
- return 'command-missing'
38
-
39
- sessions = [arg.strip(' ') for arg in ' '.join(args).split(',')]
40
- csv_cnt, log_cnt = Exporter.clean_up_sessions(state.sts, state.pod, state.namespace, sessions)
41
- log(f'Removed {csv_cnt} csv and {log_cnt} log files.')
42
-
43
- Exporter.clear_export_session_cache()
44
-
45
- return state
38
+ return state
46
39
 
47
40
  def completion(self, _: ReplState):
48
41
  return {}
@@ -1,9 +1,7 @@
1
+ from adam.commands import validate_args
1
2
  from adam.commands.command import Command
2
- from adam.commands.export.exporter import Exporter
3
+ from adam.commands.export.export_databases import export_db
3
4
  from adam.repl_state import ReplState
4
- from adam.utils import log2
5
- from adam.utils_athena import Athena
6
- from adam.utils_sqlite import SQLite
7
5
 
8
6
  class DropExportDatabase(Command):
9
7
  COMMAND = 'drop export database'
@@ -28,25 +26,11 @@ class DropExportDatabase(Command):
28
26
  return super().run(cmd, state)
29
27
 
30
28
  with self.validate(args, state) as (args, state):
31
- if not len(args):
32
- if state.in_repl:
33
- log2('Database name is required.')
34
- log2()
35
- else:
36
- log2('* Database name is missing.')
37
- Command.display_help()
29
+ with validate_args(args, state, name='database name') as db:
30
+ with export_db(state) as dbs:
31
+ dbs.drop(args[0])
38
32
 
39
- return 'command-missing'
40
-
41
- Exporter.drop_databases(state.sts, state.pod, state.namespace, args[0])
42
-
43
- SQLite.clear_cache()
44
- Athena.clear_cache()
45
-
46
- if state.export_session == args[0]:
47
- state.export_session = None
48
-
49
- return state
33
+ return state
50
34
 
51
35
  def completion(self, _: ReplState):
52
36
  return {}
@@ -1,8 +1,6 @@
1
1
  from adam.commands.command import Command
2
- from adam.commands.export.exporter import Exporter
2
+ from adam.commands.export.export_databases import export_db
3
3
  from adam.repl_state import ReplState
4
- from adam.utils_athena import Athena
5
- from adam.utils_sqlite import SQLite
6
4
 
7
5
  class DropExportDatabases(Command):
8
6
  COMMAND = 'drop all export databases'
@@ -27,12 +25,8 @@ class DropExportDatabases(Command):
27
25
  return super().run(cmd, state)
28
26
 
29
27
  with self.validate(args, state) as (args, state):
30
- Exporter.drop_databases(state.sts, state.pod, state.namespace)
31
-
32
- SQLite.clear_cache()
33
- Athena.clear_cache()
34
-
35
- state.export_session = None
28
+ with export_db(state) as dbs:
29
+ dbs.drop_all()
36
30
 
37
31
  return state
38
32
 
@@ -2,7 +2,7 @@ from adam.commands import extract_options
2
2
  from adam.commands.command import Command
3
3
  from adam.commands.cql.utils_cql import cassandra_keyspaces, cassandra_table_names
4
4
  from adam.commands.export.export_databases import ExportDatabases
5
- from adam.commands.export.export_handlers import export
5
+ from adam.commands.export.exporter import export
6
6
  from adam.repl_state import ReplState, RequiredState
7
7
  from adam.sql.sql_completer import SqlCompleter, SqlVariant
8
8
  from adam.utils import log