Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Modify idx location #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Modify idx location #6

wants to merge 6 commits into from

Conversation

JoshuaPK
Copy link

These are the modifications I created to make the index reside with the documents.

@@ -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
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)

@@ -139,6 +141,9 @@ def __init__(self):
'ocr_lang': PaperworkSetting(
"OCR", "Lang", get_default_ocr_lang
),
'index_in_workdir': PaperworkSetting(
Copy link
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.


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

if self.rootdir is not None and index_in_workdir.lower() == 'true':
Copy link
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.


else:

if indexdir is None:
Copy link
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

@@ -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
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.

@@ -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
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.

@JoshuaPK
Copy link
Author

JoshuaPK commented Feb 4, 2018

Thanks for the corrections, @jflesch . Can you take a look at the changes I just committed and see if they are satisfactory?

localdir = os.path.expanduser("~/.local")
if indexdir is None:

if index_in_workdir == True:
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: shorter: if index_in_workdir:

if indexdir is None:

if index_in_workdir == True:
self.rootdir = self.fs.unsafe(rootdir)
Copy link
Member

Choose a reason for hiding this comment

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

One minor change and you're good to go:

With your current changes, when index_in_workdir is False, self.rootdir is an URI. When index_in_workdir is True, self.rootdir is a Unix path. Having 2 different types of values for a single attribute can be really bug-prone.
I would prefer that self.rootdir always remain an URI.

Here it can be simply fixed by not changing self.rootdir ; with something like:

if index_in_workdir:
    base_data_dir = self.fs.unsafe(rootdir)
    localdir = base_data_dir
    indexdir = os.path.join(base_data_dir, "index")

@jflesch
Copy link
Member

jflesch commented Feb 6, 2018

I've merged back the backend part of Paperwork in the same Git repository repository than the frontend. Now everything is again in https://github.com/openpaperwork/paperwork/ . I'll archive this repository.

You should be able to just re-apply your changes as-is. Nothing in the code has changed (yet ;).

@jflesch
Copy link
Member

jflesch commented Feb 19, 2018

This repository has been merged with the one of the frontend to make maintenance and continous integration easier. This repository has therefore been archived. I'll have to ask you to open a new PR against https://github.com/openpaperwork/paperwork/tree/develop , sorry.

@jflesch
Copy link
Member

jflesch commented Feb 19, 2018

Also, please don't send PR to include new features into 'master'. They go in the branch 'develop'.

@jflesch
Copy link
Member

jflesch commented Feb 19, 2018

I also have to ask you to not put '.' as commit message ... Please use git rebase -i + git push -f if you want to rearrange your commit history (or messages).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants