a oe5@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z GdddZ d d Z Gd d d eZejfd dZddZdddZdS)zsdistutils.filelist Provides the FileList class, used for poking about the filesystem and building lists of files. N convert_path)DistutilsTemplateErrorDistutilsInternalError)logc@s|eZdZdZdddZddZejfddZd d Z d d Z d dZ ddZ ddZ ddZddZdddZdddZdS) FileListaA list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. Instance attributes: dir directory from which files will be taken -- only used if 'allfiles' not supplied to constructor files list of filenames currently being built/filtered/manipulated allfiles complete list of files under consideration (ie. without any filtering applied) NcCsd|_g|_dSN)allfilesfiles)selfwarn debug_printr?C:\Program Files\Certbot\pkgs\setuptools\_distutils\filelist.py__init__ szFileList.__init__cCs ||_dSr )r )r r rrr set_allfiles&szFileList.set_allfilescCst||_dSr )findallr )r dirrrrr)szFileList.findallcCsddlm}|rt|dS)z~Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. r)DEBUGN)Zdistutils.debugrprint)r msgrrrrr,s zFileList.debug_printcCs|j|dSr )r append)r itemrrrr7szFileList.appendcCs|j|dSr )r extend)r itemsrrrr:szFileList.extendcCs<tttjj|j}g|_|D]}|jtjj|qdSr )sortedmapospathsplitr rjoin)r Zsortable_filesZ sort_tuplerrrsort=sz FileList.sortcCs@tt|jdddD]$}|j||j|dkr|j|=qdS)Nrr)rangelenr )r irrrremove_duplicatesFszFileList.remove_duplicatescCs|}|d}d}}}|dvrTt|dkr ...cSsg|] }t|qSrr.0wrrr Yz1FileList._parse_template_line..r)recursive-includerecursive-excludez,'%s' expects ...cSsg|] }t|qSrrr-rrrr0`r1)graftprunez#'%s' expects a single zunknown action '%s')r r%rr)r linewordsactionpatternsr dir_patternrrr_parse_template_lineNs0      zFileList._parse_template_linecCsD||\}}}}|dkrV|dd||D]}|j|dds2td|q2n|dkr|dd||D]}|j|ddsvtd |qvn|d kr|d d||D]}|j|d dstd |qnb|dkr(|dd||D]"}|j|d dstd|qn|dkrz|d|d||D](}|j||dsNd}t|||qNn|dkr|d|d||D]$}|j||dstd||qnx|dkr|d||jd|ds@td|nB|dkr4|d||jd|ds@td|n td|dS)Nr(zinclude  r)anchorz%warning: no files found matching '%s'r)zexclude z9warning: no previously-included files found matching '%s'r*zglobal-include rz>warning: no files found matching '%s' anywhere in distributionr+zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr2zrecursive-include {} {})prefixz:warning: no files found matching '%s' under directory '%s'r3zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'r5zgraft z+warning: no directories found matching '%s'r6zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s') r<rr!include_patternrZwarningexclude_patternformatr)r r7r9r:rr;patternrrrrprocess_template_linelsx        zFileList.process_template_linerrcCsld}t||||}|d|j|jdur4||jD],}||r:|d||j|d}q:|S)aSelect strings (presumably filenames) from 'self.files' that match 'pattern', a Unix-style wildcard (glob) pattern. Patterns are not quite the same as implemented by the 'fnmatch' module: '*' and '?' match non-special characters, where "special" is platform- dependent: slash on Unix; colon, slash, and backslash on DOS/Windows; and colon on Mac OS. If 'anchor' is true (the default), then the pattern match is more stringent: "*.py" will match "foo.py" but not "foo/bar.py". If 'anchor' is false, both of these will match. If 'prefix' is supplied, then only filenames starting with 'prefix' (itself a pattern) and ending with 'pattern', with anything in between them, will match. 'anchor' is ignored in this case. If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and 'pattern' is assumed to be either a string containing a regex or a regex object -- no translation is done, the regex is just compiled and used as-is. Selected strings will be added to self.files. Return True if files are found, False otherwise. Fz%include_pattern: applying regex r'%s'Nz adding T)translate_patternrrCr rsearchr r)r rCr>r?is_regex files_found pattern_renamerrrr@s    zFileList.include_patterncCsrd}t||||}|d|jtt|jdddD]4}||j|r8|d|j||j|=d}q8|S)aRemove strings (presumably filenames) from 'files' that match 'pattern'. Other parameters are the same as for 'include_pattern()', above. The list 'self.files' is modified in place. Return True if files are found, False otherwise. Fz%exclude_pattern: applying regex r'%s'rr#z removing T)rErrCr$r%r rF)r rCr>r?rGrHrIr&rrrrAszFileList.exclude_pattern)NN)rNr)rNr)__name__ __module__ __qualname____doc__rrrcurdirrrrrr"r'r<rDr@rArrrrrs   ^ )rcCs0ttj|dd}dd|D}ttjj|S)z% Find all files under 'path' T) followlinkscss,|]$\}}}|D]}tj||VqqdSr )rrr!)r.basedirsr filerrr sz#_find_all_simple..) _UniqueDirsfilterrwalkrisfile)rZ all_uniqueresultsrrr_find_all_simples rZc@s$eZdZdZddZeddZdS)rUz Exclude previously-seen dirs from walk results, avoiding infinite recursion. Ref https://bugs.python.org/issue44497. cCsF|\}}}t|}|j|jf}||v}|r6|dd=||| S)z Given an item from an os.walk result, determine if the item represents a unique dir for this instance and if not, prevent further traversal. N)rstatst_devst_inoadd)r Z walk_itemrQrRr r[ candidatefoundrrr__call__s     z_UniqueDirs.__call__cCs t||Sr )rV)clsrrrrrV)sz_UniqueDirs.filterN)rKrLrMrNra classmethodrVrrrrrUsrUcCs6t|}|tjkr.tjtjj|d}t||}t|S)z Find all files under 'dir' and return the list of full filenames. Unless dir is '.', return full filenames with dir prepended. )start) rZrrO functoolspartialrrelpathrlist)rr Zmake_relrrrr.s   rcCs8t|}tj}tjdkrd}d|}td||}|S)zTranslate a shell-like glob pattern to a regular expression; return a string containing the regex. Differs from 'fnmatch.translate()' in that '*' does not match "special characters" (which are platform-specific). \z\\\\z\1[^%s]z((?r?rGrdrpendrIZ prefix_rerlrrrrEQs*   rE)rNr)rNrrmrjreutilrerrorsrrZ_logrrrZsetrUrOrrorErrrrs  x