diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-05-10 14:25:31 (GMT) |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-05-10 14:25:31 (GMT) |
commit | 9f203fc1820c2a2d3630b4a8d62036fcaaaa6887 (patch) | |
tree | 0dc1c78f808f728ab0162d21cea60cabb6ed98eb | |
parent | 835bc71f09aa0c56737499fd9e97a265abc46e6b (diff) | |
download | pykolab-9f203fc1820c2a2d3630b4a8d62036fcaaaa6887.tar.gz |
Provide required function for multi-line messages while keeping the source code somewhat clean
-rw-r--r-- | pykolab/utils.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py index 5e32880..6326bf8 100644 --- a/pykolab/utils.py +++ b/pykolab/utils.py @@ -123,6 +123,33 @@ def generate_password(): return output +def multiline_message(message): + _msg = "" + + column_width = 80 + + # First, replace all occurences of "\n" + message = message.replace(" ", "") + message = message.replace("\n", " ") + + lines = [] + line_length = 0 + + line = "" + for word in message.split(): + if (len(line) + len(word)) > column_width: + lines.append(line) + line = word + else: + if line == "": + line = word + else: + line += " %s" % (word) + + lines.append(line) + + return "\n".join(lines) + def normalize(_object): if type(_object) == list: result = [] |