3
# This file is part of Diamond.
5
# Diamond is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# Diamond is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with Diamond. If not, see <http://www.gnu.org/licenses/>.
20
def print_type(datatype, bracket = True):
22
Create a string to be displayed in place of empty data / attributes.
25
def familiar_type(type_as_printable):
27
Convert some type names to more familiar equivalents.
30
if type_as_printable == "decim":
32
elif type_as_printable == "int":
34
elif type_as_printable == "str":
37
return type_as_printable
39
def type_name(datatype):
41
Return a human readable version of datatype.
44
datatype_string = str(datatype)
46
if datatype_string[:7] == "<type '" and datatype_string[len(datatype_string) - 2:] == "'>":
47
value_type_split = datatype_string.split("'")
48
return familiar_type(value_type_split[1])
50
value_type_split1 = datatype_string.split(".")
51
value_type_split2 = value_type_split1[len(value_type_split1) - 1].split(" ")
52
if len(value_type_split2) == 1:
53
return familiar_type(value_type_split2[0][0:len(value_type_split2[0]) - 6])
55
return familiar_type(value_type_split2[0])
59
if isinstance(datatype, plist.List):
60
if (isinstance(datatype.cardinality, int) and datatype.cardinality == 1) or datatype.cardinality == "":
61
type_as_printable = type_name(datatype.datatype).lower()
63
type_as_printable = type_name(datatype).lower() + " of "
64
list_type_as_printable = type_name(datatype.datatype).lower()
65
if isinstance(datatype.cardinality, int):
66
type_as_printable += str(datatype.cardinality) + " " + list_type_as_printable + "s"
68
type_as_printable += list_type_as_printable + "s"
70
type_as_printable = type_name(datatype).lower()
73
type_as_printable = "(" + type_as_printable + ")"
75
return type_as_printable