#python
Вопрос:
У меня есть программа на python — selenium, для которой требуется chromedriver.exe
и license.txt
файл в корневом каталоге, я его цитонизирую и собираюсь создать исполняемый файл
мой вопрос в том, могу ли я добавить chromedriver.exe
и license.txt
прямо в exe-файл с помощью pyinstaller? правильно ли это работает?
примечание: license.txt
в процессе программы происходит редактирование
это setup.py
import Cython.Build
import distutils.core
a1 = Cython.Build.cythonize("gui.py")[0]
#Return to the list of distutils.extension.Extension objects
distutils.core.setup(
name = 'program1',#Package name
version = "1.0",#Package version number
ext_modules=[a1],#Extension Module
author = "me",#Author
)
это main.py
import gui
if __name__ == '__main__':
gui()
это вызов драйвера chrome
chromedriver_path = './chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=chromedriver_path)
driver.maximize_window()
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
и это license.txt
функция
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def find_regex_1(k, s):
reg = f'{k}s*=s*(S )'
return re.search(reg, s).group(1)
def read_configs(config_file):
with open(config_file, "r") as f:
content = f.read()
license_code = find_regex_1('LICENSE CODE', content)
activation_code = find_regex_1('ACTIVATION CODE ', content)
return license_code, activation_code
license_code, activation_code = read_configs('license.txt')
запись в license.txt
течение программы:
license_input = values['-INPUT-']
read_configs('license.txt')
lic = "license.txt"
with open(lic, 'r ') as f:
text = f.read()
text = re.sub(license_code, license_input, text)
f.seek(0)
f.write(text)
f.truncate()