From 2869d0382ffc1681205fafd44b81ad08df0247ab Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Wed, 3 Apr 2013 13:10:23 +0200 Subject: [PATCH] [bin] Added a new script odfGrep.py that allows to search for some pattern within odt and ods files. --- bin/odfGrep.py | 76 +++++++++++++++++++++++++++++++++++++++ gen/ui/ckeditor/config.js | 5 ++- 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 bin/odfGrep.py diff --git a/bin/odfGrep.py b/bin/odfGrep.py new file mode 100644 index 0000000..a22ab80 --- /dev/null +++ b/bin/odfGrep.py @@ -0,0 +1,76 @@ +'''This script allows to perform a "grep" command that will be applied on files + content.xml and styles.xml within all ODF files (odt and ods) found within a + given folder.''' + +# ------------------------------------------------------------------------------ +import sys, os.path, zipfile, time, subprocess +from appy.shared.utils import getOsTempFolder, FolderDeleter + +# ------------------------------------------------------------------------------ +usage = '''Usage: python odfGrep.py [file|folder] [keyword]. + + If *file* is given, it is the path to an ODF file (odt or ods). grep will be + run on this file only. + If *folder* is given, the grep will be run on all ODF files found in this + folder and sub-folders. + + *keyword* is the string to search within the file(s). +''' + +# ------------------------------------------------------------------------------ +class OdfGrep: + toGrep = ('content.xml', 'styles.xml') + toUnzip = ('.ods', '.odt') + def __init__(self, fileOrFolder, keyword): + self.fileOrFolder = fileOrFolder + self.keyword = keyword + self.tempFolder = getOsTempFolder() + + def callGrep(self, folder): + '''Performs a "grep" with self.keyword in p_folder.''' + cmd = 'grep -irn "%s" %s' % (self.keyword, folder) + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = proc.communicate() + return bool(out) + + def grepFile(self, fileName): + '''Unzips the .xml files from file named p_fileName and performs a + grep on it.''' + # Unzip the file in the temp folder + name = 'f%f' % time.time() + tempFolder = os.path.join(self.tempFolder, name) + os.mkdir(tempFolder) + zip = zipfile.ZipFile(fileName) + for zippedFile in zip.namelist(): + if zippedFile not in self.toGrep: continue + destFile = os.path.join(tempFolder, zippedFile) + f = open(destFile, 'wb') + fileContent = zip.read(zippedFile) + f.write(fileContent) + f.close() + # Run "grep" in this folder + match = self.callGrep(tempFolder) + if match: + print 'Found in', fileName + FolderDeleter.delete(tempFolder) + + def run(self): + if os.path.isfile(self.fileOrFolder): + self.grepFile(self.fileOrFolder) + elif os.path.isdir(self.fileOrFolder): + # Grep on all files found in this folder. + for dir, dirnames, filenames in os.walk(self.fileOrFolder): + for name in filenames: + if os.path.splitext(name)[1] in self.toUnzip: + self.grepFile(os.path.join(dir, name)) + else: + print '%s does not exist.' % self.fileOrFolder + +# ------------------------------------------------------------------------------ +if __name__ == '__main__': + if len(sys.argv) != 3: + print usage + sys.exit() + OdfGrep(sys.argv[1], sys.argv[2]).run() +# ------------------------------------------------------------------------------ diff --git a/gen/ui/ckeditor/config.js b/gen/ui/ckeditor/config.js index 889e242..264560e 100644 --- a/gen/ui/ckeditor/config.js +++ b/gen/ui/ckeditor/config.js @@ -6,10 +6,9 @@ CKEDITOR.editorConfig = function(config) { config.toolbar = 'Appy'; config.toolbar_Appy = [ { name: 'basicstyles', - items: ["Format", "Bold", "Italic", "Underline", "Strike", - "Subscript", "Superscript", "RemoveFormat"]}, + items: ["Bold", "Italic", "Underline"]}, { name: 'paragraph', - items: ["NumberedList","BulletedList"]}, + items: ["NumberedList","BulletedList","Outdent","Indent"]}, { name: 'clipboard', items: ["Cut","Copy","Paste","PasteText","Undo","Redo"]}, { name: 'editing', items: ["Scayt"]},