comparison src/tools/utils.py @ 2181:968b0d13bcc7

plugin account, tools: some cleaning account + email and password tools: - plugin misc account has been reordered and cleaned a bit. - new xmpp_domain setting is used to get the domain name of main XMPP server - password generation method has been moved to tools.utils - email sending method has been moved to tools.email
author Goffi <goffi@goffi.org>
date Sun, 12 Mar 2017 19:32:59 +0100
parents 0931b5a6213c
children 228d208fb5db
comparison
equal deleted inserted replaced
2180:be54e1c3394c 2181:968b0d13bcc7
24 from sat.core.log import getLogger 24 from sat.core.log import getLogger
25 log = getLogger(__name__) 25 log = getLogger(__name__)
26 import datetime 26 import datetime
27 import time 27 import time
28 import sys 28 import sys
29 import random
29 30
30 31
31 def clean_ustr(ustr): 32 def clean_ustr(ustr):
32 """Clean unicode string 33 """Clean unicode string
33 34
52 template_date = u"%Y-%m-%d" 53 template_date = u"%Y-%m-%d"
53 template_time = u"%H:%M:%SZ" 54 template_time = u"%H:%M:%SZ"
54 template = u"{}T{}".format(template_date, template_time) if with_time else template_date 55 template = u"{}T{}".format(template_date, template_time) if with_time else template_date
55 return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template) 56 return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template)
56 57
58 def generatePassword(vocabulary=None, size=20):
59 """Generate a password with random characters.
60
61 @param vocabulary(iterable): characters to use to create password
62 @param size(int): number of characters in the password to generate
63 @return (unicode): generated password
64 """
65 random.seed()
66 if vocabulary is None:
67 vocabulary = [chr(i) for i in range(0x30,0x3A) + range(0x41,0x5B) + range (0x61,0x7B)]
68 return u''.join([random.choice(vocabulary) for i in range(15)])
57 69
58 def getRepositoryData(module, as_string=True, is_path=False, save_dir_path=None): 70 def getRepositoryData(module, as_string=True, is_path=False, save_dir_path=None):
59 """Retrieve info on current mecurial repository 71 """Retrieve info on current mecurial repository
60 72
61 Data is gotten by using the following methods, in order: 73 Data is gotten by using the following methods, in order: