Skip to content

Commit

Permalink
Merge branch '1.0.x' into 'master'
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Sep 14, 2020
2 parents 9163d3d + dd639c9 commit a82ba28
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
42 changes: 36 additions & 6 deletions reprounzip-docker/reprounzip_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import socket
import subprocess
import sys
import tarfile

from reprounzip.common import load_config, record_usage, RPZPack
from reprounzip import signals
Expand Down Expand Up @@ -678,6 +679,16 @@ def __init__(self, target, input_files, files, unpacked_info,
docker_cmd='docker'):
self.unpacked_info = unpacked_info
self.docker_cmd = docker_cmd
config = load_config(target / 'config.yml', True)
if config.runs:
first_run = config.runs[0]
self.default_ownership = (
first_run.get('uid'),
first_run.get('gid'),
)
else:
self.default_ownership = None, None

FileUploader.__init__(self, target, input_files, files)

def prepare_upload(self, files):
Expand Down Expand Up @@ -719,13 +730,32 @@ def finalize(self):
shell_escape(unicode_(src)),
shell_escape(unicode_(target))))

if self.docker_copy:
dockerfile.write('RUN /busybox chown 1000:1000 \\\n'
' %s\n' % ' \\\n '.join(
shell_escape(unicode_(target))
for src, target in self.docker_copy))
for src, target in self.docker_copy:
uid = gid = None

# Keep permissions if the file is already in there
tar = tarfile.open(str(self.target / 'data.tgz'), 'r:*')
try:
info = tar.getmember(str(
join_root(PosixPath(b'DATA'), target)
))
uid, gid = info.uid, info.gid
except KeyError:
pass

# Otherwise default on the first run's UID/GID
if uid is None:
uid, gid = self.default_ownership

# TODO : restore permissions?
# Lastly, use 1000
if uid is None:
uid = gid = 1000

dockerfile.write(
'RUN /busybox chown %d:%d %s\n' % (
uid, gid, shell_escape(unicode_(target))
)
)

image = make_unique_name(b'reprounzip_image_')
retcode = subprocess.call(self.docker_cmd +
Expand Down
9 changes: 7 additions & 2 deletions reprozip-jupyter/reprozip_jupyter/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
from rpaths import Path
import subprocess
import sys
from tornado.concurrent import Future
from tornado.process import Subprocess
from tornado.web import RequestHandler, asynchronous
from tornado.web import RequestHandler


try:
Expand All @@ -21,8 +22,8 @@ class TraceHandler(RequestHandler):
def initialize(self, nbapp=None):
self.nbapp = nbapp
self._tempdir = None
self._future = None

@asynchronous
def post(self):
self._notebook_file = Path(self.get_body_argument('file'))
name = self._notebook_file.unicodename
Expand All @@ -35,6 +36,7 @@ def post(self):
self._tempdir = Path.tempdir()
self.nbapp.log.info("reprozip: created temp directory %r",
self._tempdir)
self._future = Future()
proc = Subprocess(
[sys.executable, '-c',
'from reprozip_jupyter.main import main; main()',
Expand All @@ -46,6 +48,7 @@ def post(self):
proc.stdin.close()
proc.set_exit_callback(self._trace_done)
self.nbapp.log.info("reprozip: started tracing...")
return self._future

def _trace_done(self, returncode):
self.nbapp.log.info("reprozip: tracing done, returned %d", returncode)
Expand All @@ -71,6 +74,7 @@ def _trace_done(self, returncode):
"bottom without error before packing."})
else:
self.send_error(500)
self._future.set_result(None)

def _packing_done(self, returncode):
self.nbapp.log.info("reprozip: packing done, returned %d", returncode)
Expand All @@ -82,6 +86,7 @@ def _packing_done(self, returncode):
else:
self.send_error(500)
self._tempdir.rmtree()
self._future.set_result(None)


def load_jupyter_server_extension(nbapp):
Expand Down
6 changes: 6 additions & 0 deletions tests/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def check_simple(args, stream, infile=1):
out, err = p.communicate()
assert p.poll() != 0
err = err.splitlines()
while b"DeprecationWarning" in err[0]:
err = err[2:]
assert b"Wrong unpacker used" in err[0]
assert err[1].startswith(b"usage: ")
# Delete directory
Expand Down Expand Up @@ -328,6 +330,8 @@ def check_simple(args, stream, infile=1):
out, err = p.communicate()
assert p.poll() != 0
err = err.splitlines()
while b"DeprecationWarning" in err[0]:
err = err[2:]
assert b"Wrong unpacker used" in err[0]
assert err[1].startswith(b"usage:")
finally:
Expand Down Expand Up @@ -873,6 +877,8 @@ def check_simple(args, stream, infile=1):
out, err = p.communicate()
assert p.poll() != 0
err = err.splitlines()
while b"DeprecationWarning" in err[0]:
err = err[2:]
assert b"Wrong unpacker used" in err[0]
assert err[1].startswith(b"usage: ")
# Delete directory
Expand Down

0 comments on commit a82ba28

Please sign in to comment.