Separate the general from the WL-specific: PDF
[librarian.git] / scripts / genslugs
index 3391d8e..a234096 100755 (executable)
@@ -1,5 +1,9 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
+#
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
 import os
 import optparse
 
 import os
 import optparse
 
@@ -22,7 +26,7 @@ if __name__ == '__main__':
         help='print status messages to stdout')
     parser.add_option('-f', '--force', action='store_true', dest='force', default=False,
         help='overwrite current identifiers')
         help='print status messages to stdout')
     parser.add_option('-f', '--force', action='store_true', dest='force', default=False,
         help='overwrite current identifiers')
-    
+
     options, input_filenames = parser.parse_args()
 
     if len(input_filenames) < 1:
     options, input_filenames = parser.parse_args()
 
     if len(input_filenames) < 1:
@@ -33,14 +37,14 @@ if __name__ == '__main__':
     for input_filename in input_filenames:
         if options.verbose:
             print input_filename
     for input_filename in input_filenames:
         if options.verbose:
             print input_filename
-        
+
         doc = etree.parse(input_filename)
         try:
             title = doc.find('//{http://purl.org/dc/elements/1.1/}title').text
         except AttributeError:
             print '%s:error:Book title not found. Skipping.' % input_filename
             continue
         doc = etree.parse(input_filename)
         try:
             title = doc.find('//{http://purl.org/dc/elements/1.1/}title').text
         except AttributeError:
             print '%s:error:Book title not found. Skipping.' % input_filename
             continue
-        
+
         parent = ''
         try:
             parent_url = doc.find('//{http://purl.org/dc/elements/1.1/}relation.isPartOf').text
         parent = ''
         try:
             parent_url = doc.find('//{http://purl.org/dc/elements/1.1/}relation.isPartOf').text
@@ -49,7 +53,7 @@ if __name__ == '__main__':
             pass
         except IndexError:
             print '%s:error:Invalid parent URL "%s". Skipping.' % (input_filename, parent_url)
             pass
         except IndexError:
             print '%s:error:Invalid parent URL "%s". Skipping.' % (input_filename, parent_url)
-            
+
         book_url = doc.find('//{http://purl.org/dc/elements/1.1/}identifier.url')
         if book_url is None:
             book_description = doc.find('//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description')
         book_url = doc.find('//{http://purl.org/dc/elements/1.1/}identifier.url')
         if book_url is None:
             book_description = doc.find('//{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description')
@@ -57,7 +61,7 @@ if __name__ == '__main__':
         if not options.force and book_url.text.startswith('http://'):
             print '%s:Notice:Book already has identifier URL "%s". Skipping.' % (input_filename, book_url.text)
             continue
         if not options.force and book_url.text.startswith('http://'):
             print '%s:Notice:Book already has identifier URL "%s". Skipping.' % (input_filename, book_url.text)
             continue
-        
+
         book_url.text = BOOK_URL + slughifi(parent + title)[:60]
 
         doc.write(input_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')
         book_url.text = BOOK_URL + slughifi(parent + title)[:60]
 
         doc.write(input_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')