Remove unused bookmarks code that supports linkcheck-gui

linkchecker does not need to find a bookmark file, it is given the URL.
Most bookmarks are detected by their MIME type, Firefox is different
because it uses a SQLite database.
This commit is contained in:
Chris Mayo 2020-05-28 19:44:53 +01:00
parent e204182acb
commit abdb160413
7 changed files with 1 additions and 255 deletions

View file

@ -1,62 +0,0 @@
# Copyright (C) 2011-2014 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import sys
from xdg.BaseDirectory import xdg_config_home
def get_profile_dir():
"""Return path where all profiles of current user are stored."""
if os.name == 'nt':
if "LOCALAPPDATA" in os.environ:
basedir = os.environ["LOCALAPPDATA"]
else:
# read local appdata directory from registry
from ..winutil import get_shell_folder
try:
basedir = get_shell_folder("Local AppData")
except EnvironmentError:
basedir = os.path.join(os.environ["USERPROFILE"],
"Local Settings", "Application Data")
dirpath = os.path.join(basedir, "Google", "Chrome", "User Data")
elif os.name == 'posix':
if sys.platform == 'darwin':
dirpath = os.path.join(os.environ["HOME"], "Library",
"Application Support")
else:
dirpath = xdg_config_home
dirpath = os.path.join(dirpath, "Google", "Chrome")
return dirpath
def find_bookmark_file(profile="Default"):
"""Return the bookmark file of the Default profile.
Returns absolute filename if found, or empty string if no bookmark file
could be found.
"""
try:
dirname = os.path.join(get_profile_dir(), profile)
if os.path.isdir(dirname):
fname = os.path.join(dirname, "Bookmarks")
if os.path.isfile(fname):
return fname
except Exception:
pass
return ""
from .chromium import parse_bookmark_data, parse_bookmark_file # noqa: F401

View file

@ -14,50 +14,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import sys
import json
from xdg.BaseDirectory import xdg_config_home
def get_profile_dir():
"""Return path where all profiles of current user are stored."""
if os.name == 'nt':
if "LOCALAPPDATA" in os.environ:
basedir = os.environ["LOCALAPPDATA"]
else:
# read local appdata directory from registry
from ..winutil import get_shell_folder
try:
basedir = get_shell_folder("Local AppData")
except EnvironmentError:
basedir = os.path.join(os.environ["USERPROFILE"],
"Local Settings", "Application Data")
dirpath = os.path.join(basedir, "Chromium", "User Data")
elif os.name == 'posix':
if sys.platform == 'darwin':
dirpath = os.path.join(os.environ["HOME"], "Library",
"Application Support")
else:
dirpath = xdg_config_home
dirpath = os.path.join(dirpath, "chromium")
return dirpath
def find_bookmark_file(profile="Default"):
"""Return the bookmark file of the Default profile.
Returns absolute filename if found, or empty string if no bookmark file
could be found.
"""
try:
dirname = os.path.join(get_profile_dir(), profile)
if os.path.isdir(dirname):
fname = os.path.join(dirname, "Bookmarks")
if os.path.isfile(fname):
return fname
except Exception:
pass
return ""
def parse_bookmark_data(data):
@ -69,15 +26,6 @@ def parse_bookmark_data(data):
yield url, name
def parse_bookmark_file(file):
"""Parse file object.
Return iterator for bookmarks of the form (url, name).
Bookmarks are not sorted.
"""
for url, name in parse_bookmark_json(json.load(file)):
yield url, name
def parse_bookmark_json(data):
"""Parse complete JSON data for Chromium Bookmarks."""
for entry in data["roots"].values():

View file

