From f1a5cd4b883cf077c30069dfb1ba3507f291e5d8 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Thu, 6 Apr 2017 07:01:27 +0530 Subject: [PATCH] Import folder names in lowercase. Document. --- README.md | 1 + buku.1 | 1 + buku.py | 28 +++++++++++++++------------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d9a5a65..d1a1e63 100644 --- a/README.md +++ b/README.md @@ -243,6 +243,7 @@ SYMBOLS: - Bookmarks with immutable titles are listed with bold `(L)` after the URL. - **Tags**: - Comma (`,`) is the tag delimiter in DB. A tag cannot have comma(s) in it. Tags are filtered (for unique tags) and sorted. Tags are stored in lower case and can be replaced, appended or deleted. + - Folder names are converted to all-lowercase tags during bookmarks html import. - Releases prior to [v2.7](https://github.com/jarun/Buku/releases/tag/v2.7) support both capital and lower cases in tags. From v2.7 all tags are stored in lowercase. An undocumented option `--fixtags` is introduced to modify the older tags. It also fixes another issue where the same tag appears multiple times in the tagset of a record. Run `buku --fixtags` once. - **Update** operation: - If --title, --tag or --comment is passed without argument, clear the corresponding field from DB. diff --git a/buku.1 b/buku.1 index 54d3b0c..94df840 100644 --- a/buku.1 +++ b/buku.1 @@ -42,6 +42,7 @@ Bookmarks with immutable titles are listed with bold '(L)' after the URL. .IP 5. 4 \fBTags\fR: - Comma (',') is the tag delimiter in DB. A tag cannot have comma(s) in it. Tags are filtered (for unique tags) and sorted. Tags are stored in lower case and can be replaced, appended or deleted. + - Folder names are converted to all-lowercase tags during bookmarks html import. - Releases prior to v2.7 support both capital and lower cases in tags. From v2.7 all tags are stored in lowercase. An undocumented option --\fIfixtags\fR is introduced to modify the older tags. It also fixes another issue where the same tag appears multiple times in the tagset of a record. Run \fBbuku --fixtags\fR once. .PP .IP 6. 4 diff --git a/buku.py b/buku.py index 144446d..b3805b8 100755 --- a/buku.py +++ b/buku.py @@ -371,7 +371,7 @@ class BukuDb: return os.path.abspath('.') else: data_home = os.path.join(os.environ.get('HOME'), - '.local', 'share') + '.local', 'share') return os.path.join(data_home, 'buku') @@ -1491,21 +1491,23 @@ class BukuDb: except Exception as e: logerr(e) return False - + html_tags = soup.findAll('a') - resp = input('Add imported folders names as tags? (y/n): ') - if resp == 'y' : - for tag in html_tags : - possible_folder = tag.find_previous('h3') # could be its folder or not - tag_list = tag.parent.parent.find_parent('dl') # get list of tags within that folder - - if (possible_folder) and possible_folder.parent in list(tag_list.parents): + if resp == 'y': + for tag in html_tags: + # could be its folder or not + possible_folder = tag.find_previous('h3') + # get list of tags within that folder + tag_list = tag.parent.parent.find_parent('dl') + + if ((possible_folder) and + possible_folder.parent in list(tag_list.parents)): # then it's the folder of this bookmark - if tag.has_attr('tags') : - tag['tags'] += (DELIMITER + possible_folder.text) - else : + if tag.has_attr('tags'): + tag['tags'] += (DELIM + possible_folder.text) + else: tag['tags'] = possible_folder.text for tag in html_tags: @@ -1515,7 +1517,7 @@ class BukuDb: if comment_tag: desc = comment_tag.text[0:comment_tag.text.find('\n')] - self.add_rec(tag['href'], tag.string, delim_wrap(tag['tags']) + self.add_rec(tag['href'], tag.string, parse_tags([tag['tags']]) if tag.has_attr('tags') else None, desc, 0, True) self.conn.commit()