ž †2{Y¹4c@sÉdZddlZddlZddlZddlZddlmZddlmZddl m Z dgZ ej e ƒZejdejƒZejd ejejBƒZGd d„deƒZdS( uu Class representing the list of files in a distribution. Equivalent to distutils.filelist, but fixes some problems. iNi(uDistlibException(ufsdecode(u convert_pathuManifestu\\w* u#.*?(?= )| (?=$)cBsË|EeZdZdZddd„Zdd„Zdd„Zdd „Zdd d „Z d d „Z dd„Z dd„Z ddddd„Zddddd„Zddddd„Zdd„ZdS(uManifestu~A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. cCsYtjjtjj|p!tjƒƒƒ|_|jtj|_d|_ t ƒ|_ dS(ud Initialise an instance. :param base: The base directory to explore under. N( uosupathuabspathunormpathugetcwdubaseusepuprefixuNoneuallfilesusetufiles(uselfubase((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu__init__#s- uManifest.__init__cCsüddlm}m}m}g|_}|j}|g}|j}|j}x¨|r÷|ƒ}tj |ƒ} xƒ| D]{} tj j || ƒ} tj| ƒ} | j } || ƒrÊ|jt | ƒƒqu|| ƒru|| ƒ ru|| ƒququWqPWdS(umFind all files under the base and set ``allfiles`` to the absolute pathnames of files found. i(uS_ISREGuS_ISDIRuS_ISLNKN(ustatuS_ISREGuS_ISDIRuS_ISLNKuallfilesubaseupopuappenduosulistdirupathujoinust_modeufsdecode(uselfuS_ISREGuS_ISDIRuS_ISLNKuallfilesurootustackupopupushunamesunameufullnameustatumode((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyufindall2s"          uManifest.findallcCsM|j|jƒs-tjj|j|ƒ}n|jjtjj|ƒƒdS(uz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N( u startswithuprefixuosupathujoinubaseufilesuaddunormpath(uselfuitem((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyuaddMsu Manifest.addcCs"x|D]}|j|ƒqWdS(u† Add a list of files to the manifest. :param items: The pathnames to add. These can be relative to the base. N(uadd(uselfuitemsuitem((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyuadd_manyWs uManifest.add_manycsއ‡fdd†‰tˆjƒ}|rjtƒ}x'|D]}ˆ|tjj|ƒƒq:W||O}ndd„tdd„|DƒƒDƒS(u8 Return sorted files in directory order csj|j|ƒtjd|ƒ|ˆjkrftjj|ƒ\}}|dksVt‚ˆ||ƒndS(Nuadd_dir added %suu/(uu/(uadduloggerudebugubaseuosupathusplituAssertionError(udirsuduparentu_(uadd_diruself(u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyuadd_dires  u Manifest.sorted..add_dircSs"g|]}tjj|Œ‘qS((uosupathujoin(u.0u path_tuple((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu ss u#Manifest.sorted..css!|]}tjj|ƒVqdS(N(uosupathusplit(u.0upath((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu tsu"Manifest.sorted..(usetufilesuosupathudirnameusorted(uselfuwantdirsuresultudirsuf((uadd_diruselfu5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyusorted`s    uManifest.sortedcCstƒ|_g|_dS(uClear all collected files.N(usetufilesuallfiles(uself((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyuclearvs uManifest.clearcCsS|j|ƒ\}}}}|dkrcx%|D].}|j|ddƒs.tjd|ƒq.q.Wnì|dkr«xÝ|D].}|j|ddƒsvtjd|ƒqvqvWn¤|dkróx•|D].}|j|ddƒs¾tjd|ƒq¾q¾Wn\|dkr;xM|D].}|j|ddƒstjd |ƒqqWn|d kr†x|D]1}|j|d |ƒsNtjd ||ƒqNqNWnÉ|d krÑxº|D]1}|j|d |ƒs™tjd||ƒq™q™Wn~|dkr|jdd |ƒsOtjd|ƒqOnG|dkr?|jdd |ƒsOtjd|ƒqOntd|ƒ‚dS(uv Process a directive which either adds some files from ``allfiles`` to ``files``, or removes some files from ``files``. :param directive: The directive to process. This should be in a format compatible with distutils ``MANIFEST.in`` files: http://docs.python.org/distutils/sourcedist.html#commands uincludeuanchoruno files found matching %ruexcludeu.no previously-included files found matching %ruglobal-includeu3no files found matching %r anywhere in distributionuglobal-excludeuGno previously-included files matching %r found anywhere in distributionurecursive-includeuprefixu-no files found matching %r under directory %rurecursive-excludeuAno previously-included files matching %r found under directory %rugraftu no directories found matching %rupruneu4no previously-included directories found matching %ruinvalid action %rNTF( u_parse_directiveu_include_patternuTrueuloggeruwarningu_exclude_patternuFalseuNoneuDistlibException(uselfu directiveuactionupatternsuthediru dirpatternupattern((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyuprocess_directive{sP                       uManifest.process_directivec Cso|jƒ}t|ƒdkrA|ddkrA|jddƒn|d}d}}}|dkrªt|ƒd krŠtd |ƒ‚nd d„|dd…Dƒ}nµ|dkr t|ƒdkrÛtd|ƒ‚nt|dƒ}dd„|d d…Dƒ}nT|dkrOt|ƒd kr<td|ƒ‚nt|dƒ}ntd|ƒ‚||||fS(uŸ Validate a directive. :param directive: The directive to validate. :return: A tuple of action, patterns, thedir, dir_patterns iiuincludeuexcludeuglobal-includeuglobal-excludeurecursive-includeurecursive-excludeugraftupruneiu$%r expects ...cSsg|]}t|ƒ‘qS((u convert_path(u.0uword((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu às u-Manifest._parse_directive..Niu*%r expects ...cSsg|]}t|ƒ‘qS((u convert_path(u.0uword((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu ès u!%r expects a single uunknown action %r(uincludeuexcludeuglobal-includeuglobal-excludeurecursive-includeurecursive-excludeugraftuprune(uincludeuexcludeuglobal-includeuglobal-exclude(urecursive-includeurecursive-exclude(ugraftuprune(usplitulenuinsertuNoneuDistlibExceptionu convert_path(uselfu directiveuwordsuactionupatternsuthediru dir_pattern((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu_parse_directiveÇs:        uManifest._parse_directivecCszd}|j||||ƒ}|jdkr:|jƒnx9|jD].}|j|ƒrD|jj|ƒd}qDqDW|S(u…Select 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. FNT( uFalseu_translate_patternuallfilesuNoneufindallusearchufilesuadduTrue(uselfupatternuanchoruprefixuis_regexufoundu pattern_reuname((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu_include_patternös  uManifest._include_patterncCsdd}|j||||ƒ}x?t|jƒD].}|j|ƒr.|jj|ƒd}q.q.W|S(utRemove 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. This API is public to allow e.g. exclusion of SCM subdirs, e.g. when packaging source distributions FT(uFalseu_translate_patternulistufilesusearchuremoveuTrue(uselfupatternuanchoruprefixuis_regexufoundu pattern_reuf((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu_exclude_patterns  uManifest._exclude_patternc Cs |r)t|tƒr"tj|ƒS|Sn|rA|j|ƒ}nd}tjtjj|j dƒƒ}|dk rè|jdƒ}|j|ƒdt |ƒ …}tj } tj dkrÄd} nd|| j|d|fƒ}n|rÿd||}ntj|ƒS(uTranslate a shell-like wildcard pattern to a compiled regular expression. Return the compiled regex. If 'is_regex' true, then 'pattern' is directly compiled to a regex (if it's a string) or just returned as-is (assumes it's a regex object). uNu\u\\u^u.*( u isinstanceustrureucompileu _glob_to_reuescapeuosupathujoinubaseuNoneulenusep( uselfupatternuanchoruprefixuis_regexu pattern_reubaseu empty_patternu prefix_reusep((u5/tmp/pip-bsqfwp-build/pip/_vendor/distlib/manifest.pyu_translate_pattern3s&  !    uManifest._translate_patterncCsStj|ƒ}tj}tjdkr0d}nd|}tjd||ƒ}|S(u÷Translate 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). u\u\\\\u\1[^%s]u((? s