Skip to content
Snippets Groups Projects
Commit 2bac6dd4 authored by Philip Chase's avatar Philip Chase Committed by Jason A. Donenfeld
Browse files

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
parent 60c8957c
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment