Merge pull request #544 from darko-poljak/ignore-dot-files-under-conf-types
Ignore directory entries that begin with dot('.').
	
	
This commit is contained in:
		
				commit
				
					
						b50e605441
					
				
			
		
					 4 changed files with 43 additions and 5 deletions
				
			
		| 
						 | 
					@ -27,3 +27,4 @@ from cdist.core.cdist_object import IllegalObjectIdError
 | 
				
			||||||
from cdist.core.explorer import Explorer
 | 
					from cdist.core.explorer import Explorer
 | 
				
			||||||
from cdist.core.manifest import Manifest
 | 
					from cdist.core.manifest import Manifest
 | 
				
			||||||
from cdist.core.code import Code
 | 
					from cdist.core.code import Code
 | 
				
			||||||
 | 
					from cdist.core.util import listdir
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -104,7 +104,7 @@ class CdistObject(object):
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def list_type_names(cls, object_base_path):
 | 
					    def list_type_names(cls, object_base_path):
 | 
				
			||||||
        """Return a list of type names"""
 | 
					        """Return a list of type names"""
 | 
				
			||||||
        return os.listdir(object_base_path)
 | 
					        return cdist.core.listdir(object_base_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def split_name(object_name):
 | 
					    def split_name(object_name):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import cdist
 | 
					import cdist
 | 
				
			||||||
 | 
					import cdist.core
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NoSuchTypeError(cdist.Error):
 | 
					class NoSuchTypeError(cdist.Error):
 | 
				
			||||||
| 
						 | 
					@ -74,7 +75,7 @@ class CdistType(object):
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def list_type_names(cls, base_path):
 | 
					    def list_type_names(cls, base_path):
 | 
				
			||||||
        """Return a list of type names"""
 | 
					        """Return a list of type names"""
 | 
				
			||||||
        return os.listdir(base_path)
 | 
					        return cdist.core.listdir(base_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _instances = {}
 | 
					    _instances = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -116,8 +117,8 @@ class CdistType(object):
 | 
				
			||||||
        """Return a list of available explorers"""
 | 
					        """Return a list of available explorers"""
 | 
				
			||||||
        if not self.__explorers:
 | 
					        if not self.__explorers:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                self.__explorers = os.listdir(os.path.join(self.absolute_path,
 | 
					                self.__explorers = cdist.core.listdir(
 | 
				
			||||||
                                                           "explorer"))
 | 
					                    os.path.join(self.absolute_path, "explorer"))
 | 
				
			||||||
            except EnvironmentError:
 | 
					            except EnvironmentError:
 | 
				
			||||||
                # error ignored
 | 
					                # error ignored
 | 
				
			||||||
                self.__explorers = []
 | 
					                self.__explorers = []
 | 
				
			||||||
| 
						 | 
					@ -221,7 +222,7 @@ class CdistType(object):
 | 
				
			||||||
                defaults_dir = os.path.join(self.absolute_path,
 | 
					                defaults_dir = os.path.join(self.absolute_path,
 | 
				
			||||||
                                            "parameter",
 | 
					                                            "parameter",
 | 
				
			||||||
                                            "default")
 | 
					                                            "default")
 | 
				
			||||||
                for name in os.listdir(defaults_dir):
 | 
					                for name in cdist.core.listdir(defaults_dir):
 | 
				
			||||||
                    try:
 | 
					                    try:
 | 
				
			||||||
                        with open(os.path.join(defaults_dir, name)) as fd:
 | 
					                        with open(os.path.join(defaults_dir, name)) as fd:
 | 
				
			||||||
                            defaults[name] = fd.read().strip()
 | 
					                            defaults[name] = fd.read().strip()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										36
									
								
								cdist/core/util.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								cdist/core/util.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,36 @@
 | 
				
			||||||
 | 
					# -*- 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.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    if include_dot:
 | 
				
			||||||
 | 
					        return os.listdir(path)
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        return [x for x in os.listdir(path) if not _ishidden(x)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def _ishidden(path):
 | 
				
			||||||
 | 
					    return path[0] in ('.', b'.'[0])
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue