Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
flamenco-worker-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
flamenco-worker-python
Commits
4dece1d4
Commit
4dece1d4
authored
8 years ago
by
Sybren A. Stüvel
Browse files
Options
Downloads
Patches
Plain Diff
Worker: implemented the move_out_of_way command.
Works on files, directories, and non-existing paths.
parent
e04a2a3c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/flamenco-worker-python/flamenco_worker/runner.py
+31
-0
31 additions, 0 deletions
packages/flamenco-worker-python/flamenco_worker/runner.py
packages/flamenco-worker-python/tests/test_runner_move_out_of_way.py
+62
-0
62 additions, 0 deletions
...amenco-worker-python/tests/test_runner_move_out_of_way.py
with
93 additions
and
0 deletions
packages/flamenco-worker-python/flamenco_worker/runner.py
+
31
−
0
View file @
4dece1d4
...
@@ -248,6 +248,37 @@ class SleepCommand(AbstractCommand):
...
@@ -248,6 +248,37 @@ class SleepCommand(AbstractCommand):
await
self
.
worker
.
register_log
(
'
Done sleeping for %s seconds
'
%
time_in_seconds
)
await
self
.
worker
.
register_log
(
'
Done sleeping for %s seconds
'
%
time_in_seconds
)
@command_executor
(
'
move_out_of_way
'
)
class
MoveOutOfWayCommand
(
AbstractCommand
):
def
validate
(
self
,
settings
:
dict
):
try
:
src
=
settings
[
'
src
'
]
except
KeyError
:
return
'
Missing
"
src
"'
if
not
isinstance
(
src
,
str
):
return
'
src must be a string
'
async
def
execute
(
self
,
settings
:
dict
):
from
pathlib
import
Path
from
datetime
import
datetime
src
=
Path
(
settings
[
'
src
'
])
if
not
src
.
exists
():
self
.
_log
.
info
(
'
Render output path %s does not exist, not moving out of way
'
,
src
)
await
self
.
worker
.
register_log
(
'
%s: Render output path %s does not exist,
'
'
not moving out of way
'
,
self
.
command_name
,
src
)
return
mtime
=
src
.
stat
().
st_mtime
mdatetime
=
datetime
.
fromtimestamp
(
mtime
)
dst
=
src
.
with_name
(
'
%s-%s
'
%
(
src
.
name
,
mdatetime
.
isoformat
()))
self
.
_log
.
info
(
'
Moving %s to %s
'
,
src
,
dst
)
await
self
.
worker
.
register_log
(
'
%s: Moving %s to %s
'
,
self
.
command_name
,
src
,
dst
)
src
.
rename
(
dst
)
@attr.s
@attr.s
class
AbstractSubprocessCommand
(
AbstractCommand
):
class
AbstractSubprocessCommand
(
AbstractCommand
):
readline_timeout
=
attr
.
ib
(
default
=
SUBPROC_READLINE_TIMEOUT
)
readline_timeout
=
attr
.
ib
(
default
=
SUBPROC_READLINE_TIMEOUT
)
...
...
This diff is collapsed.
Click to expand it.
packages/flamenco-worker-python/tests/test_runner_move_out_of_way.py
0 → 100644
+
62
−
0
View file @
4dece1d4
from
test_runner
import
AbstractCommandTest
class
MoveOutOfWayTest
(
AbstractCommandTest
):
def
setUp
(
self
):
super
().
setUp
()
from
flamenco_worker.runner
import
MoveOutOfWayCommand
import
tempfile
self
.
tmpdir
=
tempfile
.
TemporaryDirectory
()
self
.
cmd
=
MoveOutOfWayCommand
(
worker
=
self
.
fworker
,
task_id
=
'
12345
'
,
command_idx
=
0
,
)
def
tearDown
(
self
):
del
self
.
tmpdir
def
test_nonexistant_source
(
self
):
from
pathlib
import
Path
src
=
Path
(
self
.
tmpdir
.
name
)
/
'
nonexistant-dir
'
task
=
self
.
cmd
.
run
({
'
src
'
:
str
(
src
)})
ok
=
self
.
loop
.
run_until_complete
(
task
)
self
.
assertTrue
(
ok
)
self
.
assertFalse
(
src
.
exists
())
def
test_existing_source
(
self
):
from
pathlib
import
Path
import
os
src
=
Path
(
self
.
tmpdir
.
name
)
/
'
existing-dir
'
src
.
mkdir
()
os
.
utime
(
str
(
src
),
(
1330712280
,
1330712292
))
# fixed (atime, mtime) for testing
task
=
self
.
cmd
.
run
({
'
src
'
:
str
(
src
)})
ok
=
self
.
loop
.
run_until_complete
(
task
)
self
.
assertTrue
(
ok
)
dst
=
src
.
with_name
(
'
existing-dir-2012-03-02T19:18:12
'
)
self
.
assertTrue
(
dst
.
exists
())
self
.
assertFalse
(
src
.
exists
())
def
test_source_is_file
(
self
):
from
pathlib
import
Path
import
os
src
=
Path
(
self
.
tmpdir
.
name
)
/
'
existing-file
'
src
.
touch
(
exist_ok
=
False
)
os
.
utime
(
str
(
src
),
(
1330712280
,
1330712292
))
# fixed (atime, mtime) for testing
task
=
self
.
cmd
.
run
({
'
src
'
:
str
(
src
)})
ok
=
self
.
loop
.
run_until_complete
(
task
)
self
.
assertTrue
(
ok
)
dst
=
src
.
with_name
(
'
existing-file-2012-03-02T19:18:12
'
)
self
.
assertTrue
(
dst
.
exists
())
self
.
assertTrue
(
dst
.
is_file
())
self
.
assertFalse
(
src
.
exists
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment