Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tweak document file naming #831

Merged
merged 4 commits into from
Aug 10, 2024
Merged

Conversation

alexfikl
Copy link
Collaborator

This tries to be a bit smarter about adding suffixes to files in papis add and papis addto. Namely:

  • Unifies the two with a new function papis.paths.rename_document_files.
  • Makes files with different extensions not get a suffix, e.g. if one adds file.pdf and file.md it will now not rename them like <something>.pdf and <something>-a.md (with the a suffix).

@alexfikl
Copy link
Collaborator Author

I'm not convinced by the suffix logic in here.

One thing that's not great: if the user adds more PDF files without add-file-name, then they'll be renamed to <file1>.pdf, <file2>-a.pdf, <file3>-b.pdf, which is likely not the intention.

@alexfikl alexfikl marked this pull request as draft April 23, 2024 12:04
@alexfikl alexfikl changed the title feat: add fancy document file naming feat: tweak document file naming Apr 23, 2024
@jghauser
Copy link
Member

Great improvement! ❤️

I'm not convinced by the suffix logic in here.

One thing that's not great: if the user adds more PDF files without add-file-name, then they'll be renamed to <file1>.pdf, <file2>-a.pdf, <file3>-b.pdf, which is likely not the intention.

Can you explain a bit what the problem is here? It sounds like that would be the expected behaviour? Or do you think the default should be warning of clashes and abort?

@alexfikl
Copy link
Collaborator Author

Can you explain a bit what the problem is here? It sounds like that would be the expected behaviour? Or do you think the default should be warning of clashes and abort?

I was mostly thinking that if you give papis add some files ["paper1.pdf", "supplement1.pdf"], it wouldn't be very helpful to rename them to ["paper1.pdf", "supplement1-a.pdf"]. They're not overlapping in any way, so the suffix doesn't give any benefit.

@jghauser
Copy link
Member

Oh right, yeah that really isn't intuitive!

@alexfikl
Copy link
Collaborator Author

Finally got back to this a bit. With the new version it should

  • Ensure that all files are unique after renaming.
  • Not add suffixes unless needed: it keeps a set of known files and adds a suffix only when encountering a repeated one (suffixes are counted by extension as well).

For a few examples of the results (ignoring any bugs, fingers crossed)

  1. Without add-file-name set to anything (i.e. keeping the original file names)
$ papis add some-file.pdf some-other-file.pdf some-other-file.md
["some-file.pdf", "some-other-file.pdf", "some-other-file.md"]

$ papis add some-file.pdf some-file.pdf some-other-file.md
["some-file.pdf", "some-file-a.pdf", "some-other-file.md"]

we don't do any actual deduplication of whatever the user passed on the command line, so both those files will go in :\

  1. With some add-file-name, e.g. {doc[year]}-{doc[author]}
$ papis add some-file.pdf some-other-file.pdf some-other-file.md
["1918-einstein.pdf", "1918-einstein-a.pdf", "1918-einstein.md"]

and

$ papis addto --files some-new-file.pdf --files some-new-file.md
["1918-einstein.pdf", "1918-einstein-a.pdf", "1918-einstein.md", "1918-einstein-b.pdf", "1918-einstein-a.md"]

This looks pretty good to me, so unless someone notices a bug, it should go in soon-ish 😁

@alexfikl alexfikl marked this pull request as ready for review August 10, 2024 09:24
@tuurep
Copy link

tuurep commented Aug 10, 2024

Thanks very much! I don't know if I should be arsed to test it since your comment describes the cases so well, looks good and am excited for this 😄

@alexfikl
Copy link
Collaborator Author

alexfikl commented Aug 10, 2024

Thanks very much! I don't know if I should be arsed to test it since your comment describes the cases so well, looks good and am excited for this 😄

Thank you for taking a look! I'll go ahead and merge it then. Feel free to open issues if you find some bugs in there 😁

@alexfikl alexfikl merged commit 7d7900d into papis:main Aug 10, 2024
37 checks passed
@alexfikl alexfikl deleted the smart-file-names branch August 10, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants