various importer fixes

* Line breaks reinserted
* None in place of ''
* Check for browser before selecting default input format (to fix
KeyError)
* Remove redundant -S option and clarify help to make it slightly more
obvious what output formats make sense
* Added long-form arguments and slightly more sensible names (not really a
fix, but I personally like having them)
This commit is contained in:
Ryan Farley 2017-10-10 20:07:29 -05:00
parent a6ed079011
commit 73c5666ff9

View File

@ -18,13 +18,17 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. # along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Tool to import data from other browsers. """Tool to import data from other browsers.
Currently only importing bookmarks from Netscape Bookmark files is supported. Currently only importing bookmarks from Netscape Bookmark files is supported.
""" """
import argparse import argparse
browser_default_input_format = { browser_default_input_format = {
'chromium': 'netscape', 'chromium': 'netscape',
'ie': 'netscape', 'ie': 'netscape',
@ -37,9 +41,9 @@ browser_default_input_format = {
def main(): def main():
args = get_args() args = get_args()
bookmark_types = [] bookmark_types = []
output_format = '' output_format = None
input_format = args.input_format input_format = args.input_format
if args.search_query or args.search_output: if args.import_search:
bookmark_types = ['search'] bookmark_types = ['search']
if args.oldconfig: if args.oldconfig:
output_format = 'oldsearch' output_format = 'oldsearch'
@ -50,15 +54,18 @@ def main():
output_format = 'bookmark' output_format = 'bookmark'
elif args.quickmark_output: elif args.quickmark_output:
output_format = 'quickmark' output_format = 'quickmark'
if args.bookmark_query: if args.import_bookmarks:
bookmark_types.append('bookmark') bookmark_types.append('bookmark')
if args.keyword_query: if args.import_keywords:
bookmark_types.append('keyword') bookmark_types.append('keyword')
if not bookmark_types: if not bookmark_types:
bookmark_types = ['bookmark', 'keyword'] bookmark_types = ['bookmark', 'keyword']
if not output_format: if not output_format:
output_format = 'quickmark' output_format = 'quickmark'
if not input_format: if not input_format:
if not args.browser:
print("Must specify either browser or input format")
exit(1)
input_format = browser_default_input_format[args.browser] input_format = browser_default_input_format[args.browser]
import_function = {'netscape': import_netscape_bookmarks} import_function = {'netscape': import_netscape_bookmarks}
@ -85,22 +92,22 @@ def get_args():
required=False) required=False)
parser.add_argument( parser.add_argument(
'-b', '-b',
'--bookmark-output',
help="Output in bookmark format.", help="Output in bookmark format.",
dest='bookmark_output',
action='store_true', action='store_true',
default=False, default=False,
required=False) required=False)
parser.add_argument( parser.add_argument(
'-q', '-q',
'--quickmark-output',
help="Output in quickmark format (default).", help="Output in quickmark format (default).",
dest='quickmark_output',
action='store_true', action='store_true',
default=False, default=False,
required=False) required=False)
parser.add_argument( parser.add_argument(
'-s', '-s',
help="Output search engine format", '--search-output',
dest='search_output', help="Output config.py search engine format (negates -B and -K)",
action='store_true', action='store_true',
default=False, default=False,
required=False) required=False)
@ -110,24 +117,17 @@ def get_args():
default=False, default=False,
action='store_true', action='store_true',
required=False) required=False)
parser.add_argument(
'-S',
help="Import search engines",
dest='search_query',
action='store_true',
default=False,
required=False)
parser.add_argument( parser.add_argument(
'-B', '-B',
help="Import plain bookmarks (no keywords)", '--import-bookmarks',
dest='bookmark_query', help="Import plain bookmarks (can be combiend with -K)",
action='store_true', action='store_true',
default=False, default=False,
required=False) required=False)
parser.add_argument( parser.add_argument(
'-K', '-K',
help="Import keywords (no search)", '--import-keywords',
dest='keyword_query', help="Import keywords (can be combined with -B)",
action='store_true', action='store_true',
default=False, default=False,
required=False) required=False)