Package helpers :: Module AddColumns
[hide private]

Source Code for Module helpers.AddColumns

 1  #! /usr/bin/env python 
 2  #------------------------------------------------------------------------------ 
 3  #$Id: AddColumns.py 5194 2008-10-07 15:09:28Z RossCollins $ 
 4  """ 
 5     Add new attributes to a database table and update their values, or existing 
 6     attributes, from the original FITS headers values using the prescription 
 7     defined in the schema file. Note, this does not update values taken from 
 8     catalogue files. To do this use UpdateCatData.py. 
 9   
10     @author: R.S. Collins 
11     @org:    WFAU, IfA, University of Edinburgh 
12  """ 
13  #------------------------------------------------------------------------------ 
14  from   wsatools.CLI      import CLI 
15  import wsatools.CSV          as csv 
16  from   wsatools.FitsToDb import AttributeUpdater 
17  from   wsatools.Logger   import Logger 
18  #------------------------------------------------------------------------------ 
19   
20  # Allow script to be imported as well as executed from the command line 
21  if __name__ == '__main__': 
22      # Define command-line interface settings 
23      CLI.progOpts += [ 
24        CLI.Option('a', 'attrs', 
25          'comma-separated list of existing attributes to update', 
26          'LIST'), 
27        CLI.Option('l', 'tables', 
28          'comma-separated list of tables to update', 
29          'LIST', ', '.join(AttributeUpdater.tableList)), 
30        CLI.Option('o', 'only_stacks', 
31          'only update attribute values of stacked frames'), 
32        CLI.Option('s', 'schema', 
33          'schema file to parse for table attributes', 
34          'FILE', AttributeUpdater.schemaFileName)] 
35   
36      # Change default comment 
37      CLI.progArgs['comment'] = AttributeUpdater.comment 
38   
39      cli = CLI("AddColumns", "$Revision: 5194 $", __doc__) 
40      Logger.isVerbose = cli.getOpt('verbose') 
41      Logger.addMessage(cli.getProgDetails()) 
42   
43      updater = AttributeUpdater(cli=cli) 
44      if cli.getOpt('attrs'): 
45          updater.reqAttrs = list(csv.values(cli.getOpt('attrs'))) 
46      updater.schemaFileName = cli.getOpt('schema') 
47      updater.tableList = list(csv.values(cli.getOpt('tables'))) 
48      updater.doStacksOnly = cli.getOpt('only_stacks') 
49      updater.run() 
50   
51  #------------------------------------------------------------------------------ 
52  # Change log: 
53  # 
54  # 13-Jun-2006,  RSC: Original version. Derived from apply_schema_changes.py 
55