• This project
    • Loading...
  • Sign in

josch / img2pdf

Go to a project
Toggle navigation
Toggle navigation pinning
  • Projects
  • Groups
  • Snippets
  • Help
  • Project
  • Activity
  • Repository
  • Pipelines
  • Graphs
  • Issues 10
  • Merge Requests 0
  • Wiki
  • Network
  • Create a new issue
  • Builds
  • Commits
  • Issue Boards
Merged
Merge Request !7 opened 2020-09-23 17:05:23 UTC by Paul@pingemi

Add Windows support for paths containing wildcards "*" and "?"

Img2pdf accepts paths containing wildcards such as *.jpg to efficiently refer to multiple input files that match the wildcard expression. Under POSIX environments the command line shell is expected to perform this expansion, however Windows requires the command line utility itself to expand the wildcard expression.

Ideally this would be performed by argparse as described in this draft PEP: https://mail.python.org/pipermail/python-ideas/2015-August/035244.html

Since argparse doesn't do it, this commit performs expansion directly.

Some implementation notes:

  • Wildcard characters "*" and "?" are not valid in Windows filenames
  • Code doesn't support bracket wildcards such as [0-3] on Windows since they are valid filename characters
  • Due to expansion, the images list collected by argparse may contain sub-lists. Code uses chain.from_iterable to create a flat list.
  • Paths that refer to non-existant files raise an error message, while wildcards that match no files are silently ignored.

Let me know if there's any changes you'd like me to make for merging.

Edited 2020-10-05 08:25:14 UTC
Request to merge pingemi:master into master
×

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch http://gitlab.mister-muffin.de/pingemi/img2pdf.git master
git checkout -b pingemi/img2pdf-master FETCH_HEAD

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git checkout master
git merge --no-ff pingemi/img2pdf-master

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

Merged by josch 2020-10-05 08:25:14 UTC

The changes were merged into master.

  • Discussion 2
  • Commits 3
  • Changes 1
  • {{ resolvedDiscussionCount }}/{{ discussionCount }} {{ discussionCount | pluralize 'discussion' }} resolved
  • josch
    @josch commented 2020-09-23 17:42:51 UTC
    Master

    You are not the first person having suggested this feature. What I'm curious about is proof for your claim "on windows, program is responsible for expanding wildcards such as *.jpg". I'm not a windows user and I understand the the windows built-in shells do not expand wildcards. But where is it written that on windows, wildcards are expected to work and expected to be handled by the program?

  • Paul
    @pingemi commented 2020-09-23 18:19:42 UTC

    Good question. You can find that assertion and explanation in the draft PEP: "Yet Windows users generally expect wildcards to work. For example, most built-in commands such as dir and type accept wildcard arguments, and have since the early days of MS-DOS."

    Since the shell is not doing expansion, that leaves the application.

    One mechanism Windows provides for resolving wildcards is FindFirstFileA: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilea Note that the sample code is using FindFirstFileA to expand a "[target_file]" parameter suggesting handling file paths with wildcards is an intended use.

    When exploring solutions, I also tried python's os.walk(...) function figuring it would call into win32, but it does not seem to support wildcards.

  • josch
    @josch 2020-10-05 08:25:11 UTC

    Mentioned in commit 490c3f12

  • josch
    @josch 2020-10-05 08:25:14 UTC

    Status changed to merged

  • Please register or sign in to post a comment
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
2
2 participants
Reference: josch/img2pdf!7
×

Revert this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.
×

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.