Ejemplo n.º 1
0
    def createNew(self, fileName):
        """ Create empty database """

        # test if batch file exists
        if not (os.path.exists(BATCHFILENAME)):

            self.log.error(
                'IO error detected while trying to open database creation script.'
            )
            raise FileError(
                'IO error detected while trying to open database creation script.'
            )

        # before creating new DB we must delete eventual preexistent catalog
        if os.path.exists(fileName):

            self.log.warning('A file with the same name already exists.')
            raise FileError('A file with the same name already exists.')

        # create new DB
        tmpDb = sqlitetoolkit.liteDB(fileName)

        try:  # open SQL batch file

            file = open(BATCHFILENAME, 'r')

        except FileExceptionError, e:

            self.log.error("Error while trying to open batch file.")
            raise FileError("Error while trying to open batch file.")
Ejemplo n.º 2
0
	def createNew(self, fileName):
		""" Create empty database """
		
		# test if batch file exists
		if not( os.path.exists (BATCHFILENAME) ):
			
			self.log.error('IO error detected while trying to open database creation script.')
			raise FileError( 'IO error detected while trying to open database creation script.' )
		
		
		# before creating new DB we must delete eventual preexistent catalog
		if os.path.exists( fileName ):
			
			self.log.warning ('A file with the same name already exists.')
			raise FileError ('A file with the same name already exists.')
		
		# create new DB
		tmpDb = sqlitetoolkit.liteDB(fileName)
		
		try: # open SQL batch file
			
			file = open(BATCHFILENAME, 'r')
			
		except FileExceptionError, e:
			
			self.log.error ("Error while trying to open batch file.")
			raise FileError ("Error while trying to open batch file.")
Ejemplo n.º 3
0
	def checkDb(self, path):
		""" Test if given file is a catalog """
		
		testDb = sqlitetoolkit.liteDB(path)
		
		try:
			
			testDb.execStmt("select id, name, idDeviceType, idCategory from DAT_Devices limit 1;")
			
		except sqlitetoolkit.ExecutionError, e:
			
			# Problems while executing statement, file is not recognized as a catalog
			self.log.warning ("CHECK 1 - Given file is not recognized as a valid catalog.")
			return False
Ejemplo n.º 4
0
class Catalog:
    def __init__(self):

        # set up local log
        self.log = logging.getLogger('pyCatalog.catalog')

    def openCatalog(self, path):

        # TEST if path is not empty
        if path == "":

            self.log.warning("No valid catalog name provided:")
            self.log.warning(path)
            raise FileError("No valid catalog name provided:")

        # TEST if catalog file exists
        if not (self.checkExistence(path)):

            self.log.warning('Given file doesn\'t exist.')
            raise FileError('Given file doesn\'t exist.')

        # TEST if given file is a valid catalog
        if not (self.checkDb(path)):

            self.log.warning('Given file doesn\'t seem to be a valid catalog.')
            raise CatalogError(
                "Given file doesn\'t seem to be a valid catalog.")

        # set path to current catalog
        self.path = path

        # set name of current catalog
        self.name = os.path.split(path)[1]

        # set path to working copy of current catalog
        self.workPath = path + "~"

        try:  # make a work copy of catalog

            shutil.copy2(path, self.workPath)

        except Exception, e:

            self.log.error("Error while trying to make work copy of catalog")
            raise FileError("Error while trying to make work copy of catalog")

        # open SQLite connection to work copy
        self.db = sqlitetoolkit.liteDB(self.workPath)
        self.log.info('Catalog ' + path + ' is open.')
Ejemplo n.º 5
0
    def checkDb(self, path):
        """ Test if given file is a catalog """

        testDb = sqlitetoolkit.liteDB(path)

        try:

            testDb.execStmt(
                "select id, name, idDeviceType from DAT_Devices limit 1;")

        except sqlitetoolkit.ExecutionError, e:

            # Problems while executing statement, file is not recognized as a catalog
            self.log.warning(
                "CHECK 1 - Given file is not recognized as a valid catalog.")
            return False
Ejemplo n.º 6
0
class Catalog:
    def __init__(self, callback):

        # set up local log
        self.log = logging.getLogger('pyCatalog.catalog')

        # callback function to notify catalog changes
        self.callback = callback

    def setStatus(self, status):
        """
			Notify if catalog has been modified.
		"""

        assert status in (False, True)

        # set new status
        self.saved = status

        # notify status change
        self.callback(status)

    def openCatalog(self, path):

        # TEST if path is not empty
        if path == "":

            self.log.warning("No valid catalog name provided:")
            self.log.warning(path)
            raise FileError("No valid catalog name provided:")

        # TEST if catalog file exists
        if not (self.checkExistence(path)):

            self.log.warning('Given file doesn\'t exist.')
            raise FileError('Given file doesn\'t exist.')

        # TEST if given file is a valid catalog
        if not (self.checkDb(path)):

            self.log.warning('Given file doesn\'t seem to be a valid catalog.')
            raise CatalogError(
                "Given file doesn\'t seem to be a valid catalog.")

        # set path to current catalog
        self.path = path

        # set name of current catalog
        self.name = os.path.split(path)[1]

        # set path to working copy of current catalog
        self.workPath = path + "~"

        try:  # make a work copy of catalog

            shutil.copy2(path, self.workPath)

        except Exception, e:

            self.log.error("Error while trying to make work copy of catalog")
            raise FileError("Error while trying to make work copy of catalog")

        # open SQLite connection to work copy
        self.db = sqlitetoolkit.liteDB(self.workPath)
        self.log.info('Catalog ' + path + ' is open.')

        self.setStatus(True)