Skip to content

Commit 53d0c8f

Browse files
authored
Merge pull request #27 from openzim/new_arch
2 parents 45ad923 + 2fd3a98 commit 53d0c8f

10 files changed

+540
-495
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__
2+
build
3+
libzim_wrapper.*.so
4+
libzim/libzim_wrapper.cpp
5+
libzim/libzim_wrapper.h
6+
libzim/libzim_wrapper_api.h
7+
*.egg-info

libzim/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This file is part of python-libzim
2+
# (see https://github.com/libzim/python-libzim)
3+
#
4+
# Copyright (c) 2020 Juan Diego Caballero <[email protected]>
5+
# Copyright (c) 2020 Matthieu Gautier <[email protected]>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
21+
from libzim_wrapper import Blob
22+
23+
__all__ = ["Blob"]

libzim/examples.py

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

1919

20-
from libzim import ZimArticle, ZimBlob, ZimCreator
20+
# Write the article
21+
import uuid
22+
23+
from libzim.writer import Article, Blob, Creator
2124

22-
class ZimTestArticle(ZimArticle):
2325

26+
class TestArticle(Article):
2427
def __init__(self, url, title, content):
25-
ZimArticle.__init__(self)
28+
Article.__init__(self)
2629
self.url = url
2730
self.title = title
2831
self.content = content
@@ -35,58 +38,69 @@ def get_url(self):
3538

3639
def get_title(self):
3740
return f"{self.title}"
38-
41+
3942
def get_mime_type(self):
4043
return "text/html"
41-
44+
4245
def get_filename(self):
4346
return ""
44-
47+
4548
def should_compress(self):
4649
return True
4750

4851
def should_index(self):
4952
return True
5053

5154
def get_data(self):
52-
return ZimBlob(self.content)
55+
return Blob(self.content)
5356

54-
# Create a ZimTestArticle article
5557

56-
content = '''<!DOCTYPE html>
58+
# Create a TestArticle article
59+
60+
content = """<!DOCTYPE html>
5761
<html class="client-js">
5862
<head><meta charset="UTF-8">
5963
<title>Monadical</title>
6064
</head>
61-
<h1> ñññ Hello, it works ñññ </h1></html>'''
65+
<h1> ñññ Hello, it works ñññ </h1></html>"""
6266

63-
content2 = '''<!DOCTYPE html>
67+
content2 = """<!DOCTYPE html>
6468
<html class="client-js">
6569
<head><meta charset="UTF-8">
6670
<title>Monadical 2</title>
6771
</head>
68-
<h1> ñññ Hello, it works 2 ñññ </h1></html>'''
72+
<h1> ñññ Hello, it works 2 ñññ </h1></html>"""
6973

70-
article = ZimTestArticle("Monadical_SAS", "Monadical", content)
71-
article2 = ZimTestArticle("Monadical_2", "Monadical 2", content2)
74+
article = TestArticle("Monadical_SAS", "Monadical", content)
75+
article2 = TestArticle("Monadical_2", "Monadical 2", content2)
7276

7377
print(article.content)
7478

75-
# Write the article
76-
import uuid
77-
rnd_str = str(uuid.uuid1())
79+
80+
rnd_str = str(uuid.uuid1())
7881

7982
test_zim_file_path = "/opt/python-libzim/tests/kiwix-test"
8083

81-
zim_creator = ZimCreator(test_zim_file_path + '-' + rnd_str + '.zim',main_page = "Monadical",index_language= "eng", min_chunk_size= 2048)
84+
zim_creator = Creator(
85+
test_zim_file_path + "-" + rnd_str + ".zim",
86+
main_page="Monadical",
87+
index_language="eng",
88+
min_chunk_size=2048,
89+
)
8290

8391
# Add articles to zim file
8492
zim_creator.add_article(article)
8593
zim_creator.add_article(article2)
8694

8795
# Set mandatory metadata
8896
if not zim_creator.mandatory_metadata_ok():
89-
zim_creator.update_metadata(creator='python-libzim',description='Created in python',name='Hola',publisher='Monadical',title='Test Zim')
97+
zim_creator.update_metadata(
98+
creator="python-libzim",
99+
description="Created in python",
100+
name="Hola",
101+
publisher="Monadical",
102+
title="Test Zim",
103+
)
90104

91105
print(zim_creator._get_metadata())
92106

@@ -98,11 +112,13 @@ def get_data(self):
98112

99113
rnd_str = str(uuid.uuid1())
100114

101-
with ZimCreator(test_zim_file_path + '-' + rnd_str + '.zim') as zc:
115+
with Creator(test_zim_file_path + "-" + rnd_str + ".zim") as zc:
102116
zc.add_article(article)
103117
zc.add_article(article2)
104-
zc.update_metadata(creator='python-libzim',
105-
description='Created in python',
106-
name='Hola',publisher='Monadical',
107-
title='Test Zim')
108-
118+
zc.update_metadata(
119+
creator="python-libzim",
120+
description="Created in python",
121+
name="Hola",
122+
publisher="Monadical",
123+
title="Test Zim",
124+
)

libzim/lib.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <Python.h>
2424
#include "lib.h"
2525

26-
#include "libzim_api.h"
26+
#include "libzim_wrapper_api.h"
2727

2828
#include <iostream>
2929
#include <zim/writer/url.h>
@@ -38,7 +38,7 @@
3838

3939
ZimArticleWrapper::ZimArticleWrapper(PyObject *obj) : m_obj(obj)
4040
{
41-
if (import_libzim())
41+
if (import_libzim_wrapper())
4242
{
4343
std::cerr << "Error executing import_libzim!\n";
4444
throw std::runtime_error("Error executing import_libzim");

0 commit comments

Comments
 (0)