Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.toolbox
Commits
61e85392
Commit
61e85392
authored
Nov 02, 2018
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use contextmanager instead of class
parent
620c7356
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
+18
-20
slapos/resilient/runner_exporter.py
slapos/resilient/runner_exporter.py
+18
-20
No files found.
slapos/resilient/runner_exporter.py
View file @
61e85392
...
...
@@ -9,6 +9,7 @@ import subprocess
import
sys
import
time
from
contextlib
import
contextmanager
from
datetime
import
datetime
from
hashlib
import
sha256
from
zc.buildout.configparser
import
parse
...
...
@@ -20,26 +21,23 @@ from zc.buildout.configparser import parse
os
.
environ
[
'LC_ALL'
]
=
'C'
os
.
umask
(
0o77
)
class
CwdContextManager
:
# Context Manager Class for executing code
# in a given directory
# There is no need to provide fallback or basic
# checks in this code, as these checkes should
# exist in the code invoking this Context Manager.
# If someone needs to add checks here, I'm pretty
# sure it means that they are trying to hide legitimate
# errors.
# See tests to see examples of invokation
def
__init__
(
self
,
path
):
self
.
path
=
path
def
__enter__
(
self
):
self
.
oldpath
=
os
.
getcwd
()
os
.
chdir
(
self
.
path
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
os
.
chdir
(
self
.
oldpath
)
@
contextmanager
def
CwdContextManager
(
path
):
"""
Context Manager for executing code in a given directory.
There is no need to provide fallback or basic checks
in this code, as these checkes should exist in the code
invoking this Context Manager.
If someone needs to add checks here, I'm pretty sure
it means that they are trying to hide legitimate errors.
See tests to see examples of invokation
"""
old_path
=
os
.
getcwd
()
try
:
os
.
chdir
(
path
)
yield
finally
:
os
.
chdir
(
old_path
)
def
parseArgumentList
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment