-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (39 loc) · 1.83 KB
/
Copy pathmain.py
File metadata and controls
48 lines (39 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import shutil
import argparse
def main():
parser = argparse.ArgumentParser(
description="Copy .clangd, .clang-format, and .gitignore files to the specified root directory.")
parser.add_argument('root_dir', type=str, help='Root directory where files will be copied')
args = parser.parse_args()
# Get the directory of the script
script_dir = os.path.dirname(os.path.abspath(__file__))
# Ensure the root directory exists
root_dir = os.path.abspath(args.root_dir)
if not os.path.exists(root_dir):
print(f"Error: The specified root directory '{root_dir}' does not exist.")
return
script_dir = os.path.dirname(os.path.abspath(__file__))
# List of files to process
files_to_copy = ['.clangd', '.clang-format', '.gitignore']
for file_name in files_to_copy:
src = os.path.join(script_dir, file_name)
dest = os.path.join(root_dir, file_name)
if file_name == '.gitignore' and os.path.exists(dest):
print(
"You already have a .gitignore, not clobbering it. If you want to replace it, delete the current one first.")
else:
if file_name != '.gitignore' or not os.path.exists(dest):
shutil.copy(src, dest)
print(f"Copied {file_name} to {root_dir}")
# Handle special case for .gitignore
gitignore_path = os.path.join(root_dir, '.gitignore')
if os.path.exists(gitignore_path):
with open(gitignore_path, 'r+') as f:
lines = f.readlines()
if '.gitignore\n' not in lines:
f.write('.gitignore\n')
print(
"Added .gitignore to .gitignore as it was not present, this is required because the content of the gitignore is stored in clang_formatting not in this project.")
if __name__ == "__main__":
main()