Skip to content

Commit

Permalink
better handling of the selenium webdriver; fixes #80
Browse files Browse the repository at this point in the history
  • Loading branch information
aozalevsky committed Mar 26, 2024
1 parent cf90346 commit 5d29ce2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
14 changes: 1 addition & 13 deletions ihm_validation/ihm_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,6 @@ def write_json(mmcif_file: str, template_dict: dict, dirName: str, dirName_Outpu
#################################################

if __name__ == "__main__":
from pyvirtualdisplay import Display
from selenium import webdriver
# display = Display(visible=0, size=(1024, 768))
# display.start()
# driver = webdriver.Firefox()

firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('--headless')
driver = webdriver.Firefox(options=firefox_options)


logging.info("Clean up and create output directories")
utility.clean_all()

Expand All @@ -286,7 +275,6 @@ def write_json(mmcif_file: str, template_dict: dict, dirName: str, dirName_Outpu
d = manager.dict() # create only 1 dict
report = WriteReport(args.f,
db=args.databases_root,
driver=driver,
cache=args.cache_root,
nocache=args.nocache)

Expand Down Expand Up @@ -380,4 +368,4 @@ def write_json(mmcif_file: str, template_dict: dict, dirName: str, dirName_Outpu
shutil.rmtree(dirNames['root_html'])

logging.info("Final cleanup")
utility.clean_all()
utility.clean_all(report=report)
16 changes: 14 additions & 2 deletions ihm_validation/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,32 @@
from multiprocessing import Manager
from collections import Counter
import numpy as np
from selenium import webdriver

REPORT_VERSION = '1.1'

class WriteReport(object):
def __init__(self, mmcif_file, db, driver, cache, nocache=False):
def __init__(self, mmcif_file, db, cache, nocache=False):
self.mmcif_file = mmcif_file
self.db = db
self.input = GetInputInformation(self.mmcif_file)
# Webdriver for figures
self.driver = driver
self.driver = self.create_webdriver()
self.cache = cache
self.nocache = nocache
self.report_version = REPORT_VERSION

def create_webdriver(self) -> webdriver.Firefox:
'''instantiate webdriver for rendering plots'''
firefox_options = webdriver.FirefoxOptions()
firefox_options.add_argument('--headless')
driver = webdriver.Firefox(options=firefox_options)
return driver

def clean(self) -> None:
'''cleanup'''
if self.driver:
self.driver.quit()

def run_entry_composition(self, Template_Dict: dict) -> dict:
'''
Expand Down
5 changes: 4 additions & 1 deletion ihm_validation/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def get_cx_data_fits(cx_dict: dict) -> list:
return fin_cx


def clean_all():
def clean_all(report=None):
'''
delete all generated files
'''
Expand All @@ -458,6 +458,9 @@ def clean_all():
if item.endswith('.sascif'):
os.remove(item)

if report:
report.clean()


# Adapted from
# https://stackoverflow.com/questions/52859751/
Expand Down

0 comments on commit 5d29ce2

Please sign in to comment.