#!/usr/bin/env python3

import sys, os, re

# For use with rippledoc. Run this script when your doc
# numbering gets too tight and you want to spread everything
# out by 10. That is, in a directory containing
# 001-foo.md 004-bar.md 005-baz.md 006-moo.md , run this to get
# 010-foo.md 020-bar.md 030-baz.md 040-moo.md .

r1 = re.compile(r'\d{3}-')
curr_fnms = []
for fnm in os.listdir():
    if r1.match(fnm):
        curr_fnms.append(fnm)

curr_fnms.sort()

if len(curr_fnms) > 99:
    print("This script can only cope with max 99 files. Exiting.")
    sys.exit()

n = 10
for curr_fnm in curr_fnms:
    new_fnm = f"{n:03d}" + curr_fnm[3:]
    print(curr_fnm, "-->", new_fnm)
    os.rename(curr_fnm, new_fnm)
    n += 10
