Skip to content
This repository was archived by the owner on Jan 19, 2018. It is now read-only.

Commit cef5ec5

Browse files
committed
Merge pull request #705 from surajssd/abstract-get_abspath
Abstracted the way we get absolute path
2 parents 4e8b2fb + 001b3e4 commit cef5ec5

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

atomicapp/cli/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def run(self):
474474
if hasattr(args, item) and getattr(args, item) is not None:
475475
args.cli_answers[item] = getattr(args, item)
476476

477-
lock = LockFile(os.path.join(Utils.getRoot(), LOCK_FILE))
477+
lock = LockFile(Utils.get_real_abspath(LOCK_FILE))
478478
try:
479479
if args.action != 'init':
480480
lock.acquire(timeout=-1)

atomicapp/nulecule/main.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,11 @@ def __init__(self, app_spec, destination=None,
7474

7575
# Adjust app_spec, destination, and answer file paths if absolute.
7676
if os.path.isabs(app_spec):
77-
app_spec = os.path.join(Utils.getRoot(),
78-
app_spec.lstrip('/'))
77+
app_spec = Utils.get_real_abspath(app_spec)
7978
if destination and os.path.isabs(destination):
80-
destination = os.path.join(Utils.getRoot(),
81-
destination.lstrip('/'))
79+
destination = Utils.get_real_abspath(destination)
8280
if answers_file and os.path.isabs(answers_file):
83-
answers_file = os.path.join(Utils.getRoot(),
84-
answers_file.lstrip('/'))
81+
answers_file = Utils.get_real_abspath(answers_file)
8582

8683
# If the user doesn't want the files copied to a permanent
8784
# location then he provides 'none'. If that is the case we'll

atomicapp/plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def getConfigFile(self):
7575
if PROVIDER_CONFIG_KEY in self.config:
7676
self.config_file = self.config[PROVIDER_CONFIG_KEY]
7777
if os.path.isabs(self.config_file):
78-
self.config_file = os.path.join(Utils.getRoot(),
79-
self.config_file.lstrip('/'))
78+
self.config_file = Utils.get_real_abspath(self.config_file)
8079
else:
8180
logger.warning("Configuration option '%s' not found" % PROVIDER_CONFIG_KEY)
8281

atomicapp/providers/kubernetes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def init(self):
5555
if self.container:
5656
self.kubectl = self._find_kubectl(Utils.getRoot())
5757
kube_conf_path = "/etc/kubernetes"
58-
host_kube_conf_path = os.path.join(Utils.getRoot(), kube_conf_path.lstrip("/"))
58+
host_kube_conf_path = Utils.get_real_abspath(kube_conf_path)
5959
if not os.path.exists(kube_conf_path) and os.path.exists(host_kube_conf_path):
6060
if self.dryrun:
6161
logger.info("DRY-RUN: link %s from %s" % (kube_conf_path, host_kube_conf_path))

atomicapp/providers/openshift.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,7 @@ def _set_config_values(self):
680680
self.provider_tls_verify = result[PROVIDER_TLS_VERIFY_KEY]
681681
if result[PROVIDER_CA_KEY]:
682682
# if we are in container translate path to path on host
683-
self.provider_ca = os.path.join(Utils.getRoot(),
684-
result[PROVIDER_CA_KEY].lstrip('/'))
683+
self.provider_ca = Utils.get_real_abspath(result[PROVIDER_CA_KEY])
685684
else:
686685
self.provider_ca = None
687686

atomicapp/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,21 @@ def getRoot():
354354
else:
355355
return "/"
356356

357+
@staticmethod
358+
def get_real_abspath(path):
359+
"""
360+
Take the user provided 'path' and return the real path to the resource
361+
irrespective of the app running location either inside container or
362+
outside.
363+
364+
Args:
365+
path (str): path to a resource
366+
367+
Returns:
368+
str: absolute path to resource in the filesystem.
369+
"""
370+
return os.path.join(Utils.getRoot(), path.lstrip('/'))
371+
357372
# generates a unique 12 character UUID
358373
@staticmethod
359374
def getUniqueUUID():

0 commit comments

Comments
 (0)