aboutsummaryrefslogtreecommitdiffstats
path: root/update_manual.py
diff options
context:
space:
mode:
authorClaire Revillet <grenoya@zarb.org>2015-04-10 23:24:13 +0200
committerClaire Revillet <grenoya@zarb.org>2015-04-10 23:24:13 +0200
commit2a5ba81d525138f945ede1923ff3df3d44c0b21a (patch)
tree89fe402656bdedce16da668acda59ae646e25bca /update_manual.py
parent1f5096e898cf6aea1a385e5a7dfc71c29a639e7b (diff)
downloaddoc-2a5ba81d525138f945ede1923ff3df3d44c0b21a.tar
doc-2a5ba81d525138f945ede1923ff3df3d44c0b21a.tar.gz
doc-2a5ba81d525138f945ede1923ff3df3d44c0b21a.tar.bz2
doc-2a5ba81d525138f945ede1923ff3df3d44c0b21a.tar.xz
doc-2a5ba81d525138f945ede1923ff3df3d44c0b21a.zip
add script to help manual update
Diffstat (limited to 'update_manual.py')
-rw-r--r--update_manual.py108
1 files changed, 108 insertions, 0 deletions
diff --git a/update_manual.py b/update_manual.py
new file mode 100644
index 00000000..ab1c4939
--- /dev/null
+++ b/update_manual.py
@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+""" Script to update a manual in one language for one release
+
+ Usage: python3 update_manual.py <manual_name> <release> <language> <archive>
+
+ where:
+
+ * manual_name can be 'mcc' or 'installer'
+ * release can be 2 (installer only), 3, 4 or newer version
+ * language is the language abreviation in lower case (en, fr, de, uk, tr...)
+ * archive is the full path and name of the archive containing the new
+ version of the manual (keep this file out of the git local repository)
+
+ .. note:: Attention
+ You need to have a clean and uptodate git local repository to use that
+ script or it will try to 'git rm' files that are not under version
+ control!!
+
+"""
+import sys
+from os import walk
+from os.path import splitext, join
+from shutil import rmtree, move
+from zipfile import ZipFile
+from subprocess import call
+import fileinput
+
+
+
+def fix_common_path(path_to_fix):
+ # 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)
+
+
+def check_changes_in_filelist(path_to_check, archive_list):
+ toadd = [join(path_to_check, elem) for elem in archive_list
+ if not elem.startswith("common")]
+ toremove = []
+ for root, dirs, files in walk(path_to_check):
+ for elem in files:
+ namefile = join(root, elem)
+ if namefile in toadd:
+ toadd.remove(namefile)
+ else:
+ toremove.append(namefile)
+ return toadd, toremove
+
+
+if __name__ == "__main__":
+ if len(sys.argv) != 5:
+ print("Usage: python3 update_manual.py <manual_name> " +
+ "<release> <language> <archive>")
+ else:
+ manual_name = sys.argv[1]
+ release = sys.argv[2]
+ language = sys.argv[3]
+ archive = sys.argv[4]
+
+ # create the path to the manual
+ manual_path = join(manual_name, release, language)
+
+ # create the zip interface
+ archive_int = ZipFile(archive)
+
+ # check for changes
+ files_to_add, files_to_remove = \
+ check_changes_in_filelist(manual_path, archive_int.namelist())
+
+ # unzip the archive
+ archive_int.extractall(manual_path)
+ common_dir = join(manual_path, 'common')
+ common_common_path = join(manual_name, release, 'common')
+
+ if language == "en":
+ # if english, copy the common directory in the manual/release path
+ rmtree(common_common_path)
+ move(common_dir, common_common_path)
+ else:
+ # or remove the common directory and ...
+ rmtree(common_dir)
+
+ # ... fix the links
+ fix_common_path(manual_path)
+
+ # tell git about the changes
+ command_add = ['git', 'add'] + files_to_add
+ call(command_add)
+
+ command_remove = ['git', 'rm'] + files_to_remove
+ call(command_remove)
+
+ # ask for git status (the user has to commit himself)
+ command_status = ['git', 'status']
+ call(command_status)
+
+