source: TI03-DataExtractor/trunk/dxs/scripts/addDataset.py @ 1138

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/dxs/scripts/addDataset.py@1138
Revision 1138, 3.3 KB checked in by astephen, 13 years ago (diff)

Latest relatively stable version with CSML input and almost output.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
4#   This software may be distributed under the terms of the
5#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
6
7"""
8addDataset.py
9=============
10
11Script for adding a new dataset to the DX.
12
13Usage:
14======
15
16    addDataset.py -s <shortName> -l <longName> -g <datasetGroup> [-n <fileNameSection>]
17                       [-r <permittedRoles>] [-u <permittedUsers>] [-b <detailedMetadataLink>]
18                       [-d <discoveryMetadataLink>] [-a <usageMetadataLink>] [-w <documentationLink>]
19                       [-h] <outputFilePath>
20                       
21
22Where:
23======
24        <shortName>             is the short name of the item to add (mandatory).
25        <longName>              is the long name of the item to add (mandatory).
26        <datasetGroup>          is the short name of the parent dataset group that the datasets sits under (mandatory).
27        <fileNameSection>       is the file name section for the DX to use (optional).
28        <permittedRoles>        is the comma-separated list of roles allowed to access the data (default="all").
29        <permittedUsers>        is the comma-separated list of users allowed to access the data (default="all").
30        <detailedMetadataLink>  is the URI to the detailed ("B") metadata (optional).
31        <discoveryMetadataLink> is the URI to the discovery ("D") metadata record (optional).
32        <usageMetadataLink>     is the URI to the usage ("A") metadata (optional).
33        <documentationLink>     is the URI to documentation (optional).
34        -h                      prints this help message.       
35        <outputFilePath>        is an alternative output file to write to (optional).     
36
37Example
38=======
39
40    scripts/addDataset.py -s super -l "Super model 3.1" -g foam -r dset2,nqwf1,ncqw2 -u ag -b somewhere -d orother -w help.doc -a /usr/local/dxs/testdata/var1.nc
41
42"""
43
44# Import standard library modules
45import sys, getopt
46sys.path=sys.path+["..", "."]
47
48# Import local modules
49from pydxs.InputDatasetManager import *
50
51def addDataset(args):
52    """
53    Sends command-line arguments to the InputDatasetManager class.
54    """
55    outputFilePath=None
56    (argList, outputFilePath)=getopt.getopt(args, "s:l:g:n:r:u:b:d:a:hw:")
57   
58    if argList==[]: 
59        print __doc__
60        sys.exit()
61       
62    if outputFilePath: outputFilePath=outputFilePath[0]
63   
64    keyMap={"-s": "dxDatasetShortName", "-l": "dxDatasetLongName", "-g":"DXDatasetGroup", 
65            "-n": "dxDatasetFileNameSection", "-r": "permittedRoles", "-u": "permittedUsers", 
66            "-b": "detailedMetadataLink", "-d": "discoveryMetadataLink", "-a": "usageMetadataLink", 
67            "-w": "documentationLink"}
68       
69    argDict={}
70    datasetGroup=None
71    for (key, value) in argList:
72        if key=="-h":
73            print __doc__
74            return
75        elif key=="-g":
76            datasetGroup=value
77        elif key in ("-r", "-u"):
78            argDict[keyMap[key]]=value.replace(",", " ")           
79        else:
80            argDict[keyMap[key]]=value
81
82    if datasetGroup==None:
83        raise "Must provide parent dataset group to add dataset to with argument flag -g."
84    elif not argDict.has_key("usageMetadataLink"):
85        raise "Must provide the usage metadata link ('A' metadata) with argument flag -a."
86       
87    ingestor=InputDatasetManager() 
88    ingestor.addDataset(datasetGroup, argDict)
89    ingestor.writeXMLFile(outputFilePath)
90   
91
92
93if __name__=="__main__":
94
95    args=sys.argv[1:]
96    addDataset(args)
97   
Note: See TracBrowser for help on using the repository browser.