Shaman: Make checkout location available to the Packer
This commit is contained in:
parent
14417b2d73
commit
6104bd6078
@ -403,9 +403,11 @@ class Packer:
|
|||||||
log.info('Would copy %d files to %s', self._file_count, self.target)
|
log.info('Would copy %d files to %s', self._file_count, self.target)
|
||||||
return
|
return
|
||||||
self._file_transferer.done_and_join()
|
self._file_transferer.done_and_join()
|
||||||
|
self._on_file_transfer_finished(file_transfer_completed=True)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
log.info('File transfer interrupted with Ctrl+C, aborting.')
|
log.info('File transfer interrupted with Ctrl+C, aborting.')
|
||||||
self._file_transferer.abort_and_join()
|
self._file_transferer.abort_and_join()
|
||||||
|
self._on_file_transfer_finished(file_transfer_completed=False)
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
self._tscb.flush()
|
self._tscb.flush()
|
||||||
@ -416,6 +418,13 @@ class Packer:
|
|||||||
# self.abort().
|
# self.abort().
|
||||||
self._file_transferer = None
|
self._file_transferer = None
|
||||||
|
|
||||||
|
def _on_file_transfer_finished(self, *, file_transfer_completed: bool) -> None:
|
||||||
|
"""Called when the file transfer is finished.
|
||||||
|
|
||||||
|
This can be used in subclasses to perform cleanup on the file transferer,
|
||||||
|
or to obtain information from it before we destroy it.
|
||||||
|
"""
|
||||||
|
|
||||||
def _rewrite_paths(self) -> None:
|
def _rewrite_paths(self) -> None:
|
||||||
"""Rewrite paths to the new location of the assets.
|
"""Rewrite paths to the new location of the assets.
|
||||||
|
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import requests
|
|||||||
|
|
||||||
import blender_asset_tracer.pack as bat_pack
|
import blender_asset_tracer.pack as bat_pack
|
||||||
import blender_asset_tracer.pack.transfer as bat_transfer
|
import blender_asset_tracer.pack.transfer as bat_transfer
|
||||||
|
from blender_asset_tracer.pack.shaman.transfer import ShamanTransferrer
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -42,11 +43,13 @@ class ShamanPacker(bat_pack.Packer):
|
|||||||
**kwargs) -> None:
|
**kwargs) -> None:
|
||||||
"""Constructor
|
"""Constructor
|
||||||
|
|
||||||
|
:param target: mock target '/' to construct project-relative paths.
|
||||||
:param endpoint: URL of the Shaman endpoint.
|
:param endpoint: URL of the Shaman endpoint.
|
||||||
"""
|
"""
|
||||||
super().__init__(bfile, project, target, **kwargs)
|
super().__init__(bfile, project, target, **kwargs)
|
||||||
self.checkout_id = checkout_id
|
self.checkout_id = checkout_id
|
||||||
self.shaman_endpoint = endpoint
|
self.shaman_endpoint = endpoint
|
||||||
|
self._checkout_location = ''
|
||||||
|
|
||||||
def _get_auth_token(self) -> str:
|
def _get_auth_token(self) -> str:
|
||||||
# TODO: get a token from the Flamenco Server.
|
# TODO: get a token from the Flamenco Server.
|
||||||
@ -55,13 +58,30 @@ class ShamanPacker(bat_pack.Packer):
|
|||||||
return resp.text
|
return resp.text
|
||||||
|
|
||||||
def _create_file_transferer(self) -> bat_transfer.FileTransferer:
|
def _create_file_transferer(self) -> bat_transfer.FileTransferer:
|
||||||
from . import transfer
|
|
||||||
|
|
||||||
# TODO: pass self._get_auth_token itself, so that the Transferer will be able to
|
# TODO: pass self._get_auth_token itself, so that the Transferer will be able to
|
||||||
# decide when to get this token (and how many times).
|
# decide when to get this token (and how many times).
|
||||||
auth_token = self._get_auth_token()
|
auth_token = self._get_auth_token()
|
||||||
return transfer.ShamanTransferrer(auth_token, self.project, self.shaman_endpoint,
|
return ShamanTransferrer(auth_token, self.project, self.shaman_endpoint, self.checkout_id)
|
||||||
self.checkout_id)
|
|
||||||
|
|
||||||
def _make_target_path(self, target: str) -> pathlib.PurePath:
|
def _make_target_path(self, target: str) -> pathlib.PurePath:
|
||||||
return pathlib.PurePosixPath('/')
|
return pathlib.PurePosixPath('/')
|
||||||
|
|
||||||
|
def _on_file_transfer_finished(self, *, file_transfer_completed: bool):
|
||||||
|
super()._on_file_transfer_finished(file_transfer_completed=file_transfer_completed)
|
||||||
|
|
||||||
|
assert isinstance(self._file_transferer, ShamanTransferrer)
|
||||||
|
self._checkout_location = self._file_transferer.checkout_location
|
||||||
|
|
||||||
|
@property
|
||||||
|
def checkout_location(self) -> str:
|
||||||
|
"""Return the checkout location of the packed blend file."""
|
||||||
|
return self._checkout_location
|
||||||
|
|
||||||
|
@property
|
||||||
|
def output_path(self) -> pathlib.PurePath:
|
||||||
|
"""The path of the packed blend file in the target directory."""
|
||||||
|
assert self._output_path is not None
|
||||||
|
|
||||||
|
checkout_location = pathlib.PurePosixPath(self._checkout_location)
|
||||||
|
rel_output = self._output_path.relative_to(self._target_path)
|
||||||
|
return checkout_location / rel_output
|
||||||
|
|||||||
52
tests/test_pack_shaman.py
Normal file
52
tests/test_pack_shaman.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
# ***** END GPL LICENCE BLOCK *****
|
||||||
|
#
|
||||||
|
# (c) 2019, Blender Foundation - Sybren A. Stüvel
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
import responses
|
||||||
|
|
||||||
|
from test_pack import AbstractPackTest
|
||||||
|
from blender_asset_tracer.pack import shaman
|
||||||
|
|
||||||
|
httpmock = responses.RequestsMock()
|
||||||
|
|
||||||
|
|
||||||
|
class ShamanPackTest(AbstractPackTest):
|
||||||
|
@httpmock.activate
|
||||||
|
def test_all_files_already_uploaded(self):
|
||||||
|
infile = self.blendfiles / 'basic_file_ñønæščii.blend'
|
||||||
|
|
||||||
|
packer = shaman.ShamanPacker(infile, infile.parent, '/',
|
||||||
|
endpoint='http://shaman.local',
|
||||||
|
checkout_id='DA-JOBBY-ID')
|
||||||
|
|
||||||
|
# Temporary hack
|
||||||
|
httpmock.add('GET', 'http://shaman.local/get-token', body='AUTH-TOKEN')
|
||||||
|
|
||||||
|
# Just fake that everything is already available on the server.
|
||||||
|
httpmock.add('POST', 'http://shaman.local/checkout/requirements', body='')
|
||||||
|
httpmock.add('POST', 'http://shaman.local/checkout/create/DA-JOBBY-ID',
|
||||||
|
body='DA/-JOBBY-ID')
|
||||||
|
|
||||||
|
with packer:
|
||||||
|
packer.strategise()
|
||||||
|
packer.execute()
|
||||||
|
|
||||||
|
self.assertEqual(pathlib.PurePosixPath('DA/-JOBBY-ID/basic_file_ñønæščii.blend'),
|
||||||
|
packer.output_path)
|
||||||
@ -1,3 +1,22 @@
|
|||||||
|
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software Foundation,
|
||||||
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
#
|
||||||
|
# ***** END GPL LICENCE BLOCK *****
|
||||||
|
#
|
||||||
|
# (c) 2019, Blender Foundation - Sybren A. Stüvel
|
||||||
import zipfile
|
import zipfile
|
||||||
from test_pack import AbstractPackTest
|
from test_pack import AbstractPackTest
|
||||||
|
|
||||||
|
|||||||
@ -17,9 +17,7 @@
|
|||||||
# ***** END GPL LICENCE BLOCK *****
|
# ***** END GPL LICENCE BLOCK *****
|
||||||
#
|
#
|
||||||
# (c) 2019, Blender Foundation - Sybren A. Stüvel
|
# (c) 2019, Blender Foundation - Sybren A. Stüvel
|
||||||
import json
|
|
||||||
import pathlib
|
import pathlib
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
import responses
|
import responses
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user