Skip to content

Commit

Permalink
Ignore hidden files by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
yesimon committed May 21, 2012
1 parent 0df257f commit 7613341
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion icanhaz/conf.py
Expand Up @@ -2,7 +2,6 @@
from django.core.exceptions import ImproperlyConfigured



class Configuration(object):
def __init__(self, **kwargs):
self.defaults = kwargs
Expand All @@ -28,4 +27,5 @@ def __getattr__(self, k):
],
ICANHAZ_DIRS=[],
ICANHAZ_APP_DIRNAMES=["jstemplates"],
ICANHAZ_IGNORE_HIDDEN_FILES=True
)
24 changes: 6 additions & 18 deletions icanhaz/finders.py
Expand Up @@ -6,28 +6,23 @@
from .conf import conf



class BaseFinder(object):
def find(self, name):
raise NotImplementedError()



class BaseRegexFinder(object):
# Returns a list of (name, filepath) pairs
# from the given dir matching the given regex
def findAll(self, dir, regex):
raise NotImplementedError()




class FilesystemFinder(BaseFinder):
@property
def directories(self):
return conf.ICANHAZ_DIRS


def find(self, name):
for directory in self.directories:
filepath = os.path.abspath(os.path.join(
Expand All @@ -40,30 +35,28 @@ def find(self, name):
return None



class FilesystemRegexFinder(BaseRegexFinder):
@property
def directories(self):
return conf.ICANHAZ_DIRS


def findAll(self, dir, regex):
result = []

regex = re.compile("(" + regex + ").html")
for directory in self.directories:
dirpath = os.path.abspath(os.path.join(directory, dir))
for file in os.listdir(dirpath):
if not os.path.isdir(file):
match = regex.match(file)
for fn in os.listdir(dirpath):
if conf.ICANHAZ_IGNORE_HIDDEN_FILES and fn.startswith('.'):
continue
if not os.path.isdir(fn):
match = regex.match(fn)
if match is not None:
print match.groups()[0]
result += [(match.groups()[0], os.path.join(dirpath, file))]
result += [(match.groups()[0], os.path.join(dirpath, fn))]

return result



# Convenience subclass to add directory scope to
# the names of the files
class ScopedFilesystemRegexFinder(FilesystemRegexFinder):
Expand All @@ -74,7 +67,6 @@ def findAll(self, dir, regex):
return [("_".join(scope_list + [name]), dir) for (name, dir) in res]



def _get_app_template_dirs():
fs_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
ret = []
Expand All @@ -91,26 +83,22 @@ def _get_app_template_dirs():
return ret



# At import time, cache the app directories to search.
app_template_dirs = _get_app_template_dirs()



class AppFinder(FilesystemFinder):
@property
def directories(self):
return app_template_dirs



class AppRegexFinder(FilesystemRegexFinder):
@property
def directories(self):
return app_template_dirs



class ScopedAppRegexFinder(ScopedFilesystemRegexFinder):
@property
def directories(self):
Expand Down

0 comments on commit 7613341

Please sign in to comment.