예제 #1
0
    def test_database_cleaner_function_exception(self):

        from sherlock import database_cleaner
        try:
            this = database_cleaner(log=log,
                                    settings=settings,
                                    fakeKey="break the code")
            this.get()
            assert False
        except Exception, e:
            assert True
            print str(e)
예제 #2
0
    def test_database_cleaner_function(self):

        from sherlock.database_cleaner import database_cleaner
        db = database_cleaner(log=log, settings=settings)
        db.clean()
예제 #3
0
    def add_data_to_database_table(self, dictList, createStatement=False):
        """*Import data in the list of dictionaries in the requested database table*

        Also adds HTMIDs and updates the sherlock-catalogue database helper table with the time-stamp of when the imported catlogue was last updated

        **Key Arguments:**
            - ``dictList`` - a list of dictionaries containing all the rows in the catalogue to be imported
            - ``createStatement`` - the table's mysql create statement (used to generate table if it does not yet exist in database). Default *False*

        **Usage:**

            .. code-block:: python 

                self.add_data_to_database_table(
                    dictList=dictList,
                    createStatement=createStatement
                )

        .. todo ::

            - Write a checklist for creating a new sherlock database importer
        """
        self.log.debug('starting the ``add_data_to_database_table`` method')

        if len(dictList) == 0:
            return

        myPid = self.myPid
        dbTableName = self.dbTableName

        if createStatement:
            writequery(
                log=self.log,
                sqlQuery=createStatement,
                dbConn=self.cataloguesDbConn,
            )

        insert_list_of_dictionaries_into_database_tables(
            dbConn=self.cataloguesDbConn,
            log=self.log,
            dictList=dictList,
            dbTableName=dbTableName,
            uniqueKeyList=[],
            dateModified=True,
            dateCreated=True,
            batchSize=10000,
            replace=True,
            dbSettings=self.settings["database settings"]["static catalogues"])

        self._add_htmids_to_database_table()

        cleaner = database_cleaner(log=self.log, settings=self.settings)
        cleaner._update_tcs_helper_catalogue_tables_info_with_new_tables()

        self._update_database_helper_table()

        print """Now:

- [ ] edit the `%(dbTableName)s` row in the sherlock catalogues database adding relevant column mappings, catalogue version number etc
- [ ] retire any previous version of this catlogue in the database. Renaming the catalogue-table by appending `legacy_` and also change the name in the `tcs_helper_catalogue_tables_info` table
- [ ] dupliate views from the previous catalogue version to point towards the new version and then delete the old views
- [ ] run the command `sherlock clean [-s <pathToSettingsFile>]` to clean up helper tables
- [ ] switch out the old catalogue table/views in your sherlock search algorithms in the yaml settings files
- [ ] run a test batch of transients to make sure catalogue is installed as expected

""" % locals()

        self.log.debug('completed the ``add_data_to_database_table`` method')
        return None