| Conditions | 5 |
| Total Lines | 64 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 46 | sys.exit() |
||
| 47 | |||
| 48 | |||
| 49 | def get_reports_xml(gmp: Gmp, from_date: date, to_date: date) -> e.Element: |
||
| 50 | """ Getting the Reports in the defined time period """ |
||
| 51 | |||
| 52 | report_filter = "rows=-1 created>{0} and created<{1}".format( |
||
| 53 | from_date.isoformat(), to_date.isoformat() |
||
| 54 | ) |
||
| 55 | |||
| 56 | return gmp.get_reports(filter=report_filter) |
||
| 57 | |||
| 58 | |||
| 59 | def print_result_sums( |
||
| 60 | reports_xml: e.Element, from_date: date, to_date: date |
||
| 61 | ) -> None: |
||
| 62 | print('Found {0} reports'.format(len(reports_xml.xpath('report')))) |
||
| 63 | |||
| 64 | sum_high = reports_xml.xpath( |
||
| 65 | 'sum(report/report/result_count/hole/full/text())' |
||
| 66 | ) |
||
| 67 | sum_medium = reports_xml.xpath( |
||
| 68 | 'sum(report/report/result_count/warning/full/text())' |
||
| 69 | ) |
||
| 70 | sum_low = reports_xml.xpath( |
||
| 71 | 'sum(report/report/result_count/info/full/text())' |
||
| 72 | ) |
||
| 73 | |||
| 74 | print( |
||
| 75 | 'Summary of results from {3} to {4}\nHigh: {0}\nMedium: {1}\nLow: ' |
||
| 76 | '{2}\n\n'.format( |
||
| 77 | int(sum_high), |
||
| 78 | int(sum_medium), |
||
| 79 | int(sum_low), |
||
| 80 | from_date.isoformat(), |
||
| 81 | to_date.isoformat(), |
||
| 82 | ) |
||
| 83 | ) |
||
| 84 | |||
| 85 | |||
| 86 | def print_result_tables(gmp: Gmp, reports_xml: e.Element) -> None: |
||
| 87 | report_list = reports_xml.xpath('report') |
||
| 88 | |||
| 89 | for report in report_list: |
||
| 90 | report_id = report.xpath('report/@id')[0] |
||
| 91 | name = report.xpath('name/text()')[0] |
||
| 92 | |||
| 93 | res = gmp.get_report(report_id) |
||
| 94 | |||
| 95 | print('\nReport: {0}'.format(report_id)) |
||
| 96 | |||
| 97 | table_data = [['Hostname', 'IP', 'Bericht', 'high', 'medium', 'low']] |
||
| 98 | |||
| 99 | for host in res.xpath('report/report/host'): |
||
| 100 | hostname = host.xpath( |
||
| 101 | 'detail/name[text()="hostname"]/../' 'value/text()' |
||
| 102 | ) |
||
| 103 | if len(hostname) > 0: |
||
| 104 | hostname = str(hostname[0]) |
||
| 105 | else: |
||
| 106 | hostname = "" |
||
| 107 | |||
| 108 | ip = host.xpath('ip/text()')[0] |
||
| 109 | high = host.xpath('result_count/hole/page/text()')[0] |
||
| 110 | medium = host.xpath('result_count/warning/page/text()')[0] |
||
| 140 |