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
|
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import fileinput
import re
from argparse import ArgumentParser, RawTextHelpFormatter
options = ArgumentParser(description='Qhp file updater',
formatter_class=RawTextHelpFormatter)
options.add_argument('-f',
'--filename',
type=str,
help='Qhp filename with the relative path.',
required=True)
options.add_argument('-v',
'--vfolder',
type=str,
help='String to be injected into the Qhp file.')
args=options.parse_args()
try:
for line in fileinput.input(args.filename,inplace=True,backup='.bak'):
line_copy=line.strip()
if not line_copy: # check for empty line
continue
match=re.match('(^.*virtualFolder.)doc(.*$)',line)
if match:
repl=''.join([match.group(1), args.vfolder, match.group(2)])
print(line.replace(match.group(0),repl),end=' ')
else:
print(line.rstrip())
except:
pass
|