Skip to content

Commit a4da900

Browse files
authored
Merge pull request #499 from loris-imageserver/3.0
Loris 3.0, with more of the Python 2-specific code gone
2 parents fae4cc4 + 696f078 commit a4da900

File tree

9 files changed

+14
-56
lines changed

9 files changed

+14
-56
lines changed

loris/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.3.3'
1+
__version__ = '3.0.0'

loris/img.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from loris.identifiers import CacheNamer
1111
from loris.parameters import RegionParameter, RotationParameter, SizeParameter
12-
from loris.utils import mkdir_p, safe_rename, symlink
12+
from loris.utils import safe_rename, symlink
1313

1414
logger = getLogger(__name__)
1515

@@ -171,7 +171,7 @@ def get_canonical_cache_path(self, image_request, image_info):
171171
def create_dir_and_return_file_path(self, image_request, image_info):
172172
target_fp = self.get_canonical_cache_path(image_request, image_info)
173173
target_dp = path.dirname(target_fp)
174-
mkdir_p(target_dp)
174+
os.makedirs(target_dp, exist_ok=True)
175175
return target_fp
176176

177177
def upsert(self, image_request, temp_fp, image_info):

loris/img_info.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from loris.identifiers import CacheNamer
1515
from loris.jp2_extractor import JP2Extractor, JP2ExtractionError
1616
from loris.loris_exception import ImageInfoException
17-
from loris.utils import mkdir_p
1817

1918
logger = getLogger(__name__)
2019

@@ -353,7 +352,7 @@ def __setitem__(self, ident, info, _to_fs=True):
353352
# to fs
354353
logger.debug('ident passed to __setitem__: %s', ident)
355354
dp = os.path.dirname(info_fp)
356-
mkdir_p(dp)
355+
os.makedirs(dp, exist_ok=True)
357356
logger.debug('Created %s', dp)
358357

359358
with open(info_fp, 'w') as f:

loris/resolver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import glob
77
import json
88
from logging import getLogger
9+
import os
910
from os.path import join, exists, dirname, split
1011
from os import remove
1112
from shutil import copy
@@ -18,7 +19,7 @@
1819
from loris import constants
1920
from loris.identifiers import CacheNamer, IdentRegexChecker
2021
from loris.loris_exception import ResolverException, ConfigError
21-
from loris.utils import mkdir_p, safe_rename
22+
from loris.utils import safe_rename
2223
from loris.img_info import ImageInfo
2324

2425

@@ -314,7 +315,7 @@ def copy_to_cache(self, ident):
314315
assert source_url is not None
315316

316317
cache_dir = self.cache_dir_path(ident)
317-
mkdir_p(cache_dir)
318+
os.makedirs(cache_dir, exist_ok=True)
318319

319320
with closing(requests.get(source_url, stream=True, **options)) as response:
320321
if not response.ok:
@@ -531,7 +532,7 @@ def copy_to_cache(self, ident):
531532
source_fp = self.source_file_path(ident)
532533
cache_fp = self.cache_file_path(ident)
533534

534-
mkdir_p(dirname(cache_fp))
535+
os.makedirs(dirname(cache_fp), exist_ok=True)
535536
copy(source_fp, cache_fp)
536537
logger.info("Copied %s to %s", source_fp, cache_fp)
537538

loris/transforms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import multiprocessing
33
from logging import getLogger
44
from math import ceil, log
5+
import os
56
from os import path
67
import platform
78
import subprocess
@@ -22,7 +23,6 @@
2223

2324
from loris.loris_exception import ConfigError, TransformException
2425
from loris.parameters import FULL_MODE
25-
from loris.utils import mkdir_p
2626

2727
logger = getLogger(__name__)
2828

@@ -224,7 +224,7 @@ def __init__(self, config):
224224
self.tmp_dp = config['tmp_dp']
225225

