Project

General

Profile

1
<?php
2
require_once('objects/types.php');
3
require_once('objects/Entity.php');
4
require_once('objects/EntityList.php');
5
require_once('util/utilityFunctions.php');
6

    
7
$files = array(
8
               'eml-access.xsd',
9
               'eml-coverage.xsd',
10
               'eml-documentation.xsd',
11
               'eml-literature.xsd',
12
               'eml-party.xsd',
13
               'eml-project.xsd',
14
               'eml-resource.xsd',
15
               'eml-text.xsd',
16
               'tcsv101.xsd',
17
               'tdwg_basetypes.xsd',
18
#               'tdwg_dw_element.xsd',
19
               'tdwg_dw_geospatial.xsd',
20
               'veg-misc.xsd',
21
               'veg-organismobservation.xsd',
22
               'veg-plotobservation.xsd',
23
               'veg.xsd',
24
               'veg-plot.xsd');
25

    
26

    
27
$eList = new EntityList();
28
foreach($files as $file) {
29
  global $eList;
30

    
31
  $xmlDoc = new DOMDocument();
32
  $xmlDoc->load($file);
33
  $xpath = new DOMXPath($xmlDoc);
34
  $nodes = $xpath->query("child::node()",$xmlDoc->documentElement);
35
  foreach($nodes as $node) {
36
    $nodeName = preg_replace("/.*:/","",$node->nodeName);
37
    if(isIgnoreType($nodeName) || isPrimitiveType($node->getAttribute('name'))) {
38
      continue;
39
    }
40
    switch($nodeName) { 
41
      case 'group':
42
        if(!hasImportantNodes($node)) {
43
          die("Group nodes currently must define an entity. Group node in file: $file does not. Exiting.\n");
44
        }
45
      case 'simpleType':
46
      case 'complexType':
47
        $e = $eList->newEntity($node->getAttribute('name'),$node);
48
        break;
49
      case 'element':
50
        $eName = preg_replace("/\..*$/","",$file);
51
        $eName = preg_replace("/-/","_",$eName);
52
        $eParent = $eList->getEntityForReference($eName);
53

    
54
        $eParent->handleElementCase($node);
55
        break;
56
      default:
57
          die("Unsupported node type: $nodeName found in file: $file.\n");
58
    }
59
  }
60
}
61

    
62
$entities = $eList->getEntities();
63
print "#There are " . count($entities) . " defined entities.\n";
64
print "import string\n";
65
print "import xml.dom.minidom\n";
66
print "from random import choice\n";
67
print "from django.db import models\n\n";
68
print "def getRandom(length=8, chars=string.letters + string.digits):\n".
69
      "  return ''.join([choice(chars) for i in range(length)])\n\n".
70
      "def getRandomString():\n".
71
      "  return getRandom(45)\n\n".
72
      "def getRandomText():\n".
73
      "  return getRandom(450)\n\n".
74
      "def getRandomInt():\n".
75
      "  return int(getRandom(4,string.digits))\n\n".
76
      "def getRandomFloat():\n".
77
      "  return float(getRandom(4,string.digits))\n\n".
78
      "def getRandomBool():\n".
79
      "  return choice(['true','false'])\n\n".
80
      "#Not actually random, but not worth the time\n".
81
      "def getRandomDate():\n".
82
      "  return '2007-07-16'\n\n".
83
      "def getRandomTime():\n".
84
      "  return '08:30:00'\n\n";
85

    
86
$eList->printAll();
87

    
88
?>
89

    
    (1-1/1)