hack for pdf from collection
[librarian.git] / librarian / __init__.py
index 616e351..9a9e23e 100644 (file)
@@ -8,6 +8,10 @@ from __future__ import with_statement
 import os
 import re
 import shutil
+import urllib
+
+from util import makedirs
+
 
 class UnicodeException(Exception):
     def __str__(self):
@@ -63,12 +67,14 @@ class EmptyNamespace(XMLNamespace):
         return tag
 
 # some common namespaces we use
+XMLNS = XMLNamespace('http://www.w3.org/XML/1998/namespace')
 RDFNS = XMLNamespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
 DCNS = XMLNamespace('http://purl.org/dc/elements/1.1/')
 XINS = XMLNamespace("http://www.w3.org/2001/XInclude")
 XHTMLNS = XMLNamespace("http://www.w3.org/1999/xhtml")
 NCXNS = XMLNamespace("http://www.daisy.org/z3986/2005/ncx/")
 OPFNS = XMLNamespace("http://www.idpf.org/2007/opf")
+PLMETNS = XMLNamespace("http://dl.psnc.pl/schemas/plmet/")
 
 WLNS = EmptyNamespace()
 
@@ -78,7 +84,7 @@ class WLURI(object):
     slug = None
 
     example = 'http://wolnelektury.pl/katalog/lektura/template/'
-    _re_wl_uri = re.compile(r'http://(www\.)?wolnelektury.pl/katalog/lektura/'
+    _re_wl_uri = re.compile(r'http://(www\.)?wolnelektury.pl/katalog/lektur[ay]/'
             '(?P<slug>[-a-z0-9]+)/?$')
 
     def __init__(self, uri):
@@ -269,6 +275,10 @@ class OutputFile(object):
         """Save file to a path. Create directories, if necessary."""
 
         dirname = os.path.dirname(os.path.abspath(path))
-        if not os.path.isdir(dirname):
-            os.makedirs(dirname)
+        makedirs(dirname)
         shutil.copy(self.get_filename(), path)
+
+
+class URLOpener(urllib.FancyURLopener):
+    version = 'FNP Librarian (http://github.com/fnp/librarian)'
+urllib._urlopener = URLOpener()