Skip to content

Commit

Permalink
Update_cmds fixes for py3
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Sep 22, 2019
1 parent 3a35b28 commit a51f3eb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions kadi/update_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import os
import argparse
import difflib
import pickle

import numpy as np
import tables
from six.moves import cPickle as pickle
import six

import pyyaks.logger
import Ska.DBI
Expand Down Expand Up @@ -105,18 +104,15 @@ def fix_nonload_cmds(nl_cmds):
if cmd['msid'] is not None:
new_cmd['params']['msid'] = str(cmd['msid'])

# De-unicode and de-numpy (otherwise unpickling on PY3 has problems).
# De-numpy (otherwise unpickling on PY3 has problems).
if 'params' in cmd:
params = new_cmd['params']
for key, val in cmd['params'].items():
key = str(key)
if isinstance(val, six.string_types):
val = str(val)
else:
try:
val = val.item()
except Exception:
pass
try:
val = val.item()
except AttributeError:
pass
params[key] = val

new_cmds.append(new_cmd)
Expand Down Expand Up @@ -316,7 +312,10 @@ def add_h5_cmds(h5file, idx_cmds):
# Define the column names that specify a complete and unique row
key_names = ('date', 'type', 'tlmsid', 'scs', 'step', 'timeline_id', 'vcdu')

h5d_recent_vals = [tuple(str(row[x]) for x in key_names) for row in h5d_recent]
h5d_recent_vals = [tuple(
row[x].decode('ascii') if isinstance(row[x], bytes) else str(row[x])
for x in key_names)
for row in h5d_recent]
idx_cmds_vals = [tuple(str(x) for x in row[1:]) for row in idx_cmds]

diff = difflib.SequenceMatcher(a=h5d_recent_vals, b=idx_cmds_vals, autojunk=False)
Expand Down

0 comments on commit a51f3eb

Please sign in to comment.