Skip to content

Commit ec150c0

Browse files
authored
Change OSB Config directory from ~/.benchmark to ~/.osb (#732)
Signed-off-by: Michael Oviedo <[email protected]>
1 parent 4d96c35 commit ec150c0

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

it/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import pytest
3535

36-
from osbenchmark import client, config, version
36+
from osbenchmark import client, config, version, paths
3737
from osbenchmark.utils import process
3838

3939
CONFIG_NAMES = ["in-memory-it", "os-it"]
@@ -150,7 +150,7 @@ def check_prerequisites():
150150
class ConfigFile:
151151
def __init__(self, config_name):
152152
self.user_home = os.getenv("BENCHMARK_HOME", os.path.expanduser("~"))
153-
self.benchmark_home = os.path.join(self.user_home, ".benchmark")
153+
self.benchmark_home = paths.benchmark_confdir()
154154
if config_name is not None:
155155
self.config_file_name = f"benchmark-{config_name}.ini"
156156
else:

osbenchmark/paths.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,31 @@
2222
# specific language governing permissions and limitations
2323
# under the License.
2424
import os
25-
25+
from osbenchmark.utils.io import ensure_dir, ensure_symlink
26+
from osbenchmark.utils import console
2627

2728
def benchmark_confdir():
2829
default_home = os.path.expanduser("~")
29-
return os.path.join(os.getenv("BENCHMARK_HOME", default_home), ".benchmark")
30+
old_path = os.path.join(default_home, ".benchmark")
31+
new_path = os.path.join(default_home, ".osb")
32+
33+
try:
34+
# Ensure .benchmark directory exists
35+
ensure_dir(old_path)
36+
37+
# Ensure symlink from .osb to .benchmark
38+
ensure_symlink(old_path, new_path)
39+
40+
benchmark_confdir_path = os.path.join(os.getenv("BENCHMARK_HOME", default_home), ".osb")
41+
42+
return benchmark_confdir_path
3043

44+
except FileNotFoundError as e:
45+
console.print("Error in benchmark_confdir: ", str(e))
46+
raise
47+
# fallback exception
48+
except Exception as e:
49+
console.print("Unexpected error in benchmark_confdir: ", str(e))
3150

3251
def benchmark_root():
3352
return os.path.dirname(os.path.realpath(__file__))

osbenchmark/utils/io.py

+28
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,34 @@ def ensure_dir(directory, mode=0o777):
236236
if directory:
237237
os.makedirs(directory, mode, exist_ok=True)
238238

239+
def ensure_symlink(source, link_name):
240+
"""
241+
Ensure that a symlink exists from link_name to source.
242+
If link_name already exists, it will be updated or replaced as necessary.
243+
244+
:param source: The target of the symlink
245+
:param link_name: The path where the symlink should be created
246+
"""
247+
logger = logging.getLogger(__name__)
248+
if os.path.exists(link_name):
249+
if os.path.islink(link_name):
250+
if os.readlink(link_name) != source:
251+
os.remove(link_name)
252+
os.symlink(source, link_name)
253+
logger.info("Updated symlink: %s -> %s", link_name, source)
254+
else:
255+
logger.info("Symlink already correct: %s -> %s", link_name, source)
256+
elif os.path.isdir(link_name):
257+
shutil.rmtree(link_name)
258+
os.symlink(source, link_name)
259+
logger.info("Replaced directory with symlink: %s -> %s", link_name, source)
260+
else:
261+
os.remove(link_name)
262+
os.symlink(source, link_name)
263+
logger.info("Replaced file with symlink: %s -> %s", link_name, source)
264+
else:
265+
os.symlink(source, link_name)
266+
logger.info("Created symlink: %s -> %s", link_name, source)
239267

240268
def _zipdir(source_directory, archive):
241269
for root, _, files in os.walk(source_directory):

0 commit comments

Comments
 (0)