Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion annexremote/annexremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ class ExportRemote(SpecialRemote):
Note that the user is not required to provided all the settings listed here.
"""

def __init__(self, annex, force_version1=False):
self.force_version1 = force_version1
super().__init__(annex)

def exportsupported(self):
return True

Expand Down Expand Up @@ -545,10 +549,16 @@ class Protocol(object):

def __init__(self, remote):
self.remote = remote
self.version = "VERSION 1"
self.exporting = False
self.extensions = list()

@property
def version(self):
if self.remote.exportsupported() and not self.remote.force_version1:
return "VERSION 2"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't sending VERSION 2 depend on git-annex version? since if it is annex older than the one added support for VERSION 2, it would puke (or not)?

Copy link
Copy Markdown
Owner Author

@Lykos153 Lykos153 Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. Now that I'm looking into it again I think we should just scrap the last two commits. VERSION 2 basically only exists so a special remote can ensure that git-annex is new enough to not have the bug. But 78c280d already handles the bug,

else:
return "VERSION 1"

def command(self, line):
line = line.strip()
parts = line.split(" ", 1)
Expand Down Expand Up @@ -734,6 +744,8 @@ def do_EXPORTSUPPORTED(self):
return "EXPORTSUPPORTED-FAILURE"

def do_EXPORT(self, name):
if self.exporting:
raise UnexpectedMessage("Unexpected EXPORT")
self.exporting = name

def do_TRANSFEREXPORT(self, param):
Expand Down
1 change: 0 additions & 1 deletion examples/git-annex-remote-directory
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class DirectoryRemote(ExportRemote):


def main():

# Redirect output to stderr to avoid messing up the protocol
output = sys.stdout
sys.stdout = sys.stderr
Expand Down
11 changes: 8 additions & 3 deletions tests/test_GitAnnexRequestMessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
UnsupportedReqeust = utils.annexremote.UnsupportedRequest


class TestGitAnnexRequestMessages(utils.GitAnnexTestCase):
class TestGitAnnexRequestMessages(utils.ExportTestCase):
def test_InitremoteSuccess(self):
self.annex.Listen(io.StringIO("INITREMOTE"))
self.remote.initremote.call_count == 1
Expand Down Expand Up @@ -363,7 +363,7 @@ def test_Error(self):
self.remote.error.assert_called_once_with("ErrorMsg")


class TestGitAnnexRequestMessagesExporttree(utils.GitAnnexTestCase):
class TestGitAnnexRequestMessagesExporttree(utils.ExportTestCase):
def test_ExportsupportedSuccess(self):
self.annex.Listen(io.StringIO("EXPORTSUPPORTED"))
self.remote.exportsupported.call_count == 1
Expand All @@ -387,6 +387,11 @@ def test_Export_MissingName(self):
r"ERROR (Protocol\.|)do_EXPORT\(\) missing 1 required positional argument: 'name'",
)

def test_Export_DoubleExport(self):
with self.assertRaises(SystemExit):
self.annex.Listen(io.StringIO("EXPORT Name1\nEXPORT Name2"))
self.assertEqual(utils.last_buffer_line(self.output), "ERROR Unexpected EXPORT")

def test_Export_SpaceInName(self):
# testing this only with TRANSFEREXPORT
self.annex.Listen(
Expand Down Expand Up @@ -675,7 +680,7 @@ def prepare(self):
self.logger.warning("test\nthis is a new line")


class TestLogging(utils.GitAnnexTestCase):
class TestLogging(utils.ExportTestCase):
def setUp(self):
super().setUp()
self.remote = LoggingRemote(self.annex)
Expand Down
10 changes: 8 additions & 2 deletions tests/test_SpecialRemoteMessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
ProtocolError = utils.annexremote.ProtocolError


class TestSpecialRemoteMessages(utils.GitAnnexTestCase):
class TestProtocolVersion2(utils.ExportTestCase):
def TestVersion(self):
self.annex.Listen(self.input)
self.assertEqual(self.output.getvalue(), "VERSION 2\n")


class TestSpecialRemoteMessages(utils.FullTestCase):
"""
* Each protocol line starts with a command, which is followed by the command's parameters
(a fixed number per command), each separated by a single space.
Expand Down Expand Up @@ -451,7 +457,7 @@ def test_Error(self):
self._perform_test(function_to_call, function_parameters, expected_output)


class TestSpecialRemoteMessages_Extensions(utils.GitAnnexTestCase):
class TestSpecialRemoteMessages_Extensions(utils.FullTestCase):
def _perform_test(
self,
function_to_call,
Expand Down
61 changes: 56 additions & 5 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,41 @@
import annexremote


class GitAnnexTestCase(unittest.TestCase):
class MinimalTestCase(unittest.TestCase):
def setUp(self):
super().setUp()

self.output = io.StringIO()
self.input = io.StringIO()

self.annex = annexremote.Master(self.output)
self.remote = mock.MagicMock(wraps=DummyRemote(self.annex))
self.remote = MinimalRemote(self.annex)

self.annex.LinkRemote(self.remote)


class MinimalTestCase(unittest.TestCase):
class FullTestCase(unittest.TestCase):
def setUp(self):
super().setUp()

self.output = io.StringIO()
self.input = io.StringIO()

self.annex = annexremote.Master(self.output)
self.remote = MinimalRemote(self.annex)
self.remote = mock.MagicMock(wraps=FullRemote(self.annex))

self.annex.LinkRemote(self.remote)


class ExportTestCase(unittest.TestCase):
def setUp(self):
super().setUp()

self.output = io.StringIO()
self.input = io.StringIO()

self.annex = annexremote.Master(self.output)
self.remote = mock.MagicMock(wraps=FullExportRemote(self.annex))

self.annex.LinkRemote(self.remote)

Expand Down Expand Up @@ -77,7 +90,45 @@ def remove(self, key):
pass


class DummyRemote(annexremote.ExportRemote):
class FullRemote(annexremote.SpecialRemote):
def initremote(self):
pass

def prepare(self):
pass

def transfer_store(self, key, file_):
pass

def transfer_retrieve(self, key, file_):
pass

def checkpresent(self, key):
pass

def remove(self, key):
pass

def getcost(self):
pass

def getavailability(self):
pass

def claimurl(self, url):
pass

def checkurl(self, url):
pass

def whereis(self, whereis):
pass

def error(self, msg):
pass


class FullExportRemote(annexremote.ExportRemote):
def initremote(self):
pass

Expand Down