aboutsummaryrefslogtreecommitdiffstats
path: root/fix_common_path.py
blob: 20d974c44ef4a1c06c1d16e7cdf4bb5556b2b660 (plain)
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
#!/usr/bin/env python3
""" Script to fix the path to the common files in Mageia html documentation 

    Usage: python3 fix_common_path.py

"""
from os import walk
from os.path import splitext, join
import fileinput

path_to_fix = 'mcc/4/tr'

# first step: let's walk along the folder
for root, dirs, files in walk(path_to_fix):
    # second step: identification of html files
    for elem in files:
        if splitext(elem)[1] == '.html':
            # third step: replacing the path
            with fileinput.input(files=join(root, elem), inplace=True) as f:
                for line in f:
                    line = line.rstrip('\n')
                    line = line.replace('"../common/', '"../../common/')
                    line = line.replace('(../common/', '(../../common/')
                    # with fileinput, you need to us 'print' and not 'write' to
                    # write in the file
                    print(line)