source: TI03-DataExtractor/branches/old_stuff/latest_dx/dx/dxs/scripts/addDataset.py @ 793

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

Put all the old code in the old_stuff branch.

  • 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" -s foam -r dset2,nqwf1,ncqw2 -u ag
41         -b somewhere -d orother -w help.doc -g ncof -a /usr/local/dxs/testdata/var1.nc
42
43"""
44
45# Import standard library modules
46import sys, getopt
47sys.path=sys.path+["..", "."]
48
49# Import local modules
50from InputDatasetManager import *
51
52def addDataset(args):
53    """
54    Sends command-line arguments to the InputDatasetManager class.
55    """
56    outputFilePath=None
57    (argList, outputFilePath)=getopt.getopt(args, "s:l:g:n:r:u:b:d:a:hw:")
58   
59    if argList==[]: 
60        print __doc__
61        sys.exit()
62       
63    if outputFilePath: outputFilePath=outputFilePath[0]
64   
65    keyMap={"-s": "dxDatasetShortName", "-l": "dxDatasetLongName", "-g":"DXDatasetGroup", 
66            "-n": "dxDatasetFileNameSection", "-r": "permittedRoles", "-u": "permittedUsers", 
67            "-b": "detailedMetadataLink", "-d": "discoveryMetadataLink", "-a": "usageMetadataLink", 
68            "-w": "documentationLink"}
69       
70    argDict={}
71    datasetGroup=None
72    for (key, value) in argList:
73        if key=="-h":
74            print __doc__
75            return
76        elif key=="-g":
77            datasetGroup=value
78        elif key in ("-r", "-u"):
79            argDict[keyMap[key]]=value.replace(",", " ")           
80        else:
81            argDict[keyMap[key]]=value
82
83    if datasetGroup==None:
84        raise "Must provide parent dataset group to add dataset to with argument flag -g."
85    elif not argDict.has_key("usageMetadataLink"):
86        raise "Must provide the usage metadata link ('A' metadata) with argument flag -a."
87       
88    ingestor=InputDatasetManager() 
89    ingestor.addDataset(datasetGroup, argDict)
90    ingestor.writeXMLFile(outputFilePath)
91   
92
93
94if __name__=="__main__":
95
96    args=sys.argv[1:]
97    addDataset(args)
98   
Note: See TracBrowser for help on using the repository browser.