Skip to content

Commit

Permalink
use file tree func from SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
cxnt committed Oct 6, 2023
1 parent 631ce93 commit d5673c5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
26 changes: 0 additions & 26 deletions src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,3 @@ def create_coco_ann_templates(dataset, user_name, meta: sly.ProjectMeta):
],
)
return coco_ann, coco_captions


def tree(dir_path: str, file_limit) -> str:
out = subprocess.Popen(
["tree", "--filelimit", f"{file_limit}", "-h", "-n", dir_path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
stdout, stderr = out.communicate()
return stdout.decode("utf-8")


def log_tree(dir_path: str, logger, level, file_limit: int = 500):
out = tree(dir_path, file_limit)
log_levels = {
"info": logger.info,
"debug": logger.debug,
"warning": logger.warning,
"error": logger.error,
}
if level not in log_levels:
raise ValueError(
f"Unknown logger level: {level}. Available levels: info, debug, warning, error"
)
log_func = log_levels[level]
log_func("DIRECTORY_TREE", extra={"tree": out})
3 changes: 1 addition & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def export_to_coco(api: sly.Api, task_id, context, state, app_logger):

sly.logger.info(f"Dataset [{dataset.name}] processed!")

# sly.fs.log_tree(g.storage_dir, sly.logger, level="info")
f.log_tree(g.storage_dir, sly.logger, level="info", file_limit=50)
sly.fs.log_tree(g.storage_dir, sly.logger, level="info")

full_archive_name = f"{task_id}_{g.project.name}.tar"
result_archive = os.path.join(g.my_app.data_dir, full_archive_name)
Expand Down

0 comments on commit d5673c5

Please sign in to comment.