-
Notifications
You must be signed in to change notification settings - Fork 527
/
renumber-chapters.py
executable file
·52 lines (46 loc) · 1.78 KB
/
renumber-chapters.py
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
49
50
51
52
#!/usr/bin/env python
import subprocess
from pathlib import Path
MOVES = [
# change these as desired
('chapter_04b_high_gear_low_gear', 'chapter_05_high_gear_low_gear'),
('chapter_05_uow', 'chapter_06_uow'),
('chapter_06_aggregate', 'chapter_07_aggregate'),
("chapter_07_events_and_message_bus", "chapter_08_events_and_message_bus"),
("chapter_08_all_messagebus", "chapter_09_all_messagebus"),
("chapter_09_commands", "chapter_10_commands"),
("chapter_10_external_events", "chapter_11_external_events"),
("chapter_11_cqrs", "chapter_12_cqrs"),
("chapter_12_dependency_injection", "chapter_13_dependency_injection"),
]
for frm, to in MOVES:
subprocess.run(['git', 'mv', f'{frm}.asciidoc', f'{to}.asciidoc'], check=True)
sources = list(Path(__file__).absolute().parent.glob('*.asciidoc'))
otherthings = [
'chapters.py',
'atlas.json',
'Readme.md',
'rebase-chapters.sh',
'rebase-appendices.sh',
]
for frm, to in MOVES:
subprocess.run(
['sed', '-i', f's/{frm}/{to}/g'] + sources + otherthings,
check=True,
)
input('base repo done, ready to do submodules')
for frm, to in MOVES:
code = Path(__file__).absolute().parent / 'code'
subprocess.run(['git', 'branch', '-m', frm, to], cwd=code)
subprocess.run(['git', 'branch', '--unset-upstream', to], cwd=code) # untested
subprocess.run(['git', 'push', 'origin', f':{frm}'], cwd=code)
subprocess.run(['git', 'checkout', to], cwd=code)
subprocess.run(['git', 'push', '-u', 'origin', to], cwd=code)
from chapters import NO_EXERCISE
if to not in NO_EXERCISE:
# untested
subprocess.run(
['git', 'branch', '-m', f'{frm}_exercise', f'{to}_exercise'],
cwd=code, check=True,
)
input(f'{frm}->{to} done in theory')