VirtualBox

source: vbox/trunk/doc/manual/add_file_to_id_only_references.py@ 107390

Last change on this file since 107390 was 107390, checked in by vboxsync, 5 weeks ago

Docs: bugref:10705. bugref: 10829. The docs build has been modified to split generated refentry dita files and the user manual files and the following commits from doc's team git repo has been applied:

0946136c74dda0483704db891345cb39548b4e28 Started consolidating known issues and troubleshooting information
845b847e6a8e778b38a57867e25ee5e086a73800 Added individual topics for list of known issues, integrated into Troubleshooting section.
bb574836aac775889bd61e4a72f489617fcb7d18 Removed EFI firmware from experimental features for 7.2
6d2e68b244869991e713d170ecd239739d99ba56 Moved known issues into Known Issues section
e2630c896561587718b5c3197c384a38d07014d5 Merge branch 'VBP-1461_experimental-features' into 'main'
0512e2cce51f49ccdc56f3381a2a0c924f2bd278 Feedback on known issues
a77d6c980f6ff5cad9d32b2fb9290990093a03fa Restructured host and guest OS topics
988af5cc9628f5de0806531bc98686f691a911fd Updates with feedbback from Jacob
982a61c9f25b22b745ec483e763e3d88efe59c40 Included feedback from Jacob
93181c8c6cc2d9a26bcccb1145cb0423c0d9f4c9 Updated known issues with feedback from Klaus
8bc369561c383f09b409fe5e44f507440b3735fb Created Legacy Guest OS section
d7932f55accdab7a03666302d58b8c941cd48be2 Moved known issues to more appropriate places for the info
2a4aa094ba8a7ac6894d2a777316eabf41746580 Further moving of known issues
baeabd5308c5519a4dc26b4197be9b00e419a85a Updated links to cli_topics

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1#!/usr/bin/env python3
2
3# Standard python imports.
4import glob;
5import os;
6import re;
7import sys;
8
9
10g_oReHref = re.compile(r'\bhref=("[^">#./]+"|\'[^\'>#./]+\')');
11
12def modifyDitaFile(dIdToFile, sContent):
13 """
14 Modifies the href attributes in this file.
15 """
16 current_file_is_refentry = False
17 if any(current_file_name.lower() in s.lower() for s in refentry_files):
18 current_file_is_refentry = True
19 sModified = '';
20 offPrev = 0;
21 for oMatch in g_oReHref.finditer(sContent):
22 sId = oMatch.group(1)[1:-1];
23 if sId in dIdToFile:
24 reference_is_refentry = False
25 if any(os.path.splitext(dIdToFile[sId])[0].lower() in s.lower() for s in refentry_files):
26 reference_is_refentry = True
27 if current_file_is_refentry and not reference_is_refentry:
28 sModified += sContent[offPrev : oMatch.start(1)] + '"../topics/' + dIdToFile[sId] + '#' + sId + '"';
29 else:
30 sModified += sContent[offPrev : oMatch.start(1)] + '"' + dIdToFile[sId] + '#' + sId + '"';
31 if sId == "vboxmanage-modifyvm-vrde":
32 print("========*******=======")
33 print(reference_is_refentry)
34 print(current_file_name)
35 print(current_file_is_refentry)
36 print(dIdToFile[sId])
37 print(f"ppppppp{sId}")
38 print(refentry_files)
39 print("========xxxxxxx=======")
40
41 offPrev = oMatch.end(1);
42 if offPrev < len(sContent):
43 sModified += sContent[offPrev:];
44 return sModified;
45
46def info(sMessage):
47 """ Info message. """
48 print('add_file_to_id_only_references.py: info: %s' % sMessage);
49 return 1;
50
51def error(sMessage):
52 """ Reports an error. """
53 print('add_file_to_id_only_references.py: error: %s' % sMessage, file = sys.stderr);
54 return 1;
55
56def syntax(sMessage):
57 """ Reports a syntax error. """
58 print('add_file_to_id_only_references.py: syntax error: %s' % sMessage, file = sys.stderr);
59 return 2;
60
61def usage():
62 """ Reports usage. """
63 print('usage: add_file_to_id_only_references.py [--verbose|--quiet] --mapping-file <map.db> file1.dita [file2.dita [...]]');
64 return 0;
65
66def main(asArgs):
67 dIdToFile = None;
68 fEndOfArgs = False;
69 fVerbose = False;
70 iArg = 1;
71 while iArg < len(asArgs):
72 sArg = asArgs[iArg];
73 if sArg[0] == '-' and not fEndOfArgs:
74 # Options.
75 if sArg == '--':
76 fEndOfArgs = True;
77 elif sArg in ('--help', '-h', '-?'):
78 return usage();
79 elif sArg in ('--version', '-V' ):
80 print(__version__[__version__.find(':') + 2:-2]);
81 elif sArg in ('--quiet', '-q' ):
82 fVerbose = False;
83 elif sArg in ('--verbose', '-v' ):
84 fVerbose = True;
85 elif sArg in ('--refentry_file_list', '-f' ):
86 iArg += 1;
87 if iArg >= len(asArgs):
88 return syntax('Expected a list of refentry files following "--refentry_file_list"!');
89 global refentry_files
90 refentry_files = asArgs[iArg].split(' ')
91 elif sArg in ('--mapping-file', '-m'):
92 iArg += 1;
93 if iArg >= len(asArgs):
94 return syntax('Expected filename following "--mapping-file"!');
95 # Load the database file.
96 sArg = asArgs[iArg];
97 try:
98 with open(sArg, 'r', encoding = 'utf-8') as oFile:
99 dIdToFile = {};
100 for sLine in oFile:
101 sId, sFile = sLine.split('=');
102 dIdToFile[sId.strip()] = sFile.strip();
103 except Exception as oXcpt: # pylint: disable=broad-exception-caught
104 return error('Failed to open and parse "%s": %s' % (sArg, oXcpt,));
105 if fVerbose:
106 info('Loaded %s IDs from "%s"' % (len(dIdToFile), sArg));
107 else:
108 return syntax('Unknown option: %s' % (sArg,));
109 else:
110 # File to modify.
111 if dIdToFile is None:
112 return syntax('A mapping database must be given before any other files!');
113
114 try:
115 with open(sArg, 'r', encoding = 'utf-8') as oFile:
116 sContent = oFile.read();
117 except Exception as oXcpt: # pylint: disable=broad-exception-caught
118 return error('Failed to open and read "%s": %s' % (sArg, oXcpt,));
119 global current_file_name
120 current_file_name = os.path.splitext(os.path.basename(sArg))[0]
121 prefix = "flat-"
122 if current_file_name.startswith(prefix):
123 current_file_name = current_file_name[len(prefix):]
124 sModified = modifyDitaFile(dIdToFile, sContent);
125 if sModified != sContent:
126 if fVerbose:
127 info('Writing out modified "%s"...' % (sArg,));
128 try:
129 with open(sArg, 'w', encoding = 'utf-8') as oFile:
130 oFile.write(sModified);
131 except Exception as oXcpt: # pylint: disable=broad-exception-caught
132 return error('Failed to open and write back "%s": %s' % (sArg, oXcpt,));
133 elif fVerbose:
134 info('No changes to "%s"...' % (sArg,));
135
136 iArg += 1;
137 return 0;
138
139if __name__ == "__main__":
140 main(sys.argv)
141
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette