Created
April 25, 2017 03:02
-
-
Save dmsimard/7f7b5dfd0e41ec339c0c00b1909cd2e5 to your computer and use it in GitHub Desktop.
treeview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/dmsimard/dev/dlrn/venv/bin/python2.7 /home/dmsimard/dev/ara/treeview.py | |
{ | |
"home": { | |
"jenkins": { | |
"workspace": { | |
"gate-openstack-ansible-openstack-ansible-aio-ubuntu-xenial": { | |
"playbooks": [ | |
{ | |
"roles": { | |
"system_crontab_coordination": { | |
"tasks": [ | |
"main.yml" | |
] | |
} | |
} | |
}, | |
[ | |
"include-playbook.yml-os-tempest-install.yml" | |
] | |
] | |
} | |
} | |
} | |
}, | |
"etc": { | |
"ansible": { | |
"roles": { | |
"openstack_openrc": { | |
"tasks": [ | |
"main.yml" | |
] | |
}, | |
"os_tempest": { | |
"tasks": [ | |
"tempest_run.yml", | |
"tempest_resources.yml", | |
"tempest_post_install.yml", | |
"tempest_install_apt.yml", | |
"tempest_install.yml", | |
"main.yml" | |
] | |
}, | |
"apt_package_pinning": { | |
"tasks": [ | |
"main.yml" | |
] | |
}, | |
"rsyslog_client": { | |
"tasks": [ | |
"rsyslog_client_pre_install.yml", | |
"rsyslog_client_post_install.yml", | |
"rsyslog_client_install.yml", | |
"main.yml" | |
], | |
"handlers": [ | |
"main.yml" | |
] | |
} | |
} | |
} | |
} | |
} | |
Process finished with exit code 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import json | |
def path_to_dict(path): | |
dirlist = path.split('/') | |
def pack(dirlist): | |
if len(dirlist) == 1: | |
return dirlist | |
elif len(dirlist): | |
return {dirlist[0]: pack(dirlist[1:])} | |
return dirlist | |
return pack(dirlist) | |
def merge(a, b): | |
if isinstance(a, dict) and isinstance(b, dict): | |
result = {} | |
for key, value in a.iteritems(): | |
if key not in b: | |
result[key] = value | |
else: | |
result[key] = merge(value, b[key]) | |
for key, value in b.iteritems(): | |
if key not in a: | |
result[key] = value | |
return result | |
if isinstance(a, list) and isinstance(b, list): | |
return a + b | |
else: | |
return [a, b] | |
return b | |
if __name__ == '__main__': | |
paths = [ | |
'/etc/ansible/roles/apt_package_pinning/tasks/main.yml', | |
'/etc/ansible/roles/openstack_openrc/tasks/main.yml', | |
'/etc/ansible/roles/os_tempest/tasks/main.yml', | |
'/etc/ansible/roles/os_tempest/tasks/tempest_install.yml', | |
'/etc/ansible/roles/os_tempest/tasks/tempest_install_apt.yml', | |
'/etc/ansible/roles/os_tempest/tasks/tempest_post_install.yml', | |
'/etc/ansible/roles/os_tempest/tasks/tempest_resources.yml', | |
'/etc/ansible/roles/os_tempest/tasks/tempest_run.yml', | |
'/etc/ansible/roles/rsyslog_client/handlers/main.yml', | |
'/etc/ansible/roles/rsyslog_client/tasks/main.yml', | |
'/etc/ansible/roles/rsyslog_client/tasks/rsyslog_client_install.yml', | |
'/etc/ansible/roles/rsyslog_client/tasks/rsyslog_client_post_install.yml', | |
'/etc/ansible/roles/rsyslog_client/tasks/rsyslog_client_pre_install.yml', | |
'/home/jenkins/workspace/gate-openstack-ansible-openstack-ansible-aio-ubuntu-xenial/playbooks/include-playbook.yml-os-tempest-install.yml', | |
'/home/jenkins/workspace/gate-openstack-ansible-openstack-ansible-aio-ubuntu-xenial/playbooks/roles/system_crontab_coordination/tasks/main.yml' | |
] | |
parsed_dirs = dict() | |
for path in paths: | |
dir = path_to_dict(path) | |
parsed_dirs = merge(dir, parsed_dirs) | |
clean = parsed_dirs[parsed_dirs.keys()[0]] | |
print(json.dumps(clean, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment