Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 3f1c63d

Browse files
author
Aaron James Long
authored
Merge pull request #35 from ISISComputingGroup/Ticket4896_convert_to_python_3
Ticket 4896: Convert to Python 3
2 parents 167625e + e8f4349 commit 3f1c63d

21 files changed

Lines changed: 134 additions & 64 deletions

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pipeline {
5353
goto ERROR
5454
)
5555
56-
C:/Instrument/Apps/Python/python.exe run_tests.py || echo "running tests failed."
56+
C:/Instrument/Apps/Python3/python.exe run_tests.py || echo "running tests failed."
5757
"""
5858
}
5959
}

block.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
Classes for Blocks
1818
"""
1919

20+
from builtins import object
2021
from block_utils import format_block_value
2122

2223

23-
class Block:
24+
class Block(object):
2425
"""
2526
Class holding Block details. Used for displaying in dataweb
2627
"""

block_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def format_block_value(val, precision):
8686
assert small_number_threshold < big_number_threshold
8787

8888
# No precision specified = do not format.
89-
if precision is None or precision < 0:
89+
if precision is None or not isinstance(precision, int) or precision < 0:
9090
return u"{}".format(val)
9191
try:
9292
float_val = float(val)

external_webpage/data_source_reader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def read_config(self):
101101
"""
102102

103103
# read config
104-
page = requests.get('http://%s:%s/' % (self._host, PORT_CONFIG))
105-
corrected_page = page.content\
106-
.replace("'", '"')\
104+
page = requests.get('http://{}:{}/'.format(self._host, PORT_CONFIG))
105+
content = page.content.decode("utf-8")
106+
corrected_page = content.replace("'", '"')\
107107
.replace("None", "null")\
108108
.replace("True", "true")\
109109
.replace("False", "false")

external_webpage/instrument_information_collator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
Classes getting external resources from an instrument and formating them for the info page.
1818
"""
1919

20+
from builtins import str
21+
from builtins import object
2022
import logging
2123

2224
from block_utils import (format_blocks, set_rc_values_for_blocks)
@@ -87,7 +89,7 @@ def block_is_visible(self, block_name):
8789
return True
8890

8991

90-
class InstrumentInformationCollator:
92+
class InstrumentInformationCollator(object):
9193
"""
9294
Collect instrument information and summarise as a dictionary.
9395
"""

external_webpage/instrument_scapper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from builtins import str
2+
from builtins import range
13
import logging
24
import traceback
35
from threading import Thread, Event, RLock

external_webpage/request_handler_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import str
12
import re
23
from collections import OrderedDict
34

external_webpage/web_page_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
Classes for parsing web pages
1818
"""
1919

20+
from builtins import str
21+
from builtins import object
2022
import logging
2123

2224
import re
@@ -90,9 +92,9 @@ def _create_block_from_channel(self, channel):
9092
if connected:
9193
units = current_value.get("Units", "")
9294

93-
precision = unicode(current_value.get("Precision", ""))
95+
precision = str(current_value.get("Precision", ""))
9496

95-
value = unicode(current_value["Value"])
97+
value = str(current_value["Value"])
9698

9799
replaced = True
98100
while replaced:

external_webpage/web_scrapper_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
Relation to web scrapper management.
33
"""
4+
from __future__ import print_function
5+
from builtins import range
6+
from builtins import object
47
import json
58
import logging
69
import zlib
@@ -190,7 +193,7 @@ def _is_scrapper_in_inst_list(self, inst_list, scrapper):
190193
Returns: True if in; False otherwise
191194
192195
"""
193-
for name, host in inst_list.items():
196+
for name, host in list(inst_list.items()):
194197
if scrapper.is_instrument(name, host):
195198
return True
196199
return False
@@ -204,7 +207,7 @@ def _scrapper_to_start(self, instruments):
204207
Returns:
205208
206209
"""
207-
for name, host in instruments.items():
210+
for name, host in list(instruments.items()):
208211
for scrapper in self.scrappers:
209212
if scrapper.is_instrument(name, host):
210213
break

run_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# This file is part of the ISIS IBEX application.
23
# Copyright (C) 2017 Science & Technology Facilities Council.
34
# All rights reserved.
@@ -37,10 +38,10 @@
3738
test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "tests"))
3839
test_suite = unittest.TestLoader().discover(test_dir, pattern="test_*.py")
3940

40-
print "\n\n------ BEGINNING JSON Bourne UNIT TESTS ------"
41+
print("\n\n------ BEGINNING JSON Bourne UNIT TESTS ------")
4142
ret_vals = list()
4243
ret_vals.append(xmlrunner.XMLTestRunner(output=xml_dir).run(test_suite))
43-
print "------ UNIT TESTS COMPLETE ------\n\n"
44+
print("------ UNIT TESTS COMPLETE ------\n\n")
4445

4546
# Return failure exit code if a test failed
4647
sys.exit(False in ret_vals)

0 commit comments

Comments
 (0)