Commit c87ae029 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch 'py3_compatibility' into '1.4.x'

Py3 compatibility

See merge request !12
parents 34ae8bbe 45a75e51
Pipeline #19484 passed with stage
in 5 minutes and 30 seconds
......@@ -169,7 +169,7 @@ def pull(webapi, prefix, names, force, indentation, format_cache, lib_cache):
def print_examples():
print """
print("""
To feed data from a database to an algorithm:
=============================================
......@@ -247,7 +247,7 @@ To execute an analyzer:
"version": "<environment_version>"
}
}
"""
""")
......@@ -264,13 +264,13 @@ def execute(prefix, cache, instructions_file):
configuration['queue'] = 'unused'
configuration['nb_slots'] = 1
if not configuration.has_key('parameters'):
if 'parameters' not in configuration:
configuration['parameters'] = {}
for name, cfg in configuration['inputs'].items():
cfg['endpoint'] = name
suffix = ''
if cfg.has_key('database'): # Connected to a database output
if 'database' in cfg: # Connected to a database output
cfg['hash'] = hash.hashDataset(cfg['database'], cfg['protocol'], cfg['set'])
suffix = '.db'
......@@ -278,7 +278,7 @@ def execute(prefix, cache, instructions_file):
algo = AlgorithmStorage(prefix, configuration['algorithm'])
if configuration.has_key('outputs'): # Standard algorithm
if 'outputs' in configuration: # Standard algorithm
for name, cfg in configuration['outputs'].items():
cfg['endpoint'] = name
cfg['hash'] = hash.hashBlockOutput(
......@@ -322,16 +322,16 @@ def execute(prefix, cache, instructions_file):
with executor:
result = executor.process()
if result['status'] != 0:
print 'STDERR:'
print result['stderr']
print('STDERR:')
print(result['stderr'])
# Display the results
if configuration.has_key('outputs'): # Standard algorithm
print 'Outputs of the algorithms available at:'
if 'outputs' in configuration: # Standard algorithm
print('Outputs of the algorithms available at:')
for name, cfg in configuration['outputs'].items():
print ' - %s: %s' % (name, cfg['path'])
print(' - %s: %s' % (name, cfg['path']))
else:
print 'Results of the analyzer available at: %s' % configuration['result']['path']
print('Results of the analyzer available at: %s' % configuration['result']['path'])
except Exception as e:
import traceback
......
......@@ -696,7 +696,7 @@ def pull(webapi, prefix, type, names, fields, force, indentation):
return status, list(available)
def diff(webapi, prefix, type, name, fields):
def diff(webapi, prefix, type_, name, fields):
"""Shows the differences between two objects, for each of the fields
......@@ -736,9 +736,15 @@ def diff(webapi, prefix, type, name, fields):
def _eval_diff(remote, local, ext):
'''Calculates differences between two string buffers'''
if not isinstance(local, six.string_types):
local = local.decode('utf-8')
if not isinstance(remote, six.string_types):
remote = remote.decode('utf-8')
return difflib.unified_diff(remote.split('\n'), local.split('\n'),
os.path.join('remote', type, name + ext),
os.path.join('local', type, name + ext))
os.path.join('remote', type_, name + ext),
os.path.join('local', type_, name + ext))
def _show_diff(diffs):
......@@ -750,9 +756,9 @@ def diff(webapi, prefix, type, name, fields):
else: print(line)
storage = TYPE_STORAGE[type](prefix, name)
storage = TYPE_STORAGE[type_](prefix, name)
local = storage.load() #may also return a tuple, depending on the type
remote = fetch_object(webapi, type, name, fields)
remote = fetch_object(webapi, type_, name, fields)
if remote is None: return 1
if 'declaration' in remote and \
not isinstance(remote['declaration'], six.string_types):
......@@ -767,12 +773,12 @@ def diff(webapi, prefix, type, name, fields):
for field in fields:
diffs = _eval_diff(remote[field], local[field], extension[field])
if diffs:
logger.info("differences for `%s' of `%s/%s':", field, TYPE_PLURAL[type],
logger.info("differences for `%s' of `%s/%s':", field, TYPE_PLURAL[type_],
name)
_show_diff(diffs)
else:
logger.info("no differences for `%s' of `%s/%s'", field,
TYPE_PLURAL[type], name)
TYPE_PLURAL[type_], name)
return 0
......
......@@ -254,7 +254,7 @@ class Configuration(object):
c = self.__config_file()
dirname = os.path.dirname(c)
if not os.path.exists(dirname): os.makedirs(dirname)
with os.fdopen(os.open(c, os.O_WRONLY | os.O_CREAT, 0600), 'wt') as f:
with os.fdopen(os.open(c, os.O_WRONLY | os.O_CREAT, 0o600), 'wt') as f:
simplejson.dump(self.__data, f, indent=4)
def _is_valid_key(self, key):
......@@ -303,7 +303,7 @@ def process(args):
return 0
elif args['list']:
print args['config']
print(args['config'])
return 0
elif args['set']:
......
......@@ -582,7 +582,7 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
if start != previous_start:
print(80 * '-')
print 'FROM %d TO %d' % (start, end)
print('FROM %d TO %d' % (start, end))
whole_inputs = [input_ for input_ in input_group
if input_.data_index == start and
......@@ -590,7 +590,7 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
for input in whole_inputs:
label = ' - ' + str(input.name) + ': '
print label + data_to_json(input.data, len(label))
print(label + data_to_json(input.data, len(label)))
previous_start = start
......@@ -607,16 +607,15 @@ def view_outputs(configuration, dataset_name, excluded_outputs=None, uid=None,
grouped_inputs[key] = []
grouped_inputs[key].append(input)
sorted_keys = grouped_inputs.keys()
sorted_keys.sort()
sorted_keys = sorted(grouped_inputs.keys())
for key in sorted_keys:
print
print ' FROM %d TO %d' % key
print(' FROM %d TO %d' % key)
for input in grouped_inputs[key]:
label = ' - ' + str(input.name) + ': '
print label + data_to_json(input.data, len(label))
print(label + data_to_json(input.data, len(label)))
except Exception as e:
logger.error("Failed to retrieve the next data: %s", e)
......
......@@ -63,7 +63,7 @@ if platform:
try:
code = urllib.request.urlopen(platform).getcode()
disconnected = code != 200
except IOError, urllib.URLError:
except (IOError, urllib.URLError):
disconnected = True
else:
platform = 'User did not set $BEAT_CMDLINE_TEST_PLATFORM'
......
Markdown is supported
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