Package helpers :: Module UpdateCatData
[hide private]

Source Code for Module helpers.UpdateCatData

 1  #! /usr/bin/env python 
 2  #------------------------------------------------------------------------------ 
 3  #$Id: UpdateCatData.py 4083 2007-09-12 17:00:39Z RossCollins $ 
 4  """ 
 5     Updates database table values from catalogue file headers for new 
 6     attributes, given attributes or where there is missing/dodgy for a given 
 7     date. 
 8   
 9     @author: R.S. Collins 
10     @org:    WFAU, IfA, University of Edinburgh 
11  """ 
12  #------------------------------------------------------------------------------ 
13  from   wsatools.CLI       import CLI 
14  import wsatools.CSV       as csv 
15  from   wsatools.FitsToDb  import CatFileUpdater 
16  from   wsatools.Logger    import Logger 
17  #------------------------------------------------------------------------------ 
18   
19  # Allow script to be imported as well as executed from the command line 
20  if __name__ == '__main__': 
21      # Define command-line interface settings 
22      CLI.progOpts += [ 
23        CLI.Option('a', 'attrs', 
24                   'just update these attributes (comma-separated list)', 
25                   'LIST'), 
26        CLI.Option('m', 'missing_only', 
27                   'just update the missing catalogue data'), 
28        CLI.Option('n', 'night', 'just update catalogue files from this night ' 
29                   'e.g. 2005-12-11 or 20051211', 'DATE', isValOK=CLI.isDateOK) 
30        ] 
31      # Change default comment 
32      CLI.progArgs['comment'] = "Updating catalogue data" 
33   
34      cli = CLI("UpdateCatData", "$Revision: 4083 $", __doc__) 
35      Logger.isVerbose = cli.getOpt('verbose') 
36      Logger.addMessage(cli.getProgDetails()) 
37   
38      comment = cli.getArg('comment') 
39      if cli.getOpt('attrs'): 
40          comment = comment.replace('data', "attribute values for " + 
41                                            cli.getOpt('attrs')) 
42      if cli.getOpt('night'): 
43          if len(cli.getOpt('night')) < 8: 
44              raise SystemExit("Semester dates not acceptable, e.g. %s" 
45                               % cli.getOpt('night')) 
46          comment += " for %s." % cli.getOpt('night') 
47   
48      catUpdater = CatFileUpdater(cli=cli) 
49      catUpdater.date = cli.getOpt('night') 
50      catUpdater.doMissingOnly = cli.getOpt('missing_only') 
51      if cli.getOpt('attrs'): 
52          catUpdater.reqAttrs = list(csv.values(cli.getOpt('attrs'))) 
53      catUpdater.run() 
54   
55  #------------------------------------------------------------------------------ 
56  # Change log: 
57  # 
58  # 18-May-2006,  RSC: Original version. 
59