qubership-pipelines-common-library 0.1.9__tar.gz → 0.1.10__tar.gz

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.
Files changed (30) hide show
  1. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/PKG-INFO +1 -1
  2. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/pyproject.toml +1 -1
  3. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/exec_logger.py +9 -5
  4. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/git_client.py +18 -0
  5. qubership_pipelines_common_library-0.1.10/qubership_pipelines_common_library/v1/utils/utils_cli.py +73 -0
  6. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/LICENSE +0 -0
  7. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/README.md +0 -0
  8. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/__init__.py +0 -0
  9. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/__init__.py +0 -0
  10. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/artifactory_client.py +0 -0
  11. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/__init__.py +0 -0
  12. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/exec_command.py +0 -0
  13. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/exec_context.py +0 -0
  14. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/exec_context_file.py +0 -0
  15. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/execution/exec_info.py +0 -0
  16. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/github_client.py +0 -0
  17. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/gitlab_client.py +0 -0
  18. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/jenkins_client.py +0 -0
  19. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/kube_client.py +0 -0
  20. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/log_client.py +0 -0
  21. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/minio_client.py +0 -0
  22. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/__init__.py +0 -0
  23. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/rest.py +0 -0
  24. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils.py +0 -0
  25. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils_context.py +0 -0
  26. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils_dictionary.py +0 -0
  27. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils_file.py +0 -0
  28. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils_json.py +0 -0
  29. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/utils/utils_string.py +0 -0
  30. {qubership_pipelines_common_library-0.1.9 → qubership_pipelines_common_library-0.1.10}/qubership_pipelines_common_library/v1/webex_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qubership-pipelines-common-library
3
- Version: 0.1.9
3
+ Version: 0.1.10
4
4
  Summary: Qubership Pipelines common library
5
5
  License: Apache-2.0
6
6
  Author: Igor Lebedev
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "qubership-pipelines-common-library"
3
- version = "0.1.9"
3
+ version = "0.1.10"
4
4
  description = "Qubership Pipelines common library"
5
5
  authors = ["Igor Lebedev <lebedev.light@gmail.com>"]
6
6
  readme = "README.md"
@@ -18,6 +18,8 @@ import logging, os
18
18
  class ExecutionLogger:
19
19
  FILE_NAME_EXECUTION = "execution.log"
20
20
  FILE_NAME_FULL = "full.log"
21
+ EXECUTION_LOG_LEVEL = logging.INFO
22
+ FULL_LOG_LEVEL = logging.DEBUG
21
23
  DEFAULT_FORMAT = u'[%(asctime)s] [%(levelname)-5s] [class=%(filename)s:%(lineno)-3s] %(message)s'
22
24
 
23
25
  def __init__(self, path_logs):
@@ -26,18 +28,20 @@ class ExecutionLogger:
26
28
  self.path_logs = path_logs
27
29
  self.logger = logging.getLogger("execution_logger")
28
30
  self.logger.setLevel(logging.DEBUG) # set to the lowest level to allow handlers to capture anything
29
- # execution logs - only in local logger
30
31
  if path_logs:
32
+ # execution logs - only in local logger
31
33
  handler_exec = logging.FileHandler(os.path.join(path_logs, ExecutionLogger.FILE_NAME_EXECUTION))
32
- handler_exec.setLevel(logging.INFO)
34
+ handler_exec.setLevel(ExecutionLogger.EXECUTION_LOG_LEVEL)
33
35
  handler_exec.setFormatter(logging.Formatter(ExecutionLogger.DEFAULT_FORMAT))
34
36
  self.logger.addHandler(handler_exec)
35
- # full logs - attach to a global logger
36
- if path_logs:
37
+
38
+ # full logs - attach to a global logger
37
39
  handler_full = logging.FileHandler(os.path.join(path_logs, ExecutionLogger.FILE_NAME_FULL))
38
- handler_full.setLevel(logging.DEBUG)
40
+ handler_full.setLevel(ExecutionLogger.FULL_LOG_LEVEL)
39
41
  handler_full.setFormatter(logging.Formatter(ExecutionLogger.DEFAULT_FORMAT))
42
+ logging.getLogger().propagate = False
40
43
  logging.getLogger().addHandler(handler_full)
44
+ self.logger.propagate = True
41
45
 
42
46
  def info(self, msg, *args, **kwargs):
43
47
  self.logger.info(msg, *args, **kwargs)
@@ -59,7 +59,25 @@ class GitClient:
59
59
  **kwargs
60
60
  )
61
61
 
