1、tarfile (module)
def yasuoyujieyasuo(request):
env = get_env(request)message = ''
writter = StringIO()
tar = tarfile.open(fileobj=writter, mode='w:gz')
tar.add('1)
tar.add('2')
tar.add('/3')
tar.close()
response = HttpResponse(mimetype='')
response['Content-Disposition'] = 'attachment; filename=my.backup'
response.write(writter.getvalue())
writter.close()
return response
elif 'jieyasuo' in request.POST:
tar = None
fd = request.FILES.get('upload_file')
try: tar = tarfile.open(fileobj=fd, mode='r:gz')
if tar: tar.extractall(path="/", members=[s for s in tar if s.name in ['1', '2','3']])
return render_to_response('test.html', {'env': env, 'message': message})
return render_to_response('test.html', {'env': env})