This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add operadriver, add setuptools as a dependency
- Loading branch information
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
@brief test log(time=45s) | ||
""" | ||
|
||
import sys | ||
import os | ||
import unittest | ||
|
||
try: | ||
import src | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
".."))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
import src | ||
|
||
try: | ||
import pyquickhelper as skip_ | ||
except ImportError: | ||
path = os.path.normpath( | ||
os.path.abspath( | ||
os.path.join( | ||
os.path.split(__file__)[0], | ||
"..", | ||
"..", | ||
"..", | ||
"pyquickhelper", | ||
"src"))) | ||
if path not in sys.path: | ||
sys.path.append(path) | ||
if "PYQUICKHELPER" in os.environ and len(os.environ["PYQUICKHELPER"]) > 0: | ||
sys.path.append(os.environ["PYQUICKHELPER"]) | ||
import pyquickhelper as skip_ | ||
|
||
|
||
from src.pymyinstall.installcustom import install_operadriver | ||
from pyquickhelper.loghelper import fLOG | ||
|
||
if sys.version_info[0] == 2: | ||
FileNotFoundError = Exception | ||
|
||
|
||
class TestOperaDriver(unittest.TestCase): | ||
|
||
def test_install_OperaDriver(self): | ||
fLOG( | ||
__file__, | ||
self._testMethodName, | ||
OutputPrint=__name__ == "__main__") | ||
|
||
if sys.version_info[0] == 2: | ||
return | ||
|
||
fold = os.path.abspath(os.path.split(__file__)[0]) | ||
temp = os.path.join(fold, "temp_operadriver") | ||
if not os.path.exists(temp): | ||
os.mkdir(temp) | ||
for _ in os.listdir(temp): | ||
f = os.path.join(temp, _) | ||
if os.path.isfile(f): | ||
os.remove(f) | ||
|
||
r = install_operadriver(temp, fLOG=fLOG, install=True) | ||
for _ in r: | ||
fLOG(_) | ||
if sys.platform.startswith("win"): | ||
found = os.path.join(temp, "operadriver.exe") | ||
if not os.path.exists(found): | ||
raise FileNotFoundError(found) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/pymyinstall/installcustom/install_custom_operadriver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
@file | ||
@brief Various functions to install `MinGW <http://www.mingw.org/>`_. | ||
""" | ||
from __future__ import print_function | ||
import sys | ||
import os | ||
import re | ||
|
||
from .install_custom import download_page, download_file | ||
from ..installhelper.install_cmd_helper import unzip_files | ||
|
||
|
||
def install_operadriver(dest_folder=".", fLOG=print, install=True, version=None): | ||
""" | ||
install `operadriver <https://github.com/operasoftware/operachromiumdriver/releases>`_ (only on Windows) | ||
@param dest_folder where to download the setup | ||
@param fLOG logging function | ||
@param install install (otherwise only download) | ||
@param version version to install (unused) | ||
@return zip file in a list or list of unzipped files | ||
This is required for Selenium. | ||
""" | ||
if version is None: | ||
content = download_page( | ||
"https://github.com/operasoftware/operachromiumdriver/releases") | ||
reg = re.compile( | ||
"/tag/v([0-9]+[.][0-9]+[.][0-9])") | ||
f = reg.findall(content) | ||
if not f: | ||
raise Exception( | ||
"unable to get the last version number for ChromeDriver") | ||
version = f[0] | ||
if sys.platform.startswith("win"): | ||
url = "https://github.com/operasoftware/operachromiumdriver/releases/download/v{0}/operadriver_win64.zip".format( | ||
version) | ||
elif sys.platform.startswith("mac"): | ||
url = "https://github.com/operasoftware/operachromiumdriver/releases/download/v{0}/operadriver_mac64.zip".format( | ||
version) | ||
else: | ||
url = "https://github.com/operasoftware/operachromiumdriver/releases/download/v{0}/operadriver_linux64.zip".format( | ||
version) | ||
name = url.split("/")[-1] | ||
|
||
outfile = os.path.join(dest_folder, name) | ||
fLOG("operadriver, download from ", url) | ||
download_file(url, outfile, fLOG=fLOG) | ||
|
||
if install: | ||
return unzip_files(outfile, whereTo=dest_folder, fLOG=fLOG) | ||
else: | ||
return [outfile] |