diff options
-rwxr-xr-x | kpov_util.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/kpov_util.py b/kpov_util.py index 8434f85..4acaf79 100755 --- a/kpov_util.py +++ b/kpov_util.py @@ -39,11 +39,17 @@ def ssh_test(host, user, password, commands=()): results['ssh'] = 'connection to {} as {}/{} failed ({})'.format(host, user, password, e) return results -def alnum_gen(r, l=1): - s = "" - for i in range(l): - s += r.choice(string.ascii_letters + string.digits) - return s +# omit i, l, o, I, O, 1, 0 for readability +uppers = 'ABCDEFGHJKLMNPQRSTUVWXYZ' +lowers = 'abcdefghjkmnpqrstuvwxyz' +numbers = '23456789' +def alnum_gen(r, length=1, lower=True, upper=True): + return ''.join( + r.choice( + numbers + + (lowers if lower else '') + + (uppers if upper else '')) + for i in range(length)) def fortune(r, max_len): all_fortunes = [] @@ -112,8 +118,8 @@ def MAC_gen(r): [r.choice(s) + r.choice(s) for i in range(5)]) common_file_extensions = ['jpg', 'png', 'txt', 'doc', 'cfg', 'pdf', 'odt', 'cpp', 'c', 'sh', 'java'] -def fname_gen(r, extension = True): - s = alnum_gen(r, 8) +def fname_gen(r, extension=True): + s = alnum_gen(r, length=5, upper=False) if extension: s += '.' + r.choice(common_file_extensions) return s |