Skip to content

Commit 10803c6

Browse files
committed
fixup
1 parent 7f34550 commit 10803c6

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

mig/shared/_env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
MIG_BASE = os.path.realpath(os.path.join(os.path.dirname(__file__), '../..'))
4+
MIG_ENV = os.getenv('MIG_ENV', 'default')

mig/shared/conf.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import os
3333
import sys
3434

35+
from mig.shared._env import MIG_BASE
3536
from mig.shared.fileio import unpickle
3637

3738

@@ -43,17 +44,14 @@ def get_configuration_object(config_file=None, skip_log=False,
4344
"""
4445
from mig.shared.configuration import Configuration
4546
if config_file:
47+
# use config file path passed explicitly to the function
4648
_config_file = config_file
4749
elif os.environ.get('MIG_CONF', None):
50+
# use config file explicitly set in the environment
4851
_config_file = os.environ['MIG_CONF']
4952
else:
50-
app_dir = os.path.dirname(sys.argv[0])
51-
if not app_dir:
52-
_config_file = '../server/MiGserver.conf'
53-
else:
54-
_config_file = os.path.join(app_dir, '..', 'server',
55-
'MiGserver.conf')
56-
_config_file = os.path.normpath(_config_file)
53+
# find config file relative to the directory in which the scrip resides
54+
_config_file = os.path.join(MIG_BASE, 'server/MiGserver.conf')
5755
configuration = Configuration(_config_file, False, skip_log,
5856
disable_auth_log)
5957
return configuration
@@ -62,7 +60,7 @@ def get_configuration_object(config_file=None, skip_log=False,
6260
def get_resource_configuration(resource_home, unique_resource_name,
6361
logger):
6462
"""Load a resource configuration from file"""
65-
63+
6664
# open the configuration file
6765

6866
resource_config_file = resource_home + '/' + unique_resource_name\

mig/shared/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def reload_config(self, verbose, skip_log=False, disable_auth_log=False,
735735
else:
736736
print("""Could not find your configuration file (%s). You might
737737
need to point the MIG_CONF environment to your actual MiGserver.conf
738-
location.""" % self.config_file)
738+
location.""" % _config_file)
739739
raise IOError
740740

741741
config = ConfigParser()

mig/shared/defaults.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
import os
3333
import sys
3434

35-
MIG_BASE = os.path.realpath(os.path.join(os.path.dirname(__file__), '../..'))
36-
MIG_ENV = os.getenv('MIG_ENV', 'default')
35+
from mig.shared._env import MIG_BASE, MIG_ENV
3736

3837
# NOTE: python3 switched strings to use unicode by default in contrast to bytes
3938
# in python2. File systems remain with utf8 however so we need to

tests/support/_env.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
#!/usr/bin/python
2+
# -*- coding: utf-8 -*-
3+
#
4+
# --- BEGIN_HEADER ---
5+
#
6+
# mig.shared._env - environment related consants only
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
8+
#
9+
# This file is part of MiG.
10+
#
11+
# MiG is free software: you can redistribute it and/or modify
12+
# it under the terms of the GNU General Public License as published by
13+
# the Free Software Foundation; either version 2 of the License, or
14+
# (at your option) any later version.
15+
#
16+
# MiG is distributed in the hope that it will be useful,
17+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
# GNU General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; if not, write to the Free Software
23+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+
#
25+
# -- END_HEADER ---
26+
#
27+
28+
29+
"""Environment consants separated from defaults to reduce import pollution."""
30+
131
import os
232
import sys
333

0 commit comments

Comments
 (0)