~fluidity-core/fluidity/DG_Neumann

« back to all changes in this revision

Viewing changes to libspud/diamond/diamond/datatype.py

  • Committer: Timothy Bond
  • Date: 2011-12-06 11:38:19 UTC
  • mfrom: (3871.1.4 fix-diamond-4.1.1)
  • Revision ID: timothy.bond@imperial.ac.uk-20111206113819-n6utj7qfkerze9ul
This merge supplies:

* An updated version of libspud
* An install target for diamond in the root fluidity makefile
* A target in the root fluidity makefile to install user schemata

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
#    This file is part of Diamond.
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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/>.
 
17
 
 
18
import plist
 
19
 
 
20
def print_type(datatype, bracket = True):
 
21
  """
 
22
  Create a string to be displayed in place of empty data / attributes.
 
23
  """
 
24
 
 
25
  def familiar_type(type_as_printable):
 
26
    """
 
27
    Convert some type names to more familiar equivalents.
 
28
    """
 
29
 
 
30
    if type_as_printable == "decim":
 
31
      return "float"
 
32
    elif type_as_printable == "int":
 
33
      return "integer"
 
34
    elif type_as_printable == "str":
 
35
      return "string"
 
36
    else:
 
37
      return type_as_printable
 
38
 
 
39
  def type_name(datatype):
 
40
    """
 
41
    Return a human readable version of datatype.
 
42
    """
 
43
 
 
44
    datatype_string = str(datatype)
 
45
 
 
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])
 
49
 
 
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])
 
54
    else:
 
55
      return familiar_type(value_type_split2[0])
 
56
 
 
57
  #print_type
 
58
 
 
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()
 
62
    else:
 
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"
 
67
      else:
 
68
        type_as_printable += list_type_as_printable + "s"
 
69
  else:
 
70
    type_as_printable = type_name(datatype).lower()
 
71
 
 
72
  if bracket:
 
73
    type_as_printable = "(" + type_as_printable + ")"
 
74
 
 
75
  return type_as_printable