mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-20 23:44:19 +01:00
Add makedirs to file operations (#3289)
* Add makedirs to file operations * Add new directory tests for file operations * Fix wrong setUp test error * Simplify makedirs and use correct nested path * Fix linter error --------- Co-authored-by: Nicholas Tindle <nick@ntindle.com> Co-authored-by: James Collins <collijk@uw.edu>
This commit is contained in:
@@ -142,8 +142,7 @@ def write_to_file(filename: str, text: str) -> str:
|
||||
return "Error: File has already been updated."
|
||||
try:
|
||||
directory = os.path.dirname(filename)
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
with open(filename, "w", encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
log_operation("write", filename)
|
||||
@@ -167,6 +166,8 @@ def append_to_file(filename: str, text: str, should_log: bool = True) -> str:
|
||||
str: A message indicating success or failure
|
||||
"""
|
||||
try:
|
||||
directory = os.path.dirname(filename)
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
with open(filename, "a") as f:
|
||||
f.write(text)
|
||||
|
||||
@@ -236,6 +237,8 @@ def download_file(url, filename):
|
||||
filename (str): Filename to save the file as
|
||||
"""
|
||||
try:
|
||||
directory = os.path.dirname(filename)
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
message = f"{Fore.YELLOW}Downloading file from {Back.LIGHTBLUE_EX}{url}{Back.RESET}{Fore.RESET}"
|
||||
with Spinner(message) as spinner:
|
||||
session = requests.Session()
|
||||
|
||||
Reference in New Issue
Block a user