2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import logging
|
2009-11-20 22:03:40 +01:00
|
|
|
import os
|
|
|
|
import re
|
2014-08-01 22:20:23 +02:00
|
|
|
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils.logging import indent_log
|
2018-07-25 18:56:22 +02:00
|
|
|
from pip._internal.utils.misc import (
|
2019-01-13 08:39:35 +01:00
|
|
|
display_path, rmtree, split_auth_from_netloc,
|
2018-07-25 18:56:22 +02:00
|
|
|
)
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.vcs import VersionControl, vcs
|
2009-11-20 22:03:40 +01:00
|
|
|
|
|
|
|
_svn_xml_url_re = re.compile('url="([^"]+)"')
|
2017-02-23 15:02:24 +01:00
|
|
|
_svn_rev_re = re.compile(r'committed-rev="(\d+)"')
|
2012-01-18 17:26:38 +01:00
|
|
|
_svn_info_xml_rev_re = re.compile(r'\s*revision="(\d+)"')
|
|
|
|
_svn_info_xml_url_re = re.compile(r'<url>(.*)</url>')
|
2010-06-03 04:25:26 +02:00
|
|
|
|
2012-01-30 07:26:12 +01:00
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
class Subversion(VersionControl):
|
|
|
|
name = 'svn'
|
|
|
|
dirname = '.svn'
|
|
|
|
repo_name = 'checkout'
|
2011-04-15 16:27:04 +02:00
|
|
|
schemes = ('svn', 'svn+ssh', 'svn+http', 'svn+https', 'svn+svn')
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2019-01-13 08:39:35 +01:00
|
|
|
@classmethod
|
|
|
|
def should_add_vcs_url_prefix(cls, remote_url):
|
|
|
|
return True
|
|
|
|
|
2017-10-02 00:21:11 +02:00
|
|
|
def get_base_rev_args(self, rev):
|
|
|
|
return ['-r', rev]
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
def export(self, location):
|
|
|
|
"""Export the svn repository at the url to the destination location"""
|
2018-07-11 09:51:38 +02:00
|
|
|
url, rev_options = self.get_url_rev_options(self.url)
|
2018-07-08 13:21:00 +02:00
|
|
|
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.info('Exporting svn repository %s to %s', url, location)
|
|
|
|
with indent_log():
|
2009-11-20 22:03:40 +01:00
|
|
|
if os.path.exists(location):
|
2014-01-27 15:07:10 +01:00
|
|
|
# Subversion doesn't like to check out over an existing
|
|
|
|
# directory --force fixes this, but was only added in svn 1.5
|
2009-11-20 22:03:40 +01:00
|
|
|
rmtree(location)
|
2017-10-02 00:21:11 +02:00
|
|
|
cmd_args = ['export'] + rev_options.to_args() + [url, location]
|
|
|
|
self.run_command(cmd_args, show_stdout=False)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2018-07-08 05:47:16 +02:00
|
|
|
def fetch_new(self, dest, url, rev_options):
|
|
|
|
rev_display = rev_options.to_display()
|
|
|
|
logger.info(
|
|
|
|
'Checking out %s%s to %s',
|
|
|
|
url,
|
|
|
|
rev_display,
|
|
|
|
display_path(dest),
|
|
|
|
)
|
|
|
|
cmd_args = ['checkout', '-q'] + rev_options.to_args() + [url, dest]
|
|
|
|
self.run_command(cmd_args)
|
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
def switch(self, dest, url, rev_options):
|
2017-10-02 00:21:11 +02:00
|
|
|
cmd_args = ['switch'] + rev_options.to_args() + [url, dest]
|
|
|
|
self.run_command(cmd_args)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2018-07-17 18:36:48 +02:00
|
|
|
def update(self, dest, url, rev_options):
|
2017-10-02 00:21:11 +02:00
|
|
|
cmd_args = ['update'] + rev_options.to_args() + [dest]
|
|
|
|
self.run_command(cmd_args)
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2019-01-07 01:35:56 +01:00
|
|
|
@classmethod
|
|
|
|
def get_revision(cls, location):
|
2009-11-20 22:03:40 +01:00
|
|
|
"""
|
|
|
|
Return the maximum revision for all files under a given location
|
|
|
|
"""
|
|
|
|
# Note: taken from setuptools.command.egg_info
|
|
|
|
revision = 0
|
|
|
|
|
|
|
|
for base, dirs, files in os.walk(location):
|
2019-01-07 01:35:56 +01:00
|
|
|
if cls.dirname not in dirs:
|
2009-11-20 22:03:40 +01:00
|
|
|
dirs[:] = []
|
|
|
|
continue # no sense walking uncontrolled subdirs
|
2019-01-07 01:35:56 +01:00
|
|
|
dirs.remove(cls.dirname)
|
|
|
|
entries_fn = os.path.join(base, cls.dirname, 'entries')
|
2009-11-20 22:03:40 +01:00
|
|
|
if not os.path.exists(entries_fn):
|
2014-03-26 23:24:19 +01:00
|
|
|
# FIXME: should we warn?
|
2009-11-20 22:03:40 +01:00
|
|
|
continue
|
2012-01-18 17:26:38 +01:00
|
|
|
|
2019-01-07 01:35:56 +01:00
|
|
|
dirurl, localrev = cls._get_svn_url_rev(base)
|
2012-01-18 17:26:38 +01:00
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
if base == location:
|
2017-12-17 15:42:39 +01:00
|
|
|
base = dirurl + '/' # save the root url
|
|
|
|
elif not dirurl or not dirurl.startswith(base):
|
2009-11-20 22:03:40 +01:00
|
|
|
dirs[:] = []
|
|
|
|
continue # not part of the same svn tree, skip it
|
|
|
|
revision = max(revision, localrev)
|
|
|
|
return revision
|
|
|
|
|
2019-03-16 09:04:44 +01:00
|
|
|
@classmethod
|
|
|
|
def get_netloc_and_auth(cls, netloc, scheme):
|
2018-07-15 19:39:06 +02:00
|
|
|
"""
|
2018-07-25 18:56:22 +02:00
|
|
|
This override allows the auth information to be passed to svn via the
|
|
|
|
--username and --password options instead of via the URL.
|
2018-07-15 19:39:06 +02:00
|
|
|
"""
|
2018-07-28 22:47:20 +02:00
|
|
|
if scheme == 'ssh':
|
|
|
|
# The --username and --password options can't be used for
|
|
|
|
# svn+ssh URLs, so keep the auth information in the URL.
|
2019-03-16 09:04:44 +01:00
|
|
|
return super(Subversion, cls).get_netloc_and_auth(netloc, scheme)
|
2018-07-28 22:47:20 +02:00
|
|
|
|
2018-07-25 18:56:22 +02:00
|
|
|
return split_auth_from_netloc(netloc)
|
2018-07-15 19:39:06 +02:00
|
|
|
|
2018-07-19 18:13:05 +02:00
|
|
|
def get_url_rev_and_auth(self, url):
|
2010-03-11 02:41:08 +01:00
|
|
|
# hotfix the URL scheme after removing svn+ from svn+ssh:// readd it
|
2018-07-19 18:13:05 +02:00
|
|
|
url, rev, user_pass = super(Subversion, self).get_url_rev_and_auth(url)
|
2010-03-11 02:41:08 +01:00
|
|
|
if url.startswith('ssh://'):
|
|
|
|
url = 'svn+' + url
|
2018-07-19 18:13:05 +02:00
|
|
|
return url, rev, user_pass
|
2010-03-11 02:41:08 +01:00
|
|
|
|
2018-07-15 19:39:06 +02:00
|
|
|
def make_rev_args(self, username, password):
|
|
|
|
extra_args = []
|
|
|
|
if username:
|
|
|
|
extra_args += ['--username', username]
|
|
|
|
if password:
|
|
|
|
extra_args += ['--password', password]
|
2018-07-08 13:21:00 +02:00
|
|
|
|
2018-07-15 19:39:06 +02:00
|
|
|
return extra_args
|
2010-03-11 02:41:08 +01:00
|
|
|
|
2019-01-07 01:31:06 +01:00
|
|
|
@classmethod
|
|
|
|
def get_remote_url(cls, location):
|
2014-01-27 15:07:10 +01:00
|
|
|
# In cases where the source is in a subdirectory, not alongside
|
|
|
|
# setup.py we have to look up in the location until we find a real
|
|
|
|
# setup.py
|
2009-11-20 22:03:40 +01:00
|
|
|
orig_location = location
|
|
|
|
while not os.path.exists(os.path.join(location, 'setup.py')):
|
|
|
|
last_location = location
|
|
|
|
location = os.path.dirname(location)
|
|
|
|
if location == last_location:
|
2014-01-27 15:07:10 +01:00
|
|
|
# We've traversed up to the root of the filesystem without
|
|
|
|
# finding setup.py
|
2014-08-31 01:52:28 +02:00
|
|
|
logger.warning(
|
2014-01-27 15:07:10 +01:00
|
|
|
"Could not find setup.py for directory %s (tried all "
|
2014-08-31 01:52:28 +02:00
|
|
|
"parent directories)",
|
|
|
|
orig_location,
|
2014-01-27 15:07:10 +01:00
|
|
|
)
|
2009-11-20 22:03:40 +01:00
|
|
|
return None
|
2012-01-18 17:26:38 +01:00
|
|
|
|
2019-01-07 01:31:06 +01:00
|
|
|
return cls._get_svn_url_rev(location)[0]
|
2012-01-18 17:26:38 +01:00
|
|
|
|
2019-01-07 01:27:27 +01:00
|
|
|
@classmethod
|
|
|
|
def _get_svn_url_rev(cls, location):
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.exceptions import InstallationError
|
2013-07-23 20:06:11 +02:00
|
|
|
|
2019-01-07 01:27:27 +01:00
|
|
|
entries_path = os.path.join(location, cls.dirname, 'entries')
|
2016-01-07 23:22:10 +01:00
|
|
|
if os.path.exists(entries_path):
|
|
|
|
with open(entries_path) as f:
|
|
|
|
data = f.read()
|
|
|
|
else: # subversion >= 1.7 does not have the 'entries' file
|
|
|
|
data = ''
|
|
|
|
|
2015-02-24 13:46:10 +01:00
|
|
|
if (data.startswith('8') or
|
|
|
|
data.startswith('9') or
|
|
|
|
data.startswith('10')):
|
2011-03-15 20:49:48 +01:00
|
|
|
data = list(map(str.splitlines, data.split('\n\x0c\n')))
|
2009-11-20 22:03:40 +01:00
|
|
|
del data[0][0] # get rid of the '8'
|
2012-01-18 17:26:38 +01:00
|
|
|
url = data[0][3]
|
2013-02-16 19:02:41 +01:00
|
|
|
revs = [int(d[9]) for d in data if len(d) > 9 and d[9]] + [0]
|
2009-11-20 22:03:40 +01:00
|
|
|
elif data.startswith('<?xml'):
|
|
|
|
match = _svn_xml_url_re.search(data)
|
|
|
|
if not match:
|
|
|
|
raise ValueError('Badly formatted data: %r' % data)
|
2012-01-18 17:26:38 +01:00
|
|
|
url = match.group(1) # get repository URL
|
2013-02-16 19:02:41 +01:00
|
|
|
revs = [int(m.group(1)) for m in _svn_rev_re.finditer(data)] + [0]
|
2012-01-18 17:26:38 +01:00
|
|
|
else:
|
|
|
|
try:
|
|
|
|
# subversion >= 1.7
|
2019-01-07 01:27:27 +01:00
|
|
|
xml = cls.run_command(
|
2015-03-10 12:28:09 +01:00
|
|
|
['info', '--xml', location],
|
2014-01-27 15:07:10 +01:00
|
|
|
show_stdout=False,
|
|
|
|
)
|
2012-01-18 17:26:38 +01:00
|
|
|
url = _svn_info_xml_url_re.search(xml).group(1)
|
2014-01-27 15:07:10 +01:00
|
|
|
revs = [
|
|
|
|
int(m.group(1)) for m in _svn_info_xml_rev_re.finditer(xml)
|
|
|
|
]
|
2012-01-18 17:26:38 +01:00
|
|
|
except InstallationError:
|
|
|
|
url, revs = None, []
|
|
|
|
|
|
|
|
if revs:
|
|
|
|
rev = max(revs)
|
2009-11-20 22:03:40 +01:00
|
|
|
else:
|
2012-01-18 17:26:38 +01:00
|
|
|
rev = 0
|
|
|
|
|
|
|
|
return url, rev
|
2009-11-20 22:03:40 +01:00
|
|
|
|
2017-10-03 10:21:55 +02:00
|
|
|
def is_commit_id_equal(self, dest, name):
|
2015-08-31 22:52:01 +02:00
|
|
|
"""Always assume the versions don't match"""
|
|
|
|
return False
|
|
|
|
|
2012-01-31 11:56:47 +01:00
|
|
|
|
2009-11-20 22:03:40 +01:00
|
|
|
vcs.register(Subversion)
|