summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chase <philipbchase@gmail.com>2014-03-20 02:25:45 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2014-03-20 02:25:45 -0600
commit2bac6dd4bdc7f666057df1943d80d7c0cf31efd8 (patch)
treefe0f5158a17ce16f95af0c9080dbf6b0cef02a42
parent60c8957c84a8f70ddc549dc614b6d35981cb1291 (diff)
downloadpass-2bac6dd4bdc7f666057df1943d80d7c0cf31efd8.tar.gz
pass-2bac6dd4bdc7f666057df1943d80d7c0cf31efd8.tar.bz2
pass-2bac6dd4bdc7f666057df1943d80d7c0cf31efd8.zip
keepassx2pass: friendly title field
This patch removes several special characters while attempting to preserve as much meaning in the filename as possible. These changes are made to the KeepassX title before it is used as a file password store filename: - Spaces between words in file names are replaced with camelCasing. - The characters \ | ( ) are each replaced with a hyphen. - Trailing hypens are removed. - @ is replaced with "At" - ' is removed
Diffstat (limited to '')
-rwxr-xr-xcontrib/keepassx2pass.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/contrib/keepassx2pass.py b/contrib/keepassx2pass.py
index 1804e33..dc4b1e5 100755
--- a/contrib/keepassx2pass.py
+++ b/contrib/keepassx2pass.py
@@ -5,13 +5,36 @@
# This file is licensed under the GPLv2+. Please see COPYING for more information.
import sys
+import re
from subprocess import Popen, PIPE
from xml.etree import ElementTree
+def space_to_camelcase(value):
+ output = ""
+ first_word_passed = False
+ for word in value.split(" "):
+ if not word:
+ output += "_"
+ continue
+ if first_word_passed:
+ output += word.capitalize()
+ else:
+ output += word.lower()
+ first_word_passed = True
+ return output
+
+def cleanTitle(title):
+ # make the title more command line friendly
+ title = re.sub("(\\|\||\(|\))", "-", title)
+ title = re.sub("-$", "", title)
+ title = re.sub("\@", "At", title)
+ title = re.sub("'", "", title)
+ return title
+
def path_for(element, path=''):
""" Generate path name from elements title and current path """
- title = element.find('title').text.replace("/", "|")
+ title = cleanTitle(space_to_camelcase(element.find('title').text))
return '/'.join([path, title])
def password_data(element):