From 006a094865e9872479b915a137d0db198942e7a0 Mon Sep 17 00:00:00 2001 From: Satyam Kumar Date: Sun, 17 May 2020 23:58:40 +0530 Subject: [PATCH 1/4] Fixes #20 - Better docstring and support for extended to_zimwriterfs_args() arguments --- src/zimscraperlib/zim.py | 23 +++++++++++++++++++---- tests/zim/test_zim.py | 5 +++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/zimscraperlib/zim.py b/src/zimscraperlib/zim.py index ac3c8142..8135b446 100644 --- a/src/zimscraperlib/zim.py +++ b/src/zimscraperlib/zim.py @@ -100,11 +100,26 @@ def to_zimwriterfs_args( return arg_list -def make_zim_file(build_dir, output_dir, zim_fname, zim_info): - """ runs zimwriterfs """ +def make_zim_file(build_dir, output_dir, zim_fname, zim_info, **kwargs): + """ runs zimwriterfs + + The function takes in the following arguments + build_dir: The directory to convert into a ZIM file + output_dir: The directory where the ZIM file would be saved + zim_fname: The name of the ZIM file + zim_info: An object of class ZimInfo + + Also supports the following keyword arguments that are passed to to_zimwriterfs_args() + verbose: Use verbose mode while creating ZIM + inflateHtml: Whether try to inflate HTML files + uniqueNamespace: Put everything in namespace 'A' + withoutFTIndex: No fulltext index + minChunkSize: Number of bytes per ZIM cluster + redirects: Path to file containing redirects + """ args = ( - [ZimInfo.zimwriterfs_path] - + zim_info.to_zimwriterfs_args() + [zim_info.zimwriterfs_path] + + zim_info.to_zimwriterfs_args(**kwargs) + [str(build_dir), str(output_dir.joinpath(zim_fname))] ) diff --git a/tests/zim/test_zim.py b/tests/zim/test_zim.py index 00dd4ada..9ed66444 100644 --- a/tests/zim/test_zim.py +++ b/tests/zim/test_zim.py @@ -82,13 +82,14 @@ def test_zimwriterfs_command(monkeypatch, ziminfo): build_dir = pathlib.Path("build") output_dir = pathlib.Path("output") zim_fname = f"{ziminfo.name}.zim" + extras = {"uniqueNamespace": True, "withoutFTIndex": True} def mock_subprocess_run(args, **kwargs): - assert len(args) == 22 + assert len(args) == 24 assert args[-1].endswith(".zim") assert args[-1] == str(output_dir.joinpath(zim_fname)) assert args[-2] == str(build_dir) return subprocess.CompletedProcess(args=args, returncode=0) monkeypatch.setattr(subprocess, "run", mock_subprocess_run) - make_zim_file(build_dir, output_dir, zim_fname, ziminfo) + make_zim_file(build_dir, output_dir, zim_fname, ziminfo, **extras) From 2a2d496b9c933cd96d831822a0da0daf0960ed4e Mon Sep 17 00:00:00 2001 From: Satyam Kumar Date: Tue, 19 May 2020 12:49:29 +0530 Subject: [PATCH 2/4] Fixes #20 - Better docstring and removal of zimwriterfs_path from ZimInfo --- src/zimscraperlib/zim.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/zimscraperlib/zim.py b/src/zimscraperlib/zim.py index 8135b446..be5fe3e6 100644 --- a/src/zimscraperlib/zim.py +++ b/src/zimscraperlib/zim.py @@ -14,8 +14,6 @@ class ZimInfo(object): - zimwriterfs_path = os.getenv("ZIMWRITERFS_BINARY", "/usr/bin/zimwriterfs") - def __init__( self, homepage="home.html", @@ -101,24 +99,17 @@ def to_zimwriterfs_args( def make_zim_file(build_dir, output_dir, zim_fname, zim_info, **kwargs): - """ runs zimwriterfs - - The function takes in the following arguments + """ Creates a zim file using zimwriterfs + + Arguments: build_dir: The directory to convert into a ZIM file output_dir: The directory where the ZIM file would be saved zim_fname: The name of the ZIM file zim_info: An object of class ZimInfo - - Also supports the following keyword arguments that are passed to to_zimwriterfs_args() - verbose: Use verbose mode while creating ZIM - inflateHtml: Whether try to inflate HTML files - uniqueNamespace: Put everything in namespace 'A' - withoutFTIndex: No fulltext index - minChunkSize: Number of bytes per ZIM cluster - redirects: Path to file containing redirects - """ + + **kwargs: passed directly to to_zimwriterfs_args() """ args = ( - [zim_info.zimwriterfs_path] + ["/usr/bin/env", "zimwriterfs"] + zim_info.to_zimwriterfs_args(**kwargs) + [str(build_dir), str(output_dir.joinpath(zim_fname))] ) From db4180b25dc70702bb546d1a2e1e1b2737c797ed Mon Sep 17 00:00:00 2001 From: Satyam Kumar Date: Tue, 19 May 2020 13:12:32 +0530 Subject: [PATCH 3/4] Fixes #20 - Correct length of args in test --- tests/zim/test_zim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/zim/test_zim.py b/tests/zim/test_zim.py index 9ed66444..f63a89fe 100644 --- a/tests/zim/test_zim.py +++ b/tests/zim/test_zim.py @@ -85,7 +85,7 @@ def test_zimwriterfs_command(monkeypatch, ziminfo): extras = {"uniqueNamespace": True, "withoutFTIndex": True} def mock_subprocess_run(args, **kwargs): - assert len(args) == 24 + assert len(args) == 25 assert args[-1].endswith(".zim") assert args[-1] == str(output_dir.joinpath(zim_fname)) assert args[-2] == str(build_dir) From b7413424d3e639b444c82efaf4fc49b221bad80a Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Wed, 20 May 2020 09:57:48 +0000 Subject: [PATCH 4/4] updated changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32877f67..d322470a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 1.1.0 [WIP] -* added video module +* added video module with reencode, presets, config builder and video file probing +* `make_zim_file()` accepts extra kwargs for zimwriterfs # 1.0.6