python - Rename a directory after extracting zip archive uploaded by user -
i'm trying rename directory after extracting in temporary directory.the archive upload user. mean, user upload .tar or .zip file make temporary directory , extract user's file directory, want rename extracted directory inside temporary directory.
here's have tried: in views.py
if form.is_valid(): deployment = tarwithoutdocker() deployment.name = form.cleaned_data['name'] deployment.user = request.user deployment.archive = form.cleaned_data['archive'] deployment.save() tmpdir = tempfile.mkdtemp() saved_umask = os.umask(0o077) path = os.path.join(tmpdir) arpath = deployment.archive.path patoolib.extract_archive(arpath, outdir=path) os.rename(path + '/' + deployment.archive.name[:-4], 'archive') print(path+'/'+deployment.archive.name[:-4])
but when print print(path+'/'+deployment.archive.name[:-4])
should print users' file name without .zip or .tar extension.
see prints out:
archives/frequent_sign_in_form-web_free18-07-2017_1046736122_9aabzpd.zip
patool: extracting /users/abdul/documents/igui/media/archives/frequent_sign_in_form-web_free18-07-2017_1046736122_9aabzpd.zip ... patool: ... /users/abdul/documents/igui/media/archives/frequent_sign_in_form-web_free18-07-2017_1046736122_9aabzpd.zip extracted `/var/folders/g2/8fzl8mjj5xxfqdfvrl7v3q_40000gn/t/tmpj8gzegdq'. [28/jul/2017 05:16:08] "post /user/deployment/new/awd http/1.1" 302 0 [28/jul/2017 05:16:08] "get /user/deployment/new/awd http/1.1" 200 15289
Comments
Post a Comment