Merge branch 'master' into dev

pull/223/head
ibuler 2016-04-28 15:56:22 +08:00
commit d4385c7e43
2 changed files with 11 additions and 4 deletions

View File

@ -19,6 +19,7 @@ from jlog.models import Log, FileLog
from jperm.perm_api import get_group_user_perm, gen_resource from jperm.perm_api import get_group_user_perm, gen_resource
from jasset.models import Asset, IDC from jasset.models import Asset, IDC
from jperm.ansible_api import MyRunner from jperm.ansible_api import MyRunner
import zipfile
def getDaysByNum(num): def getDaysByNum(num):
@ -332,13 +333,18 @@ def download(request):
filename=file_path, type='download', remote_ip=remote_ip, result=runner.results).save() filename=file_path, type='download', remote_ip=remote_ip, result=runner.results).save()
logger.debug(runner.results) logger.debug(runner.results)
tmp_dir_name = os.path.basename(upload_dir) tmp_dir_name = os.path.basename(upload_dir)
tar_file = '%s.tar.gz' % tmp_dir_name file_zip = '/tmp/'+tmp_dir_name+'.zip'
bash('cd /tmp && tar czf %s %s' % (tar_file, tmp_dir_name)) zf = zipfile.ZipFile(file_zip, "w", zipfile.ZIP_DEFLATED)
f = open('/tmp/%s' % tar_file) for dirname, subdirs, files in os.walk(upload_dir):
zf.write(dirname)
for filename in files:
zf.write(os.path.join(dirname, filename))
zf.close()
f = open(file_zip)
data = f.read() data = f.read()
f.close() f.close()
response = HttpResponse(data, content_type='application/octet-stream') response = HttpResponse(data, content_type='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(tar_file) response['Content-Disposition'] = 'attachment; filename=%s.zip' % tmp_dir_name
return response return response
return render_to_response('download.html', locals(), context_instance=RequestContext(request)) return render_to_response('download.html', locals(), context_instance=RequestContext(request))

View File

@ -4,6 +4,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="renderer" content="webkit">
<title>Jumpserver | 开源跳板机系统</title> <title>Jumpserver | 开源跳板机系统</title>