Package invocations :: Package monitoring :: Module SpotMissingIngests
[hide private]

Source Code for Module invocations.monitoring.SpotMissingIngests

 1  #! /usr/bin/env python 
 2  #------------------------------------------------------------------------------ 
 3  # $Id: SpotMissingIngests.py 6773 2010-04-06 15:55:21Z RossCollins $ 
 4  """ 
 5     Spots missing file ingests in the database, by comparing the given transfer 
 6     log to the list of files presently stored in the database for a given 
 7     cuEventID. 
 8   
 9     @author: R.S. Collins 
10     @org:    WFAU, IfA, University of Edinburgh 
11  """ 
12  #------------------------------------------------------------------------------ 
13  import os 
14   
15  from wsatools.CLI                 import CLI 
16  from wsatools.DbConnect.DbSession import DbSession 
17  from wsatools.Logger              import Logger 
18  #------------------------------------------------------------------------------ 
19  # Entry point for script. 
20   
21  # Allow module to be imported as well as executed from the command line 
22  if __name__ == "__main__": 
23      CLI.progOpts.remove("test") 
24      CLI.progOpts.remove("user") 
25      CLI.progArgs += [ 
26        CLI.Argument("xferlog", "June05Av3_filelist20050608to14.log"), 
27        CLI.Argument("cuEventID", "1830", isValOK=lambda x: x.isdigit())] 
28      CLI.progOpts.append( 
29        CLI.Option('o', "output", 
30          "Name of file to write results to", "NAME")) 
31   
32      cli = CLI("SpotMissingIngests", "$Revision: 6773 $", __doc__) 
33      Logger.isVerbose = False 
34      Logger.addMessage(cli.getProgDetails()) 
35   
36      db = DbSession(cli.getArg("database")) 
37   
38      ingestedList = db.query("fileName", "Multiframe", 
39        "multiframeID>0 AND cuEventID="+cli.getArg("cuEventID")) 
40   
41      transList = file(os.path.join("/disk01/wsa/ingest/logs/", 
42                                    cli.getArg("xferlog"))).readlines() 
43      transSet = set(line.rstrip() for line in transList 
44                                    if not line.endswith("_cat.fits\n")) 
45   
46      ingestedSet = set(file.split(':')[-1] for file in ingestedList) 
47      notIngestedSet = transSet - ingestedSet 
48   
49      if not cli.getOpt("output"): 
50          print('\n'.join(notIngestedSet)) 
51      else: 
52          Logger.addMessage("Writing results to " + cli.getOpt("output")) 
53          open(cli.getOpt("output"), 'w').write('\n'.join(notIngestedSet)) 
54   
55  #------------------------------------------------------------------------------ 
56  # Change log: 
57  # 
58  # 20-Nov-2006,  RSC: Original version. 
59