benchmarks.wiki / Public workspace
BigCodeBench / BigCodeBench v0.1.0_hf a09d60bb-1683-5e77-b103-007fe60b6056
Problem
Answer published by the source. Consult the official source to check your work against its answer.
complete prompt
import os
import glob
import subprocess
def task_func(directory, backup_dir='/path/to/backup'):
"""
Backup all '.log' files in a specified directory to a tar.gz file and delete the original files after backup.
The backup file is named 'logs_backup.tar.gz' and placed in the specified backup directory.
Parameters:
- directory (str): The directory that contains the log files to be backed up.
- backup_dir (str, optional): The directory where the backup file will be saved.
Default is '/path/to/backup'.
Returns:
- str: The path to the backup file if logs are found, otherwise returns a message 'No logs found to backup'.
Raises:
- FileNotFoundError: If the specified directory does not exist.
Requirements:
- subprocess
- glob
- os
Example:
>>> task_func('/path/to/logs')
'/path/to/backup/logs_backup.tar.gz'
>>> task_func('/path/to/logs', '/alternative/backup/dir')
'/alternative/backup/dir/logs_backup.tar.gz'
"""
instruct prompt
Backup all '.log' files in a specified directory to a tar.gz file and delete the original files after backup. The backup file is named 'logs_backup.tar.gz' and placed in the specified backup directory.
The function should raise the exception for: FileNotFoundError: If the specified directory does not exist.
The function should output with:
str: The path to the backup file if logs are found, otherwise returns a message 'No logs found to backup'.
You should write self-contained code starting with:
Code
import os
import glob
import subprocess
def task_func(directory, backup_dir='/path/to/backup'):
code prompt
Code
import os
import glob
import subprocess
def task_func(directory, backup_dir='/path/to/backup'):
entry point
task_func
libs
- glob
- subprocess
- os
Discussion
No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
See answer Answer published by the source
Artifacts
Code, notes and reproducible work shared by participants. Files are served from a separate origin.
No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.
Source and history
initial import