<s> from __future__ import absolute_import <EOL> import logging <EOL> import os <EOL> import tempfile <EOL> from pip . utils import display_path , rmtree <EOL> from pip . vcs import vcs , VersionControl <EOL> from pip . download import path_to_url <EOL> from pip . _vendor . six . moves import configparser <EOL> logger = logging . getLogger ( __name__ ) <EOL> class Mercurial ( VersionControl ) : <EOL> name = '<STR_LIT>' <EOL> dirname = '<STR_LIT>' <EOL> repo_name = '<STR_LIT>' <EOL> schemes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def export ( self , location ) : <EOL> """<STR_LIT>""" <EOL> temp_dir = tempfile . mkdtemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . unpack ( temp_dir ) <EOL> try : <EOL> self . run_command ( <EOL> [ '<STR_LIT>' , location ] , show_stdout = False , cwd = temp_dir ) <EOL> finally : <EOL> rmtree ( temp_dir ) <EOL> def switch ( self , dest , url , rev_options ) : <EOL> repo_config = os . path . join ( dest , self . dirname , '<STR_LIT>' ) <EOL> config = configparser . SafeConfigParser ( ) <EOL> try : <EOL> config . read ( repo_config ) <EOL> config . set ( '<STR_LIT>' , '<STR_LIT:default>' , url ) <EOL> with open ( repo_config , '<STR_LIT:w>' ) as config_file : <EOL> config . write ( config_file ) <EOL> except ( OSError , configparser . NoSectionError ) as exc : <EOL> logger . warning ( <EOL> '<STR_LIT>' , url , exc , <EOL> ) <EOL> else : <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] + rev_options , cwd = dest ) <EOL> def update ( self , dest , rev_options ) : <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] , cwd = dest ) <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] + rev_options , cwd = dest ) <EOL> def obtain ( self , dest ) : <EOL> url , rev = self . get_url_rev ( ) <EOL> if rev : <EOL> rev_options = [ rev ] <EOL> rev_display = '<STR_LIT>' % rev <EOL> else : <EOL> rev_options = [ ] <EOL> rev_display = '<STR_LIT>' <EOL> if self . check_destination ( dest , url , rev_options , rev_display ) : <EOL> logger . info ( <EOL> '<STR_LIT>' , <EOL> url , <EOL> rev_display , <EOL> display_path ( dest ) , <EOL> ) <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , url , dest ] ) <EOL> self . run_command ( [ '<STR_LIT>' , '<STR_LIT>' ] + rev_options , cwd = dest ) <EOL> def get_url ( self , location ) : <EOL> url = self . run_command ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> show_stdout = False , cwd = location ) . strip ( ) <EOL> if self . _is_local_repository ( url ) : <EOL> url = path_to_url ( url ) <EOL> return url . strip ( ) <EOL> def get_revision ( self , location ) : <EOL> current_revision = self . run_command ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> show_stdout = False , cwd = location ) . strip ( ) <EOL> return current_revision <EOL> def get_revision_hash ( self , location ) : <EOL> current_rev_hash = self . run_command ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> show_stdout = False , cwd = location ) . strip ( ) <EOL> return current_rev_hash <EOL> def get_src_requirement ( self , dist , location ) : <EOL> repo = self . get_url ( location ) <EOL> if not repo . lower ( ) . startswith ( '<STR_LIT>' ) : <EOL> repo = '<STR_LIT>' + repo <EOL> egg_project_name = dist . egg_name ( ) . split ( '<STR_LIT:->' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if not repo : <EOL> return None <EOL> current_rev_hash = self . get_revision_hash ( location ) <EOL> return '<STR_LIT>' % ( repo , current_rev_hash , egg_project_name ) <EOL> def check_version ( self , dest , rev_options ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> vcs . register ( Mercurial ) </s>
