fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f062d83
)
Added overwrite option to genslugs.py.
author
Marek Stępniowski
<marek@stepniowski.com>
Tue, 16 Sep 2008 15:09:38 +0000
(17:09 +0200)
committer
Marek Stępniowski
<marek@stepniowski.com>
Tue, 16 Sep 2008 15:09:38 +0000
(17:09 +0200)
lib/librarian/bin/genslugs.py
patch
|
blob
|
history
diff --git
a/lib/librarian/bin/genslugs.py
b/lib/librarian/bin/genslugs.py
index
263e00f
..
3391d8e
100755
(executable)
--- a/
lib/librarian/bin/genslugs.py
+++ b/
lib/librarian/bin/genslugs.py
@@
-20,7
+20,9
@@
if __name__ == '__main__':
parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
help='print status messages to stdout')
parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False,
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:
@@
-36,7
+38,7
@@
if __name__ == '__main__':
try:
title = doc.find('//{http://purl.org/dc/elements/1.1/}title').text
except AttributeError:
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
+ print '%s:error:
Book title not found. Skipping.
' % input_filename
continue
parent = ''
continue
parent = ''
@@
-45,15
+47,18
@@
if __name__ == '__main__':
parent = parent_url.rsplit('/', 1)[1] + ' '
except AttributeError:
pass
parent = parent_url.rsplit('/', 1)[1] + ' '
except AttributeError:
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 = etree.SubElement(book_description, '{http://purl.org/dc/elements/1.1/}identifier.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 = etree.SubElement(book_description, '{http://purl.org/dc/elements/1.1/}identifier.url')
-
elif
book_url.text.startswith('http://'):
- print '%s:
notice:book already has identifier starting with http://, skipping' % input_filename
+
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
continue
- book_url.text = BOOK_URL + slughifi(parent + title)
+
+ book_url.text = BOOK_URL + slughifi(parent + title)[:60]
doc.write(input_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')
doc.write(input_filename, xml_declaration=True, pretty_print=True, encoding='utf-8')