Ignore directory entries that begin with dot('.').

This commit is contained in:
Darko Poljak 2017-07-06 13:30:57 +02:00
parent 1582661da9
commit 80c3dd7572
4 changed files with 40 additions and 5 deletions

View file

@ -27,3 +27,4 @@ from cdist.core.cdist_object import IllegalObjectIdError
from cdist.core.explorer import Explorer
from cdist.core.manifest import Manifest
from cdist.core.code import Code
from cdist.core.util import listdir

View file

@ -107,7 +107,7 @@ class CdistObject(object):
@classmethod
def list_type_names(cls, object_base_path):
"""Return a list of type names"""
return os.listdir(object_base_path)
return cdist.core.listdir(object_base_path)
@staticmethod
def split_name(object_name):

View file

@ -23,6 +23,7 @@
import os
import cdist
import cdist.core
class NoSuchTypeError(cdist.Error):
@ -75,7 +76,7 @@ class CdistType(object):
@classmethod
def list_type_names(cls, base_path):
"""Return a list of type names"""
return os.listdir(base_path)
return cdist.core.listdir(base_path)
_instances = {}
@ -117,8 +118,8 @@ class CdistType(object):
"""Return a list of available explorers"""
if not self.__explorers:
try:
self.__explorers = os.listdir(os.path.join(self.absolute_path,
"explorer"))
self.__explorers = cdist.core.listdir(
os.path.join(self.absolute_path, "explorer"))
except EnvironmentError:
# error ignored
self.__explorers = []
@ -222,7 +223,7 @@ class CdistType(object):
defaults_dir = os.path.join(self.absolute_path,
"parameter",
"default")
for name in os.listdir(defaults_dir):
for name in cdist.core.listdir(defaults_dir):
try:
with open(os.path.join(defaults_dir, name)) as fd:
defaults[name] = fd.read().strip()

33
cdist/core/util.py Normal file
View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
#
# 2017 Darko Poljak (darko.poljak at gmail.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
import os
def listdir(path='.', include_dot=False):
"""os.listdir but do not include entries whose names begin with a dot('.')
if include_dot is False.
"""
return [x for x in os.listdir(path) if include_dot or not _ishidden(x)]
def _ishidden(path):
return path[0] in ('.', b'.'[0])