Skip to content
Snippets Groups Projects
Commit 7cb75175 authored by Marko Kuder's avatar Marko Kuder
Browse files

unicode support + additional translations

parent d87ca381
No related branches found
Tags OPSIv0.5.1
No related merge requests found
# -*- coding: utf-8 -*-
import logging
import types
......
# -*- coding: utf-8 -*-
'''
Provide some Quality Assurance by scoring datasets against Sir Tim
Berners-Lee\'s five stars of openness
......@@ -28,12 +29,12 @@ OPENNESS_SCORE_DESCRIPTION = {
4: 'Ontologically represented',
5: 'Fully Linked Open Data as appropriate',
'''
0: 'Ni dosegljivo ali pa licenca ni odprta',
1: 'Dosegljivo ter odprta licenca',
2: 'Strojno-berljiv format',
3: 'Odprt ter standardiziran format',
4: 'Ontološko predstavljiv',
5: 'Popolnoma povezani odprti podatki',
0: u'Ni dosegljivo ali pa licenca ni odprta',
1: u'Dosegljivo ter odprta licenca',
2: u'Strojno-berljiv format',
3: u'Odprt ter standardiziran format',
4: u'Ontološko predstavljiv',
5: u'Popolnoma povezani odprti podatki',
}
def load_config(ckan_ini_filepath):
......@@ -205,7 +206,7 @@ def resource_score(resource, log):
if score == None:
log.warning('Could not score resource: "%s" with url: "%s"',
resource.id, resource.url)
score_reasons.append('Could not understand the file format, therefore score is 1.')
score_reasons.append(u'Formata datoteke ni bilo mogoče prepoznati, zato je ocena 1.')
score = 1
if format_ == None:
# use any previously stored format value for this resource
......@@ -214,7 +215,7 @@ def resource_score(resource, log):
format_ = format_ or None
except Exception, e:
log.error('Unexpected error while calculating openness score %s: %s\nException: %s', e.__class__.__name__, unicode(e), traceback.format_exc())
score_reason = "Unknown error: %s" % str(e)
score_reason = u"Neznana napaka: %s" % str(e)
raise
# Even if we can get the link, we should still treat the resource
......@@ -228,7 +229,7 @@ def resource_score(resource, log):
else:
package = resource.package
if score > 0 and not package.isopen():
score_reason = 'License not open'
score_reason = u'Licenca ni odprta'
score = 0
log.info('Score: %s Reason: %s', score, score_reason)
......@@ -253,24 +254,24 @@ def broken_link_error_message(archival):
return date.strftime('%d/%m/%Y')
else:
return ''
messages = ['File could not be downloaded.',
'Reason: %s.' % archival.status,
'Error details: %s.' % archival.reason,
'Attempted on %s.' % format_date(archival.updated)]
messages = [u'Datoteke ni bilo mogoče prenesti.',
u'Vzrok: %s.' % archival.status,
u'Opis napake: %s.' % archival.reason,
u'Preverjeno na %s.' % format_date(archival.updated)]
last_success = format_date(archival.last_success)
if archival.failure_count == 1:
if last_success:
messages.append('This URL worked the previous time: %s.' % last_success)
messages.append(u'Ta naslov je bil nazadnje dostopen %s.' % last_success)
else:
messages.append('This was the first attempt.')
messages.append(u'To je bil prvi poizkus.')
else:
messages.append('Tried %s times since %s.' % \
messages.append(u'%s poskusov od %s.' % \
(archival.failure_count,
format_date(archival.first_failure)))
if last_success:
messages.append('This URL last worked on: %s.' % last_success)
messages.append(u'Ta naslov je bil nazadnje dostopen %s.' % last_success)
else:
messages.append('This URL has not worked in the history of this tool.')
messages.append(u'Ta naslov ni bil nikoli uspešno dostopen s portala.')
return ' '.join(messages)
......@@ -305,12 +306,12 @@ def score_by_sniffing_data(archival, resource, score_reasons, log):
* If it cannot score it, then score is None
'''
if not archival or not archival.cache_filepath:
score_reasons.append('This file had not been downloaded at the time of scoring it.')
score_reasons.append(u'Ta datoteka ob ocenjevanju ni bila prenešena.')
return (None, None)
# Analyse the cached file
filepath = archival.cache_filepath
if not os.path.exists(filepath):
score_reasons.append('Cache filepath does not exist: "%s".' % filepath)
score_reasons.append(u'Lokalna kopija ne obstaja: "%s".' % filepath)
return (None, None)
else:
if filepath:
......@@ -318,24 +319,24 @@ def score_by_sniffing_data(archival, resource, score_reasons, log):
score = lib.resource_format_scores().get(sniffed_format['format']) \
if sniffed_format else None
if sniffed_format:
score_reasons.append('Content of file appeared to be format "%s" which receives openness score: %s.' % (sniffed_format['format'], score))
score_reasons.append(u'Zbirka vsebuje datoteke formata %s, kar zadošča za oceno %s.' % (sniffed_format['format'], score))
return score, sniffed_format['format']
else:
score_reasons.append('The format of the file was not recognized from its contents.')
score_reasons.append(u'Formata datoteke ni bilo mogoče prepoznati iz njene vsebine.')
return (None, None)
else:
# No cache_url
if archival.status_id == Status.by_text('Chose not to download'):
score_reasons.append('File was not downloaded deliberately. Reason: %s. Using other methods to determine file openness.' % \
score_reasons.append(u'Datoteka namenoma ni bila prenešena. Vzrok: %s. Uporabljene so druge metode določanja odprtosti.' % \
archival.reason)
return (None, None)
elif archival.is_broken is None and archival.status_id:
# i.e. 'Download failure' or 'System error during archival'
score_reasons.append('A system error occurred during downloading this file. Reason: %s. Using other methods to determine file openness.' % \
score_reasons.append(u'Pri prenosu datoteke je prišlo do sistemske napake. Vzrok: %s. Uporabljene so druge metode določanja odprtosti.' % \
archival.reason)
return (None, None)
else:
score_reasons.append('This file had not been downloaded at the time of scoring it.')
score_reasons.append(u'Ta datoteka ob ocenjevanju ni bila prenešena.')
return (None, None)
......@@ -352,20 +353,20 @@ def score_by_url_extension(resource, score_reasons, log):
'''
extension_variants_ = extension_variants(resource.url.strip())
if not extension_variants_:
score_reasons.append('Could not determine a file extension in the URL.')
score_reasons.append(u'Končnice datoteke ni bilo mogoče razbrati iz naslova URL')
return (None, None)
for extension in extension_variants_:
format_ = format_get(extension)
if format_:
score = lib.resource_format_scores().get(format_)
if score:
score_reasons.append('URL extension "%s" relates to format "%s" and receives score: %s.' % (extension, format_, score))
score_reasons.append(u'Končnica datoteke %s ustreza formatu %s in dobi oceno: %s.' % (extension, format_, score))
return score, format_
else:
score = 1
score_reasons.append('URL extension "%s" relates to format "%s" but a score for that format is not configured, so giving it default score %s.' % (extension, format_, score))
score_reasons.append(u'Končnica datoteke %s ustreza formatu %s, vendar ocena za ta format ni določena, zato dobi privzeto oceno %s.' % (extension, format_, score))
return score, format_
score_reasons.append('URL extension "%s" is an unknown format.' % extension)
score_reasons.append(u'Končnica datoteke %s ne pripada znanemu formatu.' % extension)
return (None, None)
def extension_variants(url):
......@@ -401,15 +402,15 @@ def score_by_format_field(resource, score_reasons, log):
'''
format_field = resource.format or ''
if not format_field:
score_reasons.append('Format field is blank.')
score_reasons.append(u'Polje formata je prazno.')
return (None, None)
format_tuple = ckan_helpers.resource_formats().get(format_field.lower()) or \
ckan_helpers.resource_formats().get(lib.munge_format_to_be_canonical(format_field))
if not format_tuple:
score_reasons.append('Format field "%s" does not correspond to a known format.' % format_field)
score_reasons.append(u'Polje formata %s ne pripada znanemu formatu.' % format_field)
return (None, None)
score = lib.resource_format_scores().get(format_tuple[1])
score_reasons.append('Format field "%s" receives score: %s.' %
score_reasons.append(u'Polje formata %s dobi oceno %s.' %
(format_field, score))
return (score, format_tuple[1])
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment