Home | Trees | Indices | Help |
|
---|
|
1 #! /usr/bin/env python 2 #------------------------------------------------------------------------------ 3 #$Id: AddIndices.py 6236 2009-11-02 17:34:44Z RossCollins $ 4 """ 5 Create table indexes. 6 7 Archive table indexes are defined in the script WSA_Indices.sql - this 8 application parses that static script, and then invokes index creation on 9 the database server, one by one, logging results. This application is 10 provided for routine, GUI-driven operation of the archive. 11 12 To add an index to any archive table, edit the script WSA_Indices.sql 13 and then either play the script in Query Analyser, or run this (remember to 14 re-parse the schema browser documentation to pick up newly indexed, and 15 therefore highlighted, attributes!). 16 17 @author: R.S. Collins 18 @org: WFAU, IfA, University of Edinburgh 19 20 @newfield contributors: Contributors, Contributors (Alphabetical Order) 21 @contributors: J. Bryant, N.C. Hambly, E. Sutorius 22 """ 23 #------------------------------------------------------------------------------ 24 from wsatools.CLI import CLI 25 from wsatools.DbConnect.CuSession import CuSession 26 import wsatools.DbConnect.Schema as schema 27 from wsatools.Logger import Logger 28 #------------------------------------------------------------------------------ 2931 """ Create table indexes for all programmes. 32 """ 33 # Class parameters - should not be altered 34 cuNum = 18 35 # Must be minimally logged else transaction fails without apparent error 36 _autoCommit = True 37 # User-options 38 indexName = '' #: Select just those indices with this phrase in their name. 39 releasedOnly = False #: Just apply releasable indices? 4065 66 #------------------------------------------------------------------------------ 67 # Entry point for script. 68 69 # Allow module to be imported as well as executed from the command line 70 if __name__ == '__main__': 71 # Define additional command-line options for Indexer 72 CLI.progOpts += [ 73 CLI.Option('n', 'nonsurvey', 'create indices for non-survey programmes'), 74 CLI.Option('r', 'release_only', 'only create releaseable indices'), 75 CLI.Option('s', 'selection', 76 'just indices with this phrase in their name', 'NAME')] 77 78 cli = CLI(Indexer.__name__, '$Revision: 6236 $', Indexer.__doc__) 79 Logger.isVerbose = False 80 Logger.addMessage(cli.getProgDetails()) 81 82 cu = Indexer('NONSURVEYS' if cli.getOpt('nonsurvey') else '', cli=cli) 83 if cli.getOpt('selection'): 84 cu.indexName = cli.getOpt('selection') 85 cu.releasedOnly = cli.getOpt('release_only') 86 cu.run() 87 88 #------------------------------------------------------------------------------ 89 # Change log: 90 # 91 # 14-Jul-2005, NCH: Original version: not debugged or tested. 92 # 22-Jul-2005, NCH: Testing and further development 93 # 25-Jul-2005, NCH: Finished, tested & bug fixed: completed. 94 # 25-Oct-2005, NCH: Added name to optional argument in createIndex call. 95 # 14-Nov-2005, NCH: Made a tad more robust by trapping specific 96 # exceptions thrown for an individual create index 97 # call, logging and then continuing (as opposed to 98 # halting execution completely). 99 # 5-Dec-2005, JB: Now imports sys so it can run from the command line. 100 # 5-Dec-2005, JB: Moved flushing the transaction log to after writing 101 # the log file. 102 # 13-Dec-2005, JB: Commented out flushing the transaction log 103 # 20-Jan-2006, JB: Added code so that the name of the database being used 104 # is prepended to the logfile filename and tidied text. 105 # 23-Mar-2006, ETWS: Included non survey flag as command line parameter 106 # 28-Mar-2006, JB: Changed production code to work on the WSA by default. 107 # 16-May-2006, ETWS: Fixed programme curation history update 108 # 6-Jun-2006, JB: Fixed coding errors (if statement and print statement) 109 # 31-Jul-2006, NCH: Moved core code that has SQL-specific content into 110 # new wrapper SqlWrappers.checkIndex(). 111 # 20-Sep-2006, RSC: Upgraded to OO framework. 112 # 19-Feb-2007, RSC: Made transactions auto-commit otherwise indices are never 113 # created! 114 # 28-Feb-2007, RSC: Moved cu18.py to helpers/AddIndices.py as this is no 115 # longer a necessary CU in regular use. 11642 """ 43 Creates indices for all tables. 44 45 Method: use the information parsed from the static SQL script 46 WSA_Indices.sql to cycle through every index for every table, creating 47 each one if it does not exist. The underlying assumption is that if an 48 index needs updating, then it will have been dropped by a previous 49 procedure that updated the indexed data, e.g. a bulk load operation, 50 or a recalibration operation. 51 52 """ 53 tableIndices = schema.parseIndices(self.sysc.nsIndexScript 54 if self.onlyNonSurveys else self.sysc.indexScript) 55 56 for tableName, idxList in tableIndices.items(): 57 for index in idxList: 58 if (not self.releasedOnly or index.releasable) and \ 59 (not self.indexName or self.indexName in index.name): 60 if self.archive.addIndex(index, ignoreNS=True): 61 Logger.addMessage("Index created.") 62 # If index created update list of programmes affected 63 self.programmeID.update( 64 self.programme.getProgIDsfromTable(tableName))
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Sep 8 15:47:01 2014 | http://epydoc.sourceforge.net |