From 5ff8f08df90bcb5bb1f2a741969836b4fc335f6b Mon Sep 17 00:00:00 2001 From: gulsahkose Date: Tue, 19 Oct 2021 17:16:19 +0300 Subject: Add save tool. This tool uses collabora online to create saved version of the given files. Takes input ooxml files directory. Produces output directory that contains exported files Change-Id: Id596a746db366465aca4e37b17c8dd0ee3eb3952 --- bin/ooxml-autosave.py | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 bin/ooxml-autosave.py diff --git a/bin/ooxml-autosave.py b/bin/ooxml-autosave.py new file mode 100644 index 000000000000..6800e84b3a3a --- /dev/null +++ b/bin/ooxml-autosave.py @@ -0,0 +1,76 @@ +#!/usr/bin/python + +import os, getopt, sys, shutil +import subprocess + +def main(argv): + inputdir = '' + outputdir = '' + + #read the arguments + try: + opts, args = getopt.getopt(argv,"hi:o:",["idir=","odir="]) + except getopt.GetoptError: + print ('auto-save.py -i -o ') + sys.exit(2) + + for opt, arg in opts: + if opt == '-h': + print ('auto-save.py -i -o ') + sys.exit() + elif opt in ("-i", "--idir"): + inputdir = arg + elif opt in ("-o", "--odir"): + outputdir = arg + + + subdirs = get_list_of_subdir(inputdir) + for dir in subdirs: + i = dir.rfind("/") + extension = dir[i+1:] + + saved_path = os.path.join(outputdir, extension) + if(os.path.exists(saved_path)): + shutil.rmtree(saved_path) + + os.makedirs(saved_path) + + file_list = get_list_of_files(dir) + + for file in file_list: + + j = file.rfind("/") + saved_file_path = os.path.join(saved_path, file[j+1:]) + + command = "curl --insecure -F \"file=@"+ file +"\" https://localhost:9980/lool/convert-to/"+extension+" > " + saved_file_path + os.system(command) + +def get_list_of_files(directory_name): + + list_of_file = os.listdir(directory_name) + all_files = list() + + for filename in list_of_file: + full_path = os.path.join(directory_name, filename) + if os.path.isdir(full_path): + all_files = all_files + get_list_of_files(full_path) + else: + all_files.append(full_path) + + return all_files + +def get_list_of_subdir(directory_name): + + list_of_file = os.listdir(directory_name) + subdirs = list() + + for filename in list_of_file: + full_path = os.path.join(directory_name, filename) + if os.path.isdir(full_path): + subdirs.append(full_path) + + return subdirs + + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file -- cgit