Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jarun#711] fixed profile detection for multiple Firefox installs #716

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

LeXofLeviafan
Copy link
Collaborator

fixes #711:

  • changing Firefox profile detection from single to multiple when multiple installs are found (asking which one to pick until one is chosen)
  • adding support for environment variable (FIREFOX_PROFILE) in CLI & parameter (firefox_profile) in API

also:

  • skipping nonexistent bookmark files
  • stripping commas (tag delimiter) from imported tags (particularly parent folder ones)

profiles = firefox_profile or get_firefox_profile_names(default_ff_folder)
if profiles:
ff_bm_db_paths = {s: '~/.mozilla/firefox/{}/places.sqlite'.format(s)
for s in profiles}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keys are printed in prompt (when more than 1 profiles were found).

Dicts retain insertion order (since Python 3.7).

if not os.path.exists(bookmarks_database):
raise FileNotFoundError
self.load_chrome_database(bookmarks_database, newtag, add_parent_folder_as_tag)
if os.path.isfile(os.path.expanduser(gc_bm_db_path)):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a file existence check to avoid asking about nonexistent bookmark files.
(expanduser() is required to handle ~ in paths)

if self.chatty:
profile = ('' if len(ff_bm_db_paths) < 2 else
f' profile {name} [{idx}/{len(ff_bm_db_paths)}]')
resp = input(f'Import bookmarks from Firefox{profile}? (y/n): ')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asking which profile to import from (when multiple were detected).

if not os.path.exists(bookmarks_database):
raise FileNotFoundError
self.load_firefox_database(bookmarks_database, newtag, add_parent_folder_as_tag)
break
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one Firefox profile is imported, others are skipped (this means falling back to original behaviour in library mode).

except NoOptionError:
pass
if profiles:
return profiles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When any installs are found, their default profiles are returned, in order.


profiles_names = [section for section in config.sections() if section.startswith('Profile')]
if not profiles_names:
return None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a noop anyway.

profile_path = config.get(name, 'path')
return profile_path
profiles += [config.get(name, 'path')]
continue
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adding the same profile twice

except NoOptionError:
pass
try:
# alternative way to detect default profile
if config.get(name, 'name').lower() == "default":
profile_path = config.get(name, 'path')
return profile_path
profiles += [config.get(name, 'path')]
except NoOptionError:
pass
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When no installs were found, all profiles detected as "default" are returned.


# There are no default profiles
LOGDBG('get_firefox_profile_names(): {} does not exist'.format(path))
return profiles
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty list is both valid and falsey.

@@ -2304,7 +2306,7 @@ class BukuDb:

for item in sublist:
if item['type'] == 'folder':
next_folder_name = folder_name + ',' + item['name']
next_folder_name = folder_name + DELIM + strip_delim(item['name'])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripping commas from imported bookmark folder tags

@@ -5986,7 +6002,7 @@ POSITIONAL ARGUMENTS:

# Import bookmarks from browser
if args.ai:
bdb.auto_import_from_browser()
bdb.auto_import_from_browser(firefox_profile=os.environ.get('FIREFOX_PROFILE'))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding Firefox profile detection with an environment variable (if found).

<DL><p>
<DT><A HREF="http://example.com/"></A>"""
exp_res = ("http://example.com/", None, ",1s,", None, 0, True, False)
exp_res = ("http://example.com/", None, ",1s (blah blah),", None, 0, True, False)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring that a bookmark folder with commas won't be split into multiple tags

@@ -287,7 +287,7 @@
"date_added": "13149362306507580",
"date_modified": "13149362306507581",
"id": "41",
"name": "Imported From Firefox",
"name": "Imported From Firefox (2011-09-02, 06:03:50)",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actual example of a comma in a bookmark folder name.

if profile:
ff_bm_db_path = ('~/Library/Application Support/Firefox/'
'{}/places.sqlite'.format(profile))
profiles = firefox_profile or get_firefox_profile_names(default_ff_folder)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only Firefox? Tomorrow another users may request the same for another browser. Why not do it now?

Copy link
Collaborator Author

@LeXofLeviafan LeXofLeviafan Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK no other browser has multiple switchable profiles that the import code has to pick one from (and may do so incorrectly).

For all other browsers, the bookmark files are always in fixed location – that is certainly the case according to buku code.

@jarun jarun merged commit c83362e into jarun:master Feb 17, 2024
1 check passed
@jarun
Copy link
Owner

jarun commented Feb 17, 2024

Thank you!

@jarun
Copy link
Owner

jarun commented Feb 17, 2024

@LeXofLeviafan can we make a release?

@LeXofLeviafan
Copy link
Collaborator Author

@jarun I was thinking of dealing with #702 first – it's been open for a while, come to think of it.

Also, you'll need to fork (and release on PyPI) the package that's been blocking buku from releasing updates on PyPI (it should be maintained by you to avoid repeating the issue). …Or alternatively its code could be included in bukuserver files – thus removing the external dependency altogether.

Additionally, the fix could also be applied to v4.8 (e.g. in a separate branch) to publish a post-release to PyPI as well (i.e. 4.8.0.post1), to avoid "missing" versions from release history.

@jarun
Copy link
Owner

jarun commented Feb 17, 2024

I was thinking of dealing with #702 first – it's been open for a while, come to think of it.

Sure thing!

Or alternatively its code could be included in bukuserver files – thus removing the external dependency altogether.

This works for me.

Please raise the PRs.

@jarun
Copy link
Owner

jarun commented Feb 19, 2024

Would you be able to make the next release?
The instructions are here: https://github.com/jarun/buku/wiki/Release-checklist

I can add you to Pypi.

@jarun
Copy link
Owner

jarun commented Feb 20, 2024

@LeXofLeviafan tagging in case you have missed my responses above.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2024
@LeXofLeviafan LeXofLeviafan deleted the fix-import branch August 24, 2024 17:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autoimport from firefox with several installed editions
2 participants