Commits

Olle Lundberg  committed 848ab31

Rename.

  • Participants
  • Parent commits feec152

Comments (0)

Files changed (2)

File src/registry-nerfer.py

+#! /usr/bin/python2
+#
+# Copyright (C) 2011  Red Hat
+#
+# Author: Olle Lunderg (olle@redhat.com)
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+
+
+import ConfigParser
+import StringIO
+import cx_Oracle
+import logging
+import logging.handlers
+import sys
+
+
+def __bootstraplog():
+    log = logging.getLogger(__name__)
+    log.setLevel(logging.DEBUG)
+
+    handler = logging.handlers.RotatingFileHandler("nerfer.log", backupCount = 1)
+    handler.doRollover()
+    formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(lineno)d %(message)s")
+    handler.setFormatter(formatter)
+    handler.setLevel(logging.DEBUG)
+    log.addHandler(handler)
+
+    handler = logging.StreamHandler()
+    formatter = logging.Formatter("%(levelname)s: %(message)s")
+    handler.setLevel(logging.INFO)
+    handler.setFormatter(formatter)
+    log.addHandler(handler)
+
+__bootstraplog()
+
+class SimpleConfigParser(ConfigParser.RawConfigParser):
+    """
+    Simple configuration file parser: based on ConfigParser from the standard
+    library, slightly modified to parse configuration files without sections.
+    """
+
+    def read(self, filename):
+        self.__SECTION = "OHH-IM-FAKE"
+        text = open(filename).read()
+        f = StringIO.StringIO("[%s]\n" % self.__SECTION + text)
+        self.readfp(f, filename)
+
+    def getoption(self, option):
+        'get the value of an option'
+        return self.get(self.__SECTION, option)
+
+
+    def getoptionslist(self):
+        'get a list of available options'
+        return self.options(self.__SECTION)
+
+
+    def hasoption(self, option):
+        """
+        return True if an option is available, False otherwise.
+        (NOTE: do not confuse with the original has_option)
+        """
+        return self.has_option(self.__SECTION, option)
+
+class RegistryNerfer(object):
+
+    def __init__(self, config, prefix = ""):
+        if len(prefix) > 0 and prefix[-1] != ".":
+            prefix += "."
+        self._prefix = prefix
+        self._config = config
+        self._log = logging.getLogger(__name__)
+        # Ignored errors, in this case the errors for type does not exist
+        self._ignorederrors = {"table" : [942], "sequence": [2289] }
+        # Recoverable errors, e.g errors that to us means: try again
+        self._recoverableerrors = {"table" : [2449], "sequence" : []} # Referenced by another table
+        self._tables = """j3_address
+j3_address_line
+j3_auth_token
+j3_binding_category_bag
+j3_binding_descr
+j3_binding_template
+j3_business_category_bag
+j3_business_descr
+j3_business_entity
+j3_business_identifier
+j3_business_name
+j3_business_service
+j3_category_bag
+j3_clerk
+j3_client_subscriptioninfo
+j3_contact
+j3_contact_descr
+j3_discovery_url
+j3_email
+j3_instance_details_descr
+j3_instance_details_doc_descr
+j3_keyed_reference
+j3_keyed_reference_group
+j3_node
+j3_overview_doc
+j3_overview_doc_descr
+j3_person_name
+j3_phone
+j3_publisher
+j3_publisher_assertion
+j3_service_category_bag
+j3_service_descr
+j3_service_name
+j3_service_projection
+j3_subscription
+j3_subscription_chunk_token
+j3_subscription_match
+j3_tmodel
+j3_tmodel_category_bag
+j3_tmodel_descr
+j3_tmodel_identifier
+j3_tmodel_instance_info
+j3_tmodel_instance_info_descr
+j3_transfer_token
+j3_transfer_token_keys
+j3_uddi_entity
+""".splitlines()
+        self._sequences = ["juddi_sequence"]
+
+        def _getprefixedproperty(property):
+            prop = self._prefix + "db." + property
+            self._log.debug("Fetching property: %s" % prop)
+            value = self._config.getoption(prop)
+            log.debug("Property %s is '%s' " % (prop, value))
+            return value
+
+        connectionstring = cx_Oracle.makedsn(_getprefixedproperty("host"),
+                                             _getprefixedproperty("port"),
+                                             _getprefixedproperty("name")
+                                             )
+
+        self._log.debug("Connectionstring is: %s " % connectionstring)
+
+        self._con = cx_Oracle.connect(_getprefixedproperty("user"),
+                          _getprefixedproperty("password"),
+                          connectionstring
+                          )
+        self._cur = self._con.cursor()
+
+    def nerf(self, force = False, purge = True, commit = True):
+        """
+        Drops tables and sequences. Also calls self.commit() if commit is True.
+        """
+        self.nerftables(force, purge)
+        self.nerfsequences(force)
+        if commit:
+            self.commit()
+
+    def commit(self):
+        """
+        Commits the current transaction.
+        """
+        self._con.commit()
+
+    def _donerf(self, type, item, purge):
+        """
+        Build and executes sql for dropping
+        """
+        if purge:
+            prg = "purge"
+        else:
+            prg = ""
+        dropstring = "drop %(type)s %(item)s %(purge)s"
+        dropdict = {"type": type, "item": item, "purge": purge }
+        self._log.debug("Dropping %(type)s '%(item)s' with purge: '%(purge)s'" % dropdict)
+        dropdict['purge'] = prg
+        drop = dropstring % dropdict
+        self._log.debug("Drop statement is '%s'" % drop)
+        try:
+            self._cur.execute(drop)
+        except cx_Oracle.Error, exc:
+            error, = exc.args
+            if error.code in self._ignorederrors[type]:
+                return True
+            elif error.code in self._recoverableerrors[type]:
+                return False
+            else:
+                self._log.exception(exc)
+                raise exc
+
+    def _nerf(self, type, list, force, purge):
+        """
+        Generic function for drop handling
+        """
+        for item in list:
+            self._log.info("Nerfing %s: %s" % (type, item))
+            if self._donerf(type, item, purge):
+                self._log.info("Successfully nerfed: %s" % item)
+                list.remove(item)
+            else:
+                self._log.warn("Failed to nerf: %s" % item)
+        if force and len(list) > 0:
+            self._log.debug("Force is set, recursing through failed %ss." % type)
+            self._nerf(type, list, force, purge)
+
+    def nerftables(self, force = False, purge = True):
+        """
+        Drops all juddi tables
+        """
+        self._nerf("table", self._tables, force, purge)
+
+
+    def nerfsequences(self, force = False):
+        """
+        Drops all juddi sequences
+        """
+        self._nerf("sequence", self._sequences, force, False)
+
+if __name__ == "__main__":
+    log = logging.getLogger(__name__)
+    from optparse import OptionParser
+
+    desc = """Simple python script to clean out the juddi registry"""
+    parser = OptionParser(
+            usage = "usage: %prog [options]",
+            description = desc
+            )
+    parser.add_option("-f", "--file", dest = "filename",
+            help = "Read properties this file", metavar = "FILE")
+    parser.add_option("-p", "--prefix", dest = "prefix",
+            help = "Prefix of properties. By default the following" \
+                "properties are read: db.{host,name,password,port,user}",
+                metavar = "PREFIX", default = "")
+
+    (opts, args) = parser.parse_args()
+
+    if not opts.filename:
+        parser.error("Required option missing.")
+
+    config = SimpleConfigParser()
+    config.read(opts.filename)
+    log.debug("Config is: %s " % config.getoptionslist())
+    nerfer = RegistryNerfer(config, opts.prefix)
+    nerfer.nerf(force = True, purge = True, commit = True)

