You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bazaar.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from __future__ import absolute_import
  2. import logging
  3. import os
  4. from pip._vendor.six.moves.urllib import parse as urllib_parse
  5. from pip._internal.download import path_to_url
  6. from pip._internal.utils.misc import (
  7. display_path, make_vcs_requirement_url, rmtree,
  8. )
  9. from pip._internal.utils.temp_dir import TempDirectory
  10. from pip._internal.vcs import VersionControl, vcs
  11. logger = logging.getLogger(__name__)
  12. class Bazaar(VersionControl):
  13. name = 'bzr'
  14. dirname = '.bzr'
  15. repo_name = 'branch'
  16. schemes = (
  17. 'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp',
  18. 'bzr+lp',
  19. )
  20. def __init__(self, url=None, *args, **kwargs):
  21. super(Bazaar, self).__init__(url, *args, **kwargs)
  22. # This is only needed for python <2.7.5
  23. # Register lp but do not expose as a scheme to support bzr+lp.
  24. if getattr(urllib_parse, 'uses_fragment', None):
  25. urllib_parse.uses_fragment.extend(['lp'])
  26. def get_base_rev_args(self, rev):
  27. return ['-r', rev]
  28. def export(self, location):
  29. """
  30. Export the Bazaar repository at the url to the destination location
  31. """
  32. # Remove the location to make sure Bazaar can export it correctly
  33. if os.path.exists(location):
  34. rmtree(location)
  35. with TempDirectory(kind="export") as temp_dir:
  36. self.unpack(temp_dir.path)
  37. self.run_command(
  38. ['export', location],
  39. cwd=temp_dir.path, show_stdout=False,
  40. )
  41. def fetch_new(self, dest, url, rev_options):
  42. rev_display = rev_options.to_display()
  43. logger.info(
  44. 'Checking out %s%s to %s',
  45. url,
  46. rev_display,
  47. display_path(dest),
  48. )
  49. cmd_args = ['branch', '-q'] + rev_options.to_args() + [url, dest]
  50. self.run_command(cmd_args)
  51. def switch(self, dest, url, rev_options):
  52. self.run_command(['switch', url], cwd=dest)
  53. def update(self, dest, url, rev_options):
  54. cmd_args = ['pull', '-q'] + rev_options.to_args()
  55. self.run_command(cmd_args, cwd=dest)
  56. def get_url_rev_and_auth(self, url):
  57. # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
  58. url, rev, user_pass = super(Bazaar, self).get_url_rev_and_auth(url)
  59. if url.startswith('ssh://'):
  60. url = 'bzr+' + url
  61. return url, rev, user_pass
  62. @classmethod
  63. def get_remote_url(cls, location):
  64. urls = cls.run_command(['info'], show_stdout=False, cwd=location)
  65. for line in urls.splitlines():
  66. line = line.strip()
  67. for x in ('checkout of branch: ',
  68. 'parent branch: '):
  69. if line.startswith(x):
  70. repo = line.split(x)[1]
  71. if cls._is_local_repository(repo):
  72. return path_to_url(repo)
  73. return repo
  74. return None
  75. @classmethod
  76. def get_revision(cls, location):
  77. revision = cls.run_command(
  78. ['revno'], show_stdout=False, cwd=location,
  79. )
  80. return revision.splitlines()[-1]
  81. @classmethod
  82. def get_src_requirement(cls, location, project_name):
  83. repo = cls.get_remote_url(location)
  84. if not repo:
  85. return None
  86. if not repo.lower().startswith('bzr:'):
  87. repo = 'bzr+' + repo
  88. current_rev = cls.get_revision(location)
  89. return make_vcs_requirement_url(repo, current_rev, project_name)
  90. def is_commit_id_equal(self, dest, name):
  91. """Always assume the versions don't match"""
  92. return False
  93. vcs.register(Bazaar)