Permalink
Browse files

Make file paths more operating system independent

  • Loading branch information...
tobami committed May 2, 2012
1 parent f4aa4b5 commit 0344456436f007ec9dda75cafe542bfeb23eca68
Showing with 9 additions and 9 deletions.
  1. +1 −1 littlechef/chef.py
  2. +8 −8 littlechef/lib.py
View
@@ -40,7 +40,7 @@ def save_config(node, force=False):
if no nodes/hostname.json exists, or force=True, it creates one
it also saves to tmp_node.json
"""
- filepath = os.path.join("nodes/", env.host_string + ".json")
+ filepath = os.path.join("nodes", env.host_string + ".json")
tmp_filename = 'tmp_{0}.json'.format(env.host_string)
files_to_create = [tmp_filename]
if not os.path.exists(filepath) or force:
View
@@ -48,10 +48,10 @@ def get_node(name):
def get_nodes(environment=None):
"""Gets all nodes found in the nodes/ directory"""
- if not os.path.exists('nodes/'):
+ if not os.path.exists('nodes'):
return []
nodes = []
- for filename in sorted([f for f in os.listdir('nodes/')
+ for filename in sorted([f for f in os.listdir('nodes')
if not os.path.isdir(f) and f.endswith(".json")
and not f.startswith('.')]):
fqdn = ".".join(filename.split('.')[:-1]) # Remove .json from name
@@ -313,7 +313,7 @@ def get_roles_in_node(node):
def _get_role(rolename):
"""Reads and parses a file containing a role"""
- path = 'roles/' + rolename + '.json'
+ path = os.path.join('roles', rolename + '.json')
if not os.path.exists(path):
abort("Couldn't read role file {0}".format(path))
with open(path, 'r') as f:
@@ -328,13 +328,13 @@ def _get_role(rolename):
def get_roles():
- """Gets all roles found in the roles/ directory"""
+ """Gets all roles found in the 'roles' directory"""
roles = []
- for root, subfolders, files in os.walk('roles/'):
+ for root, subfolders, files in os.walk('roles'):
for filename in files:
if filename.endswith(".json"):
path = os.path.join(
- root[len('roles/'):], filename[:-len('.json')])
+ root[len('roles'):], filename[:-len('.json')])
roles.append(_get_role(path))
return sorted(roles, key=lambda x: x['fullname'])
@@ -365,8 +365,8 @@ def print_plugin_list():
def get_plugins():
"""Gets available plugins by looking into the plugins/ directory"""
- if os.path.exists('plugins/'):
- for filename in sorted([f for f in os.listdir('plugins/')
+ if os.path.exists('plugins'):
+ for filename in sorted([f for f in os.listdir('plugins')
if not os.path.isdir(f) and f.endswith(".py")]):
plugin_name = filename[:-3]
try:

0 comments on commit 0344456

Please sign in to comment.