From: Radek Czajka Date: Wed, 27 Feb 2019 22:03:13 +0000 (+0100) Subject: Librarian in regular requirements. X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/8132fc186eb0c5fd02c86828c3a4735754296d02?hp=e81283e08cca4c47d57dd0aef34a5c598931a9d2 Librarian in regular requirements. --- diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 004f6f37..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/librarian"] - path = lib/librarian - url = git://git.nowoczesnapolska.org.pl/librarian.git diff --git a/apps/catalogue/management/commands/import_wl.py b/apps/catalogue/management/commands/import_wl.py index 7eee8977..45c9e331 100644 --- a/apps/catalogue/management/commands/import_wl.py +++ b/apps/catalogue/management/commands/import_wl.py @@ -41,7 +41,7 @@ class Command(BaseCommand): print b.slug text = b.materialize().encode('utf-8') try: - info = BookInfo.from_string(text) + info = BookInfo.from_bytes(text) except (ParseError, ValidationError): pass else: @@ -59,7 +59,7 @@ class Command(BaseCommand): for book in json.load(urllib2.urlopen(WL_API)): book_detail = json.load(urllib2.urlopen(book['href'])) xml_text = urllib2.urlopen(book_detail['xml']).read() - info = BookInfo.from_string(xml_text) + info = BookInfo.from_bytes(xml_text) previous_books = slugs.get(info.slug) if previous_books: if len(previous_books) > 1: diff --git a/apps/catalogue/models/book.py b/apps/catalogue/models/book.py index 02396737..1fcd05ac 100755 --- a/apps/catalogue/models/book.py +++ b/apps/catalogue/models/book.py @@ -339,7 +339,7 @@ class Book(models.Model): from librarian.dcparser import BookInfo from librarian import NoDublinCore, ParseError, ValidationError try: - return BookInfo.from_string(book_xml.encode('utf-8')) + return BookInfo.from_bytes(book_xml.encode('utf-8')) except (self.NoTextError, ParseError, NoDublinCore, ValidationError): return None @@ -416,8 +416,8 @@ class Book(models.Model): from catalogue.ebook_utils import RedakcjaDocProvider from librarian.parser import WLDocument - return WLDocument.from_string( - self.materialize(publishable=publishable, changes=changes), + return WLDocument.from_bytes( + self.materialize(publishable=publishable, changes=changes).encode('utf-8'), provider=RedakcjaDocProvider(publishable=publishable), parse_dublincore=parse_dublincore, strict=strict) diff --git a/apps/catalogue/models/image.py b/apps/catalogue/models/image.py index 8f044d3e..646dd0ae 100755 --- a/apps/catalogue/models/image.py +++ b/apps/catalogue/models/image.py @@ -80,7 +80,8 @@ class Image(dvcs_models.Document): picture_xml = publishable.materialize() try: - picture = WLPicture.from_string(picture_xml.encode('utf-8'), + picture = WLPicture.from_bytes( + picture_xml.encode('utf-8'), image_store=SelfImageStore) except ParseError, e: raise AssertionError(_('Invalid XML') + ': ' + str(e)) diff --git a/apps/catalogue/views.py b/apps/catalogue/views.py index b6521c7f..f6208056 100644 --- a/apps/catalogue/views.py +++ b/apps/catalogue/views.py @@ -235,7 +235,7 @@ def book_txt(request, slug): return HttpResponseForbidden("Not authorized.") doc = book.wldocument() - text = doc.as_text().get_string() + text = doc.as_text().get_bytes() response = http.HttpResponse(text, content_type='text/plain') response['Content-Disposition'] = 'attachment; filename=%s.txt' % slug return response @@ -250,7 +250,7 @@ def book_html(request, slug): doc = book.wldocument(parse_dublincore=False) html = doc.as_html(options={'gallery': "'%s'" % book.gallery_url()}) - html = html.get_string() if html is not None else '' + html = html.get_bytes() if html is not None else '' # response = http.HttpResponse(html, content_type='text/html') # return response # book_themes = {} @@ -288,7 +288,7 @@ def book_epub(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - epub = doc.as_epub(ilustr_path=book.gallery_path()).get_string() + epub = doc.as_epub(ilustr_path=book.gallery_path()).get_bytes() response = HttpResponse(content_type='application/epub+zip') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.epub' response.write(epub) @@ -304,7 +304,7 @@ def book_mobi(request, slug): # TODO: move to celery doc = book.wldocument() # TODO: error handling - mobi = doc.as_mobi(ilustr_path=book.gallery_path()).get_string() + mobi = doc.as_mobi(ilustr_path=book.gallery_path()).get_bytes() response = HttpResponse(content_type='application/x-mobipocket-ebook') response['Content-Disposition'] = 'attachment; filename=%s' % book.slug + '.mobi' response.write(mobi) diff --git a/apps/cover/views.py b/apps/cover/views.py index bbcf28e5..3f2c46fa 100644 --- a/apps/cover/views.py +++ b/apps/cover/views.py @@ -41,7 +41,7 @@ def preview(request, book, chunk=None, rev=None): xml = revision.materialize().encode('utf-8') try: - info = BookInfo.from_string(xml) + info = BookInfo.from_bytes(xml) except: return HttpResponseRedirect(os.path.join(settings.STATIC_URL, "img/sample_cover.png")) cover = make_cover(info) @@ -63,7 +63,7 @@ def preview_from_xml(request): xml = request.POST['xml'] try: - info = BookInfo.from_string(xml.encode('utf-8')) + info = BookInfo.from_bytes(xml.encode('utf-8')) except: return HttpResponse(os.path.join(settings.STATIC_URL, "img/sample_cover.png")) coverid = sha1(etree.tostring(info.to_etree())).hexdigest() diff --git a/lib/librarian b/lib/librarian deleted file mode 160000 index 03c22584..00000000 --- a/lib/librarian +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 03c2258429bf8f80e88025fce45126960bfcd827 diff --git a/manage.py b/manage.py index 29702c0e..44d4b1a0 100755 --- a/manage.py +++ b/manage.py @@ -5,8 +5,6 @@ import sys ROOT = os.path.dirname(os.path.abspath(__file__)) sys.path = [ os.path.join(ROOT, 'apps'), - os.path.join(ROOT, 'lib'), - os.path.join(ROOT, 'lib/librarian'), ] + sys.path if __name__ == "__main__": diff --git a/redakcja/wsgi.py b/redakcja/wsgi.py index 62743d6d..5ffd742e 100755 --- a/redakcja/wsgi.py +++ b/redakcja/wsgi.py @@ -8,8 +8,6 @@ ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path = [ ROOT, os.path.join(ROOT, 'apps'), - os.path.join(ROOT, 'lib'), - os.path.join(ROOT, 'lib/librarian'), ] + sys.path diff --git a/requirements.txt b/requirements.txt index a3e7a748..03c1bc48 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,13 @@ --i https://py.mdrn.pl:8443/simple +-i https://py.mdrn.pl/simple ## Python libraries -lxml>=2.2.2 Mercurial>=3.3,<3.4 PyYAML>=3.0 Pillow oauth2 httplib2 # oauth2 dependency -texml==2.0.2 -## Book conversion library -# git+git://github.com/fnp/librarian.git@master#egg=librarian +librarian ## Django Django>=1.6,<1.7 @@ -31,4 +28,3 @@ kombu>=3.0,<3.1 South>=1.0.2 raven -argparse \ No newline at end of file