-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathparser_data_types.py
77 lines (58 loc) · 2.14 KB
/
parser_data_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import argparse
import os
from smallfile import SmallfileWorkload
TypeExc = argparse.ArgumentTypeError
# if we throw exceptions, do it with this
# so caller can specifically catch them
class SmfParseException(Exception):
pass
# the next few routines implement data types
# of smallfile parameters
def boolean(boolstr):
if isinstance(boolstr, bool):
return boolstr
b = boolstr.lower()
if b == "y" or b == "yes" or b == "t" or b == "true":
bval = True
elif b == "n" or b == "no" or b == "f" or b == "false":
bval = False
else:
raise TypeExc("boolean value must be y|yes|t|true|n|no|f|false")
return bval
def positive_integer(posint_str):
intval = int(posint_str)
if intval <= 0:
raise TypeExc("integer value greater than zero expected")
return intval
def non_negative_integer(nonneg_str):
intval = int(nonneg_str)
if intval < 0:
raise TypeExc("non-negative integer value expected")
return intval
def host_set(hostname_list_str):
if os.path.isfile(hostname_list_str):
with open(hostname_list_str, "r") as f:
hostname_list = [record.strip() for record in f.readlines()]
else:
hostname_list = hostname_list_str.strip().split(",")
if len(hostname_list) < 2:
hostname_list = hostname_list_str.strip().split()
if len(hostname_list) == 0:
raise TypeExc("host list must be non-empty")
return hostname_list
def directory_list(directory_list_str):
directory_list = directory_list_str.strip().split(",")
if len(directory_list) == 1:
directory_list = directory_list_str.strip().split()
if len(directory_list) == 0:
raise TypeExc("directory list must be non-empty")
return directory_list
def file_size_distrib(fsdistrib_str):
# FIXME: should be a data type
if fsdistrib_str == "exponential":
return SmallfileWorkload.fsdistr_random_exponential
elif fsdistrib_str == "fixed":
return SmallfileWorkload.fsdistr_fixed
else:
# should never get here
raise TypeExc('file size distribution must be either "exponential" or "fixed"')