o ?Og 2@sdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z GdddZ dd Z ejfd d Zd d ZdddZdS)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 ddZddZdddZ dddZdS)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_printr9/opt/alt/python310/lib64/python3.10/distutils/filelist.py__init__s zFileList.__init__cCs ||_dSr)r )r r rrr set_allfiles#s zFileList.set_allfilescCst||_dSr)findallr )r dirrrrr&szFileList.findallcCs ddlm}|rt|dSdS)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_printcC|j|dSr)r append)r itemrrrr3zFileList.appendcCrr)r extend)r itemsrrrr6rzFileList.extendcCs<tttjj|j}g|_|D] }|jtjj|qdSr)sortedmapospathsplitr rjoin)r Zsortable_filesZ sort_tuplerrrsort9s z FileList.sortcCs@tt|jdddD]}|j||j|dkr|j|=q dS)Nr)rangelenr )r irrrremove_duplicatesCs zFileList.remove_duplicatescCs|}|d}d}}}|dvr*t|dkrtd|dd|ddD}n?|dvrLt|d kr:td |t|d}d d|ddD}n|d vrct|dkr\td |t|d}ntd|||||fS)Nr)includeexcludeglobal-includeglobal-excludez&'%s' expects ...cSg|]}t|qSrr.0wrrr Wz1FileList._parse_template_line..r$)recursive-includerecursive-excludez,'%s' expects ...cSr/rrr0rrrr3]r4)graftprunez#'%s' expects a single zunknown action '%s')r!r'rr)r lineZwordsactionpatternsr dir_patternrrr_parse_template_lineLs0       zFileList._parse_template_linecCs6||\}}}}|dkr+|dd||D]}|j|dds(td|qdS|dkrM|dd||D]}|j|ddsJtd |q;dS|d kro|d d||D]}|j|d dsltd |q]dS|dkr|dd||D]}|j|d dstd|qdS|dkr|d|d|f|D]}|j||dstd||qdS|dkr|d|d|f|D]}|j||dstd||qdS|dkr|d||jd|dstd|dSdS|dkr|d||jd|dstd|dSdStd|)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 distributionr5zrecursive-include %s %s)prefixz:warning: no files found matching '%s' under directory '%s'r6zrecursive-exclude %s %szNwarning: no previously-included files matching '%s' found under directory '%s'r8zgraft z+warning: no directories found matching '%s'r9zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')r>r r"include_patternrr exclude_patternr)r r:r;r<rr=patternrrrprocess_template_linehs   zFileList.process_template_liner$rcCsld}t||||}|d|j|jdur||jD]}||r3|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_patternr rDr rsearchr r)r rDr@rAis_regex files_found pattern_renamerrrrBs    zFileList.include_patterncCsrd}t||||}|d|jtt|jdddD]}||j|r6|d|j||j|=d}q|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'r$r%z removing T)rFr rDr&r'r rG)r rDr@rArHrIrJr(rrrrCszFileList.exclude_pattern)NNr$Nr)__name__ __module__ __qualname____doc__rrrcurdirrr rrr#r)r>rErBrCrrrrrs     L,rcCs&ddtj|ddD}ttjj|S)z% Find all files under 'path' css.|]\}}}|D] }tj||Vq qdSr)rr r")r1basedirsr filerrr s z#_find_all_simple..T) followlinks)rwalkfilterr isfile)r Zresultsrrr_find_all_simples rZcCs6t|}|tjkrtjtjj|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) rZrrQ functoolspartialr relpathrlist)rr Zmake_relrrrrs   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((?s  i