From dacb5720c51da94706fa6d5fbd89c37e9d2ed560 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Sat, 23 Jul 2016 15:11:14 +0200 Subject: [PATCH] Create hash func for string args to be used cdist wide. --- cdist/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cdist/__init__.py b/cdist/__init__.py index b7436b5a..f58bc15b 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -21,6 +21,7 @@ import os import subprocess +import hashlib import cdist.version @@ -82,3 +83,11 @@ def file_to_list(filename): lines = [] return lines + + +def str_hash(s): + """Return hash of string s""" + if isinstance(s, str): + return hashlib.md5(s.encode('utf-8')).hexdigest() + else: + raise Error("str_hash param should be string")