Skip to content

Commit 75e9ec8

Browse files
committed
make python3 only and some cleanup
1 parent e772ce7 commit 75e9ec8

25 files changed

+61
-92
lines changed

Jenkinsfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ node {
99
sh 'git clean -fxd'
1010
}
1111
stage('test') {
12-
sh 'python2.7 -V'
1312
sh 'pip3 install --ignore-installed --prefix $PWD/.vsc-tox tox'
1413
sh 'export PATH=$PWD/.vsc-tox/bin:$PATH && export PYTHONPATH=$PWD/.vsc-tox/lib/python$(python3 -c "import sys; print(\\"%s.%s\\" % sys.version_info[:2])")/site-packages:$PYTHONPATH && tox -v -c tox.ini'
1514
sh 'rm -r $PWD/.vsc-tox'

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# vsc-utils
22

3-
### Build Status
4-
- Python 2.6 : [![Build Status](https://jenkins1.ugent.be/job/vsc-utils-python26/badge/icon)](https://jenkins1.ugent.be/job/vsc-utils-python26/)
5-
- Python 2.7 : [![Build Status](https://jenkins1.ugent.be/job/vsc-utils-python27/badge/icon)](https://jenkins1.ugent.be/job/vsc-utils-python27/)
6-
73
# Description
84
Common tools used within our organization.
95
These tools live in the vsc.utils namespace, toghether with the tools from
@@ -12,8 +8,5 @@ vsc-base.
128
They have been split of from vsc-base because the tools here need aditional dependencies
139
to work correctly whereas the tools in vsc-base do not.
1410

15-
Originally created by the HPC team of Ghent University (http://ugent.be/hpc).
16-
17-
# Documentation
18-
https://jenkins1.ugent.be/job/vsc-utils-python26/Documentation/
11+
Originally created by the HPC team of Ghent University (https://ugent.be/hpc).
1912

lib/vsc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2021 Ghent University
2+
# Copyright 2015-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2021 Ghent University
2+
# Copyright 2015-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/availability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/cache.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -32,10 +32,9 @@
3232
import jsonpickle
3333
import os
3434
import time
35+
import pickle
3536

3637
from vsc.utils import fancylogger
37-
from vsc.utils.py2vs3 import pickle, FileNotFoundErrorExc
38-
3938

4039
class FileCache(object):
4140
"""File cache with a timestamp safety.
@@ -106,7 +105,7 @@ def __init__(self, filename, retain_old=True, raise_unpickable=False):
106105
finally:
107106
g.close()
108107

109-
except (OSError, IOError, ValueError, FileNotFoundErrorExc) as err:
108+
except (OSError, IOError, ValueError, FileNotFoundError) as err:
110109
self.log.warning("Could not access the file cache at %s [%s]", self.filename, err)
111110
self.shelf = {}
112111
self.log.info("Cache in %s starts with an empty shelf", (self.filename,))
@@ -158,19 +157,17 @@ def close(self):
158157
dirname = os.path.dirname(self.filename)
159158
if not os.path.exists(dirname):
160159
os.makedirs(dirname)
161-
f = open(self.filename, 'wb')
162-
if not f:
163-
self.log.error('cannot open the file cache at %s for writing', self.filename)
164-
else:
165-
if self.retain_old:
166-
self.shelf.update(self.new_shelf)
167-
self.new_shelf = self.shelf
168-
169-
g = gzip.GzipFile(mode='wb', fileobj=f)
170-
pickled = jsonpickle.encode(self.new_shelf)
171-
# .encode() is required in Python 3, since we need to pass a bytestring
172-
g.write(pickled.encode())
173-
g.close()
174-
f.close()
175-
176-
self.log.info('closing the file cache at %s', self.filename)
160+
with open(self.filename, 'wb') as fih:
161+
if not fih:
162+
self.log.error('cannot open the file cache at %s for writing', self.filename)
163+
else:
164+
if self.retain_old:
165+
self.shelf.update(self.new_shelf)
166+
self.new_shelf = self.shelf
167+
168+
with gzip.GzipFile(mode='wb', fileobj=fih) as zipf:
169+
pickled = jsonpickle.encode(self.new_shelf)
170+
# .encode() is required in Python 3, since we need to pass a bytestring
171+
zipf.write(pickled.encode())
172+
173+
self.log.info('closing the file cache at %s', self.filename)

lib/vsc/utils/fs_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/nagios.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# -*- encoding: utf-8 -*-
33
#
4-
# Copyright 2012-2021 Ghent University
4+
# Copyright 2012-2023 Ghent University
55
#
66
# This file is part of vsc-utils,
77
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -40,7 +40,6 @@
4040
@author: Andy Georges (Ghent University)
4141
@author: Luis Fernando Muñoz Mejías (Ghent University)
4242
"""
43-
from __future__ import print_function
4443

4544
import operator
4645
import os
@@ -52,7 +51,6 @@
5251

5352
from vsc.utils.cache import FileCache
5453
from vsc.utils.fancylogger import getLogger
55-
from vsc.utils.py2vs3 import is_string, FileNotFoundErrorExc
5654

5755
log = getLogger(__name__)
5856

@@ -155,7 +153,7 @@ def __init__(self, nrange):
155153
"""
156154
self.log = getLogger(self.__class__.__name__, fname=False)
157155

158-
if not is_string(nrange):
156+
if not isinstance(nrange, str):
159157
newnrange = str(nrange)
160158
self.log.debug("nrange %s of type %s, converting to string (%s)", str(nrange), type(nrange), newnrange)
161159
try:
@@ -316,7 +314,7 @@ def cache(self, nagios_exit, nagios_message):
316314
else:
317315
self.log.warn("Not running as root: Cannot chown the nagios check file %s to %s",
318316
self.filename, self.nagios_username)
319-
except (OSError, FileNotFoundErrorExc):
317+
except (OSError, FileNotFoundError):
320318
self.log.raiseException("Cannot chown the nagios check file %s to the nagios user" % (self.filename))
321319

322320
return True

lib/vsc/utils/pickle_files.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2021 Ghent University
2+
# Copyright 2012-2023 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -38,10 +38,7 @@
3838
import logging
3939
import os
4040
import stat
41-
42-
43-
from vsc.utils.py2vs3 import pickle, FileNotFoundErrorExc
44-
41+
import pickle
4542

4643
class TimestampPickle(object):
4744
"""Stores a timestamp in some format in a file."""
@@ -60,8 +57,9 @@ def read(self):
6057
"""
6158

6259
try:
63-
timestamp = pickle.load(open(self.filename, "rb"))
64-
except (IOError, OSError, FileNotFoundErrorExc):
60+
with open (self.filename, "rb") as fih:
61+
timestamp = pickle.load(fih)
62+
except (IOError, OSError, FileNotFoundError):
6563
logging.exception("Failed to load timestamp pickle from filename %s.", self.filename)
6664
return None
6765

@@ -78,7 +76,8 @@ def write(self, timestamp):
7876
"""
7977

8078
try:
81-
pickle.dump(timestamp, open(self.filename, "wb"))
79+
with open(self.filename, "wb") as fih:
80+
pickle.dump(timestamp, fih)
8281
except Exception:
8382
logging.exception("Failed to dump timestamp %s to pickle in filename %s", timestamp, self.filename)
8483
raise

0 commit comments

Comments
 (0)