Skip to content
This repository was archived by the owner on Jun 14, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions paperwork_backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def get_default_ocr_lang():
return lang.terminology
return DEFAULT_OCR_LANG

def get_default_iiw():
return False

class PaperworkConfig(object):
"""
Expand All @@ -139,6 +141,9 @@ def __init__(self):
'ocr_lang': PaperworkSetting(
"OCR", "Lang", get_default_ocr_lang
),
'index_in_workdir': PaperworkSetting(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make things a little bit simpler:

'index_in_workdir': PaperworkSetting(
    "Global", "index_in_workdir", lambda: False, paperwork_cfg_boolean
),

(see frontend:src/paperwork/frontend/util/config.py for examples)

paperwork_cfg_boolean will take care of converting for you the read value from the configuration to a boolean.

"Global", "index_in_workdir", get_default_iiw
),
}

self._configparser = None
Expand Down
29 changes: 18 additions & 11 deletions paperwork_backend/docsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class DocSearch(object):
LABEL_STEP_UPDATING = "label updating"
LABEL_STEP_DESTROYING = "label deletion"

def __init__(self, rootdir, indexdir=None, language=None,
def __init__(self, rootdir, indexdir=None, index_in_workdir=None, language=None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add this argument at the end please ? So it doesn't break the Flatpak build if it is built before the corresponding changes in the frontend are merged.

use_default_index_client=True):
"""
Index files in rootdir (see constructor)
Expand All @@ -263,17 +263,23 @@ def __init__(self, rootdir, indexdir=None, language=None,
self.index = PaperworkIndexClient()

self.fs = fs.GioFileSystem()
self.rootdir = self.fs.safe(rootdir)

self.rootdir = self.fs.unsafe(rootdir)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will break if rootdir (the work directory) is not on a local path (Samba GVfs or SSH GVfs for instance)

localdir = os.path.expanduser("~/.local")
if indexdir is None:
base_data_dir = os.getenv(
"XDG_DATA_HOME",
os.path.join(localdir, "share")
)
indexdir = os.path.join(base_data_dir, "paperwork")

indexdir = os.path.join(indexdir, "index")

if self.rootdir is not None and index_in_workdir.lower() == 'true':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. No need to check self.rootdir is not None here. If it would be None, the call to self.fs.unsafe(rootdir) would raise an Exception

  2. index_in_workdir.lower() == 'true' will break with the default value passed of the constructor (__init__(..., index_in_workdir=None, ...)). I think it would be best if the constructor takes a boolean (letting the caller do the conversion if required), with a default value of False.

base_data_dir = self.rootdir
localdir = base_data_dir
indexdir = os.path.join(base_data_dir, "index")

else:

if indexdir is None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the if and the else above it can be merged --> elif

base_data_dir = os.getenv(
"XDG_DATA_HOME",
os.path.join(localdir, "share")
)
indexdir = os.path.join(base_data_dir, "paperwork/index")

label_guesser_dir = os.path.join(indexdir, "label_guessing")
self.index.open(localdir, base_data_dir, indexdir, label_guesser_dir,
rootdir, language=language)
Expand Down Expand Up @@ -351,6 +357,7 @@ def get_doc_from_docid(self, docid, doc_type_name=None, inst=True):

def find_documents(self, sentence, limit=None, must_sort=True,
search_type='fuzzy'):

return self.index.find_documents(sentence, limit=limit,
must_sort=must_sort,
search_type=search_type)
Expand Down
2 changes: 1 addition & 1 deletion paperwork_backend/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_docsearch():

verbose("Work directory: {}".format(pconfig.settings['workdir'].value))

dsearch = docsearch.DocSearch(pconfig.settings['workdir'].value)
dsearch = docsearch.DocSearch(pconfig.settings['workdir'].value, index_in_workdir = pconfig.settings['index_in_workdir'].value)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: No spaces around the '=' in this case.

dsearch.reload_index()
return dsearch

Expand Down