î œ0{Y¼ã@sÃddlZddlZddlZddlZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZddlmZGdd „d e ƒZe jeƒdS) éN)Úcall_subprocess)Ú display_pathÚrmtree)Úlogger)ÚvcsÚVersionControl)Ú path_to_url)Ú ConfigParserc@s¸eZdZdZdZdZd!ZdZd Zd d „Z d d „Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd S)"Ú MercurialÚhgz.hgÚcloneúhg+httpúhg+httpsúhg+sshúhg+static-httpz hg-clone.txtzg# This was a Mercurial repo; to make it a repo again run: hg init hg pull %(url)s hg update -r %(rev)s cCsÃd}}x²|jƒD]¤}|jƒ s|jƒjdƒrEqntjd|ƒ}|ru|jdƒjƒ}ntjd|ƒ}|r¥|jdƒjƒ}n|r|r||fSqWdS)Nú#zhg\s*pull\s*(.*)\s*éz^hg\s*update\s*-r\s*(.*)\s*)NN)Ú splitlinesÚstripÚ startswithÚreÚsearchÚgroup)ÚselfÚcontentÚurlÚrevÚlineÚ url_matchÚ rev_match©r ú,/tmp/pip-ok8sy_ze-build/pip/vcs/mercurial.pyÚparse_vcs_bundle_files " zMercurial.parse_vcs_bundle_filecCs`tjddƒ}|j|ƒz/t|jd|gd|jddd|ƒWdt|ƒXdS) z?Export the Hg repository at the url to the destination locationz-exportzpip-ÚarchiveÚ filter_stdoutÚ show_stdoutFÚcwdN)ÚtempfileÚmkdtempÚunpackrÚcmdÚ_filterr)rÚlocationÚtemp_dirr r r!Úexport%s zMercurial.exportc CsÚtjj||jdƒ}tjƒ}yJ|j|ƒ|jdd|ƒt|dƒ}|j |ƒ|j ƒWnBt tj fk rµt jƒd}tjd||fƒYn!Xt|jddg|d |ƒdS) NÚhgrcÚpathsÚdefaultÚwrz/Could not switch Mercurial repository to %s: %sÚupdatez-qr&)ÚosÚpathÚjoinÚdirnamer ÚSafeConfigParserÚreadÚsetÚopenÚwriteÚcloseÚOSErrorÚNoSectionErrorÚsysÚexc_inforÚwarnrr*)rÚdestrÚ rev_optionsÚ repo_configÚconfigÚ config_fileÚer r r!Úswitch0s   zMercurial.switchcCs@t|jddgd|ƒt|jddg|d|ƒdS)NÚpullz-qr&r3)rr*)rrCrDr r r!r3AszMercurial.updatecCs¸|jƒ\}}|r.|g}d|}n g}d}|j||||ƒr´tjd||t|ƒfƒt|jddd||gƒt|jddg|d|ƒndS) Nz (to revision %s)ÚzCloning hg %s%s to %sr z --noupdatez-qr3r&)Ú get_url_revÚcheck_destinationrÚnotifyrrr*)rrCrrrDÚ rev_displayr r r!ÚobtainFs   zMercurial.obtaincCsRt|jddgddd|ƒjƒ}|j|ƒrHt|ƒ}n|jƒS)NÚ showconfigz paths.defaultr%Fr&)rr*rÚ_is_local_repositoryr)rr,rr r r!Úget_urlTs zMercurial.get_urlcCs¯t|jdgddd|ƒ}g}x{|jƒD]m}tjd|ƒ}|r4|jdƒ}|jdƒ}d|kr¡|j|jƒ|jƒfƒq¡q4q4Wt|ƒS) NÚtagsr%Fr&z([\w\d\.-]+)\s*([\d]+):.*$réÚtip) rr*rrrrÚappendrÚdict)rr,rTÚtag_revsrÚ tags_matchÚtagrr r r!Ú get_tag_revs\s )zMercurial.get_tag_revscCs¯t|jdgddd|ƒ}g}x{|jƒD]m}tjd|ƒ}|r4|jdƒ}|jdƒ}d|kr¡|j|jƒ|jƒfƒq¡q4q4Wt|ƒS) NÚbranchesr%Fr&z([\w\d\.-]+)\s*([\d]+):.*$rrUr1) rr*rrrrrWrrX)rr,r]Ú branch_revsrÚbranches_matchÚbranchrr r r!Úget_branch_revsis )zMercurial.get_branch_revscCs.t|jddgddd|ƒjƒ}|S)NÚparentsz--template={rev}r%Fr&)rr*r)rr,Úcurrent_revisionr r r!Ú get_revisionvszMercurial.get_revisioncCs.t|jddgddd|ƒjƒ}|S)Nrbz--template={node}r%Fr&)rr*r)rr,Úcurrent_rev_hashr r r!Úget_revision_hash|szMercurial.get_revision_hashc Csô|j|ƒ}|jƒjdƒs1d|}n|jƒjddƒd}|sWdS|j|ƒ}|j|ƒ}|j|ƒ}|j|ƒ} ||kr¶d|||f} n-|| krÙd|| |f} n d|} d||| fS) Nzhg:zhg+ú-rrz%s-%sz%s-devz %s@%s#egg=%s) rSÚlowerrÚegg_nameÚsplitrdrfr\ra) rÚdistr,Ú find_tagsÚrepoÚegg_project_nameÚ current_revrerYr^Ú full_egg_namer r r!Úget_src_requirement‚s     zMercurial.get_src_requirementN)zhgr rrr)Ú__name__Ú __module__Ú __qualname__Únamer7Ú repo_nameÚschemesÚ bundle_fileÚguider"r.rIr3rPrSr\rardrfrqr r r r!r s"        r )r4r'rr@Úpip.utilrrrÚpip.logrÚpip.vcsrrÚ pip.downloadrZpip.backwardcompatr r Úregisterr r r r!Ús    Š