<s> import os <EOL> import tempfile <EOL> import re <EOL> from pip import call_subprocess <EOL> from pip . log import logger <EOL> from pip . util import rmtree , display_path <EOL> from pip . vcs import vcs , VersionControl <EOL> from pip . download import path_to_url2 <EOL> class Bazaar ( VersionControl ) : <EOL> name = '<STR_LIT>' <EOL> dirname = '<STR_LIT>' <EOL> repo_name = '<STR_LIT>' <EOL> bundle_file = '<STR_LIT>' <EOL> schemes = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> guide = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def parse_vcs_bundle_file ( self , content ) : <EOL> url = rev = None <EOL> for line in content . splitlines ( ) : <EOL> if not line . strip ( ) or line . strip ( ) . startswith ( '<STR_LIT:#>' ) : <EOL> continue <EOL> match = re . search ( r'<STR_LIT>' , line ) <EOL> if match : <EOL> rev = match . group ( <NUM_LIT:1> ) . strip ( ) <EOL> url = line [ match . end ( ) : ] . strip ( ) . split ( None , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if url and rev : <EOL> return url , rev <EOL> return None , None <EOL> def export ( self , location ) : <EOL> """<STR_LIT>""" <EOL> temp_dir = tempfile . mkdtemp ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . unpack ( temp_dir ) <EOL> if os . path . exists ( location ) : <EOL> rmtree ( location ) <EOL> try : <EOL> call_subprocess ( [ self . cmd , '<STR_LIT>' , location ] , cwd = temp_dir , <EOL> filter_stdout = self . _filter , show_stdout = False ) <EOL> finally : <EOL> rmtree ( temp_dir ) <EOL> def switch ( self , dest , url , rev_options ) : <EOL> call_subprocess ( [ self . cmd , '<STR_LIT>' , url ] , cwd = dest ) <EOL> def update ( self , dest , rev_options ) : <EOL> call_subprocess ( <EOL> [ self . cmd , '<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 = [ '<STR_LIT>' , 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 . notify ( '<STR_LIT>' <EOL> % ( url , rev_display , display_path ( dest ) ) ) <EOL> call_subprocess ( <EOL> [ self . cmd , '<STR_LIT>' , '<STR_LIT>' ] + rev_options + [ url , dest ] ) <EOL> def get_url_rev ( self ) : <EOL> url , rev = super ( Bazaar , self ) . get_url_rev ( ) <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> url = '<STR_LIT>' + url <EOL> return url , rev <EOL> def get_url ( self , location ) : <EOL> urls = call_subprocess ( <EOL> [ self . cmd , '<STR_LIT:info>' ] , show_stdout = False , cwd = location ) <EOL> for line in urls . splitlines ( ) : <EOL> line = line . strip ( ) <EOL> for x in ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> if line . startswith ( x ) : <EOL> repo = line . split ( x ) [ <NUM_LIT:1> ] <EOL> if self . _is_local_repository ( repo ) : <EOL> return path_to_url2 ( repo ) <EOL> return repo <EOL> return None <EOL> def get_revision ( self , location ) : <EOL> revision = call_subprocess ( <EOL> [ self . cmd , '<STR_LIT>' ] , show_stdout = False , cwd = location ) <EOL> return revision . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> def get_tag_revs ( self , location ) : <EOL> tags = call_subprocess ( <EOL> [ self . cmd , '<STR_LIT>' ] , show_stdout = False , cwd = location ) <EOL> tag_revs = [ ] <EOL> for line in tags . splitlines ( ) : <EOL> tags_match = re . search ( r'<STR_LIT>' , line ) <EOL> if tags_match : <EOL> tag = tags_match . group ( <NUM_LIT:1> ) <EOL> rev = tags_match . group ( <NUM_LIT:2> ) <EOL> tag_revs . append ( ( rev . strip ( ) , tag . strip ( ) ) ) <EOL> return dict ( tag_revs ) <EOL> def get_src_requirement ( self , dist , location , find_tags ) : <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 = self . get_revision ( location ) <EOL> tag_revs = self . get_tag_revs ( location ) <EOL> if current_rev in tag_revs : <EOL> full_egg_name = '<STR_LIT>' % ( egg_project_name , tag_revs [ current_rev ] ) <EOL> else : <EOL> full_egg_name = '<STR_LIT>' % ( dist . egg_name ( ) , current_rev ) <EOL> return '<STR_LIT>' % ( repo , current_rev , full_egg_name ) <EOL> vcs . register ( Bazaar ) </s>
