From 01a8cf2b0140e64aeaf3b062ab9642cdfc594281 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Fri, 9 Dec 2016 10:44:10 -0500 Subject: [PATCH] Make python2/3 compatible Versioneer needs to be updated to 0.17 still. --- finddata/__init__.py | 2 +- finddata/publish_plot.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/finddata/__init__.py b/finddata/__init__.py index c2c6c80..eb5c1ee 100644 --- a/finddata/__init__.py +++ b/finddata/__init__.py @@ -3,4 +3,4 @@ __version__ = get_versions()['version'] del get_versions # everything else -from publish_plot import publish_plot +from .publish_plot import publish_plot diff --git a/finddata/publish_plot.py b/finddata/publish_plot.py index d78802e..084558e 100644 --- a/finddata/publish_plot.py +++ b/finddata/publish_plot.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import (absolute_import, division, print_function, unicode_literals) import json import logging import os @@ -17,7 +18,7 @@ class Configuration(object): """ def __init__(self, config_file): if os.access(config_file, os.R_OK) == False: - raise RuntimeError, "Configuration file doesn't exist or is not readable: %s" % config_file + raise RuntimeError("Configuration file doesn't exist or is not readable: %s" % config_file) with open(config_file, 'r') as cfg: json_encoded = cfg.read() config = json.loads(json_encoded) @@ -64,8 +65,8 @@ def read_configuration(config_file=None): def _loadDiv(filename): if not os.path.exists(filename): raise RuntimeError('\'%s\' does not exist' % filename) - print 'loading \'%s\'' % filename - with file(filename, 'r') as handle: + print('loading \'%s\'' % filename) + with open(filename, 'r') as handle: div = handle.read() return div @@ -88,7 +89,7 @@ def publish_plot(instrument, run_number, files, config=None): run_number = str(run_number) url = _getURL(config.publish_url, instrument, run_number) - print 'posting to \'%s\'' % url + print('posting to \'%s\'' % url) # these next 2 lines are explicity bad - and doesn't seem # to do ANYTHING @@ -105,8 +106,8 @@ def publish_plot(instrument, run_number, files, config=None): if __name__ == '__main__': import sys div = _loadDiv(sys.argv[1]) - #print '**********' - #print div + #print('**********') + #print(div) # run information is generated from the filename name = os.path.split(sys.argv[1])[-1] @@ -115,4 +116,4 @@ def publish_plot(instrument, run_number, files, config=None): config = read_configuration('post_processing.conf') #config = read_configuration('post_processing_full.conf') request = publish_plot(instr, runnumber, {'file':div}, config) - print 'request returned', request.status_code + print('request returned', request.status_code)