Skip to content

Commit

Permalink
Release 2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dev@domcie.net authored and dev@domcie.net committed Sep 20, 2021
1 parent 5976a36 commit e47ce2a
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.idea/
/D2F.egg-info/
/d2f2.egg-info/
/build/
/dist/
/Pipfile
/Pipfile.lock
/Pipfile.lock
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Modify names of output files
* Standalone GUI client

## [2.1.2] - 2021-09-20

### Changed

* Command can now only be invoked with ``d2f2``
* Option flags are now all lowercase

## [2.1.0] - 2021-04-16

### Changed
Expand Down Expand Up @@ -100,7 +107,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Core functionality: convert image folders into PDF files over CLI
* "Multiple" mode for converting batches of folders more easily

[Unreleased]: https://github.com/DomCie/D2F2/compare/v2.1.0...HEAD
[Unreleased]: https://github.com/DomCie/D2F2/compare/v2.1.2...HEAD
[2.1.2]: https://github.com/DomCie/D2F2/compare/v2.1.0...v2.1.2
[2.1.0]: https://github.com/DomCie/D2F2/compare/v2.0.3...v2.1.0
[2.0.3]: https://github.com/DomCie/D2F2/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/DomCie/D2F2/compare/v2.0.1...v2.0.2
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# d2f2 2.1.0
# d2f2 2.1.2

*d2f2* is a tool written in Python to convert image folders into files.

Expand Down Expand Up @@ -28,18 +28,18 @@ d2f2 /a/path /another/path ...

#### Batch mode

Useful for converting big batches of folders, this mode converts each subdirectory within the given directories into a file. To use it, add the ``-B``/``--batch`` option to the command:
Useful for converting big batches of folders, this mode converts each subdirectory within the given directories into a file. To use it, add the ``-b``/``--batch`` option to the command:

```commandline
d2f2 -B /a/path /another/path ...
d2f2 -b /a/path /another/path ...
```

### Output format

By default, *d2f2* saves files in the PDF format. If you want to use another supported format, use the ``-F``/``--format`` option:
By default, *d2f2* saves files in the PDF format. If you want to use another supported format, use the ``-f``/``--format`` option:

```commandline
d2f2 /a/path ... -F FORMAT
d2f2 /a/path ... -f FORMAT
```

Currently, there are 2 supported formats (with more to be added in the future). Use the appropriate format as the FORMAT parameter:
Expand All @@ -49,18 +49,18 @@ Currently, there are 2 supported formats (with more to be added in the future).

### Output path

By standard, *d2f2* saves files to the current directory. If you want another output path, use the ``-O``/``--output`` option:
By standard, *d2f2* saves files to the current directory. If you want another output path, use the ``-o``/``--output`` option:

```commandline
d2f2 /a/path ... -O /an/output/path
d2f2 /a/path ... -o /an/output/path
```

### Sorting mode

By default, *d2f2* sorts the images in alphanumeric, ascending order (A-Z). If you want to use another sorting mode you can specify one by using the ``-S``/``--sort`` option:
By default, *d2f2* sorts the images in alphanumeric, ascending order (A-Z). If you want to use another sorting mode you can specify one by using the ``-s``/``--sort`` option:

```commandline
d2f2 /a/path ... -S MODE
d2f2 /a/path ... -s MODE
```

Currently, there are 6 sorting modes available. Use the corresponding number from the following list as the MODE parameter:
Expand Down Expand Up @@ -93,4 +93,4 @@ d2f2 --shell

## Disclaimer

