Merge pull request #266 from eikenb/master

auto-import's folder as tags uses parent hierarchy
This commit is contained in:
Arun Prakash Jana 2018-05-08 06:54:35 +05:30 committed by GitHub
commit 42429c3f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 218 additions and 28 deletions

12
buku.py
View File

@ -2029,7 +2029,8 @@ class BukuDb:
for item in sublist:
if item['type'] == 'folder':
for i in self.traverse_bm_folder(item['children'], unique_tag, item['name'], add_parent_folder_as_tag):
next_folder_name = folder_name + ',' + item['name']
for i in self.traverse_bm_folder(item['children'], unique_tag, next_folder_name, add_parent_folder_as_tag):
yield (i)
elif item['type'] == 'url':
try:
@ -2110,8 +2111,13 @@ class BukuDb:
if add_parent_folder_as_tag:
# add folder name
res = cur.execute('SELECT title FROM moz_bookmarks WHERE id={}'.format(row[1]))
bookmark_tags.append(res.fetchone()[0])
parent_id = row[1]
while parent_id:
res = cur.execute('SELECT title,parent FROM moz_bookmarks WHERE id={}'.format(parent_id))
parent = res.fetchone()
if parent:
title, parent_id = parent
bookmark_tags.append(title)
if unique_tag:
# add timestamp tag

View File

@ -17,7 +17,7 @@ with open('README.md', encoding='utf-8') as f:
tests_require = [
'pytest-cov', 'hypothesis>=3.7.0', 'py>=1.5.0',
'beautifulsoup4>=4.6.0', 'flake8>=3.4.1', 'pylint>=1.7.2'
'beautifulsoup4>=4.6.0', 'flake8>=3.4.1', 'pylint>=1.7.2', 'PyYAML>=3.12'
]
if sys.version_info.major == 3 and sys.version_info.minor == 6:
tests_require.append('pytest>=3.4.2,!=3.5.0,!=3.5.1')

View File

