generated from awegroup/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding pictures, figures, yaml files
- Loading branch information
1 parent
b396077
commit 08865c7
Showing
4 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import importlib | ||
import pprintpp | ||
from importlib.resources import files | ||
from typing import List, Dict, Union | ||
|
||
|
||
def extract_package_contents(package, top_level=True) -> Dict[str, Union[str, Dict]]: | ||
package_path = files(package) | ||
package_name = package.__name__.split(".")[0] | ||
contents = {} | ||
|
||
for item in package_path.iterdir(): | ||
if item.is_file(): | ||
contents[item.name] = "file" | ||
elif item.is_dir(): | ||
try: | ||
subpackage = importlib.import_module(f"{package.__name__}.{item.name}") | ||
subcontents = extract_package_contents(subpackage, top_level=False) | ||
contents[item.name] = subcontents | ||
except ImportError: | ||
# If it's not a valid Python package, just add it as an empty directory | ||
contents[item.name] = "empty directory" | ||
|
||
if top_level: | ||
print(f"{package_name} package content extracted from path:") | ||
print(f" {package_path}") | ||
print(f"--------------------------------") | ||
return contents | ||
|
||
|
||
if __name__ == "__main__": | ||
import TUDELFT_V3_LEI_KITE | ||
from TUDELFT_V3_LEI_KITE.print_dict_content import print_dict_content | ||
|
||
package_content = extract_package_contents(TUDELFT_V3_LEI_KITE) | ||
print_dict_content(package_content) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
def print_dict_content(d, depth_level=0): | ||
indent = " " * depth_level # Create indentation based on depth_level | ||
|
||
for key, value in d.items(): | ||
if value == "file": | ||
print(f"{indent}file: {key}") | ||
elif value == "empty directory": | ||
print(f"{indent}empty directory: {key}") | ||
else: | ||
if depth_level == 0: | ||
print(f"{indent}directory: {key}") | ||
else: | ||
print(f"{indent}{'sub_' * depth_level}directory: {key}") | ||
|
||
print_dict_content(value, depth_level + 1) # Recursive call |