| Conditions | 8 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 | """ |
||
| 51 | def get_profile_choices_for_input(input_tree, benchmark_id, tailoring_tree): |
||
| 52 | """Returns a dictionary that maps profile_ids to their respective titles. |
||
| 53 | """ |
||
| 54 | |||
| 55 | # Ideally oscap would have a command line to do this, but as of now it |
||
| 56 | # doesn't so we have to implement it ourselves. Importing openscap Python |
||
| 57 | # bindings is nasty and overkill for this. |
||
| 58 | |||
| 59 | ret = {} |
||
| 60 | |||
| 61 | def scrape_profiles(root_element, namespace, dest): |
||
| 62 | candidates = \ |
||
| 63 | list(root_element.findall(".//{%s}Benchmark" % (namespace))) |
||
| 64 | if root_element.tag == "{%s}Benchmark" % (namespace): |
||
| 65 | candidates.append(root_element) |
||
| 66 | |||
| 67 | for benchmark in candidates: |
||
| 68 | if benchmark.get("id") != benchmark_id: |
||
| 69 | continue |
||
| 70 | |||
| 71 | for elem in benchmark.findall(".//{%s}Profile" % (namespace)): |
||
| 72 | id_ = elem.get("id") |
||
| 73 | if id_ is None: |
||
| 74 | continue |
||
| 75 | |||
| 76 | title = "<unknown>" |
||
| 77 | for element in elem.findall("{%s}title" % (namespace)): |
||
| 78 | title = element.text |
||
| 79 | break |
||
| 80 | |||
| 81 | dest[id_] = title |
||
| 82 | |||
| 83 | input_root = input_tree.getroot() |
||
| 84 | |||
| 85 | scrape_profiles( |
||
| 86 | input_root, XCCDF11_NS, ret |
||
| 87 | ) |
||
| 88 | scrape_profiles( |
||
| 89 | input_root, XCCDF12_NS, ret |
||
| 90 | ) |
||
| 91 | |||
| 92 | if tailoring_tree is not None: |
||
| 93 | tailoring_root = tailoring_tree.getroot() |
||
| 94 | |||
| 95 | scrape_profiles( |
||
| 96 | tailoring_root, XCCDF11_NS, ret |
||
| 97 | ) |
||
| 98 | scrape_profiles( |
||
| 99 | tailoring_root, XCCDF12_NS, ret |
||
| 100 | ) |
||
| 101 | |||
| 102 | return ret |
||
| 103 | |||
| 113 |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.