diff --git a/beat/cmdline/algorithms.py b/beat/cmdline/algorithms.py index 659d877b1bdee7a317728459b7ad6ce4dadbc6f1..4dcfea2c6efcb5592b8435afed1b4dc287450dc6 100755 --- a/beat/cmdline/algorithms.py +++ b/beat/cmdline/algorithms.py @@ -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": "" } } -""" +""") @@ -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 diff --git a/beat/cmdline/common.py b/beat/cmdline/common.py index 17ba5d7b0ecd87bee26135bab5e7cf726af072d2..e4fbc9943362b08ee39cf097dc1a4b40b6f6686e 100644 --- a/beat/cmdline/common.py +++ b/beat/cmdline/common.py @@ -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 diff --git a/beat/cmdline/config.py b/beat/cmdline/config.py index f272a9b6f500423ace378091e8001d624b044822..37ac70869ccbb3d177806085937206b66cbe8a9f 100644 --- a/beat/cmdline/config.py +++ b/beat/cmdline/config.py @@ -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']: diff --git a/beat/cmdline/databases.py b/beat/cmdline/databases.py index 1d8d46325c761139e2efe21242fc34a1404c8f7c..499d7d78318bfedfaae4b31efe6c5520ba7f8c44 100755 --- a/beat/cmdline/databases.py +++ b/beat/cmdline/databases.py @@ -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) diff --git a/beat/cmdline/test/__init__.py b/beat/cmdline/test/__init__.py index 7fff177eb0d9301c1cefa3cdd4c7d0de754453e8..f0c20161030774160abef5eac40ab14ba59c5a14 100644 --- a/beat/cmdline/test/__init__.py +++ b/beat/cmdline/test/__init__.py @@ -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'