예제 #1
0
파일: MySQL.py 프로젝트: sodaphish/break
 def db_init(self, schema ):
     """
     function to initialize a database's table(s) in the event they have not already been initialized.
     """
     #TODO: initialize the database schema
     try: 
             pass
     except:
         raise Exceptions.ConfigFault("Couldn't initialize database")
예제 #2
0
파일: SQLite3.py 프로젝트: sodaphish/break
 def db_init(self, schema):
     """
     function to initialize a database's table(s) in the event they have not already been initialized.
     
     schema here is the XML schema, filename, or open file handle, which gets turned into a DBSchema object
     """
     #TODO: initialize the database schema
     try:
         pass
     except:
         raise Exceptions.ConfigFault("Couldn't initialize database")
예제 #3
0
파일: MySQL.py 프로젝트: sodaphish/break
    def __init__(self, host, port, user, password, db, cursorclass="dict"):
        """
        Class to use to connect to Mysql database.  Must specify host, port,
        user, password and database.  Default cursor is dict unless otherwise
        specified.
        """
        self.host = host

        try:
            self.port = int(port)
        except ValueError, e:
            raise Exceptions.DatabaseConnectError(e)
예제 #4
0
    def _validate_loglevel(self, level):
        _level = level

        if isinstance(_level, str):

            result = logging.getLevelName(_level)

            if isinstance(result, int):
                return result
            else:
                raise Exceptions.InvalidLogLevelType(
                    "'%s' in not a valid log level" % _level)
        else:
            return _level
예제 #5
0
    def _validate_syslogfacility(self, level):
        _level = level

        if isinstance(_level, str):

            result = logging.handlers.SysLogHandler.facility_names.get(
                _level.lower())

            if result:
                return result
            else:
                raise Exceptions.InvalidSyslogFacilityType(
                    "'%s' is not a valid Syslog facility level" % _level)
        else:
            return _level
예제 #6
0
    def _check_dirpath(self, filename):
        try:
            _dirname = os.path.dirname(filename)

            if not _dirname:
                _dirname = os.path.curdir

            if all(
                [os.access(_dirname, os.R_OK),
                 os.access(_dirname, os.W_OK)]):
                return filename
            else:
                raise Exceptions.DirectoryAccessError(
                    "Unable to read or write to directory location '%s'" %
                    _dirname)

        except AttributeError:  # If original 'None' type is passed in
            return None
예제 #7
0
_ver = Version(int(cfg.get_value('version.major')),
               int(cfg.get_value('version.minor')),
               int(cfg.get_value('version.patch')))

loglevel = cfg.get_value('logging.loglevel')
logcfg = LoggerConfig(loglevel, **cfg.config)
logging.config.dictConfig(logcfg.config)
log = logging.getLogger()
"""
Verify that the configuration file is defined and that our database type is defined.
"""
try:
    cfg
except NameError:
    raise Exceptions.ConfigFault(
        "configuration file not defined as 'cfg', that's a no no.")
#NOTE: this is optional for some projects.
try:
    cfg.get_value('db.type')
except Exception as e:
    print "database type not defined in configuration file"
    sys.exit(1)

try:
    db = None
    if cfg.get_value(db.type):
        if cfg.get_value(db.type) == 'mysql':
            #TODO: attempt the database connection using the MySQL
            pass
        elif cfg.get_value(db.type) == 'sqlite3':
            try: