simulate_local_edits.py

This commit is contained in:
Alex Fedulov Local user 2024-11-22 15:29:08 +05:00
parent a73f81aec4
commit 590f1871fe

View File

@ -1,72 +1,28 @@
import os
Added line: 7248
Added line: 4601
Added line: 7287
import random
Added line: 3198
Added line: 464
Added line: 8777
Added line: 7695
Added line: 3652
# Constants
NUM_FILES = 1009 # Number of files to edit
LINES_TO_ADD = 99 # Number of lines to add per file
Added line: 7096
LINES_TO_DELETE = 10 # Number of lines to delete per file
Added line: 5245
Added line: 2526
NUM_FILES = 100 # Number of files to edit
LINES_TO_ADD = 5 # Number of lines to add per file
LINES_TO_DELETE = 3 # Number of lines to delete per file
Added line: 8787
Added line: 8734
Added line: 1113
Added line: 4290
Added line: 2417
Added line: 3230
Added line: 515
# Generate random text
Added line: 9723
Added line: 8656
Added line: 1597
Added line: 3065
def random_text(num_lines):
return [f"Random line {random.randint(1, 10000)}\n" for _ in range(num_lines)]
# Modify a file
Added line: 4165
Added line: 8245
Added line: 142
Added line: 5023
Added line: 7357
Added line: 6040
def modify_file(file_path):
try:
Added line: 1099
Added line: 9646
Added line: 7923
with open(file_path, 'r') as f:
lines = f.readlines()
Added line: 6542
# Add random lines
Added line: 4251
Added line: 5740
Added line: 9844
for _ in range(LINES_TO_ADD):
Added line: 6
Added line: 8338
insert_pos = random.randint(0, len(lines)) # Insert at a random position
Added line: 2319
Added line: 4032
lines.insert(insert_pos, f"Added line: {random.randint(1, 10000)}\n")
Added line: 2411
# Delete random lines (if possible)
Added line: 5478
Added line: 4841
Added line: 9340
Added line: 4310
for _ in range(min(LINES_TO_DELETE, len(lines))):
Added line: 3757
delete_pos = random.randint(0, len(lines) - 1)
lines.pop(delete_pos)
@ -76,80 +32,35 @@ Added line: 3757
print(f"Modified: {file_path}")
Added line: 8705
Added line: 1398
except Exception as e:
print(f"Error modifying {file_path}: {e}")
# Get a list of files in the repository
Added line: 7545
Added line: 3285
Added line: 2452
def get_repo_files():
files = []
for root, _, filenames in os.walk("."):
Added line: 7042
for filename in filenames:
Added line: 7053
Added line: 5803
Added line: 3443
Added line: 3726
if filename.endswith(".txt") or filename.endswith(".md") or filename.endswith(".py"): # Edit suitable file types
files.append(os.path.join(root, filename))
Added line: 8634
return files
Added line: 3558
Added line: 742
Added line: 9708
Added line: 6501
# Main script logic
def main():
Added line: 3526
Added line: 3995
Added line: 4562
# Get files in the repository
Added line: 4108
Added line: 6257
Added line: 3916
repo_files = get_repo_files()
if len(repo_files) == 0:
Added line: 4603
Added line: 201
print("No suitable files found in the repository.")
Added line: 9504
return
Added line: 7884
Added line: 8407
# Shuffle and select a subset of files
random.shuffle(repo_files)
files_to_edit = repo_files[:NUM_FILES]
Added line: 917
Added line: 4478
Added line: 4075
Added line: 6205
# Modify selected files
for file_path in files_to_edit:
Added line: 6202
modify_file(file_path)
Added line: 2634
Added line: 8711
Added line: 5191
Added line: 9471
Added line: 2941
Added line: 6864
Added line: 1581
Added line: 8327
Added line: 4067
Added line: 3166
Added line: 3212
Added line: 8222
print("All changes have been made locally. Review the files and commit the changes if needed.")
Added line: 8114
Added line: 9918
if __name__ == "__main__":
Added line: 7986
Added line: 5485
main()