3 ]V0@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 dddZ ddZ ddZddZZS) VcsSupportsshgithgbzrsftpsvncs:tjj|jttddr(tjj|jtt|jdS)N uses_fragment) urllib_parse uses_netlocextendschemesgetattrrsuperr __init__)self) __class__//tmp/pip-build-8jg9gmni/pip/pip/vcs/__init__.pyrs zVcsSupport.__init__cCs |jjS)N) _registry__iter__)rrrrr $szVcsSupport.__iter__cCst|jjS)N)listrvalues)rrrrbackends'szVcsSupport.backendscCsdd|jDS)NcSsg|] }|jqSr)dirname).0backendrrr -sz'VcsSupport.dirnames..)r#)rrrrdirnames+szVcsSupport.dirnamescCs$g}x|jD]}|j|jq W|S)N)r#rr)rrr&rrr all_schemes/s zVcsSupport.all_schemescCsFt|dstjd|jdS|j|jkrB||j|j<tjd|jdS)NnamezCannot register VCS %szRegistered VCS backend: %s)hasattrloggerwarning__name__r*rdebug)rclsrrrregister6s    zVcsSupport.registerNcCs<||jkr|j|=n$||jjkr.|j|j=n tjddS)Nz0Cannot unregister because no class or name given)rr"r*r,r-)rr0r*rrr unregister>s    zVcsSupport.unregistercCs8x2|jjD]$}|j|r tjd||j|jSq WdS)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)NN)r. __module__ __qualname__rrrr propertyr#r(r)r1r2r6r8r9 __classcell__rr)rrr s      r cseZdZdZdZfZd+fdd ZddZddZd d Z d d Z d dZ ddZ ddZ ddZddZddZddZddZddZdd Zd!d"Zd#d$Zd,d'd(Zed)d*ZZS)-VersionControlNcs||_tt|j||dS)N)urlrr>r)rr@argskwargs)rrrrgszVersionControl.__init__cCs"tjj|\}}|jtjjp |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_surnamecCstdS)z Export the repository at the url to the destination location i.e. only download the files, without vcs informations N)NotImplementedError)rr4rrrexportyszVersionControl.exportc Cszd}d|jkst||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@schemenetlocrDqueryfragrevrrr get_url_revszVersionControl.get_url_revcCs4|jdj|j s td||j||j|fS)zA Returns (url, revision), where both are strings rLzBad directory: %s)rstripendswithr$rVget_url get_revision)rr4rrrget_infos zVersionControl.get_infocCstj|jdS)zi Normalize a URL for comparison by unquoting it and removing any trailing slash. rL)runquoterb)rr@rrr normalize_urlszVersionControl.normalize_urlcCs|j||j|kS)zV Compare two repo URLs for identity, ignoring incidental differences. )rh)rurl1url2rrr compare_urlsszVersionControl.compare_urlscCstdS)zx Called when installing or updating an editable package, takes the source path of the checkout. N)rQ)rdestrrrobtainszVersionControl.obtaincCstdS)zB Switch the repo at ``dest`` to point to ``URL``. N)rQ)rrlr@ rev_optionsrrrswitchszVersionControl.switchcCstdS)zO Update an already-existing repo to the given ``rev_options``. N)rQ)rrlrnrrrupdateszVersionControl.updatecCstdS)zp Return True if the version is identical to what exists and doesn't need to be updated. N)rQ)rrlrnrrr check_versionszVersionControl.check_versionc Csd}d}tjj|rd}tjjtjj||jr|j|}|j||rtjd|j j t |||j ||stj dt ||j ||j||qtj dqtjd|j|j t ||d}ntjd ||j|j d}|rtjd|j|td|d|d}|dkr2tj d|j t ||||j|||n~|d kr>nr|d krftjdt |t|d}nJ|d krt|} tjdt || tj|| d}n|dkrtjd|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? %srrTzSwitching %s %s to %s%sz Deleting %szBacking up %s to %sarsrtrurv)rrryrtrurv)rwrz)rCrDexistsjoinr$rdrkr,r/ repo_nametitlerrqinforpr-r*r rorrshutilmovesysexit) rrlr@rn 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)rCrDr|rrm)rr4rrrunpacks zVersionControl.unpackcCstdS)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)rQ)rdistr4rrrr sz"VersionControl.get_src_requirementcCstdS)z_ Return the url used at location Used in get_info or check_destination N)rQ)rr4rrrrd)szVersionControl.get_urlcCstdS)z_ Return the current revision of the files at location Used in get_info N)rQ)rr4rrrre0szVersionControl.get_revisionTraisec Csf|jg|}yt|||||||Stk r`}z$|jtjkrNtd|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_commandcCs0tjd||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*rCrDr}r|)r0r4rDrrrr3Nsz VersionControl.controls_location)N)TNrNNN)r.r:r;r*r$rrrKrPrRrarfrhrkrmrorprqrrr rdrer classmethodr3r=rr)rrr>as2 U   r>c CsZtj|}|rFy|j||Stk rDtjd||j|jSXtjd||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__rrloggingrCrrZpip._vendor.six.moves.urllibrrpip.exceptionsr pip.utilsrrrrr __all__ getLoggerr.r,objectr r r>r rrrrs     G{