Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic folder function #58

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: basic folder function
  • Loading branch information
scrambldchannel committed Dec 5, 2022
commit eb73ff62169da4085cfd432d330c989a9ba5cf1d
15 changes: 15 additions & 0 deletions src/tm1filetools/tools/filetool.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,21 @@ def _find_files(self, suffix: str, recursive: bool = False, prefix: str = "", pa

return self._case_insensitive_glob(self._data_path, f"{prefix}*.{suffix}", recursive=recursive)

def _find_folders(self, recursive: bool = False, path: Path = None):
"""
Return list of all folders in the given path or within the data directory
"""

# this doesn't really belong here but put here for now
# also need to think about what else needs to be added to this list
static_folders = ["}applications", "}async", "}externals"] # noqa

if path:

return [f for f in path.iterdir() if f.is_dir()]

return [f for f in self._data_path.iterdir() if f.is_dir()]

@staticmethod
def _filter_model_and_or_control(objects, model: bool = True, control: bool = False):

Expand Down
17 changes: 17 additions & 0 deletions tests/test_tools/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from tm1filetools.files import TM1SubsetFile
from tm1filetools.tools import TM1FileTool


Expand Down Expand Up @@ -41,3 +42,19 @@ def test_find_all(test_folder):
ft.find_all()

assert all(f.stem != "cat" for f in ft._feeders_files)


def test_find_folders(test_folder):

ft = TM1FileTool(test_folder)

folders = ft._find_folders()

# make sure we get something
assert len(folders) > 0

# make sure suffix taken into account
assert all(f.name != "cat" for f in folders)

assert any(f.name == f"cat{TM1SubsetFile.folder_suffix}" for f in folders)
assert all(f.name != f"frog{TM1SubsetFile.folder_suffix}" for f in folders)