Reformat with Black
No functional changes.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,6 @@ class BatProgress(progress.Callback):
|
||||
self.loop = asyncio.get_event_loop()
|
||||
|
||||
def _set_attr(self, attr: str, value):
|
||||
|
||||
async def do_it():
|
||||
setattr(bpy.context.window_manager, attr, value)
|
||||
|
||||
@@ -44,48 +43,48 @@ class BatProgress(progress.Callback):
|
||||
|
||||
def _txt(self, msg: str):
|
||||
"""Set a text in a thread-safe way."""
|
||||
self._set_attr('flamenco_status_txt', msg)
|
||||
self._set_attr("flamenco_status_txt", msg)
|
||||
|
||||
def _status(self, status: str):
|
||||
"""Set the flamenco_status property in a thread-safe way."""
|
||||
self._set_attr('flamenco_status', status)
|
||||
self._set_attr("flamenco_status", status)
|
||||
|
||||
def _progress(self, progress: int):
|
||||
"""Set the flamenco_progress property in a thread-safe way."""
|
||||
self._set_attr('flamenco_progress', progress)
|
||||
self._set_attr("flamenco_progress", progress)
|
||||
|
||||
def pack_start(self) -> None:
|
||||
self._txt('Starting BAT Pack operation')
|
||||
self._txt("Starting BAT Pack operation")
|
||||
|
||||
def pack_done(self,
|
||||
output_blendfile: pathlib.Path,
|
||||
missing_files: typing.Set[pathlib.Path]) -> None:
|
||||
def pack_done(
|
||||
self, output_blendfile: pathlib.Path, missing_files: typing.Set[pathlib.Path]
|
||||
) -> None:
|
||||
if missing_files:
|
||||
self._txt('There were %d missing files' % len(missing_files))
|
||||
self._txt("There were %d missing files" % len(missing_files))
|
||||
else:
|
||||
self._txt('Pack of %s done' % output_blendfile.name)
|
||||
self._txt("Pack of %s done" % output_blendfile.name)
|
||||
|
||||
def pack_aborted(self, reason: str):
|
||||
self._txt('Aborted: %s' % reason)
|
||||
self._status('ABORTED')
|
||||
self._txt("Aborted: %s" % reason)
|
||||
self._status("ABORTED")
|
||||
|
||||
def trace_blendfile(self, filename: pathlib.Path) -> None:
|
||||
"""Called for every blendfile opened when tracing dependencies."""
|
||||
self._txt('Inspecting %s' % filename.name)
|
||||
self._txt("Inspecting %s" % filename.name)
|
||||
|
||||
def trace_asset(self, filename: pathlib.Path) -> None:
|
||||
if filename.stem == '.blend':
|
||||
if filename.stem == ".blend":
|
||||
return
|
||||
self._txt('Found asset %s' % filename.name)
|
||||
self._txt("Found asset %s" % filename.name)
|
||||
|
||||
def rewrite_blendfile(self, orig_filename: pathlib.Path) -> None:
|
||||
self._txt('Rewriting %s' % orig_filename.name)
|
||||
self._txt("Rewriting %s" % orig_filename.name)
|
||||
|
||||
def transfer_file(self, src: pathlib.Path, dst: pathlib.Path) -> None:
|
||||
self._txt('Transferring %s' % src.name)
|
||||
self._txt("Transferring %s" % src.name)
|
||||
|
||||
def transfer_file_skipped(self, src: pathlib.Path, dst: pathlib.Path) -> None:
|
||||
self._txt('Skipped %s' % src.name)
|
||||
self._txt("Skipped %s" % src.name)
|
||||
|
||||
def transfer_progress(self, total_bytes: int, transferred_bytes: int) -> None:
|
||||
self._progress(round(100 * transferred_bytes / total_bytes))
|
||||
@@ -98,15 +97,17 @@ class BatProgress(progress.Callback):
|
||||
class ShamanPacker(shaman.ShamanPacker):
|
||||
"""Packer with support for getting an auth token from Flamenco Server."""
|
||||
|
||||
def __init__(self,
|
||||
bfile: pathlib.Path,
|
||||
project: pathlib.Path,
|
||||
target: str,
|
||||
endpoint: str,
|
||||
checkout_id: str,
|
||||
*,
|
||||
manager_id: str,
|
||||
**kwargs) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
bfile: pathlib.Path,
|
||||
project: pathlib.Path,
|
||||
target: str,
|
||||
endpoint: str,
|
||||
checkout_id: str,
|
||||
*,
|
||||
manager_id: str,
|
||||
**kwargs
|
||||
) -> None:
|
||||
self.manager_id = manager_id
|
||||
super().__init__(bfile, project, target, endpoint, checkout_id, **kwargs)
|
||||
|
||||
@@ -116,25 +117,27 @@ class ShamanPacker(shaman.ShamanPacker):
|
||||
from ..blender import PILLAR_SERVER_URL
|
||||
from ..pillar import blender_id_subclient, uncached_session, SUBCLIENT_ID
|
||||
|
||||
url = urllib.parse.urljoin(PILLAR_SERVER_URL,
|
||||
'flamenco/jwt/generate-token/%s' % self.manager_id)
|
||||
auth_token = blender_id_subclient()['token']
|
||||
url = urllib.parse.urljoin(
|
||||
PILLAR_SERVER_URL, "flamenco/jwt/generate-token/%s" % self.manager_id
|
||||
)
|
||||
auth_token = blender_id_subclient()["token"]
|
||||
|
||||
resp = uncached_session.get(url, auth=(auth_token, SUBCLIENT_ID))
|
||||
resp.raise_for_status()
|
||||
return resp.text
|
||||
|
||||
|
||||
async def copy(context,
|
||||
base_blendfile: pathlib.Path,
|
||||
project: pathlib.Path,
|
||||
target: str,
|
||||
exclusion_filter: str,
|
||||
*,
|
||||
relative_only: bool,
|
||||
packer_class=pack.Packer,
|
||||
**packer_args) \
|
||||
-> typing.Tuple[pathlib.Path, typing.Set[pathlib.Path]]:
|
||||
async def copy(
|
||||
context,
|
||||
base_blendfile: pathlib.Path,
|
||||
project: pathlib.Path,
|
||||
target: str,
|
||||
exclusion_filter: str,
|
||||
*,
|
||||
relative_only: bool,
|
||||
packer_class=pack.Packer,
|
||||
**packer_args
|
||||
) -> typing.Tuple[pathlib.Path, typing.Set[pathlib.Path]]:
|
||||
"""Use BAT🦇 to copy the given file and dependencies to the target location.
|
||||
|
||||
:raises: FileTransferError if a file couldn't be transferred.
|
||||
@@ -145,30 +148,36 @@ async def copy(context,
|
||||
loop = asyncio.get_event_loop()
|
||||
wm = bpy.context.window_manager
|
||||
|
||||
packer = packer_class(base_blendfile, project, target,
|
||||
compress=True, relative_only=relative_only, **packer_args)
|
||||
packer = packer_class(
|
||||
base_blendfile,
|
||||
project,
|
||||
target,
|
||||
compress=True,
|
||||
relative_only=relative_only,
|
||||
**packer_args
|
||||
)
|
||||
with packer:
|
||||
with _packer_lock:
|
||||
if exclusion_filter:
|
||||
# There was a mistake in an older version of the property tooltip,
|
||||
# showing semicolon-separated instead of space-separated. We now
|
||||
# just handle both.
|
||||
filter_parts = re.split('[ ;]+', exclusion_filter.strip(' ;'))
|
||||
filter_parts = re.split("[ ;]+", exclusion_filter.strip(" ;"))
|
||||
packer.exclude(*filter_parts)
|
||||
|
||||
packer.progress_cb = BatProgress()
|
||||
_running_packer = packer
|
||||
|
||||
log.debug('awaiting strategise')
|
||||
wm.flamenco_status = 'INVESTIGATING'
|
||||
log.debug("awaiting strategise")
|
||||
wm.flamenco_status = "INVESTIGATING"
|
||||
await loop.run_in_executor(None, packer.strategise)
|
||||
|
||||
log.debug('awaiting execute')
|
||||
wm.flamenco_status = 'TRANSFERRING'
|
||||
log.debug("awaiting execute")
|
||||
wm.flamenco_status = "TRANSFERRING"
|
||||
await loop.run_in_executor(None, packer.execute)
|
||||
|
||||
log.debug('done')
|
||||
wm.flamenco_status = 'DONE'
|
||||
log.debug("done")
|
||||
wm.flamenco_status = "DONE"
|
||||
|
||||
with _packer_lock:
|
||||
_running_packer = None
|
||||
@@ -184,7 +193,7 @@ def abort() -> None:
|
||||
|
||||
with _packer_lock:
|
||||
if _running_packer is None:
|
||||
log.debug('No running packer, ignoring call to bat_abort()')
|
||||
log.debug("No running packer, ignoring call to bat_abort()")
|
||||
return
|
||||
log.info('Aborting running packer')
|
||||
log.info("Aborting running packer")
|
||||
_running_packer.abort()
|
||||
|
@@ -7,7 +7,8 @@ from pillarsdk.resource import List, Find, Create
|
||||
|
||||
class Manager(List, Find):
|
||||
"""Manager class wrapping the REST nodes endpoint"""
|
||||
path = 'flamenco/managers'
|
||||
|
||||
path = "flamenco/managers"
|
||||
PurePlatformPath = pathlib.PurePath
|
||||
|
||||
@functools.lru_cache(maxsize=1)
|
||||
@@ -18,10 +19,12 @@ class Manager(List, Find):
|
||||
"""
|
||||
settings_version = self.settings_version or 1
|
||||
try:
|
||||
settings_func = getattr(self, '_path_replacements_v%d' % settings_version)
|
||||
settings_func = getattr(self, "_path_replacements_v%d" % settings_version)
|
||||
except AttributeError:
|
||||
raise RuntimeError('This manager has unsupported settings version %d; '
|
||||
'upgrade Blender Cloud add-on')
|
||||
raise RuntimeError(
|
||||
"This manager has unsupported settings version %d; "
|
||||
"upgrade Blender Cloud add-on"
|
||||
)
|
||||
|
||||
def longest_value_first(item):
|
||||
var_name, var_value = item
|
||||
@@ -40,9 +43,11 @@ class Manager(List, Find):
|
||||
items = self.path_replacement.to_dict().items()
|
||||
|
||||
this_platform = platform.system().lower()
|
||||
return [(varname, platform_replacements[this_platform])
|
||||
for varname, platform_replacements in items
|
||||
if this_platform in platform_replacements]
|
||||
return [
|
||||
(varname, platform_replacements[this_platform])
|
||||
for varname, platform_replacements in items
|
||||
if this_platform in platform_replacements
|
||||
]
|
||||
|
||||
def _path_replacements_v2(self) -> typing.List[typing.Tuple[str, str]]:
|
||||
import platform
|
||||
@@ -51,21 +56,21 @@ class Manager(List, Find):
|
||||
return []
|
||||
|
||||
this_platform = platform.system().lower()
|
||||
audiences = {'users', 'all'}
|
||||
audiences = {"users", "all"}
|
||||
|
||||
replacements = []
|
||||
for var_name, variable in self.variables.to_dict().items():
|
||||
# Path replacement requires bidirectional variables.
|
||||
if variable.get('direction') != 'twoway':
|
||||
if variable.get("direction") != "twoway":
|
||||
continue
|
||||
|
||||
for var_value in variable.get('values', []):
|
||||
if var_value.get('audience') not in audiences:
|
||||
for var_value in variable.get("values", []):
|
||||
if var_value.get("audience") not in audiences:
|
||||
continue
|
||||
if var_value.get('platform', '').lower() != this_platform:
|
||||
if var_value.get("platform", "").lower() != this_platform:
|
||||
continue
|
||||
|
||||
replacements.append((var_name, var_value.get('value')))
|
||||
replacements.append((var_name, var_value.get("value")))
|
||||
return replacements
|
||||
|
||||
def replace_path(self, some_path: pathlib.PurePath) -> str:
|
||||
@@ -74,8 +79,9 @@ class Manager(List, Find):
|
||||
Tries to find platform-specific path prefixes, and replaces them with
|
||||
variables.
|
||||
"""
|
||||
assert isinstance(some_path, pathlib.PurePath), \
|
||||
'some_path should be a PurePath, not %r' % some_path
|
||||
assert isinstance(some_path, pathlib.PurePath), (
|
||||
"some_path should be a PurePath, not %r" % some_path
|
||||
)
|
||||
|
||||
for varname, path in self._path_replacements():
|
||||
replacement = self.PurePlatformPath(path)
|
||||
@@ -85,25 +91,26 @@ class Manager(List, Find):
|
||||
# Not relative to each other, so no replacement possible
|
||||
continue
|
||||
|
||||
replacement_root = self.PurePlatformPath('{%s}' % varname)
|
||||
replacement_root = self.PurePlatformPath("{%s}" % varname)
|
||||
return (replacement_root / relpath).as_posix()
|
||||
|
||||
return some_path.as_posix()
|
||||
|
||||
|
||||
class Job(List, Find, Create):
|
||||
"""Job class wrapping the REST nodes endpoint
|
||||
"""
|
||||
path = 'flamenco/jobs'
|
||||
ensure_query_projections = {'project': 1}
|
||||
"""Job class wrapping the REST nodes endpoint"""
|
||||
|
||||
path = "flamenco/jobs"
|
||||
ensure_query_projections = {"project": 1}
|
||||
|
||||
def patch(self, payload: dict, api=None):
|
||||
import pillarsdk.utils
|
||||
|
||||
api = api or self.api
|
||||
|
||||
url = pillarsdk.utils.join_url(self.path, str(self['_id']))
|
||||
headers = pillarsdk.utils.merge_dict(self.http_headers(),
|
||||
{'Content-Type': 'application/json'})
|
||||
url = pillarsdk.utils.join_url(self.path, str(self["_id"]))
|
||||
headers = pillarsdk.utils.merge_dict(
|
||||
self.http_headers(), {"Content-Type": "application/json"}
|
||||
)
|
||||
response = api.patch(url, payload, headers=headers)
|
||||
return response
|
||||
|
Reference in New Issue
Block a user