62
+ def clone_repo_from_commit_hash(self, repo_path: str, commit_hash: str, temp_path: str):
63
+ """"""
64
+ repo_path = repo_path.lstrip("/").rstrip("/")
65
+ if not repo_path:
66
+ raise Exception("Repository path should be defined")
67
+ if not commit_hash:
68
+ raise Exception("Commit hash should be defined")
69
+ if not temp_path:
70
+ raise Exception("Temporary path should be defined")
71
+ self._cleanup_resources()
72
+ self.repo_path = repo_path
73
+ self.temp_path = temp_path
74
+ self.repo = Repo.init(path=temp_path)
75
+ self.repo.create_remote(name="origin", url=self._gen_repo_auth_url(self.host, self.username, self.password, self.repo_path))
76
+ self.repo.git.fetch("--depth", "1", "origin", commit_hash)
77
+ self.repo.git.checkout("FETCH_HEAD")
78
+
62
79
  def commit_and_push(self, commit_message: str):
80
+ """"""
63
81
  self.commit(commit_message)
64
82
  self.push()
65
83
 
@@ -0,0 +1,73 @@
1
+ import re
2
+ import click
3
+ import logging
4
+ import sys, os
5
+ from qubership_pipelines_common_library.v1.execution.exec_logger import ExecutionLogger
6
+
7
+ DEFAULT_CONTEXT_FILE_PATH = 'context.yaml'
8
+
9
+
10
+ def utils_cli(func):
11
+ """Decorator to add CLI options for logging level, context path and custom input params."""
12
+ @click.option('--log-level', default='INFO', show_default=True,
13
+ type=click.Choice(['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], case_sensitive=False),
14
+ help="Set the logging level")
15
+ @click.option('--context_path', required=True, default=DEFAULT_CONTEXT_FILE_PATH, type=str, help="Path to context")
16
+ @click.option("--input_params", "-p", multiple=True, callback=_input_params_to_dict,
17
+ help="Params to use instead of context as key-values. Nested keys are supported with double-underscores or dots as separators, e.g. -p params__group__key=value")
18
+ @click.pass_context
19
+ def wrapper(ctx, *args, log_level, **kwargs):
20
+ ExecutionLogger.EXECUTION_LOG_LEVEL = getattr(logging, log_level.upper(), logging.INFO)
21
+ _configure_global_logger(logging.getLogger(), log_level, ExecutionLogger.DEFAULT_FORMAT)
22
+ _transform_kwargs(kwargs)
23
+ return ctx.invoke(func, *args, **kwargs)
24
+ return wrapper
25
+
26
+
27
+ def _configure_global_logger(global_logger: logging.Logger, log_level: str, formatter_str: str):
28
+ """Configure the global logger with a specific log level and formatter."""
29
+ log_level_value = getattr(logging, log_level.upper(), logging.INFO)
30
+ global_logger.setLevel(logging.DEBUG)
31
+ if global_logger.hasHandlers():
32
+ global_logger.handlers.clear()
33
+ global_logger.propagate = True
34
+ stdout_handler = logging.StreamHandler(sys.stdout)
35
+ stdout_handler.setLevel(log_level_value)
36
+ stdout_handler.setFormatter(logging.Formatter(formatter_str))
37
+ global_logger.addHandler(stdout_handler)
38
+
39
+
40
+ def _transform_kwargs(kwargs):
41
+ if kwargs.get("input_params"):
42
+ kwargs.pop("context_path")
43
+
44
+
45
+ def _input_params_to_dict(ctx, param, values: tuple[str, ...]):
46
+ result = {}
47
+ for kvp in values:
48
+ key, value = [item.strip() for item in kvp.split("=", 1)]
49
+ if _validate_key(key):
50
+ _set_item_by_path(result, key, _transform_value(value))
51
+ return result if result else None
52
+
53
+
54
+ def _validate_key(key):
55
+ return True
56
+
57
+
58
+ def _transform_value(value):
59
+ return value
60
+
61
+
62
+ _KEY_PARTS_DELIMITER_PATTERN = re.compile(r'\.|__')
63
+ def _set_item_by_path(target_dict: dict, path, value):
64
+ current_dict = target_dict
65
+ key_parts = _KEY_PARTS_DELIMITER_PATTERN.split(path)
66
+ for i, key in enumerate(key_parts):
67
+ if i == len(key_parts) - 1:
68
+ current_dict[key] = value
69
+ break
70
+ if not isinstance(current_dict.get(key), dict):
71
+ current_dict[key] = {}
72
+ current_dict = current_dict[key]
73
+ return target_dict