Skip to content

Instantly share code, notes, and snippets.

@khancyr
Last active May 4, 2022 11:40
Show Gist options
  • Save khancyr/5c53a527280f99b4313cd10ed2a202f3 to your computer and use it in GitHub Desktop.
Save khancyr/5c53a527280f99b4313cd10ed2a202f3 to your computer and use it in GitHub Desktop.
create500logs.py
#!/usr/bin/env python
from pathlib import Path
from shutil import move
import random
import time
# ArduPilot SITL Logs path
LOGSPATH = Path("logs")
if LOGSPATH.exists() and any(LOGSPATH.iterdir()):
print("Backing up current log directory")
for i in range(0, 500):
backupdir = Path(LOGSPATH.name + str(i))
if not backupdir.exists():
move(str(LOGSPATH.absolute()), backupdir.absolute())
break
LOGSPATH.mkdir()
print("Add LASTLOG.TXT file with counter at 11")
with open("logs/LASTLOG.TXT", 'w') as lastlogfile:
lastlogfile.write("11\n")
print("Create fakelogs from 11 to 500 on logs directory")
for i in range(11, 501):
new_log = LOGSPATH / Path(f"{str(i).zfill(8)}.BIN")
with open(new_log, 'w+') as logfile:
logfile.write(f"I AM LOG {i}\n")
for j in range(1, random.randint(0, 5000)):
logfile.write("FAKELOG")
time.sleep(0.05)
print("Wait 5 seconds to have significant different creation time")
time.sleep(5)
print("Create fakelogs from 1 to 11")
for i in range(1, 11):
new_log = LOGSPATH / Path(f"{str(i).zfill(8)}.BIN")
with open(new_log, 'w+') as logfile:
logfile.write(f"I AM LOG {i}\n")
for j in range(1, random.randint(0, 5000)):
logfile.write("FAKELOG")
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment