mpdot/linkcheck.py
author Michel Szarindar <Michel.Szarindar@Nokia.com>
Fri, 23 Apr 2010 20:47:58 +0100
changeset 3 d8fccb2cd802
parent 2 932c358ece3e
permissions -rw-r--r--
Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     1
# Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     2
# This component and the accompanying materials are made available under the terms of the License 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     3
# "Eclipse Public License v1.0" which accompanies this distribution, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     4
# and is available at the URL "http://www.eclipse.org/legal/epl-v10.html".
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     5
#
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     6
# Initial Contributors:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     7
# Nokia Corporation - initial contribution.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     8
#
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
     9
# Contributors:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    10
#
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    11
# Description:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    12
# Checks links in DITA XML and reports issues.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    13
"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    14
Created on 12 Feb 2010
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    15
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    16
@author: p2ross
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    17
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    18
Definitions
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    19
===========
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    20
Doctype
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    21
-------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    22
See: http://www.w3.org/TR/2008/REC-xml-20081126/#dt-root
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    23
Note: this is sometimes called the Doctype because of http://www.w3.org/TR/2008/REC-xml-20081126/#vc-roottype
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    24
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    25
ID
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    26
--
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    27
The value of the 'id' attribute of an element.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    28
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    29
Root ID
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    30
-------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    31
The value of the 'id' attribute of the root element.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    32
Note: A development would allow differently named attributes provided that they
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    33
were ID types. See http://www.w3.org/TR/2008/REC-xml-20081126/#sec-attribute-types
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    34
for validity constraints for ID types.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    35
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    36
Reference
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    37
---------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    38
The value of the href attribute of an element.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    39
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    40
Map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    41
---
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    42
An XML file whose root element name is 'map' or ends with 'Map'.   
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    43
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    44
Topic
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    45
-----
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    46
An XML file that is not a Map.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    47
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    48
Lonely topic
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    49
------------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    50
A topic whose root ID is not referenced by any map. 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    51
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    52
Lonely map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    53
----------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    54
A map whose root ID is not referenced by any map. 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    55
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    56
Map Cycle
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    57
---------
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    58
A sequence of map references whose members are not unique.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    59
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    60
"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    61
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    62
import os
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    63
import unittest
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    64
import sys
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    65
import logging
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    66
import pprint
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    67
import fnmatch
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    68
import re
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    69
import urllib
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    70
import time
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    71
from optparse import OptionParser, check_choice
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    72
try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    73
    from xml.etree import cElementTree as etree
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    74
except ImportError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    75
    from xml.etree import ElementTree as etree
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    76
import urlparse
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    77
import multiprocessing
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    78
# used for DitaFileObj persistence
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    79
import shelve
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    80
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    81
__version__ = '0.1.5'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    82
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    83
class ExceptionLinkCheck(Exception):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    84
    pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    85
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    86
class CountDict(dict):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    87
    """Dictionary with a default value of 0 for unknown keys."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    88
    def __getitem__(self, key):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    89
        if key not in self: 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    90
            self[key] = 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    91
        return self.get(key)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    92
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    93
# Matches stuff like: GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    94
RE_GUID = re.compile(r'GUID-[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}', re.IGNORECASE)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    95
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    96
# Of the form {integer_error_code : (format_string, num_args), ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    97
PROBLEM_CODE_FORMAT = {
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    98
    # 'id_syntax'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
    99
    100 : ('Character \'#\' not allowed in id="%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   100
    101 : ('NMTOKEN character \'%s\' not allowed in id="%s"', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   101
    102 : ('GUID specification does not match id="%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   102
    # 'ref_syntax'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   103
    200 : ('Multiple \'#\' not allowed in reference "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   104
    201 : ('Reference element "%s" is missing href=... attribute', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   105
    202 : ('URL has missing type/format in reference "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   106
    203 : ('GUID specification does not match file reference "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   107
    204 : ('GUID specification does not match fragment reference "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   108
    # 'ref'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   109
    300 : ('Can not resolve URI "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   110
    # 'file'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   111
    400 : ('Failed to open: "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   112
    401 : ('Multiple id="%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   113
    402 : ('No id attribute on root element', 0),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   114
    403 : ('Root ID in cycle: %s', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   115
    404 : ('Can not parse: "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   116
    410 : ('Can not resolve reference to file "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   117
    411 : ('Can resolve reference to file "%s" but not to fragment "%s"', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   118
    412 : ('Referencing element "%s" does not match target root element "%s"', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   119
    413 : ('Referencing element "%s" does not match target element "%s" for id="%s"', 3),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   120
    414 : ('topicref element with format="ditamap" does not match target root element "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   121
    415 : ('topicref to <map> does not have format="ditamap" but format="%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   122
    416 : ('topicref element type="%s" does not match target root element "%s"', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   123
    417 : ('topicref element type="%s" does not match target element "%s" for id="%s"', 3),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   124
    418 : ('Unknown referencing element "%s" does not match target root element "%s"', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   125
    419 : ('Unknown referencing element "%s" does not match target element "%s" for id="%s"', 3),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   126
    # 'file_set'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   127
    500 : ('Not a directory: %s', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   128
    501 : ('Duplicate root id="%s" in files: %s', 2), 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   129
    #502 : ('Can not resolve reference to "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   130
    #503 : ('Reference type "%s" does not match target type "%s" for id="%s"', 3),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   131
    504 : ('Duplicate file path: "%s"', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   132
    505 : ('Duplicate id="%s" in files: %s', 2),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   133
    # 'topic_set'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   134
    600 : ('Topic id="%s" is not referenced by any map', 1), 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   135
    # 'map_set'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   136
    700 : ('More than one top level map exists: %s', 1),  
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   137
    701 : ('Maps "%s" are in a a cycle.', 1),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   138
}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   139
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   140
GENERIC_STRING = '...'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   141
PRINT_WIDTH = 75
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   142
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   143
def genericStringForErrorCode(ec):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   144
    assert(PROBLEM_CODE_FORMAT.has_key(ec))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   145
    f, c = PROBLEM_CODE_FORMAT[ec]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   146
    if c == 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   147
        return f
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   148
    return f % ((GENERIC_STRING,) * c)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   149
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   150
def writeGenericStringsForErrorCodes(s=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   151
    s.write(' All Error Codes '.center(PRINT_WIDTH, '='))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   152
    s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   153
    s.write('%4s  %s\n' % ('Code', 'Error'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   154
    s.write('%4s  %s\n' % ('----', '-----'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   155
    ecS = PROBLEM_CODE_FORMAT.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   156
    ecS.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   157
    for ec in ecS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   158
        s.write('%4d  %s\n' % (ec, genericStringForErrorCode(ec)))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   159
    s.write('='*PRINT_WIDTH)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   160
    s.write('\n\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   161
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   162
def normalisePath(thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   163
    # TODO: How come this does not work?
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   164
    #return os.path.abspath(thePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   165
    return os.path.abspath(thePath).replace('\\', '/')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   166
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   167
FNMATCH_PATTERNS = ['*.xml', '*.dita', '*.ditamap']
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   168
FNMATCH_STRING = ' '.join(FNMATCH_PATTERNS)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   169
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   170
# These elements descend from topic/xref so can be treated as referencing elements
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   171
XREF_DESCENDENTS = set(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   172
    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   173
        # From the api specialisation
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   174
        'apiRelation',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   175
        'apiBaseClassifier',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   176
        'apiOtherClassifier',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   177
        'apiOperationClassifier',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   178
        'apiValueClassifier',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   179
        # From the C++ specialisation
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   180
        'cxxfile',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   181
        'cxxclass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   182
        'cxxstruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   183
        'cxxunion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   184
        'cxxfunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   185
        'cxxdefine',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   186
        'cxxtypedef',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   187
        'cxxvariable',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   188
        'cxxenumeration',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   189
        'cxxClassBaseClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   190
        'cxxClassBaseStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   191
        'cxxClassBaseUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   192
        'cxxClassNestedClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   193
        'cxxClassNestedStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   194
        'cxxClassNestedUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   195
        'cxxClassEnumerationInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   196
        'cxxClassEnumeratorInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   197
        'cxxClassFunctionInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   198
        'cxxClassVariableInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   199
        'cxxDefineReimplemented',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   200
        'cxxEnumerationReimplemented',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   201
        'cxxFunctionReimplemented',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   202
        'cxxStructBaseClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   203
        'cxxStructBaseStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   204
        'cxxStructBaseUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   205
        'cxxStructNestedClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   206
        'cxxStructNestedStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   207
        'cxxStructNestedUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   208
        'cxxStructEnumerationInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   209
        'cxxStructEnumeratorInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   210
        'cxxStructFunctionInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   211
        'cxxStructVariableInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   212
        'cxxTypedefReimplemented',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   213
        'cxxUnionBaseClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   214
        'cxxUnionBaseStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   215
        'cxxUnionBaseUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   216
        'cxxUnionNestedClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   217
        'cxxUnionNestedStruct',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   218
        'cxxUnionNestedUnion',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   219
        'cxxUnionEnumerationInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   220
        'cxxUnionFunctionInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   221
        'cxxUnionVariableInherited',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   222
        'cxxVariableReimplemented',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   223
    )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   224
)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   225
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   226
class UrlAccessCache(object):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   227
    def __init__(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   228
        # {URL : True/False, ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   229
        self._cache = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   230
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   231
    def clear(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   232
        self._cache = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   233
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   234
    def canAccess(self, theUrl):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   235
        if not self._cache.has_key(theUrl):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   236
            try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   237
                u = urllib.urlopen(theUrl)#, data, proxies)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   238
                u.read()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   239
                self._cache[theUrl] = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   240
                logging.debug('URL: %s  for %s' % (True, theUrl))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   241
            except IOError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   242
                self._cache[theUrl] = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   243
                logging.debug('URL: %s for %s' % (False, theUrl))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   244
        return self._cache[theUrl]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   245
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   246
GlobalUrlCache = UrlAccessCache()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   247
 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   248
class DitaLinkCheckBase(object):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   249
    """Base class that holds some common functionality."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   250
    def __init__(self, theIdentity):#=None):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   251
        self.__identity = theIdentity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   252
        # Set of error strings, lazily evaluated
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   253
        self._errS = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   254
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   255
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   256
    def identity(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   257
        return self.__identity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   258
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   259
    def __cmp__(self, other):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   260
        assert(self.identity is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   261
        assert(other.identity is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   262
        return cmp(self.identity, other.identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   263
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   264
    def __eq__(self, other):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   265
        assert(self.identity is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   266
        assert(other.identity is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   267
        return self.identity == other.identity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   268
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   269
    def __hash__(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   270
        assert(self.identity is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   271
        return hash(self.identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   272
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   273
    def __str__(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   274
        return str(self.__identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   275
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   276
    def debugDump(self, s=sys.stdout, prefix=''):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   277
        """Dump of IR for debug purposes."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   278
        raise NotImplementedError
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   279
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   280
    def addError(self, errCode, argTuple):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   281
        assert(errCode in PROBLEM_CODE_FORMAT.keys()), 'No error code: %s' % errCode
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   282
        assert(PROBLEM_CODE_FORMAT[errCode][1] == len(argTuple)), \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   283
            'Length missmatch for error code %d: %d != %d for %s' \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   284
            % (errCode, PROBLEM_CODE_FORMAT[errCode][1], len(argTuple), str(argTuple))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   285
        if self._errS is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   286
            self._errS = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   287
        try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   288
            self._errS[errCode].add(argTuple)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   289
        except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   290
            self._errS[errCode] = set((argTuple,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   291
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   292
    def errStrings(self, generic, theFilter):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   293
        """Return a sorted list of error messages without duplicates."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   294
        if self._errS is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   295
            mySet = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   296
            for ec in self._errS.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   297
                if theFilter is None or ec in theFilter:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   298
                    assert(ec in PROBLEM_CODE_FORMAT.keys())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   299
                    for tu in self._errS[ec]:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   300
                        if generic:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   301
                            mySet.add(genericStringForErrorCode(ec))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   302
                        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   303
                            f, c = PROBLEM_CODE_FORMAT[ec]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   304
                            assert(len(tu) == c)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   305
                            mySet.add(f % tu)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   306
            l = list(mySet)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   307
            l.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   308
            return l
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   309
        return []
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   310
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   311
    def updateErrorCount(self, theMap):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   312
        """Updates a map of {error_code, : count, ...}.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   313
        Overridden for file and file set."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   314
        if self._errS is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   315
            for e in self._errS.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   316
                theMap[e] += len(self._errS[e])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   317
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   318
    def writeErrors(self, isGeneric, theFilter, theStream=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   319
        """Can be overridden in child classes to recurse into
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   320
        their data structures."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   321
        theStream.write('\n'.join(self.errStrings(isGeneric, theFilter)))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   322
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   323
class DitaId(DitaLinkCheckBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   324
    """Represents a node with an id."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   325
    def __init__(self, theN):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   326
        assert(theN.get('id', None) is not None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   327
        super(DitaId, self).__init__(theN.get('id', None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   328
        self._elem = theN.tag
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   329
        if '#' in self.id:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   330
            self.addError(100, (self.id,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   331
        # TODO: NMTOKENS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   332
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   333
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   334
    def elem(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   335
        return self._elem
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   336
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   337
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   338
    def id(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   339
        return self.identity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   340
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   341
    def checkGuid(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   342
        """optionally applies additional checks for GUID requirements."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   343
        if RE_GUID.match(self.id) is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   344
            self.addError(102, (self.id,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   345
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   346
    def debugDump(self, s=sys.stdout, prefix=''):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   347
        """Dump of IR for debug purposes."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   348
        s.write('%sID:  <%s id="%s" />\n' % (prefix, self.elem, self.id))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   349
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   350
class DitaRef(DitaLinkCheckBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   351
    """Represents a reference node."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   352
    def __init__(self, theN):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   353
        self._elem = theN.tag
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   354
        self._href = theN.get('href', None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   355
        super(DitaRef, self).__init__('%s %s' % (self._elem, self._href))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   356
        # This is used when figuring out of the target is the correct element
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   357
        # e.g. in Vanilla DITA
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   358
        # <topicref href="batcaring.dita" type="task"></topicref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   359
        self._refType = theN.get('type', None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   360
        # Format attribute, this can be format="ditamap"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   361
        self._format = theN.get('format', None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   362
        if self._href is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   363
            self.addError(201, (self._elem,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   364
            self._url = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   365
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   366
            self._url = urlparse.urlparse(self._href)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   367
            if '#' in self._url.fragment:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   368
                self.addError(200, (self._href,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   369
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   370
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   371
    def elem(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   372
        return self._elem
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   373
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   374
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   375
    def href(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   376
        """The value of the href attribute."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   377
        return self._href
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   378
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   379
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   380
    def refType(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   381
        """The value of the type attribute."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   382
        return self._refType
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   383
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   384
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   385
    def format(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   386
        """The value of the format attribute."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   387
        return self._format
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   388
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   389
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   390
    def path(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   391
        """The value of the path part of the href attribute."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   392
        return self._url.path
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   393
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   394
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   395
    def fragment(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   396
        """The value of the fragment part of the href attribute."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   397
        return self._url.fragment
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   398
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   399
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   400
    def scheme(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   401
        """The URI scheme e.g. 'http' or '' if no scheme."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   402
        return self._url.scheme
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   403
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   404
    def fileFragment(self, theRefFile):                               
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   405
        """The absolute path of the file and the fragment identifier or (None, None)."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   406
        if self.scheme not in ('', 'file'):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   407
            return (None, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   408
        if len(self.path) == 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   409
            myPath = theRefFile
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   410
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   411
            myPath = os.path.join(os.path.dirname(theRefFile), self.path)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   412
        return normalisePath(myPath), self.fragment
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   413
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   414
    def checkGuid(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   415
        """optionally applies additional checks for GUID requirements."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   416
        if RE_GUID.match(self.path) is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   417
            self.addError(203, (self.path,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   418
        if RE_GUID.match(self.fragment) is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   419
            self.addError(204, (self.fragment,))                
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   420
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   421
    def checkUrl(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   422
        if self.scheme:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   423
            myU = urlparse.urlunparse(self._url)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   424
            if not GlobalUrlCache.canAccess(myU):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   425
                self.addError(300, (myU,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   426
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   427
    def debugDump(self, s=sys.stdout, prefix=''):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   428
        """Dump of IR for debug purposes."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   429
        s.write('%sREF: <%s href="%s" />\n' % (prefix, self.elem, self._href))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   430
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   431
class DitaFileObj(DitaLinkCheckBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   432
    """Base class for a DITA topic or map."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   433
    def __init__(self, theFileObj, theFileName=None):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   434
        """Initialiser with a file object and a file path"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   435
        #print '\nDitaFileObj(%s, %s)' % (theFileObj, theFileName)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   436
        if theFileName is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   437
            super(DitaFileObj, self).__init__(normalisePath(theFileName))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   438
        elif theFileObj is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   439
            super(DitaFileObj, self).__init__(theFileObj.name)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   440
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   441
            super(DitaFileObj, self).__init__(None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   442
        self._rootId = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   443
        self._doctype = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   444
        # Sets of class DitaId
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   445
        self._idS = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   446
        self._dupeIdS = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   447
        # Set of class DitaRef
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   448
        self._xrefS = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   449
        # Ouptut control
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   450
        self._hasWritten = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   451
        # Size of input
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   452
        try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   453
            self._bytes = os.path.getsize(theFileName)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   454
        except Exception:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   455
            # Try as if a StringIO
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   456
            try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   457
                self._bytes = theFileObj.len
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   458
            except AttributeError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   459
                # Give up
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   460
                self._bytes = 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   461
        # Process the file object
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   462
        if theFileObj is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   463
            try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   464
                # TODO: use iterparse?
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   465
                theTree = etree.parse(theFileObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   466
            except SyntaxError, err:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   467
                self.addError(404, (str(err),))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   468
            else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   469
                # Walk the tree
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   470
                for i, e in enumerate(theTree.getiterator()):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   471
                    #print 'TRACE: e', e
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   472
                    # Element [0] is the root element
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   473
                    if i == 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   474
                        assert(self._rootId is None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   475
                        assert(self._doctype is None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   476
                        self._doctype = e.tag
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   477
                        if e.get('id', None) is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   478
                            self._rootId = DitaId(e)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   479
                            self._addId(self._rootId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   480
                        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   481
                            self.addError(402, ())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   482
                    else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   483
                        # NOTE: Elements with id attributes can also have href
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   484
                        # attributes. For example a <topicref> in a <bookmap>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   485
                        # Thus these tests are not exclusive
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   486
                        if e.get('id', None) is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   487
                            self._addId(DitaId(e))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   488
                        if e.get('href', None) is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   489
                            # TODO: Do we limit ourselves to only a certain set of elements?
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   490
                            self._xrefS.add(DitaRef(e))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   491
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   492
            self.addError(400, (self.identity,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   493
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   494
    def _addId(self, theId):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   495
        #print 'TRACE: adding %s' % theId
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   496
        #print 'TRACE: self._idS %s' % self._idS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   497
        if theId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   498
            # Remove from self._idS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   499
            #print 'TRACE: removing %s' % theId
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   500
            self._idS.remove(theId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   501
            self._dupeIdS.add(theId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   502
            self.addError(401, (theId.identity,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   503
        elif theId not in self._dupeIdS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   504
            self._idS.add(theId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   505
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   506
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   507
    def bytes(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   508
        return self._bytes
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   509
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   510
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   511
    def doctype(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   512
        return self._doctype
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   513
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   514
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   515
    def rootId(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   516
        if self._rootId is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   517
            return self._rootId.id
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   518
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   519
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   520
    def isMap(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   521
        return self.doctype == "map" \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   522
        or self.doctype == 'bookmap' \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   523
        or (self.doctype is not None and self.doctype.endswith('Map'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   524
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   525
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   526
    def idS(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   527
        """The set of IDs."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   528
        return self._idS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   529
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   530
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   531
    def refS(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   532
        """The set of DitaRef objects."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   533
        return self._xrefS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   534
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   535
    def idElemMap(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   536
        """Returns a map {id : elem name, ...}."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   537
        retVal = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   538
        for anId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   539
            retVal[anId.id] = anId.elem
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   540
        return retVal
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   541
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   542
    def hasId(self, theString):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   543
        for anId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   544
            if theString == anId.id:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   545
                return True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   546
        return False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   547
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   548
    def idElem(self, theString):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   549
        for anId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   550
            if theString == anId.id:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   551
                return anId.elem
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   552
        return None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   553
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   554
    def idObj(self, theString):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   555
        for anId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   556
            if theString == anId.id:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   557
                return anId
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   558
        return None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   559
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   560
    def updateErrorCount(self, theMap):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   561
        """Updates a map of {error_code, : count, ...}."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   562
        if self._errS is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   563
            for e in self._errS.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   564
                theMap[e] += len(self._errS[e])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   565
        for idObj in self.idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   566
            idObj.updateErrorCount(theMap)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   567
        for refObj in self.refS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   568
            refObj.updateErrorCount(theMap)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   569
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   570
    def writeErrorList(self, theList, theSubHead='', theS=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   571
        if len(theList) > 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   572
            theList.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   573
            if not self._hasWritten:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   574
                theS.write('File: %s\n' % self.identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   575
            self._hasWritten = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   576
            if len(theSubHead) > 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   577
                theS.write('%s [%d]:\n' % (theSubHead, len(theList)))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   578
            theS.write('\n'.join(theList))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   579
            theS.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   580
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   581
    def writeErrors(self, isGeneric, theFilter, theStream=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   582
        """Writes out errors for me, my IDs and my Refs."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   583
        self._hasWritten = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   584
        self.writeErrorList(self.errStrings(isGeneric, theFilter), 'File errors:', theStream)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   585
#===============================================================================
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   586
#        # Duplicate IDs
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   587
#        myList = (list(self._dupeIdS))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   588
#        if len(myList):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   589
#            self.writeErrorList(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   590
#                    [i.identity for i in myList],
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   591
#                    'Duplicate ID',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   592
#                    theStream)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   593
#===============================================================================
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   594
        # Now IDs
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   595
        myList = (list(self.idS))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   596
        myList.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   597
        for anId in myList:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   598
            self.writeErrorList(anId.errStrings(isGeneric, theFilter), 'ID=%s' % anId.identity, theStream)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   599
        # Now Refs
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   600
        myList = (list(self._xrefS))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   601
        myList.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   602
        for anId in myList:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   603
            self.writeErrorList(anId.errStrings(isGeneric, theFilter), 'Ref=%s' % anId.identity, theStream)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   604
        if self._hasWritten:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   605
            theStream.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   606
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   607
    def debugDump(self, s=sys.stdout, prefix=''):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   608
        """Dump of IR for debug purposes."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   609
        s.write('%sFile: %s\n' % (prefix, self.identity))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   610
        for anId in self._idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   611
            anId.debugDump(s, prefix=prefix+'  ')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   612
        for aRef in self._xrefS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   613
            aRef.debugDump(s, prefix=prefix+'  ')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   614
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   615
class DitaFilePath(DitaFileObj):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   616
    """Base class for a DITA topic or map from the file system."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   617
    def __init__(self, theFilePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   618
        """Initialiser with a file path"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   619
        try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   620
            f = open(theFilePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   621
        except IOError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   622
            f = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   623
        #print 'DitaFilePath(%s)' % theFilePath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   624
        super(DitaFilePath, self).__init__(f, theFilePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   625
        if f is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   626
            self.addError(400, (theFilePath,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   627
            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   628
            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   629
class DitaFileMapBase(object):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   630
    """Base class for holding a map of {file path : class DitaFile, ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   631
    Actual implementation can be in-memory or via a database e.g. the
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   632
    shelve module."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   633
    def keys(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   634
        """Returns an unsorted list of keys in the map."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   635
        raise NotImplementedError()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   636
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   637
    def has_key(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   638
        """Return True if the key exists."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   639
        raise NotImplementedError()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   640
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   641
    def remove(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   642
        """Remove the entry corresponding to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   643
        raise NotImplementedError()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   644
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   645
    def getDitaFileObj(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   646
        """Return a DitaFileObj that corresponds to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   647
        raise NotImplementedError()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   648
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   649
    def setDitaFileObj(self, thePath, theObj):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   650
        """Load a DitaFileObj or update a mutated DitaFileObj."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   651
        raise NotImplementedError()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   652
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   653
class DitaFileMapInMemory(DitaFileMapBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   654
    """Holds map of {file path : class DitaFile, ...} in memory."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   655
    def __init__(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   656
        # Map of {file path : class DitaFile, ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   657
        self._fileMap = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   658
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   659
    def keys(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   660
        """Returns an unsorted list of keys in the map."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   661
        return self._fileMap.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   662
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   663
    def has_key(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   664
        """Return True if the key exists."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   665
        return self._fileMap.has_key(thePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   666
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   667
    def remove(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   668
        """Remove the entry corresponding to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   669
        del self._fileMap[thePath]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   670
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   671
    def getDitaFileObj(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   672
        """Return a DitaFileObj that corresponds to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   673
        return self._fileMap[thePath]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   674
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   675
    def setDitaFileObj(self, thePath, theObj):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   676
        """Load a DitaFileObj or update a mutated DitaFileObj."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   677
        self._fileMap[thePath] = theObj
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   678
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   679
class DitaFileMapShelve(DitaFileMapBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   680
    """Holds map of {file path : class DitaFile, ...} in a shelve database."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   681
    DBASE_FILENAME = 'linkchecker.dbase'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   682
    def __init__(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   683
        if os.path.exists(self.DBASE_FILENAME):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   684
            os.remove(self.DBASE_FILENAME)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   685
        self._db = shelve.open(self.DBASE_FILENAME)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   686
        # Use this as a 'cache' as shelf.keys() is slow
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   687
        self._keys = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   688
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   689
    def keys(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   690
        """Returns an unsorted list of keys in the map."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   691
        return list(self._keys)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   692
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   693
    def has_key(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   694
        """Return True if the key exists."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   695
        return thePath in self._keys
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   696
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   697
    def remove(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   698
        """Remove the entry corresponding to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   699
        del self._db[thePath]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   700
        self._keys.remove(thePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   701
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   702
    def getDitaFileObj(self, thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   703
        """Return a DitaFileObj that corresponds to thePath, may raise KeyError."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   704
        return self._db[thePath]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   705
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   706
    def setDitaFileObj(self, thePath, theObj):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   707
        """Load a DitaFileObj or update a mutated DitaFileObj."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   708
        self._db[thePath] = theObj
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   709
        self._keys.add(thePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   710
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   711
class DitaFileSet(DitaLinkCheckBase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   712
    """Holds information about a set of DITA files."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   713
    STATS_KEYS = ('Maps', 'Non-maps', 'Files', 'Bytes', 'IDs', 'Refs')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   714
    def __init__(self,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   715
                 theDir,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   716
                 procDir=True,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   717
                 thePatterns=None,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   718
                 recursive=False,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   719
                 testExt=False,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   720
                 useDbase=False):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   721
        """Constructor. theDir is the root directory of DITA XML.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   722
        procDir - If True then process this directory immediately, otherwise
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   723
                    the directory can be processed independently and
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   724
                    _addFileObj() or _addDitaFileObj() invoked.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   725
        thePatterns - If supplied this should be a space separated string of
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   726
                        fnmatch extensions.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   727
        recursive - If True and procDir True the directory is processed recursively.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   728
        testExt - If True then test external URLs.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   729
        useDbase - If True then store all DitaFile objects in an external dbase
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   730
                    (slower but less memory issues).
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   731
        """
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   732
        if thePatterns is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   733
            thePatterns = FNMATCH_STRING.split(' ')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   734
        if theDir is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   735
            theDir = normalisePath(theDir)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   736
        super(DitaFileSet, self).__init__(theDir)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   737
        logging.info('DitaFileSet starting to read...')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   738
        GlobalUrlCache.clear()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   739
        self._testExt = testExt
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   740
        # Set up how we store the DitaFile objects
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   741
        if useDbase:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   742
            self._fileMap = DitaFileMapShelve()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   743
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   744
            self._fileMap = DitaFileMapInMemory()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   745
        # Map of (str(rootId) : filepath, ...) with no duplicates
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   746
        # Keys will be in self._uniqueRootIds
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   747
        self._rootIdToFilePathMap = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   748
        # Path to the unique DITA map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   749
        self._uniqueMapPath = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   750
        # Count of {error_code : count, ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   751
        self._errCountMap = CountDict()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   752
        # Statistics
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   753
        self._statsMap = CountDict()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   754
        ## and initialise
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   755
        #for k in self.STATS_KEYS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   756
        #    self._statsMap[k]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   757
        # Finalisation control (weak)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   758
        self._hasFinalised = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   759
        # Timers
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   760
        self._timeRead = time.clock()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   761
        self._timeAnalyse = 0.0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   762
        if procDir:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   763
            if theDir is not None and os.path.isdir(theDir):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   764
                self._readDir(theDir, thePatterns, recursive)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   765
            else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   766
                self.addError(500, (theDir,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   767
            # Finalise and run all the tests
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   768
            self.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   769
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   770
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   771
    def errCountMap(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   772
        return self._errCountMap
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   773
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   774
    @property
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   775
    def statsMap(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   776
        return self._statsMap
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   777
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   778
    def writeStatistics(self, s=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   779
        """Writes out read statistics."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   780
        s.write(' Statistics '.center(PRINT_WIDTH, '='))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   781
        s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   782
        if len(self._statsMap) > 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   783
            o = self.STATS_KEYS
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   784
            #assert(set(o) == set(self._statsMap.keys())), \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   785
            #    '%s != %s' % (o, self._statsMap.keys())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   786
            for k in o:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   787
                try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   788
                    m = self._statsMap[k] / (1024.0*1024.0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   789
                    s.write('%20s: %10d [%10.3f M]\n' % (k, self._statsMap[k], m))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   790
                except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   791
                    s.write('%20s: %10s \n' % (k, 'Not seen'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   792
            s.write('%20s: %10.3f (s)\n' % ('Read time', self._timeRead))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   793
            s.write('%20s: %10.3f (s)\n' % ('Analysis time', self._timeAnalyse))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   794
            s.write('='*PRINT_WIDTH)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   795
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   796
            s.write('Nothing processed.')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   797
        s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   798
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   799
    def writeErrorSummary(self, s=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   800
        s.write(' Error Summary '.center(PRINT_WIDTH, '='))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   801
        s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   802
        if len(self._errCountMap):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   803
            s.write('%4s %10s %s\n' % ('Code', 'Count', 'Error'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   804
            s.write('%4s %10s %s\n' % ('----', '-----', '-----'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   805
            errCodeS = self._errCountMap.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   806
            errCodeS.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   807
            for c in errCodeS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   808
                s.write('%4d %10d %s\n' \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   809
                        % (c, self._errCountMap[c], genericStringForErrorCode(c)))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   810
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   811
            s.write('No errors\n')            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   812
        s.write('='*PRINT_WIDTH)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   813
        s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   814
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   815
    def writeErrors(self, isGeneric, theFilter, theStream=sys.stdout):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   816
        """Writes out errors for me and my files."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   817
        theStream.write('\n'.join(self.errStrings(isGeneric, theFilter)))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   818
        fileS = self._fileMap.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   819
        fileS.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   820
        for aFile in fileS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   821
            # Immutable call so just use get
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   822
            self._fileMap.getDitaFileObj(aFile).writeErrors(isGeneric, theFilter, theStream)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   823
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   824
    def allErrStrings(self, isGeneric, theFilter):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   825
        """Return a sorted list of error messages without duplicates including
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   826
        files."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   827
        retSet = set(self.errStrings(isGeneric, theFilter))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   828
        fileS = self._fileMap.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   829
        fileS.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   830
        for aFilePath in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   831
            # Immutable call so just use get
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   832
            for anErr in self._fileMap.getDitaFileObj(aFilePath).errStrings(isGeneric, theFilter): 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   833
                retSet.add(anErr)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   834
        retList = list(retSet)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   835
        retList.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   836
        return retList
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   837
            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   838
    def _readDir(self, theDir, thePatS, recursive):    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   839
        assert(os.path.isdir(theDir))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   840
        for aName in os.listdir(theDir):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   841
            aPath = os.path.join(theDir, aName)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   842
            if os.path.isdir(aPath) and recursive:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   843
                self._readDir(aPath, thePatS, recursive)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   844
            elif os.path.isfile(aPath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   845
                for aPat in thePatS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   846
                    if fnmatch.fnmatch(aName, aPat):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   847
                        assert(not self._fileMap.has_key(aPath))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   848
                        logging.debug(' Reading %s' % aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   849
                        try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   850
                            f = open(aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   851
                        except IOError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   852
                            f = None
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   853
                        self._addFileObj(f, aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   854
                        break
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   855
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   856
    def _addFileObj(self, theFileObj, theFilePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   857
        myObj = DitaFileObj(theFileObj, theFilePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   858
        self._addDitaFileObj(myObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   859
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   860
    def _addDitaFileObj(self, theDitaFileObj):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   861
        if self._fileMap.has_key(theDitaFileObj.identity):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   862
            self.addError(504, (theDitaFileObj.identity,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   863
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   864
            # Mutable call so use set
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   865
            self._fileMap.setDitaFileObj(theDitaFileObj.identity, theDitaFileObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   866
        # Update statistics (files, bytes, ids, refs) etc.
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   867
        self._statsMap['Files'] += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   868
        self._statsMap['Bytes'] += theDitaFileObj.bytes
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   869
        self._statsMap['IDs'] += len(theDitaFileObj.idS)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   870
        self._statsMap['Refs'] += len(theDitaFileObj.refS)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   871
        if theDitaFileObj.isMap:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   872
            self._statsMap['Maps'] += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   873
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   874
            self._statsMap['Non-maps'] += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   875
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   876
    def finalise(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   877
        """Creates the environment for all checks and then runs them."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   878
        logging.info('DitaFileSet.finalise() start...')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   879
        if not self._hasFinalised:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   880
            self._timeRead = time.clock() - self._timeRead
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   881
            self._timeAnalyse = time.clock()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   882
            self._initRootIdToFilePathMap()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   883
            self._checkDupeIdS()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   884
            self._setMapCycles()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   885
            self._checkLonely()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   886
            self._checkRefArcs()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   887
            self._errCountMap = CountDict()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   888
            self.updateErrorCount(self._errCountMap)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   889
            self._hasFinalised = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   890
            self._timeAnalyse = time.clock() - self._timeAnalyse
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   891
        logging.info('DitaFileSet.finalise() done.')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   892
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   893
    def _initRootIdToFilePathMap(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   894
        # Map of (str(rootId) : filepath, ...) with no duplicates
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   895
        self._rootIdToFilePathMap = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   896
        # Temporary map of (str(rootId) : [filepath, ...], ...)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   897
        myDupeIdFiles = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   898
        for fPath in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   899
            # fObj is not written to so we don't need to use set
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   900
            fObj = self._fileMap.getDitaFileObj(fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   901
            #print 'TRACE: _initRootIdToFilePathMap() fPath:', fPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   902
            rId = fObj.rootId
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   903
            if rId is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   904
                if myDupeIdFiles.has_key(rId):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   905
                    #print 'TRACE: _initRootIdToFilePathMap() another dupe:', fPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   906
                    myDupeIdFiles[rId].append(fObj.identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   907
                elif self._rootIdToFilePathMap.has_key(rId):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   908
                    #print 'TRACE: _initRootIdToFilePathMap() first dupe:', fPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   909
                    # Remove from map and add to myDupeIdFiles
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   910
                    myFile = self._rootIdToFilePathMap.pop(rId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   911
                    try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   912
                        myDupeIdFiles[rId].append(myFile)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   913
                    except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   914
                        myDupeIdFiles[rId] = [myFile,]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   915
                    myDupeIdFiles[rId].append(fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   916
                else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   917
                    #print 'TRACE: _initRootIdToFilePathMap() adding:', fPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   918
                    self._rootIdToFilePathMap[rId] = fObj.identity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   919
        # Set duplicate errors
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   920
        for k in myDupeIdFiles.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   921
            myDupeIdFiles[k].sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   922
            self.addError(501, (k, tuple(myDupeIdFiles[k])))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   923
            #self.addError(501, (k, str([str(a) for a in myDupeIdFiles[k]])))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   924
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   925
    def _checkDupeIdS(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   926
        """Checks if there are any duplicate IDs anywhere."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   927
        # {ID : [fileS, ...], ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   928
        myDupeIdMap = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   929
        # Temporary data structure
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   930
        # {ID : first file ID is seen in, ...}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   931
        seenIdMap = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   932
        for f in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   933
            # o is not written to so we don't need set...
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   934
            o = self._fileMap.getDitaFileObj(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   935
            for anId in o.idS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   936
                if seenIdMap.has_key(anId):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   937
                    try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   938
                        myDupeIdMap[anId].append(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   939
                    except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   940
                        myDupeIdMap[anId] = [seenIdMap[anId],]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   941
                        myDupeIdMap[anId].append(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   942
                else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   943
                    seenIdMap[anId] = f
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   944
        # Now add to errs as a 505 error message
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   945
        # Sort the files in the map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   946
        for k in myDupeIdMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   947
            myDupeIdMap[k].sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   948
            self.addError(505, (k, tuple(myDupeIdMap[k])))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   949
            #self.addError(505, (k, str([str(a) for a in myDupeIdMap[k]])))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   950
                    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   951
    def _retMapAdjList(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   952
        """Create an adjacency list {file_path : set(refs), ...} (all strings)"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   953
        adjList = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   954
        for f in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   955
            fObj = self._fileMap.getDitaFileObj(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   956
            if fObj.isMap:# and fObj.rootId is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   957
                assert(fObj.identity not in adjList.keys())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   958
                refSet = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   959
                for r in fObj.refS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   960
                    refSet.add(r.fileFragment(fObj.identity)[0])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   961
                adjList[fObj.identity] = refSet
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   962
        return adjList
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   963
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   964
    def _setMapCycles(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   965
        """Sets any cyclic references seen in DITA maps."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   966
        adjList = self._retMapAdjList()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   967
        # A branch
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   968
        myBr = []
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   969
        myCycles = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   970
        for aPath, aSet in adjList.items():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   971
            myBr.append(aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   972
            self._recurseCycles(adjList, myBr, myCycles)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   973
            myBr.pop()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   974
        self._setCycleErrors(myCycles)      
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   975
            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   976
    def _recurseCycles(self, a, b, c):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   977
        assert(len(b) > 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   978
        try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   979
            myPath = b[-1]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   980
            for r in a[myPath]:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   981
                #print '_recurseCycles() testing r', r
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   982
                #print '_recurseCycles() testing b', b
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   983
                if r in b:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   984
                    #print 'Adding cycle', tuple(b[b.index(r):])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   985
                    c.add(tuple(b[b.index(r):]))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   986
                else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   987
                    b.append(r)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   988
                    self._recurseCycles(a, b, c)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   989
                    b.pop()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   990
        except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   991
            pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   992
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   993
    def _setCycleErrors(self, theC):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   994
        for aT in theC:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   995
            self.addError(701, (str(aT),))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   996
            myL = list(aT)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   997
            assert(len(myL) > 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   998
            i = 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
   999
            while i < len(myL):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1000
                myL.append(myL[0])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1001
                # Should this be in the file thus, or in the files set?
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1002
                # As we are mutating the file object we need to use both
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1003
                # getDitaFileObj() and setDitaFileObj()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1004
                fObj = self._fileMap.getDitaFileObj(myL[0])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1005
                fObj.addError(701, (str(myL),))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1006
                self._fileMap.setDitaFileObj(myL[0], fObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1007
                myL.pop()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1008
                myL.append(myL.pop(0))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1009
                i += 1    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1010
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1011
    def _checkLonely(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1012
        self._checkLonelyMaps()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1013
        self._checkLonelyTopics()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1014
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1015
    def _checkLonelyMaps(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1016
        """Checks for lonely maps."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1017
        mapPathSet = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1018
        pathSetRemain = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1019
        for f in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1020
            if self._fileMap.getDitaFileObj(f).isMap:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1021
                mapPathSet.add(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1022
                pathSetRemain.add(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1023
        for aPath in mapPathSet:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1024
            myMapObj = self._fileMap.getDitaFileObj(aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1025
            for r in myMapObj.refS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1026
                refFile, frag = r.fileFragment(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1027
                try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1028
                    pathSetRemain.remove(refFile)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1029
                except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1030
                    # refFile is a topic or an already seen map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1031
                    pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1032
        if len(pathSetRemain) > 1:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1033
            for aPath in pathSetRemain:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1034
                self.addError(700, (aPath,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1035
        elif len(pathSetRemain) == 1:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1036
            self._uniqueMapPath = pathSetRemain.pop()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1037
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1038
    def _checkLonelyTopics(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1039
        """Checks for topics that are not referenced by any map."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1040
        mapPathSet = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1041
        pathSetRemain = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1042
        for f in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1043
            #print 'TRACE: f:', f
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1044
            if self._fileMap.getDitaFileObj(f).isMap:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1045
                mapPathSet.add(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1046
            else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1047
                pathSetRemain.add(f)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1048
        #print 'TRACE: mapPathSet', mapPathSet
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1049
        #print 'TRACE: pathSetRemain', pathSetRemain
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1050
        for aMapPath in mapPathSet:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1051
            myMapObj = self._fileMap.getDitaFileObj(aMapPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1052
            for r in myMapObj.refS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1053
                refFile, frag = r.fileFragment(aMapPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1054
                #print 'TRACE: removing:', refFile
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1055
                try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1056
                    pathSetRemain.remove(refFile)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1057
                except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1058
                    # topic has already been seen in another map
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1059
                    pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1060
        if len(pathSetRemain) > 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1061
            for aPath in pathSetRemain:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1062
                self.addError(600, (aPath,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1063
            
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1064
    def _checkRefArcs(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1065
        """Checks all references are reachable."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1066
        for fPath in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1067
            fObjSrc = self._fileMap.getDitaFileObj(fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1068
            hasMutated = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1069
            for rObjSrc in fObjSrc.refS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1070
                if rObjSrc.scheme:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1071
                    # Decide whether to test and external URL
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1072
                    if self._testExt:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1073
                        rObjSrc.checkUrl()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1074
                else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1075
                    fi, fr = rObjSrc.fileFragment(fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1076
                    assert(fi is not None), 'fi is None for rObjSrc: %s in file: %s' % (rObjSrc, fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1077
                    assert(fr is not None), 'fr is None for rObjSrc: %s in file: %s' % (rObjSrc, fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1078
                    ## If a url then fileFragment() returns (None, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1079
                    #if fi is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1080
                    #    print 'fPath', fPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1081
                    #    print 'rObjSrc', rObjSrc
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1082
                    #    print 'fi', fi
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1083
                    #    print 'fr', fr
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1084
                    try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1085
                        fObjTgt = self._fileMap.getDitaFileObj(fi)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1086
                    except KeyError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1087
                        # Target file can not be found in the IR
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1088
                        # check the file system to see if it is a non-DITA resource
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1089
                        if not os.path.isfile(fi):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1090
                            #print 'TRACE: adding 410 to', fObj.identity
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1091
                            fObjSrc.addError(410, (fi,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1092
                            hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1093
                    else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1094
                        if len(fr) > 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1095
                            # Target file is found, test fragment
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1096
                            if not fObjTgt.hasId(fr):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1097
                                # Fragment not found
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1098
                                fObjSrc.addError(411, (fi, fr))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1099
                                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1100
                        if self._checkRefArcElemName(fObjSrc, rObjSrc, fObjTgt, fr):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1101
                            hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1102
            if hasMutated:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1103
                self._fileMap.setDitaFileObj(fPath, fObjSrc)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1104
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1105
    def _checkRefArcElemName(self, fObjSrc, rObjSrc, fObjTgt, frag):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1106
        """Test source and target element names
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1107
        e.g. Source <cxxClassRef> should match target <cxxClass>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1108
        And in vanilla DITA:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1109
        <topicref href="batcaring.dita" type="task"></topicref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1110
        or:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1111
        <topicref href="batcaring.dita" format="ditamap"></topicref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1112
        Should match target element <task>."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1113
        isRootTgt = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1114
        hasMutated = False
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1115
        if len(frag) == 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1116
            # iObjTgt is the root element of fObjTgt
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1117
            if fObjTgt.rootId is None or fObjTgt.idElem(fObjTgt.rootId) is None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1118
                # Covered by other error codes
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1119
                return
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1120
            iObjTgt = fObjTgt.idObj(fObjTgt.rootId)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1121
            isRootTgt = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1122
        elif fObjTgt.hasId(frag):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1123
            iObjTgt = fObjTgt.idObj(frag)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1124
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1125
            # frag not found that will be a 411 error (handled by caller).
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1126
            return
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1127
        # Have an rObjSrc + iObjTgt so check elements
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1128
        # First case:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1129
        if rObjSrc.elem.endswith('Ref'):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1130
            if rObjSrc.elem[:-3] != iObjTgt.elem:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1131
                if isRootTgt:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1132
                    fObjSrc.addError(412, (rObjSrc.elem, iObjTgt.elem))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1133
                else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1134
                    fObjSrc.addError(413, (fObjTgt.idElem(frag), rObjSrc.elem, frag))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1135
                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1136
        # Second case(s) for vanilla DITA
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1137
        elif rObjSrc.elem == 'topicref':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1138
            # Check DITA map links
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1139
            if rObjSrc.format == 'ditamap' and iObjTgt.elem != 'map':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1140
                # Target must be a root element (actually we don't care)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1141
                fObjSrc.addError(414, (iObjTgt.elem,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1142
                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1143
            elif iObjTgt.elem == 'map' and rObjSrc.format != 'ditamap':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1144
                fObjSrc.addError(415, (rObjSrc.format,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1145
                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1146
            elif not (rObjSrc.format == 'ditamap' and iObjTgt.elem == 'map'):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1147
                # Treat refType None as type="topic", see DITA standard for <topicref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1148
                # Well, also look at the type attribute in chapter 25
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1149
                # "When the type attribute is unspecified, it should be
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1150
                # determined by inspecting the target if possible. If the
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1151
                # target cannot be inspected for some reason, the value
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1152
                # should default to "topic".
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1153
                # Note: DITA 1.2 takes a different view...
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1154
                # Was:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1155
                #if (rObjSrc.refType is None and iObjTgt.elem != 'topic') \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1156
                #or (rObjSrc.refType is not None and rObjSrc.refType != iObjTgt.elem):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1157
                if rObjSrc.refType is not None and rObjSrc.refType != iObjTgt.elem:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1158
                    if isRootTgt:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1159
                        fObjSrc.addError(416, (rObjSrc.refType, iObjTgt.elem,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1160
                        hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1161
                    else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1162
                        fObjSrc.addError(417, (rObjSrc.refType, iObjTgt.elem, frag,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1163
                        hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1164
                # Otherwise topicref looks OK
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1165
        elif rObjSrc.elem != 'xref' and rObjSrc.elem not in XREF_DESCENDENTS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1166
            # Unknown referencing element
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1167
            if isRootTgt:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1168
                fObjSrc.addError(418, (rObjSrc.elem, fObjTgt.doctype))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1169
                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1170
            else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1171
                fObjSrc.addError(419, (rObjSrc.elem, fObjTgt.idElem(frag), frag))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1172
                hasMutated = True
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1173
        return hasMutated
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1174
                                        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1175
    def updateErrorCount(self, theMap):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1176
        """Updates a map of {error_code, : count, ...}."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1177
        if self._errS is not None:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1178
            for e in self._errS.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1179
                theMap[e] += len(self._errS[e])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1180
        for fPath in self._fileMap.keys():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1181
            fObj = self._fileMap.getDitaFileObj(fPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1182
            # Mutable call so need to update
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1183
            fObj.updateErrorCount(theMap)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1184
            self._fileMap.setDitaFileObj(fPath, fObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1185
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1186
    def debugDump(self, s=sys.stdout, prefix=''):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1187
        """Dump of IR for debug purposes."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1188
        s.write(' Debug Dump '.center(PRINT_WIDTH, '+'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1189
        s.write('\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1190
        fileS = self._fileMap.keys()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1191
        fileS.sort()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1192
        for f in fileS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1193
            self._fileMap.getDitaFileObj(f).debugDump(s, prefix)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1194
        s.write(' END Debug Dump '.center(PRINT_WIDTH, '+'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1195
        s.write('\n\n')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1196
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1197
#####################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1198
# Multiprocessing code
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1199
#####################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1200
def retDitaFileObj(thePath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1201
    return DitaFilePath(thePath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1202
 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1203
def genDitaPath(theDir, thePatS, recursive):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1204
    assert(os.path.isdir(theDir))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1205
    for aName in os.listdir(theDir):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1206
        aPath = os.path.join(theDir, aName)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1207
        if os.path.isdir(aPath) and recursive:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1208
            for p in genDitaPath(aPath, thePatS, recursive):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1209
                yield p
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1210
        elif os.path.isfile(aPath):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1211
            for aPat in thePatS:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1212
                if fnmatch.fnmatch(aName, aPat):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1213
                    #logging.info('genDitaPath(): %s' % aPath)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1214
                    yield aPath
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1215
                    break    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1216
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1217
def retMpDitaFileSetObj(theDir,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1218
                        thePatterns,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1219
                        recursive,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1220
                        numJobs, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1221
                        checkExt,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1222
                        useDb):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1223
    assert(os.path.isdir(theDir))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1224
    assert(numJobs >= 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1225
    retObj = DitaFileSet(theDir, procDir=False, testExt=checkExt, useDbase=useDb)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1226
    myNumJobs = numJobs
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1227
    if numJobs == 0:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1228
        myNumJobs = multiprocessing.cpu_count()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1229
        logging.info('Set multiprocessing number of jobs to %d' % myNumJobs)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1230
    myPool = multiprocessing.Pool(processes=myNumJobs)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1231
    for result in [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1232
            myPool.apply_async(retDitaFileObj, (f,))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1233
                for f in genDitaPath(theDir, thePatterns, recursive)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1234
            ]:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1235
        myObj = result.get()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1236
        logging.debug('Got %s' % myObj.identity)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1237
        retObj._addDitaFileObj(myObj)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1238
    # Note: finalise() is a serial process
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1239
    logging.info('retMpDitaFileSetObj(): finalising')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1240
    retObj.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1241
    return retObj
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1242
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1243
######################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1244
# Test code
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1245
######################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1246
try:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1247
    import cStringIO as StringIO
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1248
except ImportError:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1249
    import StringIO
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1250
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1251
class NullClass(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1252
    pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1253
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1254
class TestCountDict(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1255
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1256
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1257
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1258
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1259
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1260
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1261
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1262
        """TestCountDict: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1263
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1264
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1265
    def test_basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1266
        """TestCountDict: test basic functionality."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1267
        myMap = CountDict()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1268
        self.assertEqual(myMap.has_key('wtf'), False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1269
        self.assertEqual(myMap['wtf'], 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1270
        self.assertEqual(myMap.has_key('wtf'), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1271
        myMap['wtf'] += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1272
        self.assertEqual(myMap['wtf'], 1)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1273
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1274
class TestDitaId(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1275
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1276
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1277
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1278
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1279
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1280
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1281
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1282
        """DitaId: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1283
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1284
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1285
    def test_basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1286
        """DitaId: basic read of an node with an id"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1287
        myXml = """<cxxClass id="class_big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1288
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1289
        myObj = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1290
        self.assertEqual(myObj.id, 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1291
        self.assertEqual(str(myObj), 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1292
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1293
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1294
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1295
    def test_guid_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1296
        """DitaId: basic read of an node with an GUID id"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1297
        myXml = """<cxxClass id="GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1298
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1299
        myObj = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1300
        self.assertEqual(myObj.id, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1301
        myObj.checkGuid()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1302
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1303
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1304
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1305
    def test_guid_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1306
        """DitaId: basic read of an node with an GUID id fails"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1307
        myXml = """<cxxClass id="25825EC4-341F-3EA4-94AA-7DCE380E6D2E"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1308
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1309
        myObj = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1310
        self.assertEqual(myObj.id, '25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1311
        myObj.checkGuid()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1312
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1313
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1314
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1315
             'GUID specification does not match id="25825EC4-341F-3EA4-94AA-7DCE380E6D2E"'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1316
            ])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1317
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1318
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1319
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1320
             'GUID specification does not match id="%s"' % GENERIC_STRING,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1321
            ])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1322
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1323
    def test_cmp_eq_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1324
        """DitaId: cmp(), == of two identical nodes"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1325
        myXml = """<cxxClass id="class_big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1326
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1327
        myObj_00 = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1328
        myObj_01 = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1329
        self.assertEqual(cmp(myObj_00, myObj_01), 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1330
        self.assertEqual((myObj_00 == myObj_01), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1331
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1332
    def test_cmp_eq_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1333
        """DitaId: cmp(), == of two identical nodes from different elements."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1334
        myXml_00 = """<cxxClass id="big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1335
        myTree_00 = etree.parse(StringIO.StringIO(myXml_00))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1336
        myObj_00 = DitaId(myTree_00.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1337
        myXml_01 = """<cxxStruct id="big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1338
        myTree_01 = etree.parse(StringIO.StringIO(myXml_01))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1339
        myObj_01 = DitaId(myTree_01.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1340
        self.assertEqual(cmp(myObj_00, myObj_01), 0)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1341
        self.assertEqual((myObj_00 == myObj_01), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1342
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1343
    def test_set(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1344
        """DitaId: read of an node with an id several times into a set and check unique,"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1345
        myXml = """<cxxClass id="class_big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1346
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1347
        s = set()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1348
        i = 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1349
        while i < 8:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1350
            s.add(DitaId(myTree.getroot()))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1351
            i += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1352
        self.assertEqual(len(s), 1)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1353
        self.assertEqual(DitaId(myTree.getroot()) in s, True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1354
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1355
    def test_map(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1356
        """DitaId: read of an node with an id several times into a map and check unique,"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1357
        myXml = """<cxxClass id="class_big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1358
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1359
        m = {}
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1360
        i = 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1361
        while i < 8:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1362
            m[DitaId(myTree.getroot())] = 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1363
            i += 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1364
        self.assertEqual(len(m), 1)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1365
        self.assertEqual(m.has_key(DitaId(myTree.getroot())), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1366
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1367
    def test_error_hash(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1368
        """DitaId: error with a '#' in an id"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1369
        myXml = """<cxxClass id="class_#big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1370
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1371
        myObj = DitaId(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1372
        self.assertEqual(myObj.id, 'class_#big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1373
        self.assertEqual(str(myObj), 'class_#big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1374
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1375
                myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1376
                [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1377
                    genericStringForErrorCode(100),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1378
                ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1379
            )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1380
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1381
                myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1382
                [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1383
                 'Character \'#\' not allowed in id="class_#big_endian"',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1384
                 ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1385
            )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1386
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1387
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1388
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1389
class TestDitaRef(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1390
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1391
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1392
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1393
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1394
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1395
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1396
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1397
        """DitaRef: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1398
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1399
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1400
    def test_basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1401
        """DitaRef: basic read of an xref node, no fragment"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1402
        myXml = """<xref href="class_big_endian"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1403
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1404
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1405
        self.assertEqual(myObj.href, 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1406
        self.assertEqual(myObj.path, 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1407
        self.assertEqual(myObj.elem, 'xref')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1408
        self.assertEqual(str(myObj), 'xref class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1409
        self.assertEqual(myObj.fragment, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1410
        self.assertEqual(myObj.scheme, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1411
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1412
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1413
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1414
    def test_basic_frag(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1415
        """DitaRef: basic read of an xref node, with fragment"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1416
        myXml = """<xref href="class_big_endian.xml#function"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1417
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1418
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1419
        self.assertEqual(myObj.href, 'class_big_endian.xml#function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1420
        self.assertEqual(myObj.path, 'class_big_endian.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1421
        self.assertEqual(myObj.fragment, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1422
        self.assertEqual(myObj.scheme, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1423
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1424
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1425
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1426
    def test_file_frag_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1427
        """DitaRef: accessing an xref node, with a file and a fragment"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1428
        myXml = """<xref href="class_big_endian.xml#function"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1429
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1430
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1431
        self.assertEqual(myObj.href, 'class_big_endian.xml#function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1432
        self.assertEqual(myObj.path, 'class_big_endian.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1433
        self.assertEqual(myObj.fragment, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1434
        self.assertEqual(myObj.scheme, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1435
        srcPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1436
        expPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'class_big_endian.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1437
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1438
            myObj.fileFragment(srcPath),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1439
            (expPath, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1440
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1441
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1442
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1443
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1444
    def test_file_frag_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1445
        """DitaRef: accessing an xref node, with a file and a fragment and relative path with '\\'."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1446
        myXml = """<xref href="..\\chips\\class_big_endian.xml#function"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1447
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1448
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1449
        srcPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1450
        expPath = normalisePath(os.path.join('C:%s' % os.sep, 'chips', 'class_big_endian.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1451
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1452
            myObj.fileFragment(srcPath),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1453
            (expPath, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1454
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1455
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1456
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1457
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1458
    def test_file_frag_02(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1459
        """DitaRef: accessing an xref node, with a file and a fragment and relative path with '/'."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1460
        myXml = """<xref href="../chips/class_big_endian.xml#function"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1461
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1462
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1463
        srcPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1464
        expPath = normalisePath(os.path.join('C:%s' % os.sep, 'chips', 'class_big_endian.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1465
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1466
            myObj.fileFragment(srcPath),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1467
            (expPath, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1468
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1469
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1470
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1471
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1472
    def test_file_frag_03(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1473
        """DitaRef: accessing an xref node, with a no file but with a fragment"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1474
        myXml = """<xref href="#function"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1475
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1476
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1477
        self.assertEqual(myObj.href, '#function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1478
        self.assertEqual(myObj.path, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1479
        self.assertEqual(myObj.fragment, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1480
        self.assertEqual(myObj.scheme, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1481
        srcPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1482
        expPath = normalisePath(os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1483
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1484
            myObj.fileFragment(srcPath),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1485
            (expPath, 'function')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1486
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1487
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1488
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1489
        
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1490
    def test_basic_scheme(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1491
        """DitaRef: an xref node with a URI scheme"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1492
        myXml = """<xref href="http://www.cwi.nl:80/%7Eguido/Python.html#fragment"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1493
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1494
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1495
        self.assertEqual(myObj.href, 'http://www.cwi.nl:80/%7Eguido/Python.html#fragment')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1496
        self.assertEqual(myObj.path, '/%7Eguido/Python.html')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1497
        self.assertEqual(myObj.fragment, 'fragment')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1498
        self.assertEqual(myObj.scheme, 'http')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1499
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1500
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1501
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1502
    def test_basic_scheme_file_frag(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1503
        """DitaRef: an xref node with a URI scheme, invoking fileFragment()"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1504
        myXml = """<xref href="http://www.cwi.nl:80/%7Eguido/Python.html#fragment"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1505
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1506
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1507
        self.assertEqual(myObj.href, 'http://www.cwi.nl:80/%7Eguido/Python.html#fragment')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1508
        self.assertEqual(myObj.path, '/%7Eguido/Python.html')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1509
        self.assertEqual(myObj.fragment, 'fragment')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1510
        self.assertEqual(myObj.scheme, 'http')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1511
        srcPath = os.path.join('C:%s' % os.sep, 'spam', 'eggs.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1512
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1513
            myObj.fileFragment(srcPath),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1514
            (None, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1515
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1516
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1517
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1518
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1519
    def test_fail_no_href(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1520
        """DitaRef: Fails on an xref node with no href attribute"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1521
        myXml = """<xref />"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1522
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1523
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1524
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1525
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1526
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1527
             'Reference element "xref" is missing href=... attribute',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1528
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1529
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1530
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1531
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1532
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1533
             'Reference element "%s" is missing href=... attribute' % GENERIC_STRING,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1534
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1535
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1536
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1537
    def test_fail_bad_frag(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1538
        """DitaRef: Fails on an xref node with href attribute that has multiple '#' characters"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1539
        myXml = """<xref href="a#b#c" />"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1540
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1541
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1542
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1543
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1544
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1545
             'Multiple \'#\' not allowed in reference "a#b#c"',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1546
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1547
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1548
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1549
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1550
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1551
             'Multiple \'#\' not allowed in reference "%s"' % GENERIC_STRING,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1552
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1553
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1554
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1555
    def test_guid_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1556
        """DitaRef: basic read of an node with an GUID file/fragment reference"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1557
        myXml = """<xref href="GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1558
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1559
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1560
        self.assertEqual(myObj.href, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1561
        self.assertEqual(myObj.path, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1562
        self.assertEqual(myObj.elem, 'xref')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1563
        self.assertEqual(str(myObj), 'xref GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1564
        self.assertEqual(myObj.fragment, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1565
        self.assertEqual(myObj.scheme, '')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1566
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1567
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1568
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1569
    def test_guid_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1570
        """DitaRef: basic read of an node with an GUID file part fails"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1571
        myXml = """<xref href="GUID-.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1572
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1573
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1574
        self.assertEqual(myObj.href, 'GUID-.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1575
        self.assertEqual(myObj.path, 'GUID-.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1576
        self.assertEqual(myObj.elem, 'xref')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1577
        self.assertEqual(str(myObj), 'xref GUID-.xml#GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1578
        self.assertEqual(myObj.fragment, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1579
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1580
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1581
        myObj.checkGuid()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1582
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1583
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1584
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1585
             'GUID specification does not match file reference "GUID-.xml"'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1586
            ])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1587
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1588
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1589
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1590
             genericStringForErrorCode(203),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1591
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1592
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1593
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1594
    def test_guid_02(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1595
        """DitaRef: basic read of an node with an GUID fragment part fails"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1596
        myXml = """<xref href="GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1597
        myTree = etree.parse(StringIO.StringIO(myXml))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1598
        myObj = DitaRef(myTree.getroot())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1599
        self.assertEqual(myObj.href, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1600
        self.assertEqual(myObj.path, 'GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1601
        self.assertEqual(myObj.elem, 'xref')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1602
        self.assertEqual(str(myObj), 'xref GUID-25825EC4-341F-3EA4-94AA-7DCE380E6D2E.xml#GUID-25825EC4')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1603
        self.assertEqual(myObj.fragment, 'GUID-25825EC4')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1604
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1605
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1606
        myObj.checkGuid()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1607
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1608
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1609
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1610
             'GUID specification does not match fragment reference "GUID-25825EC4"'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1611
            ])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1612
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1613
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1614
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1615
             genericStringForErrorCode(204),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1616
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1617
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1618
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1619
class TestDitaFile(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1620
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1621
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1622
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1623
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1624
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1625
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1626
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1627
        """DitaFile: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1628
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1629
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1630
    def test_Basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1631
        """DitaFile: basic read of an XML file"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1632
        myXml = """<?xml version='1.0' encoding='UTF-8' standalone='no'?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1633
<!DOCTYPE cxxClass PUBLIC "-//NOKIA//DTD DITA C++ API Class Reference Type v0.1.0//EN" "dtd/cxxClass.dtd" >
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1634
<cxxClass id="class_big_endian">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1635
    <apiName>BigEndian</apiName>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1636
    <shortdesc/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1637
    <cxxClassDetail>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1638
        <cxxClassDefinition>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1639
            <cxxClassAccessSpecifier value="public"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1640
            <cxxClassAPIItemLocation>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1641
                <cxxClassDeclarationFile name="filePath" value="K:/sf/os/commsfw/datacommsserver/esockserver/inc/es_sock.h"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1642
                <cxxClassDeclarationFileLine name="lineNumber" value="1520"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1643
                <cxxClassDefinitionFile name="filePath" value="K:/sf/os/commsfw/datacommsserver/esockserver/inc/es_sock.h"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1644
                <cxxClassDefinitionFileLineStart name="lineNumber" value="1516"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1645
                <cxxClassDefinitionFileLineEnd name="lineNumber" value="1526"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1646
            </cxxClassAPIItemLocation>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1647
        </cxxClassDefinition>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1648
        <apiDesc>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1649
            <p>Inserts and extracts integers in big-endian format.   </p>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1650
        </apiDesc>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1651
    </cxxClassDetail>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1652
    <cxxFunction id="class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1653
    </cxxFunction>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1654
    <cxxFunction id="class_big_endian_1aedf702f5c0118e4294d1a6d9684f8441">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1655
    </cxxFunction>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1656
    <cxxFunction id="class_big_endian_1ae266722f7bb965c971155a3315bad484">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1657
    </cxxFunction>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1658
    <cxxFunction id="class_big_endian_1a497d5248ea259f8490fb40ac4f2aafb2">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1659
    </cxxFunction>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1660
</cxxClass>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1661
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1662
        myObj = DitaFileObj(myFile, 'foo')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1663
        self.assertEqual(myObj.identity, normalisePath('foo'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1664
        self.assertEqual(myObj.doctype, 'cxxClass')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1665
        self.assertEqual(myObj.rootId, 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1666
        #print myObj.idMap()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1667
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1668
            myObj.idElemMap(),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1669
            {
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1670
                'class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1671
                'class_big_endian_1aedf702f5c0118e4294d1a6d9684f8441'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1672
                'class_big_endian'                                      : 'cxxClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1673
                'class_big_endian_1a497d5248ea259f8490fb40ac4f2aafb2'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1674
                'class_big_endian_1ae266722f7bb965c971155a3315bad484'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1675
                }
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1676
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1677
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1678
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1679
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1680
    def test_missing_file(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1681
        """DitaFile: read an missing XML file"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1682
        myObj = DitaFileObj(None, 'foo')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1683
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1684
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1685
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1686
             'Failed to open: "%s"' % normalisePath('foo'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1687
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1688
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1689
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1690
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1691
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1692
             genericStringForErrorCode(400),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1693
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1694
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1695
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1696
    def test_IllFormedFile(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1697
        """DitaFile: read an ill-formed XML file"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1698
        myXml = """<?xml version='1.0' encoding='UTF-8' standalone='no'?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1699
<!DOCTYPE cxxClass PUBLIC "-//NOKIA//DTD DITA C++ API Class Reference Type v0.1.0//EN" "dtd/cxxClass.dtd" >
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1700
<cxxClass id="class_big_endian">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1701
"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1702
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1703
        myObj = DitaFileObj(myFile, 'foo')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1704
        self.assertEqual(myObj.identity, normalisePath('foo'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1705
        self.assertEqual(myObj.doctype, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1706
        self.assertEqual(myObj.rootId, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1707
        #print myObj.idMap()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1708
        self.assertEqual(myObj.idElemMap(), {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1709
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1710
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1711
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1712
             'Can not parse: "no element found: line 4, column 0"',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1713
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1714
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1715
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1716
            myObj.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1717
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1718
             genericStringForErrorCode(404),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1719
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1720
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1721
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1722
    def test_missing_root_id(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1723
        """DitaFile: read of an XML file with no id on root element"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1724
        myXml = """<?xml version='1.0' encoding='UTF-8' standalone='no'?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1725
<!DOCTYPE cxxClass PUBLIC "-//NOKIA//DTD DITA C++ API Class Reference Type v0.1.0//EN" "dtd/cxxClass.dtd" >
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1726
<cxxClass>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1727
    <xref href="OtherClass">OtherClass</xref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1728
    <cxxFunction id="class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1729
</cxxClass>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1730
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1731
        myObj = DitaFileObj(myFile, 'foo')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1732
        self.assertEqual(myObj.identity, normalisePath('foo'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1733
        self.assertEqual(myObj.doctype, 'cxxClass')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1734
        self.assertEqual(myObj.rootId, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1735
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1736
            myObj.idElemMap(),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1737
            {
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1738
                'class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1739
                }
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1740
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1741
        self.assertEqual(myObj.errStrings(False, None), [genericStringForErrorCode(402)])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1742
        self.assertEqual(myObj.errStrings(True, None), [genericStringForErrorCode(402)])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1743
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1744
    def test_duplicate_id(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1745
        """DitaFile: duplicate IDs"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1746
        myXml = """<root id="AnID">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1747
<elem id="AnID"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1748
</root>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1749
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1750
        myObj = DitaFileObj(myFile, 'spam.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1751
        self.assertEqual(myObj.identity, normalisePath('spam.xml'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1752
        self.assertEqual(myObj.doctype, 'root')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1753
        self.assertEqual(myObj.rootId, 'AnID')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1754
        self.assertEqual(myObj.idElemMap(), {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1755
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1756
            myObj.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1757
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1758
                'Multiple id="AnID"',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1759
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1760
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1761
        self.assertEqual(myObj.errStrings(True, None), [genericStringForErrorCode(401)])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1762
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1763
    def test_ismap_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1764
        """DitaFile: Is a map for <map>."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1765
        myXml = """<map id="myMap"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1766
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1767
        myObj = DitaFileObj(myFile, 'spam.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1768
        self.assertEqual(myObj.isMap, True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1769
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1770
    def test_ismap_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1771
        """DitaFile: Is a map for <cxxAPIMap>."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1772
        myXml = """<cxxAPIMap id="myMap"/>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1773
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1774
        myObj = DitaFileObj(myFile, 'spam.xml')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1775
        self.assertEqual(myObj.isMap, True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1776
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1777
    def test_Basic_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1778
        """DitaFile: read of an simple XML file with id and xref"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1779
        myXml = """<?xml version='1.0' encoding='UTF-8' standalone='no'?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1780
<!DOCTYPE cxxClass PUBLIC "-//NOKIA//DTD DITA C++ API Class Reference Type v0.1.0//EN" "dtd/cxxClass.dtd" >
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1781
<cxxClass id="class_big_endian">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1782
    <xref href="OtherClass">OtherClass</xref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1783
    <cxxFunction id="class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f"/>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1784
</cxxClass>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1785
        myFile = StringIO.StringIO(myXml)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1786
        myObj = DitaFileObj(myFile, 'foo')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1787
        self.assertEqual(myObj.identity, normalisePath('foo'))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1788
        self.assertEqual(myObj.doctype, 'cxxClass')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1789
        self.assertEqual(myObj.rootId, 'class_big_endian')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1790
        self.assertEqual(myObj.isMap, False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1791
        self.assertEqual(len(myObj.idS), 2)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1792
        self.assertEqual(len(myObj.refS), 1)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1793
        self.assertEqual(myObj.hasId('class_big_endian'), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1794
        self.assertEqual(myObj.hasId('class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f'), True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1795
        self.assertEqual(myObj.hasId('noID'), False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1796
        self.assertEqual(myObj.idElem('class_big_endian'), 'cxxClass')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1797
        self.assertEqual(myObj.idElem('noID'), None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1798
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1799
            myObj.idElem('class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1800
            'cxxFunction'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1801
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1802
        #print myObj.idMap()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1803
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1804
            myObj.idElemMap(),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1805
            {
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1806
                'class_big_endian_1a9f78fb092e713acf6ffe3e8e11f1626f'   : 'cxxFunction',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1807
                'class_big_endian'                                      : 'cxxClass',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1808
                }
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1809
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1810
        self.assertEqual(myObj.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1811
        self.assertEqual(myObj.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1812
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1813
class TestDitaFileSet(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1814
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1815
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1816
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1817
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1818
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1819
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1820
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1821
        """DitaFileSet: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1822
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1823
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1824
    def test_None(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1825
        """DitaFileSet: read of None."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1826
        myO = DitaFileSet(None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1827
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1828
        self.assertEqual(myO.errStrings(False, None), ['Not a directory: None'])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1829
        self.assertEqual(myO.errStrings(True, None), ['Not a directory: %s' % GENERIC_STRING, ])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1830
        self.assertEqual(myO.errCountMap, {500 : 1})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1831
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1832
    def test_basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1833
        """DitaFileSet: Test reading a map and a couple of files."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1834
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1835
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1836
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1837
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1838
    <topicref href="spam.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1839
    <topicref href="eggs.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1840
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1841
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1842
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1843
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1844
        myO._addFileObj(StringIO.StringIO('<topic id="spam"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1845
        myO._addFileObj(StringIO.StringIO('<topic id="eggs"/>'), 'eggs.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1846
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1847
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1848
        #myO.writeErrors(False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1849
        self.assertEqual(myO.allErrStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1850
        self.assertEqual(myO.allErrStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1851
        self.assertEqual(myO.errCountMap, {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1852
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1853
    def test_duplicate_paths(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1854
        """DitaFileSet: Test reading a couple of files in duplicate paths."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1855
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1856
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1857
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1858
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1859
    <topicref href="spam.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1860
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1861
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1862
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1863
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1864
        myO._addFileObj(StringIO.StringIO('<topic id="spam"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1865
        myO._addFileObj(StringIO.StringIO('<topic id="eggs"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1866
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1867
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1868
            myO.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1869
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1870
                'Duplicate file path: "%s"' % normalisePath('spam.dita'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1871
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1872
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1873
        self.assertEqual(myO.errStrings(True, None), [genericStringForErrorCode(504),])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1874
        self.assertEqual(myO.errCountMap, {504 : 1})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1875
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1876
    def test_duplicate_ids(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1877
        """DitaFileSet: Test reading a map and a couple of files with duplicate IDs."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1878
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1879
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1880
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1881
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1882
    <topicref href="spam.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1883
    <topicref href="eggs.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1884
    <topicref href="chips.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1885
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1886
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1887
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1888
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1889
        myO._addFileObj(StringIO.StringIO('<topic id="chips"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1890
        myO._addFileObj(StringIO.StringIO('<topic id="chips"/>'), 'eggs.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1891
        myO._addFileObj(StringIO.StringIO('<topic id="chips"/>'), 'chips.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1892
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1893
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1894
        #myO.writeErrors(False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1895
        #pprint.pprint(myO.errStrings(False, None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1896
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1897
            myO.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1898
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1899
             genericStringForErrorCode(505),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1900
             genericStringForErrorCode(501),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1901
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1902
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1903
        expErrs = [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1904
                """Duplicate id="chips" in files: ('%s', '%s', '%s')""" \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1905
                    % (normalisePath('chips.dita'), normalisePath('eggs.dita'), normalisePath('spam.dita')),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1906
                """Duplicate root id="chips" in files: ('%s', '%s', '%s')""" \
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1907
                    % (normalisePath('chips.dita'), normalisePath('eggs.dita'), normalisePath('spam.dita')),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1908
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1909
        myErrs = myO.errStrings(False, None)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1910
#===============================================================================
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1911
#        for i in range(2):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1912
#            if myErrs[i] != expErrs[i]:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1913
#                print myErrs[i]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1914
#                print expErrs[i]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1915
#                print
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1916
#===============================================================================
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1917
        self.assertEqual(myErrs, expErrs)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1918
        self.assertEqual(myO.errCountMap, {505: 1, 501: 1})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1919
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1920
    def test_lonely_topics(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1921
        """DitaFileSet: Test a couple of lonely topics."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1922
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1923
        myO._addFileObj(StringIO.StringIO('<spam id="spam"/>'), 'spam')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1924
        myO._addFileObj(StringIO.StringIO('<eggs id="eggs"/>'), 'eggs')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1925
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1926
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1927
            myO.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1928
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1929
             'Topic id="%s" is not referenced by any map' % normalisePath('eggs'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1930
             'Topic id="%s" is not referenced by any map' % normalisePath('spam'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1931
             ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1932
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1933
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1934
            myO.errStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1935
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1936
                genericStringForErrorCode(600),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1937
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1938
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1939
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1940
    def test_map_cycles_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1941
        """DitaFileSet: Cyclic references between two maps."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1942
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1943
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1944
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1945
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1946
    <topicref href="map_01.ditamap" format="ditamap" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1947
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1948
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1949
            'map_00.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1950
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1951
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1952
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1953
"""<map id="map_01">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1954
    <topicref href="map_00.ditamap" format="ditamap" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1955
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1956
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1957
            'map_01.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1958
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1959
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1960
        #print 'HI test_map_cycles_00()'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1961
        #pprint.pprint(myO._retMapAdjList())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1962
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1963
            myO.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1964
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1965
                'Maps "%s" are in a a cycle.' % str(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1966
                    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1967
                     normalisePath('map_00.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1968
                     normalisePath('map_01.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1969
                     )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1970
                ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1971
                'Maps "%s" are in a a cycle.' % str(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1972
                    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1973
                     normalisePath('map_01.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1974
                     normalisePath('map_00.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1975
                     )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1976
                ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1977
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1978
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1979
        #print
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1980
        #pprint.pprint(myO.allErrStrings(False, None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1981
        self.assertEqual(myO.allErrStrings(True, None), [genericStringForErrorCode(701)])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1982
        self.assertEqual(myO.errCountMap, {701 : 4})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1983
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1984
    def test_map_cycles_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1985
        """DitaFileSet: Cyclic references between three maps."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1986
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1987
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1988
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1989
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1990
    <topicref href="map_01.ditamap" format="ditamap" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1991
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1992
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1993
            'map_00.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1994
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1995
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1996
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1997
"""<map id="map_01">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1998
    <topicref href="map_02.ditamap" format="ditamap" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  1999
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2000
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2001
            'map_01.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2002
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2003
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2004
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2005
"""<map id="map_02">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2006
    <topicref href="map_00.ditamap" format="ditamap" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2007
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2008
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2009
            'map_02.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2010
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2011
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2012
        #print 'HI test_map_cycles_00()'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2013
        #pprint.pprint(myO._retMapAdjList())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2014
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2015
            myO.errStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2016
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2017
                'Maps "%s" are in a a cycle.' % str(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2018
                    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2019
                     normalisePath('map_00.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2020
                     normalisePath('map_01.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2021
                     normalisePath('map_02.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2022
                     )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2023
                ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2024
                'Maps "%s" are in a a cycle.' % str(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2025
                    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2026
                     normalisePath('map_01.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2027
                     normalisePath('map_02.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2028
                     normalisePath('map_00.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2029
                     )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2030
                ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2031
                'Maps "%s" are in a a cycle.' % str(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2032
                    (
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2033
                     normalisePath('map_02.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2034
                     normalisePath('map_00.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2035
                     normalisePath('map_01.ditamap'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2036
                     )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2037
                ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2038
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2039
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2040
        self.assertEqual(myO.errStrings(True, None), [genericStringForErrorCode(701)])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2041
        self.assertEqual(myO.errCountMap, {701 : 6})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2042
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2043
    def test_refarc_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2044
        """DitaFileSet: Test ref arcing - all resolve."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2045
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2046
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2047
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2048
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2049
    <topicref href="spam.dita#spam" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2050
    <topicref href="eggs.dita#eggs" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2051
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2052
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2053
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2054
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2055
        myO._addFileObj(StringIO.StringIO('<topic id="spam"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2056
        myO._addFileObj(StringIO.StringIO('<topic id="eggs"/>'), 'eggs.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2057
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2058
        self.assertEqual(myO.errCountMap, {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2059
        self.assertEqual(myO.allErrStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2060
        self.assertEqual(myO.allErrStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2061
        self.assertEqual(myO.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2062
        self.assertEqual(myO.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2063
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2064
    def test_refarc_fail_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2065
        """DitaFileSet: Test ref arcing - can't find file."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2066
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2067
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2068
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2069
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2070
    <topicref href="spam_.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2071
    <topicref href="eggs_for_tea.dita" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2072
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2073
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2074
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2075
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2076
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2077
        self.assertEqual(myO.errCountMap, {410: 2})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2078
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2079
        #pprint.pprint(myO.allErrStrings(False, None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2080
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2081
            myO.allErrStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2082
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2083
                'Can not resolve reference to file "%s"' % normalisePath('eggs_for_tea.dita'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2084
                'Can not resolve reference to file "%s"' % normalisePath('spam_.dita'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2085
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2086
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2087
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2088
            myO.allErrStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2089
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2090
                'Can not resolve reference to file "..."',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2091
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2092
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2093
        self.assertEqual(myO.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2094
        self.assertEqual(myO.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2095
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2096
    def test_refarc_fail_01(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2097
        """DitaFileSet: Test ref arcing - can't find fragment."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2098
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2099
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2100
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2101
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2102
    <topicref href="spam.dita#spam_" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2103
    <topicref href="eggs.dita#eggs_" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2104
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2105
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2106
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2107
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2108
        myO._addFileObj(StringIO.StringIO('<spam id="spam"/>'), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2109
        myO._addFileObj(StringIO.StringIO('<eggs id="eggs"/>'), 'eggs.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2110
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2111
        self.assertEqual(myO.errCountMap, {411: 2})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2112
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2113
        #pprint.pprint(myO.allErrStrings(False, None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2114
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2115
            myO.allErrStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2116
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2117
                'Can resolve reference to file "%s" but not to fragment "eggs_"' % normalisePath('eggs.dita'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2118
                'Can resolve reference to file "%s" but not to fragment "spam_"' % normalisePath('spam.dita'),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2119
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2120
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2121
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2122
            myO.allErrStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2123
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2124
                'Can resolve reference to file "%s" but not to fragment "%s"' % (GENERIC_STRING, GENERIC_STRING),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2125
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2126
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2127
        self.assertEqual(myO.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2128
        self.assertEqual(myO.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2129
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2130
    def test_refarc_url_00(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2131
        """DitaFileSet: Test ref arcing - URL."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2132
        myO = DitaFileSet(None, procDir=False, testExt=True)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2133
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2134
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2135
"""<map id="map_00">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2136
    <topicref href="spam.dita#spam" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2137
    <topicref href="eggs.dita#eggs" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2138
</map>"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2139
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2140
            'map.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2141
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2142
        myO._addFileObj(StringIO.StringIO("""<topic id="spam">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2143
        <xref href="http://www.nokia.com">Nokia</xref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2144
</topic>"""), 'spam.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2145
        myO._addFileObj(StringIO.StringIO("""<topic id="eggs">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2146
        <xref href="http://www.google.com">Google</xref>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2147
</topic>"""), 'eggs.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2148
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2149
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2150
        #pprint.pprint(myO.allErrStrings(False, None))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2151
        self.assertEqual(myO.errCountMap, {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2152
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2153
            myO.allErrStrings(False, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2154
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2155
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2156
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2157
        self.assertEqual(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2158
            myO.allErrStrings(True, None),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2159
            [
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2160
            ]
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2161
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2162
        self.assertEqual(myO.errStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2163
        self.assertEqual(myO.errStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2164
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2165
class TestDitaBookmapFileSet(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2166
    def setUp(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2167
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2168
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2169
    def tearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2170
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2171
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2172
    def testSetUpTearDown(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2173
        """TestDitaBookmapFileSet: test setUp() and tearDown()."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2174
        pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2175
    
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2176
    def test_basic(self):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2177
        """TestDitaBookmapFileSet: Test reading a bookmap and a topic."""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2178
        myO = DitaFileSet(None, procDir=False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2179
        myO._addFileObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2180
            StringIO.StringIO(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2181
"""<?xml version="1.0" encoding="utf-8"?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2182
<!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2183
"bookmap.dtd">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2184
<bookmap id="GUID-5BDFDB6B-7801-4804-9F41-2BDC5BE53DDF">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2185
  <booktitle>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2186
    <mainbooktitle>My Bookmap</mainbooktitle>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2187
    <booktitlealt>Alternate title</booktitlealt>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2188
  </booktitle>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2189
  <frontmatter id="GUID-DA857913-F826-4CF7-A135-93F2AEB48353">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2190
    <topicref href="GUID-00025EAD-C4B6-5408-96A3-FFDBBBDC7CAB.dita" id="GUID-994B1764-393F-401F-8571-CE0955AB6CA6" />
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2191
  </frontmatter>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2192
</bookmap>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2193
"""
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2194
            ),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2195
            'bookmap.ditamap'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2196
        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2197
        myO._addFileObj(StringIO.StringIO("""<?xml version="1.0" encoding="utf-8"?>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2198
<!DOCTYPE concept  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2199
<concept id="GUID-00025EAD-C4B6-5408-96A3-FFDBBBDC7CAB" xml:lang="en">
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2200
    <title>How to read and write a file</title>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2201
</concept>
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2202
"""), 'GUID-00025EAD-C4B6-5408-96A3-FFDBBBDC7CAB.dita')
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2203
        myO.finalise()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2204
        #print
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2205
        #myO.debugDump()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2206
        #print 'HI'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2207
        #myO.writeErrors(False)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2208
        self.assertEqual(myO.allErrStrings(False, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2209
        self.assertEqual(myO.allErrStrings(True, None), [])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2210
        self.assertEqual(myO.errCountMap, {})
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2211
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2212
class Special(unittest.TestCase):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2213
    pass
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2214
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2215
def unitTest(theVerbosity=2):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2216
    suite = unittest.TestLoader().loadTestsFromTestCase(NullClass)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2217
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestCountDict))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2218
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDitaId))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2219
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDitaRef))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2220
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDitaFile))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2221
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDitaFileSet))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2222
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestDitaBookmapFileSet))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2223
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(Special))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2224
    myResult = unittest.TextTestRunner(verbosity=theVerbosity).run(suite)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2225
    return (myResult.testsRun, len(myResult.errors), len(myResult.failures))
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2226
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2227
######################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2228
# main() stuff
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2229
######################################
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2230
def main():
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2231
    print 'CMD: %s' % ' '.join(sys.argv)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2232
    usage = "usage: %prog [options] <Directory of XML content>"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2233
    parser = OptionParser(usage, version='%prog ' + __version__)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2234
    parser.add_option("-d", action="store_true", dest="dump", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2235
                      help="Dump internal representation. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2236
    parser.add_option(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2237
            "-e", "--errors",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2238
            type="str",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2239
            dest="error_codes",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2240
            default='All',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2241
            help="Only report on certain error codes (space seperated list). [default: \"%default\"]"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2242
        )      
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2243
    parser.add_option("-f", "--file", dest="file", type="str", default='None', 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2244
                      help="Report of errors by file either 'None', 'generic', 'specific'. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2245
    parser.add_option("-g", action="store_true", dest="guid", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2246
                      help="Enforce GUID specification. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2247
    parser.add_option(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2248
            "-j", "--jobs",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2249
            type="int",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2250
            dest="jobs",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2251
            default=-1,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2252
            help="Max processes when multiprocessing. 0 takes CPUs, -1 no MP. [default: %default]"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2253
        )      
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2254
    parser.add_option(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2255
            "-l", "--loglevel",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2256
            type="int",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2257
            dest="loglevel",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2258
            default=20,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2259
            help="Log Level (debug=10, info=20, warning=30, [error=40], critical=50) [default: %default]"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2260
        )      
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2261
    parser.add_option(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2262
            "-p", "--pattern",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2263
            type="str",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2264
            dest="pattern",
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2265
            default=FNMATCH_STRING,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2266
            help="Pattern match. [default: \"%default\"]"
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2267
        )      
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2268
    parser.add_option("-r", action="store_true", dest="recursive", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2269
                      help="Recursive. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2270
    parser.add_option("-s", action="store_true", dest="shelve", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2271
                      help="Use the shelve dBase rather than storing the internal representation in memory. This is slower but is useful for large data sets where a memory error might occur. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2272
    parser.add_option("-u", action="store_true", dest="unit_test", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2273
                      help="Execute unit tests and exit. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2274
    parser.add_option("-x", action="store_true", dest="ext_url", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2275
                      help="Test external |URLs. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2276
    parser.add_option("-?", action="store_true", dest="query_errors", default=False, 
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2277
                      help="Display the error types that are detected. [default: %default]")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2278
    (options, args) = parser.parse_args()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2279
    logging.basicConfig(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2280
        level=options.loglevel,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2281
        format='%(asctime)s %(levelname)-8s %(message)s',
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2282
        stream=sys.stdout,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2283
    )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2284
    if options.file not in ('None', 'generic', 'specific'):
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2285
        parser.error("--file option must be: 'None' | 'generic' | 'specific'")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2286
        return 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2287
    if options.unit_test:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2288
        unitTest()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2289
    if options.query_errors:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2290
        writeGenericStringsForErrorCodes()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2291
    if len(args) < 1 and not options.unit_test:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2292
        parser.print_help()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2293
        parser.error("I can't do much without a path to the XML content.")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2294
        return 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2295
    elif len(args) == 1:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2296
        if options.jobs > -1:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2297
            myObj = retMpDitaFileSetObj(
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2298
                        args[0],
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2299
                        options.pattern.split(' '),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2300
                        options.recursive,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2301
                        options.jobs,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2302
                        options.ext_url,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2303
                        options.shelve,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2304
                        )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2305
        else:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2306
            myObj = DitaFileSet(args[0],
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2307
                                procDir=True,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2308
                                thePatterns=options.pattern.split(' '),
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2309
                                recursive=options.recursive,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2310
                                testExt=options.ext_url,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2311
                                useDbase=options.shelve,
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2312
                                )
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2313
            #print 'MyObj:', myObj
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2314
        if options.dump:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2315
            myObj.debugDump()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2316
        myObj.writeStatistics()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2317
        myObj.writeErrorSummary()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2318
        #pprint.pprint(myObj.statsMap)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2319
        # TODO: Write out the results in different ways
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2320
        errFilter = set(PROBLEM_CODE_FORMAT.keys())
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2321
        if options.error_codes != 'All':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2322
            errFilter = set([int(i) for i in options.error_codes.split()])
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2323
        if options.file == 'generic':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2324
            print 'Generic problems:'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2325
            myObj.writeErrors(True, errFilter)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2326
        elif options.file == 'specific':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2327
            print 'Specific problems:'
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2328
            myObj.writeErrors(False, errFilter)
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2329
    elif len(args) > 1:
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2330
        parser.error("Too many arguments, I need only one.")
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2331
        return 1
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2332
    return 0
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2333
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2334
if __name__ == '__main__':
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2335
    multiprocessing.freeze_support()
932c358ece3e Orb version 0.1.9. Fixes Bug 1965, Bug 2401
Michel Szarindar <Michel.Szarindar@Nokia.com>
parents:
diff changeset
  2336
    sys.exit(main())