@ -4,7 +4,6 @@
#
import math
import os
import pickle
import re
import shutil
import sqlite3
@ -20,6 +19,7 @@ from hypothesis import strategies as st
from unittest import mock as mock
import pytest
import unittest
import yaml
from buku import BukuDb, parse_tags, prompt
@ -1240,10 +1240,6 @@ def bookmark_folder(tmpdir):
zip_url = 'https://github.com/jarun/Buku/files/1319933/bookmarks.zip'
tmp_zip = tmpdir.join('bookmarks.zip')
extract_all_from_zip_url(zip_url, tmp_zip, tmpdir)
# expected res
zip_url = 'https://github.com/jarun/Buku/files/1321193/bookmarks_res.zip'
tmp_zip = tmpdir.join('bookmarks_res.zip')
extract_all_from_zip_url(zip_url, tmp_zip, tmpdir)
return tmpdir
@ -1253,11 +1249,10 @@ def chrome_db(bookmark_folder):
tmpdir = bookmark_folder
json_file = [x.strpath for x in tmpdir.listdir() if x.basename == 'Bookmarks'][0]
res_pickle_file = [
x.strpath for x in tmpdir.listdir() if x.basename == '25491522_res.pickle'][0]
res_nopt_pickle_file = [
x.strpath for x in tmpdir.listdir() if x.basename == '25491522_res_nopt.pickle'][0]
return json_file, res_pickle_file, res_nopt_pickle_file
dir_path = os.path.dirname(os.path.realpath(__file__))
res_yaml_file = os.path.join(dir_path, 'test_bukuDb', '25491522_res.yaml')
res_nopt_yaml_file = os.path.join(dir_path, 'test_bukuDb', '25491522_res_nopt.yaml')
return json_file, res_yaml_file, res_nopt_yaml_file
@pytest.mark.parametrize('add_pt', [True, False])
@ -1265,9 +1260,11 @@ def test_load_chrome_database(chrome_db, add_pt):
"""test method."""
# compatibility
json_file = chrome_db[0]
res_pickle_file = chrome_db[1] if add_pt else chrome_db[2]
with open(res_pickle_file, 'rb') as f:
res_pickle = pickle.load(f)
res_yaml_file = chrome_db[1] if add_pt else chrome_db[2]
dump_data = False
if not dump_data:
with open(res_yaml_file, 'r') as f:
res_yaml = yaml.load(f)
# init
import buku
bdb = buku.BukuDb()
@ -1275,7 +1272,12 @@ def test_load_chrome_database(chrome_db, add_pt):
bdb.load_chrome_database(json_file, None, add_pt)
call_args_list_dict = dict(bdb.add_rec.call_args_list)
# test
assert call_args_list_dict == res_pickle
if not dump_data:
assert call_args_list_dict == res_yaml
# dump data for new test
if dump_data:
with open(res_yaml_file, 'w') as f:
yaml.dump(call_args_list_dict, f)
@pytest.fixture()
@ -1284,21 +1286,21 @@ def firefox_db(bookmark_folder):
tmpdir = bookmark_folder
ff_db_path = [x.strpath for x in tmpdir.listdir() if x.basename == 'places.sqlite'][0]
res_pickle_file = [
x.strpath for x in tmpdir.listdir() if x.basename == 'firefox_res.pickle'][0]
res_nopt_pickle_file = [
x.strpath for x in tmpdir.listdir() if x.basename == 'firefox_res_nopt.pickle'][0]
return ff_db_path, res_pickle_file, res_nopt_pickle_file
dir_path = os.path.dirname(os.path.realpath(__file__))
res_yaml_file = os.path.join(dir_path, 'test_bukuDb', 'firefox_res.yaml')
res_nopt_yaml_file = os.path.join(dir_path, 'test_bukuDb', 'firefox_res_nopt.yaml')
return ff_db_path, res_yaml_file, res_nopt_yaml_file
@pytest.mark.parametrize('add_pt', [True, False])
def test_load_firefox_database(firefox_db, add_pt):
# compatibility
ff_db_path = firefox_db[0]
res_pickle_file = firefox_db[1] if add_pt else firefox_db[2]
with open(res_pickle_file, 'rb') as f:
res_pickle = pickle.load(f)
dump_data = False
res_yaml_file = firefox_db[1] if add_pt else firefox_db[2]
if not dump_data:
with open(res_yaml_file, 'r') as f:
res_yaml = yaml.load(f)
# init
import buku
bdb = buku.BukuDb()
@ -1306,7 +1308,11 @@ def test_load_firefox_database(firefox_db, add_pt):
bdb.load_firefox_database(ff_db_path, None, add_pt)
call_args_list_dict = dict(bdb.add_rec.call_args_list)
# test
assert call_args_list_dict == res_pickle
if not dump_data:
assert call_args_list_dict == res_yaml
if dump_data:
with open(res_yaml_file, 'w') as f:
yaml.dump(call_args_list_dict, f)
@pytest.mark.parametrize(

View File

@ -0,0 +1,45 @@
? !!python/tuple ['http://voyagerlive.org/', Voyager, ',bookmarks bar,', null, 0,
true]
: {}
? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website),
',bookmarks bar,imported from firefox,ubuntu and free software links,', null, 0,
true]
: {}
? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',bookmarks
bar,imported from firefox,ubuntu and free software links,', null, 0, true]
: {}
? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',bookmarks bar,imported from
firefox,ubuntu and free software links,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock
Plus, ',bookmarks bar,f+,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview,
',bookmarks bar,f+,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language
Tools, ',bookmarks bar,f+,', null, 0, true]
: {}
? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support
Request to the Ubuntu Community, ',bookmarks bar,imported from firefox,ubuntu
and free software links,', null, 0, true]
: {}
? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that
brings your digital life together, ',bookmarks bar,imported from firefox,ubuntu
and free software links,', null, 0, true]
: {}
? !!python/tuple ['https://www.google.com/', Google, ',other bookmarks,', null, 0,
true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',bookmarks bar,imported
from firefox,mozilla firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',bookmarks
bar,imported from firefox,mozilla firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox,
',bookmarks bar,imported from firefox,mozilla firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials,
',bookmarks bar,imported from firefox,mozilla firefox,', null, 0, true]
: {}

