source: TI01-discovery-OaiInfoEditor/trunk/v3n_NDG3/OAIInfoEditor/oai_info_editor/model/formattype.py @ 6843

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery-OaiInfoEditor/trunk/v3n_NDG3/OAIInfoEditor/oai_info_editor/model/formattype.py@6843
Revision 6843, 2.0 KB checked in by sdonegan, 10 years ago (diff)

Added DIF_9.4 type to allow for full MEDIN provider portal ingestion

  • Property svn:executable set to *
Line 
1'''
2 Simple data structure representing format type values
3   
4 @author: C Byrom, Tessella Apr 2009
5'''
6import logging
7
8class FormatType(object):
9   
10    def __init__(self, typeFlag, typeName, htmlColour, title = None):
11        '''
12        Associate a format type name with a numerical flag to associate it with
13        @param typeFlag: int representing the format type
14        @param typeName: name representing the format type
15        @param htmlColour: colour to represent format in html
16        @keyword title: title to give the format type; if this is None (the
17        default), the title is set to equal the typeName
18        '''
19        self.typeFlag = typeFlag
20        self.typeName = typeName
21        self.htmlColour = htmlColour
22        self.title = typeName
23        if title:
24            self.title = title
25
26    def __str__(self):
27        return self.typeName
28
29
30DIF_FLAG = 1
31MDIP_FLAG = 2
32GCMD_FLAG = 4
33ISO_FLAG = 8
34MEDIN_FLAG = 999 # !!
35DIF94_FLAG = 123 # !!
36
37
38DIF_NAME = 'dif'
39MDIP_NAME = 'mdip'
40GCMD_NAME = 'gcmd'
41ISO_NAME = 'iso'
42MEDIN_NAME = 'MEDIN_2.3'
43DIF94_NAME = 'DIF_9.4'
44
45DIF = FormatType(DIF_FLAG, DIF_NAME, 'PaleTurquoise')
46MDIP = FormatType(MDIP_FLAG, MDIP_NAME, 'PaleGreen')
47GCMD = FormatType(GCMD_FLAG, GCMD_NAME, 'Chartreuse')
48ISO = FormatType(ISO_FLAG, ISO_NAME, 'Wheat')
49MEDIN = FormatType(MEDIN_FLAG, MEDIN_NAME, 'Yellow')
50DIF94 = FormatType(DIF94_FLAG, DIF94_NAME, 'PaleBlue')
51
52ALL_TYPES = [DIF, MDIP, GCMD, ISO, MEDIN, DIF94]
53ALL_NAMES = [DIF_NAME, MDIP_NAME, GCMD_NAME, ISO_NAME, MEDIN_NAME, DIF94_NAME]
54
55def getFormatType(name):
56    '''
57    Retrieve the format type object with the specified name
58    @param name: name of the FormatType to look up
59    @raise ValueError if the name doesn't correspond to a format type
60    @return FormatType matching the input name
61    '''
62    logging.debug("Looking for format type with name, '%s'" %name)
63    for type in ALL_TYPES:
64        if type.typeName == name:
65            logging.debug("- found matching format type")
66            return type
67   
68    raise ValueError("Unrecognised format type, '%s'" %name)
69
Note: See TracBrowser for help on using the repository browser.