diff --git a/linkcheck/bookmarks/chrome.py b/linkcheck/bookmarks/chrome.py deleted file mode 100644 index e05b0e6c..00000000 --- a/linkcheck/bookmarks/chrome.py +++ /dev/null @@ -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 diff --git a/linkcheck/bookmarks/chromium.py b/linkcheck/bookmarks/chromium.py index 95cc39a2..4a4bf026 100644 --- a/linkcheck/bookmarks/chromium.py +++ b/linkcheck/bookmarks/chromium.py @@ -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(): diff --git a/linkcheck/bookmarks/firefox.py b/linkcheck/bookmarks/firefox.py index 692220de..a6eb5e02 100644 --- a/linkcheck/bookmarks/firefox.py +++ b/linkcheck/bookmarks/firefox.py @@ -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. diff --git a/linkcheck/bookmarks/opera.py b/linkcheck/bookmarks/opera.py index 5fc8eb21..a0517325 100644 --- a/linkcheck/bookmarks/opera.py +++ b/linkcheck/bookmarks/opera.py @@ -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): diff --git a/linkcheck/bookmarks/safari.py b/linkcheck/bookmarks/safari.py index 8fa7272d..bbfe6431 100644 --- a/linkcheck/bookmarks/safari.py +++ b/linkcheck/bookmarks/safari.py @@ -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.""" diff --git a/linkcheck/winutil.py b/linkcheck/winutil.py deleted file mode 100644 index 63d5d3e3..00000000 --- a/linkcheck/winutil.py +++ /dev/null @@ -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() diff --git a/setup.cfg b/setup.cfg index 328d1896..1faca06b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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