View File

@ -0,0 +1,39 @@
? !!python/tuple ['http://voyagerlive.org/', Voyager, ',', null, 0, true]
: {}
? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website),
',', null, 0, true]
: {}
? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',',
null, 0, true]
: {}
? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock
Plus, ',', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview,
',', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language
Tools, ',', null, 0, true]
: {}
? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support
Request to the Ubuntu Community, ',', null, 0, true]
: {}
? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that
brings your digital life together, ',', null, 0, true]
: {}
? !!python/tuple ['https://www.google.com/', Google, ',', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',', null, 0,
true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',',
null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox,
',', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials,
',', null, 0, true]
: {}

View File

@ -0,0 +1,49 @@
? !!python/tuple ['http://voyagerlive.org/', Voyager, ',bookmarks toolbar,', null,
0, true]
: {}
? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website),
',bookmarks menu,ubuntu and free software links,', null, 0, true]
: {}
? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',bookmarks
menu,ubuntu and free software links,', null, 0, true]
: {}
? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',bookmarks menu,ubuntu and free
software links,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', '',
',language,tags,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock
Plus, ',bookmarks toolbar,f+,language,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview,
',bookmarks toolbar,f+,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', '', ',hello,language,tags,',
null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language
Tools, ',bookmarks toolbar,f+,hello,language,', null, 0, true]
: {}
? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support
Request to the Ubuntu Community, ',bookmarks menu,ubuntu and free software links,',
null, 0, true]
: {}
? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that
brings your digital life together, ',bookmarks menu,ubuntu and free software links,',
null, 0, true]
: {}
? !!python/tuple ['https://www.google.co.in/', '', ',bookmarks menu,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',bookmarks menu,mozilla
firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',bookmarks
menu,mozilla firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox,
',bookmarks menu,mozilla firefox,', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials,
',bookmarks menu,mozilla firefox,', null, 0, true]
: {}

View File

@ -0,0 +1,45 @@
? !!python/tuple ['http://voyagerlive.org/', Voyager, ',', null, 0, true]
: {}
? !!python/tuple ['http://wiki.ubuntu.com/', Ubuntu Wiki (community-edited website),
',', null, 0, true]
: {}
? !!python/tuple ['http://www.debian.org/', Debian (Ubuntu is based on Debian), ',',
null, 0, true]
: {}
? !!python/tuple ['http://www.ubuntu.com/', Ubuntu, ',', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', '',
',language,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/adblock-plus/', Adblock
Plus, ',language,', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/addon/searchpreview/', SearchPreview,
',', null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', '', ',hello,language,',
null, 0, true]
: {}
? !!python/tuple ['https://addons.mozilla.org/fr/firefox/language-tools/', Language
Tools, ',hello,language,', null, 0, true]
: {}
? !!python/tuple ['https://answers.launchpad.net/ubuntu/+addquestion', Make a Support
Request to the Ubuntu Community, ',', null, 0, true]
: {}
? !!python/tuple ['https://one.ubuntu.com/', Ubuntu One - The personal cloud that
brings your digital life together, ',', null, 0, true]
: {}
? !!python/tuple ['https://www.google.co.in/', '', ',', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/about/', About Us, ',', null, 0,
true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/contribute/', Get Involved, ',',
null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/customize/', Customize Firefox,
',', null, 0, true]
: {}
? !!python/tuple ['https://www.mozilla.org/en-US/firefox/help/', Help and Tutorials,
',', null, 0, true]
: {}