YV0@sdZddlmZddlZddlZddlZddlZddlZddlm Z ddl m Z ddl mZmZmZmZmZddgZejeZGd d d eZeZGd d d eZd dZdS)z)Handles all VCS (version control) support)absolute_importN)parse) BadCommand) display_path backup_dircall_subprocessrmtreeask_path_existsvcsget_src_requirementcseZdZiZddddddgZfddZd d Zed d Zed dZ eddZ ddZ ddddZ ddZ ddZddZS) VcsSupportsshgithgbzrsftpsvncsOtjj|jttddr8tjj|jtt|jdS)N uses_fragment) urllib_parse uses_netlocextendschemesgetattrrsuperr __init__)self) __class__//tmp/pip-build-3puug3g5/pip/pip/vcs/__init__.pyrszVcsSupport.__init__cCs |jjS)N) _registry__iter__)rrrrr $szVcsSupport.__iter__cCst|jjS)N)listrvalues)rrrrbackends'szVcsSupport.backendscCsdd|jDS)NcSsg|]}|jqSr)dirname).0backendrrr -s z'VcsSupport.dirnames..)r#)rrrrdirnames+szVcsSupport.dirnamescCs.g}x!|jD]}|j|jqW|S)N)r#rr)rrr&rrr all_schemes/szVcsSupport.all_schemescCs_t|ds&tjd|jdS|j|jkr[||j|js  zVcsSupport.unregistercCsJxC|jjD]2}|j|rtjd||j|jSqWdS)z Return the name of the version control backend if found at given location, e.g. vcs.get_backend_name('/path/to/vcs/checkout') zDetermine that %s uses VCS: %sN)rr"controls_locationr,r/r*)rlocationvc_typerrrget_backend_nameFs    zVcsSupport.get_backend_namecCs*|j}||jkr&|j|SdS)N)lowerr)rr*rrr get_backendRs zVcsSupport.get_backendcCs&|j|}|r"|j|SdS)N)r6r8)rr4r5rrrget_backend_from_locationWs z$VcsSupport.get_backend_from_location)r. __module__ __qualname__rrrr propertyr#r(r)r1r2r6r8r9rr)rrr s    r cs'eZdZdZdZfZdfddZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%dd&dddd'd(Zed)d*ZS)+VersionControlNcs&||_tt|j||dS)N)urlrr=r)rr?argskwargs)rrrrgs zVersionControl.__init__cCs1tjj|\}}|jtjjp0|S)zy posix absolute paths start with os.path.sep, win32 ones start with drive (like c:\folder) )ospath splitdrive startswithsep)rrepodrivetailrrr_is_local_repositoryksz#VersionControl._is_local_repositorycCs|jddS)N/_)replace)rsurnamerrrtranslate_egg_surnameusz$VersionControl.translate_egg_surnamecCs tdS)z Export the repository at the url to the destination location i.e. only download the files, without vcs informations N)NotImplementedError)rr4rrrexportyszVersionControl.exportc Csd}d|jks(t||j|jjddd}tj|\}}}}}d}d|kr|jdd\}}tj||||df}||fS)zm Returns the correct repository URL and revision by parsing the given repository URL zvSorry, '%s' is a malformed VCS url. The format is +://, e.g. svn+http://myrepo/svn/MyApp#egg=MyApp+N@r>)r?AssertionErrorsplitrurlsplitrsplit urlunsplit) r error_messager?schemenetlocrCqueryfragrevrrr get_url_revs" zVersionControl.get_url_revcCsH|jdj|j s,td||j||j|fS)zA Returns (url, revision), where both are strings rKzBad directory: %s)rstripendswithr$rUget_url get_revision)rr4rrrget_infos zVersionControl.get_infocCstj|jdS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. rK)runquotera)rr?rrr normalize_urlszVersionControl.normalize_urlcCs|j||j|kS)zV Compare two repo URLs for identity, ignoring incidental differences. )rg)rurl1url2rrr compare_urlsszVersionControl.compare_urlscCs tdS)zx Called when installing or updating an editable package, takes the source path of the checkout. N)rP)rdestrrrobtainszVersionControl.obtaincCs tdS)zB Switch the repo at ``dest`` to point to ``URL``. N)rP)rrkr? rev_optionsrrrswitchszVersionControl.switchcCs tdS)zO Update an already-existing repo to the given ``rev_options``. N)rP)rrkrmrrrupdateszVersionControl.updatecCs tdS)zp Return True if the version is identical to what exists and doesn't need to be updated. N)rP)rrkrmrrr check_versionszVersionControl.check_versionc CsXd}d}tjj|r2d}tjjtjj||jr|j|}|j||rtjd|j j t |||j ||stj dt ||j ||j||q tj dq2tjd|j|j t ||d}n"tjd ||j|j d}|rTtjd|j|td|d|d}|dkrtj d|j t ||||j|||n|d krn|d krtjdt |t|d}nc|d kr;t|} tjdt || tj|| d}n|dkrTtjd|S)z Prepare a location to receive a checkout/clone. Return True if the location is ready for (and requires) a checkout/clone, False otherwise. TFz)%s in %s exists, and has correct URL (%s)zUpdating %s %s%sz$Skipping because already up-to-date.z%s %s in %s exists with URL %s%(s)witch, (i)gnore, (w)ipe, (b)ackup siwbz0Directory %s already exists, and is not a %s %s.(i)gnore, (w)ipe, (b)ackup z+The plan is to install the %s repository %szWhat to do? %srrSzSwitching %s %s to %s%sz Deleting %szBacking up %s to %sarrrsrtru)rqrxrsrtru)rvry)rBrCexistsjoinr$rcrjr,r/ repo_nametitlerrpinforor-r*r rnrrshutilmovesysexit) rrkr?rm rev_displaycheckoutprompt existing_urlresponsedest_dirrrrcheck_destinations$                   z VersionControl.check_destinationcCs-tjj|rt||j|dS)zq Clean up current location and download the url repository (and vcs infos) into location N)rBrCr{rrl)rr4rrrunpacks zVersionControl.unpackcCs tdS)z Return a string representing the requirement needed to redownload the files currently present in location, something like: {repository_url}@{revision}#egg={project_name}-{version_identifier} N)rP)rdistr4rrrr sz"VersionControl.get_src_requirementcCs tdS)z_ Return the url used at location Used in get_info or check_destination N)rP)rr4rrrrc)szVersionControl.get_urlcCs tdS)z_ Return the current revision of the files at location Used in get_info N)rP)rr4rrrrd0szVersionControl.get_revisionTraisec Cs|jg|}y t|||||||SWnPtk r}z0|jtjkrmtd|jnWYdd}~XnXdS)z Run a VCS subcommand This is simply a wrapper around call_subprocess that adds the VCS command name, and checks that the VCS is available zCannot find command %rN)r*rOSErrorerrnoENOENTr) rcmd show_stdoutcwd on_returncode command_desc extra_environspinnererrr run_command7s   zVersionControl.run_commandcCsDtjd||j|jtjj||j}tjj|S)z Check if a location is controlled by the vcs. It is meant to be overridden to implement smarter detection mechanisms for specific vcs. zChecking in %s for %s (%s)...)r,r/r$r*rBrCr|r{)r0r4rCrrrr3Ns z VersionControl.controls_location)r.r:r;r*r$rrrJrOrQr`rergrjrlrnrorprrr rcrdr classmethodr3rr)rrr=as2            U  r=c Cs{tj|}|ray|j||SWn2tk r`tjd||j|jSYnXtjd||jS)NzPcannot determine version of editable source in %s (%s command not found in path)ztcannot determine version of editable source in %s (is not SVN checkout, Git clone, Mercurial clone or Bazaar branch))r r9r rr,r-r*as_requirement)rr4version_controlrrrr [s    )__doc__ __future__rrloggingrBrrZpip._vendor.six.moves.urllibrrpip.exceptionsr pip.utilsrrrrr __all__ getLoggerr.r,objectr r r=r rrrrs     ( G