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.contrib.gis.geos import *\n";
68
print "from django.contrib.gis.db import models\n\n";
69
print "def getRandom(length=8, chars=string.letters + string.digits):\n".
70
      "  return ''.join([choice(chars) for i in range(length)])\n\n".
71
      "def getRandomString():\n".
72
      "  return getRandom(45)\n\n".
73
      "def getRandomText():\n".
74
      "  return getRandom(450)\n\n".
75
      "def getRandomInt():\n".
76
      "  return int(getRandom(4,string.digits))\n\n".
77
      "def getRandomFloat():\n".
78
      "  return float(getRandom(4,string.digits))\n\n".
79
      "def getRandomBool():\n".
80
      "  return choice(['true','false'])\n\n".
81
      "#Not actually random, but not worth the time\n".
82
      "def getRandomDate():\n".
83
      "  return '2007-07-16'\n\n".
84
      "def getRandomTime():\n".
85
      "  return '08:30:00'\n\n".
86
      "class EntryInfo(models.Model):\n".
87
      "  creationDate = models.DateTimeField(auto_now_add=True)\n".
88
      "  lastUpdatedDate = models.DateTimeField(auto_now=True)\n".
89
      "  dataSource = models.CharField(max_length=255, db_index=True)\n\n";
90

    
91
$eList->printAll();
92

    
93
?>
94

    
(9-9/19)