Skip to content

Commit

Permalink
Merge pull request #44 from Yannig/master_sub_dir
Browse files Browse the repository at this point in the history
Allow Ansigenome to scan roles in a sub directory
  • Loading branch information
nickjj committed Jan 26, 2016
2 parents ada7f61 + d0e5d21 commit eb85483
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 7 additions & 4 deletions ansigenome/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def graph_dot(self):
color_length = len(adjusted_colors) - 1

random_index = random.randint(1, color_length)
roles_list += " role_{0} [label = \"{0}\"]\n" \
.format(re.sub(r'[.-]', '_', name))
roles_list += " role_{0} [label = \"{1}\"]\n" \
.format(re.sub(r'[.-/]', '_', name), name)

edge = '\n edge [color = "{0}"];\n' \
.format(adjusted_colors[random_index])
Expand All @@ -137,8 +137,11 @@ def graph_dot(self):
for dependency in sorted(fields["dependencies"]):
dependency_name = utils.role_name(dependency)
dependencies += " role_{0} -> role_{1}\n".format(
re.sub(r'[.-]', '_', name),
utils.normalize_role(dependency_name, self.config)
re.sub(r'[.-/]', '_', name),
re.sub(r'[.-/]', '_',
utils.normalize_role(dependency_name,
self.config)
)
)

edges += "{0}{1}\n".format(edge, dependencies)
Expand Down
9 changes: 8 additions & 1 deletion ansigenome/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def exit_if_no_roles(roles_count, roles_path):
sys.exit()


def roles_dict(path, repo_prefix=""):
def roles_dict(path, repo_prefix="", repo_sub_dir=""):
"""
Return a dict of role names and repo paths.
"""
Expand All @@ -319,6 +319,13 @@ def roles_dict(path, repo_prefix=""):

roles = os.walk(path).next()[1]

# First scan all directories
for role in roles:
for sub_role in roles_dict(path + "/" + role, repo_prefix="",
repo_sub_dir=role + "/"):
aggregated_roles[role + "/" + sub_role] = role + "/" + sub_role

# Then format them
for role in roles:
if is_role(os.path.join(path, role)):
if isinstance(role, basestring):
Expand Down

0 comments on commit eb85483

Please sign in to comment.