@ -14,8 +14,7 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Parser for FireFox bookmark file."""
import os
import glob
import re
try:
import sqlite3
@ -27,33 +26,6 @@ except ImportError:
extension = re.compile(r'/places.sqlite$', re.IGNORECASE)
def get_profile_dir():
"""Return path where all profiles of current user are stored."""
if os.name == 'nt':
basedir = os.environ["APPDATA"]
dirpath = os.path.join(basedir, "Mozilla", "Firefox", "Profiles")
elif os.name == 'posix':
dirpath = os.path.join(os.environ["HOME"], ".mozilla", "firefox")
return dirpath
def find_bookmark_file(profile="*.default"):
"""Return the first found places.sqlite file of the profile directories
ending with '.default' (or another given profile name).
Returns absolute filename if found, or empty string if no bookmark file
could be found.
"""
try:
for dirname in glob.glob("%s/%s" % (get_profile_dir(), profile)):
if os.path.isdir(dirname):
fname = os.path.join(dirname, "places.sqlite")
if os.path.isfile(fname):
return fname
except Exception:
pass
return ""
def parse_bookmark_file(filename):
"""Return iterator for bookmarks of the form (url, name).
Bookmarks are not sorted.

View file

@ -13,40 +13,6 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
# List of possible Opera bookmark files.
OperaBookmarkFiles = (
"bookmarks.adr", # for Opera >= 10.0
"opera6.adr",
)
def get_profile_dir():
"""Return path where all profiles of current user are stored."""
if os.name == 'nt':
basedir = os.environ["APPDATA"]
dirpath = os.path.join(basedir, "Opera", "Opera")
elif os.name == 'posix':
dirpath = os.path.join(os.environ["HOME"], ".opera")
return dirpath
def find_bookmark_file():
"""Return the bookmark file of the Opera profile.
Returns absolute filename if found, or empty string if no bookmark file
could be found.
"""
try:
dirname = get_profile_dir()
if os.path.isdir(dirname):
for name in OperaBookmarkFiles:
fname = os.path.join(dirname, name)
if os.path.isfile(fname):
return fname
except Exception:
pass
return ""
def parse_bookmark_data(data):

View file

@ -14,8 +14,6 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os
import sys
import plistlib
try:
import biplist
@ -24,36 +22,6 @@ except ImportError:
has_biplist = False
def get_profile_dir():
"""Return path where all profiles of current user are stored."""
return os.path.join(os.environ["HOME"], "Library", "Safari")
def find_bookmark_file():
"""Return the bookmark file of the Default profile.
Returns absolute filename if found, or empty string if no bookmark file
could be found.
"""
if sys.platform != 'darwin':
return ""
try:
dirname = get_profile_dir()
if os.path.isdir(dirname):
fname = os.path.join(dirname, "Bookmarks.plist")
if os.path.isfile(fname):
return fname
except Exception:
pass
return ""
def parse_bookmark_file(filename):
"""Return iterator for bookmarks of the form (url, name).
Bookmarks are not sorted.
"""
return parse_plist(get_plist_data_from_file(filename))
def parse_bookmark_data(data):
"""Return iterator for bookmarks of the form (url, name).
Bookmarks are not sorted.
@ -61,19 +29,6 @@ def parse_bookmark_data(data):
return parse_plist(get_plist_data_from_string(data))
def get_plist_data_from_file(filename):
"""Parse plist data for a file. Tries biplist, falling back to
plistlib."""
if has_biplist:
return biplist.readPlist(filename)
# fall back to normal plistlist
try:
return plistlib.readPlist(filename)
except Exception:
# not parseable (eg. not well-formed, or binary)
return {}
def get_plist_data_from_string(data):
"""Parse plist data for a string. Tries biplist, falling back to
plistlib."""

View file

@ -1,32 +0,0 @@
# Copyright (C) 2010-2014 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Windows utility functions."""
def get_shell_folder(name):
"""Get Windows Shell Folder locations from the registry."""
try:
import _winreg as winreg
except ImportError:
import winreg
lm = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
try:
key = winreg.OpenKey(lm, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
try:
return winreg.QueryValueEx(key, name)[0]
finally:
key.Close()
finally:
lm.Close()

View file

@ -33,7 +33,6 @@ per-file-ignores =
linkchecker: E402
setup.py: E402
linkcheck/__init__.py: E402,F401
linkcheck/bookmarks/chrome.py: E402
linkcheck/checker/httpurl.py: E402
linkcheck/htmlutil/htmlsoup.py: E402
linkcheck/parser/__init__.py: E402