mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-03-20 06:41:54 +01:00
133 lines
4.8 KiB
Plaintext
133 lines
4.8 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "",
|
|
"evalue": "",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31mThe kernel failed to start as the Python Environment 'Python 3.11.10' is no longer available. Consider selecting another kernel or refreshing the list of Python Environments."
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os\n",
|
|
"import shutil\n",
|
|
"\n",
|
|
"import os\n",
|
|
"import shutil\n",
|
|
"\n",
|
|
"def rename_files(directory):\n",
|
|
" for root, dirs, files in os.walk(directory, topdown=True):\n",
|
|
" # Skip .git directory\n",
|
|
" if '.git' in dirs:\n",
|
|
" dirs.remove('.git')\n",
|
|
" \n",
|
|
" # Rename files\n",
|
|
" for filename in files:\n",
|
|
" if not filename.startswith('.'): # Avoid dotfiles\n",
|
|
" new_filename = filename.replace(\"danswer\", \"onyx\").replace(\"Danswer\", \"Onyx\")\n",
|
|
" if new_filename != filename:\n",
|
|
" old_path = os.path.join(root, filename)\n",
|
|
" new_path = os.path.join(root, new_filename)\n",
|
|
" os.rename(old_path, new_path)\n",
|
|
" print(f\"Renamed file: {old_path} -> {new_path}\")\n",
|
|
" \n",
|
|
" # Rename directories\n",
|
|
" for dir_name in dirs:\n",
|
|
" if not dir_name.startswith('.'): # Avoid dotfiles\n",
|
|
" new_dir_name = dir_name.replace(\"danswer\", \"onyx\").replace(\"Danswer\", \"Onyx\")\n",
|
|
" if new_dir_name != dir_name:\n",
|
|
" old_dir_path = os.path.join(root, dir_name)\n",
|
|
" new_dir_path = os.path.join(root, new_dir_name)\n",
|
|
" try:\n",
|
|
" os.rename(old_dir_path, new_dir_path)\n",
|
|
" print(f\"Renamed directory: {old_dir_path} -> {new_dir_path}\")\n",
|
|
" except OSError as e:\n",
|
|
" if e.errno == 66: # Directory not empty\n",
|
|
" # Move all contents to the new directory\n",
|
|
" if not os.path.exists(new_dir_path):\n",
|
|
" os.makedirs(new_dir_path)\n",
|
|
" for item in os.listdir(old_dir_path):\n",
|
|
" s = os.path.join(old_dir_path, item)\n",
|
|
" d = os.path.join(new_dir_path, item)\n",
|
|
" if os.path.isdir(s):\n",
|
|
" shutil.copytree(s, d, dirs_exist_ok=True)\n",
|
|
" else:\n",
|
|
" shutil.copy2(s, d)\n",
|
|
" shutil.rmtree(old_dir_path)\n",
|
|
" print(f\"Moved contents and renamed directory: {old_dir_path} -> {new_dir_path}\")\n",
|
|
" else:\n",
|
|
" raise\n",
|
|
"\n",
|
|
"def process_directory(directory):\n",
|
|
" rename_files(directory)\n",
|
|
" print(\"File and directory renaming complete.\")\n",
|
|
"\n",
|
|
"# Specify the directory path here\n",
|
|
"directory_path = \"./\"\n",
|
|
"\n",
|
|
"# Confirm before proceeding\n",
|
|
"# confirm = input(f\"This will rename files and directories in {os.path.abspath(directory_path)}. Are you sure? (y/n): \")\n",
|
|
"# if confirm.lower() != 'y':\n",
|
|
"# print(\"Operation cancelled.\")\n",
|
|
"# else:\n",
|
|
"# process_directory(directory_path)\n",
|
|
"# print(\"File and directory renaming complete.\")\n",
|
|
"\n",
|
|
"def process_directory(directory):\n",
|
|
" rename_files(directory)\n",
|
|
" print(\"File and directory renaming complete.\")\n",
|
|
"\n",
|
|
"# # Specify the directory path here\n",
|
|
"# directory_path = \"./\"\n",
|
|
"\n",
|
|
"# process_directory(directory_path)\n",
|
|
"# print(\"File and directory renaming complete.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "",
|
|
"evalue": "",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[1;31mThe kernel failed to start as the Python Environment 'Python 3.11.10' is no longer available. Consider selecting another kernel or refreshing the list of Python Environments."
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"process_directory(directory_path)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": ".venv",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.11.10"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|