Last change
on this file was
d90ab82,
checked in by Jose M. Guisado <jguisado@…>, 2 years ago
|
format: use autopep8
Use autopep8 for coding format, and only for whitespace changes. This
change drops use of tabs in favor of spaces.
Doesn't use autopep8 --aggresive option.
Format command:
$ autopep8 --inline --recursive .
When using git-blame, use --ignore-rev in order to ignore this
reformatting commit.
|
-
Property mode set to
100644
|
File size:
942 bytes
|
Rev | Line | |
---|
[5f92257] | 1 | # Copyright (C) 2020-2021 Soleta Networks <info@soleta.eu> |
---|
[be84b0a] | 2 | # |
---|
| 3 | # This program is free software: you can redistribute it and/or modify it under |
---|
| 4 | # the terms of the GNU Affero General Public License as published by the |
---|
[5f92257] | 5 | # Free Software Foundation; either version 3 of the License, or |
---|
| 6 | # (at your option) any later version. |
---|
[be84b0a] | 7 | |
---|
[b765ee5] | 8 | import json |
---|
| 9 | |
---|
[d90ab82] | 10 | |
---|
[40bd146] | 11 | def scope_lookup(scope_id, scope_type, d): |
---|
[d90ab82] | 12 | if scope_id == d.get('id') and scope_type == d.get('type'): |
---|
| 13 | return d |
---|
| 14 | for scope in d['scope']: |
---|
| 15 | lookup = scope_lookup(scope_id, scope_type, scope) |
---|
| 16 | if lookup is not None: |
---|
| 17 | return lookup |
---|
| 18 | return None |
---|
| 19 | |
---|
[be84b0a] | 20 | |
---|
| 21 | def ips_in_scope(scope): |
---|
[d90ab82] | 22 | if scope is None: |
---|
| 23 | return [] |
---|
| 24 | if 'ip' in scope: |
---|
| 25 | return [scope['ip']] |
---|
| 26 | ips = [] |
---|
| 27 | for child in scope['scope']: |
---|
| 28 | ips += ips_in_scope(child) |
---|
| 29 | return ips |
---|
| 30 | |
---|
[b765ee5] | 31 | |
---|
| 32 | def print_json(text): |
---|
[d90ab82] | 33 | payload = json.loads(text) |
---|
| 34 | print(json.dumps(payload, sort_keys=True, indent=2)) |
---|
Note: See
TracBrowser
for help on using the repository browser.