Skip to content

Commit 6a58558

Browse files
Merge pull request #101 from seibert-media/remove-imports
Remove imports
2 parents 92fb685 + 9738433 commit 6a58558

File tree

6 files changed

+8
-62
lines changed

6 files changed

+8
-62
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# 3.0.0
44
- Removed deprecated syntax and features:
55
- `a_vars`
6+
- "imports" feature (replaced with precommands)
67

78
# 2.13.0
89
- Using "imports" is now deprecated

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,13 @@ All (string) configuration values can be overwritten by the
7171

7272
# Encoding
7373
encoding: 'utf-8'
74-
75-
# Path for shell imports
76-
import_path: '.'
7774

7875
# Path to local bash (default: /bin/bash)
7976
bash_path: '/bin/bash'
8077

8178
# SSH Command used for remote connections
8279
ssh_cmd: 'ssh {hostname} sudo '
8380

84-
# Temporary directory on remote machines for shell imports
85-
remote_tmp_dir: 'automatix_tmp'
86-
8781
# Logger
8882
logger: 'mylogger'
8983

@@ -299,13 +293,6 @@ You can refer to these systems in the command pipeline in multiple ways:
299293
The resolved secret values are accessible in command line via
300294
{secretname}. *(only if teamvault is enabled)*
301295

302-
**imports** _(list)_, deprecated
303-
: Listed shell files (see **CONFIGURATION** section, _import_path_)
304-
will be sourced before every local or remote command execution.
305-
For remote commands, these files are transferred via tar and ssh to
306-
your home directory on the remote system beforehand and deleted
307-
afterwards. This is meant to define some functions you may need.
308-
309296
**precommands** _(associative array)_
310297
: Define a command which is executed before every shell command.
311298
You can specify a command for local and remote commands separately.
@@ -515,10 +502,9 @@ Do the same with variable content like URLs, to make it possible to
515502
parameters.
516503

517504
Preferred way of using **automatix** is to put often used and complex
518-
algorithms in shell functions or python libraries (shelllib/pylib)
519-
and import them. Advantage of this approach is that you can use your
520-
implemented functions multiple times and build up a toolbox of nice
521-
functionality over time.
505+
algorithms in python libraries and import them. Advantage of this
506+
approach is that you can use your implemented functions multiple
507+
times and build up a toolbox of nice functionality over time.
522508

523509

524510
# NOTES

automatix/command.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,16 @@ def _python_action(self) -> int:
406406
return 1
407407

408408
def _local_action(self) -> int:
409-
cmd = self._build_command(path=self.env.config['import_path'])
409+
cmd = self._build_command()
410410
try:
411411
return self._run_local_command(cmd=cmd)
412412
except KeyboardInterrupt:
413413
self.env.LOG.info(KEYBOARD_INTERRUPT_MESSAGE)
414414
return 130
415415

416-
def _build_command(self, path: str = '') -> str:
416+
def _build_command(self) -> str:
417417
if self.precommand:
418418
return f'{self.precommand}; {self.get_resolved_value()}'
419-
elif self.env.imports:
420-
return f'. {path}/' + f'; . {path}/'.join(self.env.imports) + '; ' + self.get_resolved_value()
421419
else:
422420
return self.get_resolved_value()
423421

@@ -458,28 +456,11 @@ def _remote_action_on_hostname(self, hostname: str) -> int:
458456
exitcode = 130
459457
self._remote_handle_keyboard_interrupt(hostname=hostname)
460458

461-
if self.env.imports:
462-
self._remote_cleanup_imports(hostname=hostname)
463-
464459
return exitcode
465460

466461
def _get_remote_command(self, hostname: str) -> str:
467462
ssh_cmd = self.env.config["ssh_cmd"].format(hostname=hostname)
468-
remote_cmd = self._build_command()
469-
prefix = ''
470-
if self.env.imports:
471-
# How is this working?
472-
# - Create a tar archive with all imports
473-
# - Pipe it through SSH
474-
# - Create tmp dir on remote
475-
# - Extract tar archive there
476-
# - Source imports in _build_command
477-
prefix = f'tar -C {self.env.config["import_path"]} -cf - ' + ' '.join(self.env.imports) + ' | '
478-
remote_cmd = f'mkdir {self.env.config["remote_tmp_dir"]};' \
479-
f' tar -C {self.env.config["remote_tmp_dir"]} -xf -;' \
480-
f' {self._build_command(path=self.env.config["remote_tmp_dir"])}'
481-
482-
return f'{prefix}{ssh_cmd}{quote("RUNNING_INSIDE_AUTOMATIX=1 bash -c " + quote(remote_cmd))}'
463+
return f'{ssh_cmd}{quote("RUNNING_INSIDE_AUTOMATIX=1 bash -c " + quote(self._build_command()))}'
483464

484465
def _remote_handle_keyboard_interrupt(self, hostname: str):
485466
ssh_cmd = self.env.config["ssh_cmd"].format(hostname=hostname)
@@ -537,19 +518,6 @@ def get_remote_pids(self, hostname) -> list:
537518

538519
return pids
539520

540-
def _remote_cleanup_imports(self, hostname: str):
541-
ssh_cmd = self.env.config["ssh_cmd"].format(hostname=hostname)
542-
cleanup_cmd = f'{ssh_cmd} rm -r {self.env.config["remote_tmp_dir"]}'
543-
self.env.LOG.debug(f'Executing: {cleanup_cmd}')
544-
proc = subprocess.run(cleanup_cmd, shell=True, executable=self.bash_path)
545-
if proc.returncode != 0:
546-
self.env.LOG.warning(
547-
'Failed to remove {tmp_dir}, exitcode: {return_code}'.format(
548-
tmp_dir=self.env.config["remote_tmp_dir"],
549-
return_code=proc.returncode,
550-
)
551-
)
552-
553521

554522
def parse_key(key) -> tuple[str, ...]:
555523
"""

automatix/config.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
'script_dir': '~/automatix-config',
4141
'constants': {},
4242
'encoding': 'utf-8',
43-
'import_path': '.',
4443
'bash_path': '/bin/bash',
4544
'ssh_cmd': 'ssh {hostname} sudo ',
46-
'remote_tmp_dir': 'automatix_tmp',
4745
'logger': 'automatix',
4846
'logfile_dir': 'automatix_logs',
4947
'bundlewrap': False,
@@ -307,7 +305,7 @@ def validate_script(script: dict):
307305
warn = 0
308306

309307
if script.get('imports'):
310-
LOG.warning('Using "imports" is deprecated. '
308+
LOG.warning('The "imports" feature was removed in 3.0.0. '
311309
'Please refactor your script or use the "precommands" feature instead.')
312310
warn += 1
313311

automatix/environment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def __init__(
5050
self.name = script['name']
5151
self.script_file_path = script['_script_file_path']
5252
self.systems = script.get('systems', {})
53-
self.imports = script.get('imports', [])
5453
self.batch_mode = script.get('_batch_mode', False)
5554
self.batch_items_count = script.get('_batch_items_count', 1)
5655

example.automatix.cfg.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@ constants:
1010
# Encoding
1111
encoding: 'utf-8'
1212

13-
# Path to shell imports
14-
import_path: '.'
15-
1613
# Path to local bash (default: /bin/bash)
1714
bash_path: '/bin/bash'
1815

1916
# SSH Command used for remote connections
2017
ssh_cmd: 'ssh {hostname} sudo '
2118

22-
# Temporary directory on remote machines for shell imports
23-
remote_tmp_dir: 'automatix_tmp'
24-
2519
# Logger
2620
logger: 'mylogger'
2721

0 commit comments

Comments
 (0)