Files
OpenHands/opendevin/runtime/files.py
Robert Brennan fadcdc117e Migrate to new folder structure in preparation for refactor (#1531)
* fix up folder structure

* update docs

* fix imports

* fix imports

* fix imoprt

* fix imports

* fix imports

* fix imports

* fix test import

* fix tests

* fix main import
2024-05-02 17:01:54 +00:00

43 lines
1.1 KiB
Python

from pathlib import Path
from typing import Any, Dict, List
class WorkspaceFile:
name: str
children: List['WorkspaceFile']
def __init__(self, name: str, children: List['WorkspaceFile']):
self.name = name
self.children = children
def to_dict(self) -> Dict[str, Any]:
"""Converts the File object to a dictionary.
Returns:
The dictionary representation of the File object.
"""
return {
'name': self.name,
'children': [child.to_dict() for child in self.children],
}
def get_folder_structure(workdir: Path) -> WorkspaceFile:
"""Gets the folder structure of a directory.
Args:
workdir: The directory path.
Returns:
The folder structure.
"""
root = WorkspaceFile(name=workdir.name, children=[])
for item in workdir.iterdir():
if item.is_dir():
dir = get_folder_structure(item)
if dir.children:
root.children.append(dir)
else:
root.children.append(WorkspaceFile(name=item.name, children=[]))
return root