Skip to content

Commit

Permalink
fix Firefox persistent profile directory path
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdemin committed May 1, 2018
1 parent e116d1c commit 7f1483b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

## Unreleased

## Changed
- Firefox persistent profile mode now prompts for Return to save profile

## [5.1.1] - 2018-04-19

## Added
Expand Down
17 changes: 14 additions & 3 deletions kibitzr/fetcher/browser/fetcher.py
Expand Up @@ -13,6 +13,7 @@

from kibitzr.conf import settings
from .launcher import firefox, PROFILE_DIR
from .trigger import prompt_return


logger = logging.getLogger(__name__)
Expand All @@ -22,25 +23,35 @@
def persistent_firefox():
if not os.path.exists(PROFILE_DIR):
os.makedirs(PROFILE_DIR)
print("Kibitzr is running Firefox in persistent profile mode.")
with firefox(headless=False) as driver:
driver.get(HOME_PAGE)
while True:
prompt_return()
try:
# Property raises when browser is closed:
driver.title
except:
# All kinds of things happen when closing Firefox
break
else:
time.sleep(0.2)
update_profile(driver)
update_profile(driver)
print(
"Firefox profile is saved. "
"Close browser now to reuse profile in further runs."
)
print(
"Firefox is closed. "
"To delete saved profile remove following directory: {0}"
.format(os.path.abspath(PROFILE_DIR))
)


def update_profile(driver):
if os.path.exists(PROFILE_DIR):
shutil.rmtree(PROFILE_DIR)
shutil.copytree(
driver.profile.profile_dir,
driver.capabilities['moz:profile'],
PROFILE_DIR,
ignore=shutil.ignore_patterns(
"parent.lock",
Expand Down
8 changes: 8 additions & 0 deletions kibitzr/fetcher/browser/trigger.py
@@ -0,0 +1,8 @@
from six.moves import input as compat_input


def prompt_return():
compat_input(
"Press Enter to save Firefox profile; "
"or close Firefox to cancel: "
)
2 changes: 1 addition & 1 deletion kibitzr/main.py
Expand Up @@ -81,7 +81,7 @@ def execute_conf(conf):


def run_firefox():
setup_logger(logging.DEBUG)
setup_logger(logging.INFO)
persistent_firefox()


Expand Down

0 comments on commit 7f1483b

Please sign in to comment.