This tool uses the [PyMuPDF](https://github.com/pymupdf/PyMuPDF) library, which provides the core functionality of inserting images into PDF files. According to its licensing terms, this project is released under the AGPLv3 license (for more information, see LICENSE)
This tool uses the [PyMuPDF](https://github.com/pymupdf/PyMuPDF) library, which provides the core functionality of inserting images into PDF files. According to its licensing terms, this project is released under the AGPLv3 license (for more information, see LICENSE)
2 changes: 1 addition & 1 deletion d2f2/CONFIGURATIONS.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MODULE_NAME = "d2f2"
VERSION = "2.1.0"
VERSION = "2.1.2"
AUTHOR = "DomCie"
23 changes: 12 additions & 11 deletions d2f2/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from d2f2.CONFIGURATIONS import *
from d2f2.convert import *

import d2f2.shell as shell
Expand All @@ -9,18 +10,18 @@
def main() -> int:
argv = sys.argv

help_msg = f"{argv[0]} [OPTIONS] PATH [PATH...]\nConvert image folders into files\n\nOPTIONS:\n-H, " \
f"--help\t\t\t\tShow this help\n-B, --batch\t\t\t\tConvert each subfolder of PATH to a " \
f"file\n-F, --format FORMAT\t\t\tSpecify an output format\n\t\t\t\t\tAVAILABLE FORMATS:\t[PDF] " \
help_msg = f"{MODULE_NAME} [OPTIONS] PATH [PATH...]\nConvert image folders into files\n\nOPTIONS:\n-h, " \
f"--help\t\t\t\tShow this help\n-b, --batch\t\t\t\tConvert each subfolder of PATH to a " \
f"file\n-f, --format FORMAT\t\t\tSpecify an output format\n\t\t\t\t\tAVAILABLE FORMATS:\t[PDF] " \
f"Portable Document Format (default)\n\t\t\t\t\t\t\t\t[CBZ] Comic Book Format, " \
f"ZIP-compressed\n--shell\t\t\t\t\tOpen interactive shell\n-S, --sort MODE\t\t\t\tSpecify a sorting " \
f"ZIP-compressed\n--shell\t\t\t\t\tOpen interactive shell\n-s, --sort MODE\t\t\t\tSpecify a sorting " \
f"mode\n\t\t\t\t\tAVAILABLE MODES:\t[ 1] A-Z (default)\n\t\t\t\t\t\t\t\t[-1] Z-A\n\t\t\t\t\t\t\t\t" \
f"[ 2] Last time modified, oldest first\n\t\t\t\t\t\t\t\t[-2] Last time modified, " \
f"newest first\n\t\t\t\t\t\t\t\t[ 3] Time of creation / metadata change, " \
f"oldest first\n\t\t\t\t\t\t\t\t[-3] Time of creation / metadata change, newest first\n-O, --output " \
f"oldest first\n\t\t\t\t\t\t\t\t[-3] Time of creation / metadata change, newest first\n-o, --output " \
f"OUTPUT_PATH\t\tSave files to OUTPUT_PATH (default: current directory)"
try:
opts, args = getopt.getopt(argv[1:], 'BF:HO:S:', ['batch', 'format=', 'help', 'output=', 'shell', 'sort='])
opts, args = getopt.getopt(argv[1:], 'bf:ho:s:', ['batch', 'format=', 'help', 'output=', 'shell', 'sort='])
except getopt.GetoptError:
print(help_msg)
return 2
Expand All @@ -31,9 +32,9 @@ def main() -> int:
sorting_mode = 1

for opt, par in opts:
if opt in ('-B', '--batch'):
if opt in ('-b', '--batch'):
is_batch = True
elif opt in ('-F', '--format'):
elif opt in ('-f', '--format'):
if par in ('PDF', 'CBZ'):
converter = ConverterFactory.create(par)
elif par == '':
Expand All @@ -42,10 +43,10 @@ def main() -> int:
else:
print(f"error: {par} isn't a valid output format", file=sys.stderr)
return 2
elif opt in ('-H', '--help'):
elif opt in ('-h', '--help'):
print(help_msg)
return 0
elif opt in ('-O', '--output'):
elif opt in ('-o', '--output'):
if os.path.exists(par):
output_path = par
elif par == '':
Expand All @@ -57,7 +58,7 @@ def main() -> int:
elif opt == '--shell':
shell.start()
return 0
elif opt in ('-S', '--sort'):
elif opt in ('-s', '--sort'):
if par in ('1', '-1', '2', '-2', '3', '-3'):
sorting_mode = int(par)
elif par == '':
Expand Down
9 changes: 5 additions & 4 deletions d2f2/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def single(self, input_path: str, output_path=os.getcwd(), sorting_mode=1) -> No
"""

entries = list(filter(lambda x: x.is_file(), self.sorted_entries(os.scandir(input_path), sorting_mode)))
len_entries = len(entries)

if input_path[-1] in ('/', '\\'):
input_path = input_path[:-1]

if len(entries) > 0:
if len_entries > 0:
doc_name = os.path.basename(input_path) + self.file_extension
self.convert(entries, doc_name, output_path)
else:
print(f"\nskipping {os.path.basename(input_path)}, empty directory...")
print(f"skipping {os.path.basename(input_path)}, empty directory...")

def batch(self, input_path: str, output_path=os.getcwd(), sorting_mode=1) -> None:
"""Converts each subdirectory of a directory into a file.
Expand Down Expand Up @@ -113,7 +114,7 @@ def convert(self, entries: list, doc_name: str, output_path: str) -> None:

doc.save(os.path.join(output_path, doc_name))

print(f"\n\"{doc_name}\" saved to {output_path}")
print(f"\"{doc_name}\" saved to {output_path}")


class CBZConverter(Converter):
Expand All @@ -128,7 +129,7 @@ def convert(self, entries: list, doc_name: str, output_path: str) -> None:
suffix = pathlib.Path(e.path).suffix
zf.write(e.path, f"{i + 1}{suffix}", compress_type=zipfile.ZIP_DEFLATED)

print(f"\n\"{doc_name}\" saved to {output_path}")
print(f"\"{doc_name}\" saved to {output_path}")


class ConverterFactory:
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = d2f2
version = 2.1.0
version = 2.1.2
author = DomCie
author_email = dev@domcie.net
description = Tool to convert image folders into files
Expand All @@ -20,4 +20,4 @@ install_requires =

[options.entry_points]
console_scripts =
d2f2 = D2F2:main
d2f2 = d2f2:main

0 comments on commit e47ce2a

Please sign in to comment.