diff options
author | gulsahkose <gulsah.kose@collabora.com> | 2021-10-19 17:16:19 +0300 |
---|---|---|
committer | gulsahkose <gulsah.kose@collabora.com> | 2021-10-19 17:16:19 +0300 |
commit | 5ff8f08df90bcb5bb1f2a741969836b4fc335f6b (patch) | |
tree | 4cac0ddf9140fdda1d61da5bd7038ab703da1b09 | |
parent | 001ab94b0af51d9908ce078b4f422a87ad79d971 (diff) |
Add save tool.feature/ooxml-analyze
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
-rw-r--r-- | bin/ooxml-autosave.py | 76 |
1 files changed, 76 insertions, 0 deletions
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 <inputdir> -o <outputdir>') + sys.exit(2) + + for opt, arg in opts: + if opt == '-h': + print ('auto-save.py -i <inputdir> -o <outputdir>') + 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 |