File src/regsitry-nerfer.py

-#! /usr/bin/python2
-#
-# Copyright (C) 2011  Red Hat
-#
-# Author: Olle Lunderg (olle@redhat.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-
-
-
-import ConfigParser
-import StringIO
-import cx_Oracle
-import logging
-import logging.handlers
-import sys
-
-
-def __bootstraplog():
-    log = logging.getLogger(__name__)
-    log.setLevel(logging.DEBUG)
-
-    handler = logging.handlers.RotatingFileHandler("nerfer.log", backupCount = 1)
-    handler.doRollover()
-    formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(lineno)d %(message)s")
-    handler.setFormatter(formatter)
-    handler.setLevel(logging.DEBUG)
-    log.addHandler(handler)
-
-    handler = logging.StreamHandler()
-    formatter = logging.Formatter("%(levelname)s: %(message)s")
-    handler.setLevel(logging.INFO)
-    handler.setFormatter(formatter)
-    log.addHandler(handler)
-
-__bootstraplog()
-
-class SimpleConfigParser(ConfigParser.RawConfigParser):
-    """
-    Simple configuration file parser: based on ConfigParser from the standard
-    library, slightly modified to parse configuration files without sections.
-    """
-
-    def read(self, filename):
-        self.__SECTION = "OHH-IM-FAKE"
-        text = open(filename).read()
-        f = StringIO.StringIO("[%s]\n" % self.__SECTION + text)
-        self.readfp(f, filename)
-
-    def getoption(self, option):
-        'get the value of an option'
-        return self.get(self.__SECTION, option)
-
-
-    def getoptionslist(self):
-        'get a list of available options'
-        return self.options(self.__SECTION)
-
-
-    def hasoption(self, option):
-        """
-        return True if an option is available, False otherwise.
-        (NOTE: do not confuse with the original has_option)
-        """
-        return self.has_option(self.__SECTION, option)
-
-class RegistryNerfer(object):
-
-    def __init__(self, config, prefix = ""):
-        if len(prefix) > 0 and prefix[-1] != ".":
-            prefix += "."
-        self._prefix = prefix
-        self._config = config
-        self._log = logging.getLogger(__name__)
-        # Ignored errors, in this case the errors for type does not exist
-        self._ignorederrors = {"table" : [942], "sequence": [2289] }
-        # Recoverable errors, e.g errors that to us means: try again
-        self._recoverableerrors = {"table" : [2449], "sequence" : []} # Referenced by another table
-        self._tables = """j3_address
-j3_address_line
-j3_auth_token
-j3_binding_category_bag
-j3_binding_descr
-j3_binding_template
-j3_business_category_bag
-j3_business_descr
-j3_business_entity
-j3_business_identifier
-j3_business_name
-j3_business_service
-j3_category_bag
-j3_clerk
-j3_client_subscriptioninfo
-j3_contact
-j3_contact_descr
-j3_discovery_url
-j3_email
-j3_instance_details_descr
-j3_instance_details_doc_descr
-j3_keyed_reference
-j3_keyed_reference_group
-j3_node
-j3_overview_doc
-j3_overview_doc_descr
-j3_person_name
-j3_phone
-j3_publisher
-j3_publisher_assertion
-j3_service_category_bag
-j3_service_descr
-j3_service_name
-j3_service_projection
-j3_subscription
-j3_subscription_chunk_token
-j3_subscription_match
-j3_tmodel
-j3_tmodel_category_bag
-j3_tmodel_descr
-j3_tmodel_identifier
-j3_tmodel_instance_info
-j3_tmodel_instance_info_descr
-j3_transfer_token
-j3_transfer_token_keys
-j3_uddi_entity
-""".splitlines()
-        self._sequences = ["juddi_sequence"]
-
-        def _getprefixedproperty(property):
-            prop = self._prefix + "db." + property
-            self._log.debug("Fetching property: %s" % prop)
-            value = self._config.getoption(prop)
-            log.debug("Property %s is '%s' " % (prop, value))
-            return value
-
-        connectionstring = cx_Oracle.makedsn(_getprefixedproperty("host"),
-                                             _getprefixedproperty("port"),
-                                             _getprefixedproperty("name")
-                                             )
-
-        self._log.debug("Connectionstring is: %s " % connectionstring)
-
-        self._con = cx_Oracle.connect(_getprefixedproperty("user"),
-                          _getprefixedproperty("password"),
-                          connectionstring
-                          )
-        self._cur = self._con.cursor()
-
-    def nerf(self, force = False, purge = True, commit = True):
-        """
-        Drops tables and sequences. Also calls self.commit() if commit is True.
-        """
-        self.nerftables(force, purge)
-        self.nerfsequences(force)
-        if commit:
-            self.commit()
-
-    def commit(self):
-        """
-        Commits the current transaction.
-        """
-        self._con.commit()
-
-    def _donerf(self, type, item, purge):
-        """
-        Build and executes sql for dropping
-        """
-        if purge:
-            prg = "purge"
-        else:
-            prg = ""
-        dropstring = "drop %(type)s %(item)s %(purge)s"
-        dropdict = {"type": type, "item": item, "purge": purge }
-        self._log.debug("Dropping %(type)s '%(item)s' with purge: '%(purge)s'" % dropdict)
-        dropdict['purge'] = prg
-        drop = dropstring % dropdict
-        self._log.debug("Drop statement is '%s'" % drop)
-        try:
-            self._cur.execute(drop)
-        except cx_Oracle.Error, exc:
-            error, = exc.args
-            if error.code in self._ignorederrors[type]:
-                return True
-            elif error.code in self._recoverableerrors[type]:
-                return False
-            else:
-                self._log.exception(exc)
-                raise exc
-
-    def _nerf(self, type, list, force, purge):
-        """
-        Generic function for drop handling
-        """
-        for item in list:
-            self._log.info("Nerfing %s: %s" % (type, item))
-            if self._donerf(type, item, purge):
-                self._log.info("Successfully nerfed: %s" % item)
-                list.remove(item)
-            else:
-                self._log.warn("Failed to nerf: %s" % item)
-        if force and len(list) > 0:
-            self._log.debug("Force is set, recursing through failed %ss." % type)
-            self._nerf(type, list, force, purge)
-
-    def nerftables(self, force = False, purge = True):
-        """
-        Drops all juddi tables
-        """
-        self._nerf("table", self._tables, force, purge)
-
-
-    def nerfsequences(self, force = False):
-        """
-        Drops all juddi sequences
-        """
-        self._nerf("sequence", self._sequences, force, False)
-
-if __name__ == "__main__":
-    log = logging.getLogger(__name__)
-    from optparse import OptionParser
-
-    desc = """Simple python script to clean out the juddi registry"""
-    parser = OptionParser(
-            usage = "usage: %prog [options]",
-            description = desc
-            )
-    parser.add_option("-f", "--file", dest = "filename",
-            help = "Read properties this file", metavar = "FILE")
-    parser.add_option("-p", "--prefix", dest = "prefix",
-            help = "Prefix of properties. By default the following" \
-                "properties are read: db.{host,name,password,port,user}",
-                metavar = "PREFIX", default = "")
-
-    (opts, args) = parser.parse_args()
-
-    if not opts.filename:
-        parser.error("Required option missing.")
-
-    config = SimpleConfigParser()
-    config.read(opts.filename)
-    log.debug("Config is: %s " % config.getoptionslist())
-    nerfer = RegistryNerfer(config, opts.prefix)
-    nerfer.nerf(force = True, purge = True, commit = True)