Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. @api_view(['POST'])
  2. def file_upload(request):
  3.     if request.method=='POST':
  4.         serializer=FileSerializer()
  5.         #ipdb.set_trace()
  6.         file=request.data['data']
  7.  
  8.         shutil.move(file, '/home/pypi/Desktop/casefiles/python_solutions/')
  9.         filename = file.split('/')
  10.         #ipdb.set_trace()
  11.         client=docker.from_env()
  12.         container=client.containers.run('python:3.6', command=['python', str(filename[-1])], detach=True, volumes={'/home/pypi/Desktop/casefiles/':{'bind':'/container', 'mode':'rw'}}, working_dir='/container/python_solutions', stdout=True, name='vleung6',)
  13.         logs=container.logs(stdout=True, timestamps=True, tail='all', follow=True)
  14.  
  15.         #logs=container.logs()
  16.         #logs=logs.decode("utf-8")
  17.         print('RUNNING IT NOW!')
  18.         #print(logs)
  19.         container.stop()
  20.         container.remove()
  21.         return Response(logs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement