I'm trying to rename the directory after extracting it in a temporary directory.The archive upload by user. What I mean, User will upload a .tar OR .zip file then I will make a temporary directory and extract user's file into that directory, now I want to rename it extracted directory which is inside temporary directory.
Here's what I have tried: In my 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 I print print(path+'/'+deployment.archive.name[:-4])
it should print users' file name without .zip OR .tar extension.
See what it 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 to `/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