Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, time, shutil
- def find_file(type):
- adress=str(os.getcwd())+"/build"
- for root, dirs, files in os.walk(adress):
- for file in files:
- if file.endswith(type) and file !='con in bin.py':
- adress_to_file=os.path.join(root, file)
- adress_to_file=adress_to_file.replace(" ", "\ ")
- break
- return adress_to_file
- py_scrypt= find_file("py")# нахождения расположения скрипта.
- # adress_icon= find_file("ico")#нахождения расположения иконки.
- home=os.getcwd()
- home1=str(home+"/build")#новое расположения exe файла.
- home1= home1+'/dist'
- if os.path.isfile(home1):
- print("del file")
- shutil.rmtree(home1)
- if os.path.exists(home1):
- print("del folder")
- shutil.rmtree(home1)
- os.system(str('pyinstaller --onefile '+ py_scrypt))# сборка в exe файл.
- time.sleep(1)
- adress=str(os.getcwd()+"/dist")# директория с exe файлом.
- py_scrypt= os.path.basename(py_scrypt)# получить имя скрипта.
- name_file=py_scrypt[:-3]#
- #
- adress=str(adress+"/"+name_file) # расположения exe файла.
- home=os.getcwd()
- home1=str(home+"/build")#новое расположения exe файла.
- shutil.rmtree(home1+'/'+name_file)
- shutil.rmtree(home1+'/__pycache__')
- home1= home1+'/dist'
- if not os.path.isfile(home1):
- print("cre")
- os.mkdir(home1)
- else:
- print("del")
- shutil.rmtree(home1)
- time.sleep(3)
- os.mkdir(home1)
- # print(adress)
- home1=str(home1)
- # print(home1)
- shutil.move(adress, home1)# переместить файл в новую директорию.
- shutil.rmtree((home+"/dist"), ignore_errors=True)# удалить папки
- shutil.rmtree((os.getcwd()+'/'+name_file+'.spec'), ignore_errors=True)
- shutil.rmtree((os.getcwd()+'/onefile.spec'), ignore_errors=True)
- s=str("#!/bin/bash \n"
- "a=\"{0}\"\n"
- "dir=($pwd)\n"
- "gnome-terminal -e \"bash -c \\\"./${2}; exec bash\\\"\""
- ).format(name_file,"{b}","{a}","{dir}")
- name_file = str(home1+"/"+name_file+".bash")
- with open(name_file,"w") as f:
- f.write(s)
Advertisement
RAW Paste Data
Copied
Advertisement