-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search: Replace third-party OpenDocument search helper.
The odt2txt package is extremely slow when working with larger documents, and has not seen an update in 7+ years. Fixes #3481
- Loading branch information
Showing
5 changed files
with
53 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,7 +94,6 @@ Depends: | |
poppler-utils, | ||
exif, | ||
id3, | ||
odt2txt, | ||
catdoc, | ||
untex, | ||
html2text, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import zipfile | ||
from pathlib import Path | ||
from html.parser import HTMLParser | ||
|
||
class Parser(HTMLParser): | ||
parsed = [] | ||
get_next_data = False | ||
concat_next_data = False | ||
|
||
def handle_starttag(self, tag, attrs): | ||
if tag.startswith("text") or tag.startswith("meta"): | ||
if tag == "text:s": | ||
self.concat_next_data = True | ||
self.get_next_data = True | ||
|
||
def handle_endtag(self, tag): | ||
pass | ||
|
||
def handle_data(self, data): | ||
if self.get_next_data: | ||
if data != "\n": | ||
if self.concat_next_data: | ||
self.parsed[-1] += " " + data | ||
self.concat_next_data = False | ||
else: | ||
self.parsed.append(data.strip()) | ||
self.get_next_data = False | ||
|
||
path = sys.argv[1] | ||
|
||
parser = Parser() | ||
zipfile = zipfile.ZipFile(path) | ||
files = zipfile.infolist() | ||
|
||
for f in files: | ||
if f.filename in ("meta.xml", "content.xml"): | ||
contents = zipfile.read(f.filename).decode() | ||
parser.feed(contents) | ||
if len(parser.parsed) == 0: | ||
continue | ||
|
||
out_str = ", ".join(parser.parsed) | ||
print(f"{Path(f.filename).stem}: {out_str}\n", flush=True, file=sys.stdout) | ||
parser.parsed = [] | ||
exit(0) |
6 changes: 3 additions & 3 deletions
6
...hird-party/libreoffice.nemo_search_helper → search-helpers/odf.nemo_search_helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[Nemo Search Helper] | ||
TryExec=odt2txt; | ||
Exec=odt2txt %s | ||
TryExec=nemo-odf-to-txt; | ||
Exec=nemo-odf-to-txt %s | ||
MimeType=application/vnd.oasis.opendocument.text;application/vnd.oasis.opendocument.spreadsheet;application/vnd.oasis.opendocument.presentation;application/vnd.oasis.opendocument.graphics; | ||
priority=100 | ||
Priority=100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters