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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/latest_dx/dx/dxs/scripts/addDatasetGroup.py@793
Revision 793, 2.8 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"""
8addDatasetGroups.py
9===================
10
11Script for adding a new dataset group to the DX.
12
13Usage:
14======
15
16    addDatasetGroup.py -s <shortName> -l <longName> [-p <fileNamePrefix>]
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        <fileNamePrefix>        is the file name prefix for the DX to use (optional).
27        <permittedRoles>        is the list of roles allowed to access the data (default="all").
28        <permittedUsers>        is the list of users allowed to access the data (default="all").
29        <detailedMetadataLink>  is the URI to the detailed ("B") metadata (optional).
30        <discoveryMetadataLink> is the URI to the discovery ("D") metadata record (optional).
31        <usageMetadataLink>     is the URI to the usage ("A") metadata (optional).
32        <documentationLink>     is the URI to documentation (optional).
33        -h                      prints this help message.
34        <outputFilePath>        is an alternative output file to write to (optional).     
35
36Example
37=======
38
39scripts/addDatasetGroup.py -s goodstuff -l "National Toast Forecasting Unit Data"
40     -p ntfud -r dset2,dset3 -u ag -b somewhere -d orother -w help.doc
41
42"""
43
44# Import standard library modules
45import os, sys, re, glob, commands, getopt
46sys.path=sys.path+["..", "."]
47
48# Import local modules
49from InputDatasetManager import *
50
51def addDatasetGroup(args):
52    """
53    Sends command-line arguments to the InputDatasetManager class.
54    """
55    outputFilePath=None
56    (argList, outputFilePath)=getopt.getopt(args, "s:l:p: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": "dxGroupShortName", "-l": "dxGroupLongName", "-p": "dxGroupFileNamePrefix",
65            "-r": "permittedRoles", "-u": "permittedUsers", "-b": "detailedMetadataLink",
66            "-d": "discoveryMetadataLink", "-a": "usageMetadataLink", "-w": "documentationLink"}
67       
68    argDict={}           
69    for (key, value) in argList:
70        if key=="-h":
71            print __doc__
72            return
73        elif key in ("-r", "-u"):
74            argDict[keyMap[key]]=value.replace(",", " ")         
75        else:
76            argDict[keyMap[key]]=value
77
78    ingestor=InputDatasetManager() 
79    ingestor.addDatasetGroup(argDict)
80    ingestor.writeXMLFile(outputFilePath)
81   
82
83
84if __name__=="__main__":
85
86    args=sys.argv[1:]
87    addDatasetGroup(args)
88   
Note: See TracBrowser for help on using the repository browser.