def get_mtimes(directory): global _win mtimes = {} for root, dirs, files in walk_ignore(directory): for filename in files: filepath = os.path.join(root, filename) stat = os.stat(filepath) mtime = stat.st_mtime if _win: mtime -= stat.st_ctime mtimes[filepath] = mtime return mtimes
def _read_files(self): """ Walks through the project directory and separates files into parseable files (file extensions for which a parser exists) and static files (file extensions for which no parser exists) """ data = OrderedDict() for root, dirs, files in walk_ignore(self.settings['project_dir']): pages = [] # parseable files; rename to (pages) static = [] # rename to (static) # check if a parser exists and append to corresponding list for file in files: path = join(root, file) if parser.get_parser_for_filename(path): pages.append(path) else: static.append(path) # assign static files with pages if pages: data[root] = (pages, static) elif static: # dir has static file(s) but no pages. check if one of # the parent dirs has a page and associate the static files # with it has_parent = False if root != self.settings['project_dir']: parent_dir = dirname(root) while parent_dir != self.settings['project_dir']: if parent_dir in data: data.setdefault(parent_dir, ([], []))[1].\ extend(static) has_parent = True parent_dir = dirname(parent_dir) # if no parent dir could be found, or the file is in the # root dir associate the files with the root of the project dir if not has_parent: data.setdefault(self.settings['project_dir'], ([], []))[1].extend(static) return data