226226
try:
227-
mkdir_p(self.tmp_dp)
227+
os.makedirs(self.tmp_dp, exist_ok=True)
228228
except OSError as ose:
229229
# Almost certainly a permissions error on one of the required dirs
230230
from sys import exit

loris/user_commands.py

100644100755
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import os
33
import shutil
44
from configobj import ConfigObj
5-
from loris.utils import mkdir_p
65

76

87
CONFIG_FILE_NAME = 'loris2.conf'
@@ -55,7 +54,7 @@ def _copy_index_and_favicon(config):
5554
index_target = os.path.join(www_dir, 'index.txt')
5655
favicon_target_dir = os.path.join(www_dir, 'icons')
5756
favicon_target = os.path.join(favicon_target_dir, 'favicon.ico')
58-
mkdir_p(favicon_target_dir)
57+
os.makedirs(favicon_target_dir, exist_ok=True)
5958
shutil.copyfile(index_src, index_target)
6059
shutil.copyfile(favicon_src, favicon_target)
6160

@@ -74,7 +73,7 @@ def _make_directories(config):
7473
log_dir,
7574
]
7675
for d in loris_directories:
77-
mkdir_p(d)
76+
os.makedirs(d, exist_ok=True)
7877

7978

8079
def display_default_config_file():

loris/utils.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88
logger = logging.getLogger(__name__)
99

1010

11-
def mkdir_p(path):
12-
"""Create a directory if it doesn't already exist."""
13-
try:
14-
os.makedirs(path)
15-
except OSError as err:
16-
if err.errno == errno.EEXIST:
17-
pass
18-
else:
19-
raise
20-
21-
2211
def symlink(src, dst):
2312
"""Create a symlink from ``src`` to ``dst``.
2413
@@ -32,7 +21,7 @@ def symlink(src, dst):
3221
src, dst)
3322
return
3423

35-
mkdir_p(os.path.dirname(dst))
24+
os.makedirs(os.path.dirname(dst), exist_ok=True)
3625

3726
# Shouldn't be the case, but helps with debugging.
3827
if os.path.lexists(dst):

loris/webapp.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
SyntaxException,
3636
TransformException,
3737
)
38-
from loris.utils import mkdir_p
3938

4039

4140
getcontext().prec = 25 # Decimal precision. This should be plenty.
@@ -353,7 +352,7 @@ def __init__(self, app_configs={}):
353352
self.tmp_dp = _loris_config['tmp_dp']
354353

355354
try:
356-
mkdir_p(self.tmp_dp)
355+
os.makedirs(self.tmp_dp, exist_ok=True)
357356
except Exception as exc:
358357
raise ConfigError("Error creating tmp_dp %s: %r" % (self.tmp_dp, exc))
359358

tests/utils_t.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,6 @@
66
from loris import utils
77

88

9-
class TestMkdirP:
10-
11-
def test_creates_directory(self, tmpdir):
12-
path = str(tmpdir.join('test_creates_directory'))
13-
assert not os.path.exists(path)
14-
15-
# If we create the directory, it springs into being
16-
utils.mkdir_p(path)
17-
assert os.path.exists(path)
18-
19-
# If we try to create the directory a second time, we don't throw
20-
# an exception just because it already exists.
21-
utils.mkdir_p(path)
22-
23-
def test_if_error_is_unexpected_then_is_raised(self, tmpdir):
24-
"""
25-
If the error from ``os.makedirs()`` isn't because the directory
26-
already exists, we get an error.
27-
"""
28-
path = str(tmpdir.join('test_if_error_is_unexpected_then_is_raised'))
29-
30-
message = "Exception thrown in utils_t.py for TestMkdirP"
31-
32-
m = mock.Mock(side_effect=OSError(-1, message))
33-
with mock.patch('loris.utils.os.makedirs', m):
34-
with pytest.raises(OSError):
35-
utils.mkdir_p(path)
36-
37-
389
@pytest.fixture
3910
def src(tmpdir):
4011
path = str(tmpdir.join('src.txt'))

0 commit comments

Comments
 (0)