Advertisement
egor230

linux build in bin file

Jan 4th, 2022 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | Gaming | 0 0
  1. import os, time, shutil, subprocess, glob
  2. from PIL import Image
  3.  
  4. def find_image():
  5.  t=['*.png', '*.jpg','*.jpeg','*.bmp']
  6.  number=0
  7.  for i in t:
  8.    i2=str(i)
  9.    for file in glob.glob(i2):
  10.     adress=os.path.join(os.getcwd(), file).lstrip('\u202a')
  11.     return adress
  12.  return ''
  13. def convert_to_ico(input_path):
  14.   if input_path != '':
  15.     image = Image.open(input_path)
  16.     output_path=adress[:-3]+'ico'
  17.     image.save(output_path, format='ico')
  18. def find_file(type):
  19.   adress_to_file=""
  20.   adress=str(os.getcwd())
  21.   for root, dirs, files in os.walk(adress):
  22.     for file in files:
  23.       if file.endswith(type) and file !='con_in_bin.py':
  24.         adress_to_file=os.path.join(root, file)
  25.         adress_to_file=adress_to_file.replace(" ", "\ ")
  26.         break
  27.   return adress_to_file
  28.  
  29. # adress = find_image()
  30. # convert_to_ico(adress)
  31. py_scrypt= find_file("py")# нахождения расположения скрипта.
  32. # adress_icon= find_file("ico")#нахождения расположения иконки.
  33. os.system(str('pyinstaller --onefile '+ py_scrypt))# сборка в exe файл.
  34.  
  35. adress=str(os.getcwd()+"/dist")# директория с exe файлом.
  36. py_scrypt= os.path.basename(py_scrypt)# получить имя скрипта.
  37. name_file=py_scrypt[:-3]#.replace("\\","")
  38. home=str(os.getcwd()) #
  39. adress=str(adress+"/"+name_file).replace('\\','') # расположения exe файла.
  40. shutil.move(adress, os.getcwd())# переместить файл в новую директорию.
  41.  
  42. shutil.rmtree(home+'/dist')
  43. shutil.rmtree(home+'/build')
  44. script = '''#!/bin/bash
  45. gnome-terminal -- bash -c ' chmod +x $i
  46. done
  47. exit'
  48. '''
  49. subprocess.call(['bash', '-c', script])
  50. name_file=name_file.replace("\\","")
  51. os.remove(os.getcwd()+'/'+name_file+'.spec')
  52.  
  53. s=str("#!/bin/bash \n"
  54.        # Переход в текущую директорию
  55.        "cd $(dirname $0)\n"
  56.        "./{0}"
  57.       ).format(name_file)
  58.  
  59. name_file = str(name_file+".sh")
  60. with open(name_file,"w") as f:
  61.   f.write(s)
  62.  
  63. script = '''#!/bin/bash
  64. gnome-terminal -- bash -c ' chmod +x name_file
  65. done
  66. exit'
  67. '''
  68. subprocess.call(['bash', '-c', script])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement