Merge branch 'pr/fix_W1612' into 'master'
Fix demod data display for utf-8 decode-able non-CW observations (W1612) Closes #699 See merge request librespacefoundation/satnogs/satnogs-network!847merge-requests/847/merge
commit
5a6f28e11f
|
@ -13,7 +13,6 @@ disable=
|
|||
W0201, # attribute-defined-outside-init
|
||||
W0703, # broad-except
|
||||
# py3k transition issues:
|
||||
W1612, # unicode-builtin
|
||||
W1619, # old-divison
|
||||
W1633, # round-builtin
|
||||
W1645, # exception-message-attribute
|
||||
|
|
|
@ -60,6 +60,13 @@ TRANSMITTER_STATUS = ['active', 'inactive', 'invalid']
|
|||
TRANSMITTER_TYPE = ['Transmitter', 'Transceiver', 'Transponder']
|
||||
|
||||
|
||||
def _decode_pretty_hex(binary_data):
|
||||
"""Return the binary data as hex dump of the following form: `DE AD C0 DE`"""
|
||||
|
||||
data = codecs.encode(binary_data, 'hex').decode('ascii').upper()
|
||||
return ' '.join(data[i:i + 2] for i in range(0, len(data), 2))
|
||||
|
||||
|
||||
def _name_obs_files(instance, filename):
|
||||
"""Return a filepath formatted by Observation ID"""
|
||||
return 'data_obs/{0}/{1}'.format(instance.id, filename)
|
||||
|
@ -563,15 +570,27 @@ class DemodData(models.Model):
|
|||
else:
|
||||
return True
|
||||
|
||||
def display_payload(self):
|
||||
"""Return the content of the data file"""
|
||||
with open(self.payload_demod.path) as file_path:
|
||||
payload = file_path.read()
|
||||
try:
|
||||
return unicode(payload)
|
||||
except UnicodeDecodeError:
|
||||
data = codecs.encode(payload, 'hex').encode('ascii').upper()
|
||||
return ' '.join(data[i:i + 2] for i in range(0, len(data), 2))
|
||||
def display_payload_hex(self):
|
||||
"""
|
||||
Return the content of the data file as hex dump of the following form: `DE AD C0 DE`.
|
||||
"""
|
||||
with open(self.payload_demod.path) as data_file:
|
||||
payload = data_file.read()
|
||||
|
||||
return _decode_pretty_hex(payload)
|
||||
|
||||
def display_payload_utf8(self):
|
||||
"""
|
||||
Return the content of the data file decoded as UTF-8. If this fails,
|
||||
show as hex dump.
|
||||
"""
|
||||
with open(self.payload_demod.path) as data_file:
|
||||
payload = data_file.read()
|
||||
|
||||
try:
|
||||
return payload.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
return _decode_pretty_hex(payload)
|
||||
|
||||
def __str__(self):
|
||||
return '{} - {}'.format(self.id, self.payload_demod)
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import absolute_import
|
|||
import csv
|
||||
import urllib
|
||||
import urllib2
|
||||
from builtins import str
|
||||
from datetime import datetime
|
||||
|
||||
import requests
|
||||
|
@ -21,14 +22,14 @@ def export_as_csv(modeladmin, request, queryset):
|
|||
"""Exports admin panel table in csv format"""
|
||||
if not request.user.is_staff:
|
||||
raise PermissionDenied
|
||||
opts = modeladmin.model._meta
|
||||
field_names = modeladmin.list_display
|
||||
if 'action_checkbox' in field_names:
|
||||
field_names.remove('action_checkbox')
|
||||
|
||||
response = HttpResponse(content_type="text/csv")
|
||||
response['Content-Disposition'] = 'attachment; filename=%s.csv' % unicode(opts)\
|
||||
.replace('.', '_')
|
||||
response['Content-Disposition'] = 'attachment; filename={}.csv'.format(
|
||||
str(modeladmin.model._meta).replace('.', '_')
|
||||
)
|
||||
|
||||
writer = csv.writer(response)
|
||||
headers = []
|
||||
|
@ -54,7 +55,7 @@ def export_as_csv(modeladmin, request, queryset):
|
|||
value = value(row)
|
||||
if value is None:
|
||||
value = ''
|
||||
values.append(unicode(value).encode('utf-8'))
|
||||
values.append(str(value))
|
||||
writer.writerow(values)
|
||||
return response
|
||||
|
||||
|
|
|
@ -385,11 +385,11 @@
|
|||
</div>
|
||||
{% elif observation.transmitter_mode == 'CW' %}
|
||||
<div class="well well-sm data-well">
|
||||
{{ demoddata.display_payload }}
|
||||
{{ demoddata.display_payload_utf8 }}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="well well-sm data-well hex">
|
||||
{{ demoddata.display_payload }}
|
||||
{{ demoddata.display_payload_hex }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
@ -35,6 +35,7 @@ docopt==0.6.2
|
|||
enum34==1.1.6
|
||||
ephem==3.7.7.0
|
||||
eventlet==0.25.1
|
||||
future==0.18.2
|
||||
greenlet==0.4.15
|
||||
gunicorn==19.9.0
|
||||
idna==2.8
|
||||
|
|
Loading…
Reference in New Issue