summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-03-02 13:14:38 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-03-02 13:14:38 +0100
commitf3a88b207e5e2c781374127c81c2924062757613 (patch)
treec5a0bb5aae1989488b9b3832c1f69876a103d45c
parent797933d200d597c88f266ada122383925ed455e7 (diff)
kpov_util: better random strings and filenames
Do not use hard-to-distinguish characters, and use shorter names by default.
-rwxr-xr-xkpov_util.py20
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