Line with a job error will be highlighted
The 'rp-reporter version' return version og the package
Related-Prod: PRODX-53429
Change-Id: I8003297c679c06af256874d9b7312d5425fce3dd
diff --git a/rp_reporter/rp_reporter/__init__.py b/rp_reporter/rp_reporter/__init__.py
index cd4189b..d46c59e 100644
--- a/rp_reporter/rp_reporter/__init__.py
+++ b/rp_reporter/rp_reporter/__init__.py
@@ -1 +1,2 @@
-from .batch_reporter import upload_job
\ No newline at end of file
+from .settings import *
+from .batch_reporter import upload_job
diff --git a/rp_reporter/rp_reporter/batch_reporter.py b/rp_reporter/rp_reporter/batch_reporter.py
index 1f6ec61..5cbcc04 100755
--- a/rp_reporter/rp_reporter/batch_reporter.py
+++ b/rp_reporter/rp_reporter/batch_reporter.py
@@ -1,15 +1,15 @@
-from time import sleep
-
+#!/usr/bin/python
import click
-import logging
-from collections import deque
-
-import yaml
-import itertools
-import jmespath
-from typing import List, Optional
-
import jenkins_jinny.main as jj
+import jmespath
+import itertools
+import logging
+import yaml
+
+from collections import deque
+from time import sleep
+from typing import List, Optional
+from pbr.version import VersionInfo
from rp_reporter.settings import TIME_FORMAT
from rp_reporter.report_from_xml import timestamp, Reporter
@@ -17,7 +17,7 @@
LOG = logging.getLogger("rp_reporter")
def grep(text: List, patterns: List, context_size: int,
- blacklist: List[str] = None ) :
+ blacklist: List[str] = None ):
"""Works like `grep -rn`
returns found text with line before and after
:param text:
@@ -25,25 +25,39 @@
:param context_size: count of lines before and after to return
:return: Yields list of lines
"""
- context = deque(maxlen=context_size)
+
+ context = deque(maxlen=context_size + 1)
result = list()
- after_count = 0
+ lines_to_read_after_fail = 0
+
+ def found(_line):
+ if any(pattern.lower() in _line.lower() for pattern in patterns):
+ if any(blacklisted.lower() in _line.lower()
+ for blacklisted in blacklist):
+ return False
+ return True
+ return False
+
for num, line in enumerate(text, start=1):
context.append(f"{num} {line}")
- if any(pattern.lower() in line.lower() for pattern in patterns):
- if any(blacklisted.lower() in line.lower()
- for blacklisted in blacklist):
- continue
+
+ if result:
+ result.append(f"{num} {line}")
+
+ if found(line):
+ # import ipdb; ipdb.set_trace()
if not result:
result = list(context)
- after_count = context_size
- continue
- if after_count > 0:
- result.append(f"{num} {line}")
- after_count -= 1
- if result and after_count == 0:
+ result.append("^" * 100)
+ lines_to_read_after_fail = context_size + 1
+
+ if lines_to_read_after_fail > 0:
+ lines_to_read_after_fail -= 1
+
+ if result and lines_to_read_after_fail == 0:
yield result
result = list()
+
if result:
yield result
@@ -212,7 +226,7 @@
name=job.name,
start_time=timestamp(),
attributes=tags,
- description=f"Deploy job {job.url}"
+ description=f"Deployed job {job.url} by {job.triggered_by}"
)
print(f"(^-^)_日 report will be here {rp_client.get_launch_ui_url()}")
job_suite_id = rp_client.start_test_item(
@@ -398,6 +412,12 @@
title=title,
)
+@cli.command()
+def version():
+ package_name = 'rp-reporter'
+ info = VersionInfo(package_name)
+ print("rp-reporter " + info.version_string_with_vcs())
+
if __name__ == '__main__':
cli()
diff --git a/rp_reporter/rp_reporter/settings.py b/rp_reporter/rp_reporter/settings.py
index 9cdd7cd..c07fe2a 100644
--- a/rp_reporter/rp_reporter/settings.py
+++ b/rp_reporter/rp_reporter/settings.py
@@ -1,7 +1,8 @@
-from os import environ
-import yaml
-from pathlib import Path
import logging
+import yaml
+
+from os import environ
+from pathlib import Path
LOG = logging.getLogger("rp_reporter")
@@ -23,12 +24,8 @@
raise Exception(f"{key_name} should be defined in {RP_CONFIG_FILE} or "
f"by environment variable")
-RP_APIKEY = environ.get('RP_APIKEY') or from_conf('RP_APIKEY') or call_error("RP_APIKEY")
-RP_ENDPOINT = environ.get('RP_ENDPOINT') or from_conf('RP_ENDPOINT') or call_error("RP_ENDPOINT")
-RP_PROJECT = environ.get('RP_PROJECT') or from_conf('RP_PROJECT') or call_error("RP_PROJECT")
-
-RP_LOG_FILE = environ.get('RP_LOG_FILE') or from_conf('RP_LOG_FILE')
RP_LOGGING = environ.get('RP_LOGGING') or from_conf('RP_LOGGING') or logging.WARNING
+RP_LOG_FILE = environ.get('RP_LOG_FILE') or from_conf('RP_LOG_FILE')
logging.basicConfig(level=RP_LOGGING,
format='%(asctime)s %(levelname)s - %(filename)s:%(lineno)d (%(funcName)s) - %(message)s',
@@ -36,6 +33,10 @@
filemode='w'
)
+RP_APIKEY = environ.get('RP_APIKEY') or from_conf('RP_APIKEY') or call_error("RP_APIKEY")
+RP_ENDPOINT = environ.get('RP_ENDPOINT') or from_conf('RP_ENDPOINT') or call_error("RP_ENDPOINT")
+RP_PROJECT = environ.get('RP_PROJECT') or from_conf('RP_PROJECT') or call_error("RP_PROJECT")
+
TIME_FORMAT = "%Y-%m-%d"
if __name__ == "__main__":