Beispiel #1
0
    def setup(self, location=None):
        """Setup the data connector."""
        if location is None:
            raise exceptions.InsufficientConfiguration(
                    "the location for storing datas was not specified for " \
                    "the YAML data connector")

        location = location.replace("\\", "/")
        if location.startswith("~"):
            location = os.path.expanduser("~") + location[1:]

        if location.endswith("/"):
            location = location[:-1]

        if not os.path.exists(location):
            # Try to create it
            os.makedirs(location)

        if not os.access(location, os.R_OK):
            raise exceptions.DriverInitializationError(
                "cannot read in {}".format(location))
        if not os.access(location, os.W_OK):
            raise exceptions.DriverInitializationError(
                "cannot write in {}".format(location))

        DataConnector.__init__(self)
        self.location = location
        self.files = {}
Beispiel #2
0
 def record_model(self, model):
     """Record the given model."""
     DataConnector.record_model(self, model)
     name = DataConnector.record_model(self, model)
     self.collections[name] = self.datas[name]
     self.inc_collections[name] = self.increments[name]
     self.object_ids[name] = {}
Beispiel #3
0
 def setup(self, location=None):
     """Setup the data connector."""
     if location is None:
         raise exceptions.InsufficientConfiguration(
                 "the location for storing datas was not specified for " \
                 "the YAML data connector")
     
     location = location.replace("\\", "/")
     if location.startswith("~"):
         location = os.path.expanduser("~") + location[1:]
     
     if location.endswith("/"):
         location = location[:-1]
     
     if not os.path.exists(location):
         # Try to create it
         os.makedirs(location)
     
     if not os.access(location, os.R_OK):
         raise exceptions.DriverInitializationError(
                 "cannot read in {}".format(location))
     if not os.access(location, os.W_OK):
         raise exceptions.DriverInitializationError(
                 "cannot write in {}".format(location))
     
     DataConnector.__init__(self)
     self.location = location
     self.files = {}
Beispiel #4
0
 def clear(self):
     """Clear the stored datas."""
     for name in self.models.keys():
         self.datas[name].remove()
         self.datas.drop_collection(name)
         self.increments[name].remove({})
         self.increments.drop_collection(name)
     DataConnector.clear(self)
Beispiel #5
0
 def record_tables(self, classes):
     """Record the tables."""
     cursor = self.connection.cursor()
     cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
     tables = [row[0] for row in cursor.fetchall()]
     self.created_tables = tuple(tables)
     DataConnector.record_tables(self, classes)
     self.connection.commit()
Beispiel #6
0
 def record_tables(self, classes):
     """Record the tables."""
     cursor = self.connection.cursor()
     cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
     tables = [row[0] for row in cursor.fetchall()]
     self.created_tables = tuple(tables)
     DataConnector.record_tables(self, classes)
     self.connection.commit()
Beispiel #7
0
    def __init__(self):
        """Check the driver presence.

        If not found, raise a DriverNotFound exception.

        """
        if not driver:
            raise exceptions.DriverNotFound(
                    "the pymongo library can not be found")

        DataConnector.__init__(self)
        self.db_name = "datas"
        self.inc_name = "increments"
Beispiel #8
0
 def setup(self, location=None):
     """Setup the data connector."""
     if location is None:
         raise exceptions.InsufficientConfiguration(
                 "the location for storing datas was not specified for " \
                 "the sqlite3 data connector")
     
     location = location.replace("\\", "/")
     if location.startswith("~"):
         location = os.path.expanduser("~") + location[1:]
     
     DataConnector.__init__(self)
     self.location = location
     self.connection = sqlite3.connect(self.location)
Beispiel #9
0
    def setup(self, location=None):
        """Setup the data connector."""
        if location is None:
            raise exceptions.InsufficientConfiguration(
                    "the location for storing datas was not specified for " \
                    "the sqlite3 data connector")

        location = location.replace("\\", "/")
        if location.startswith("~"):
            location = os.path.expanduser("~") + location[1:]

        DataConnector.__init__(self)
        self.location = location
        self.connection = sqlite3.connect(self.location)
Beispiel #10
0
    def record_model(self, model):
        """Record the given model."""
        name = DataConnector.record_model(self, model)
        filename = self.location + "/" + name + ".yml"
        if os.path.exists(filename):
            with open(filename, "r") as file:
                self.read_table(name, file)

        self.files[name] = filename
Beispiel #11
0
 def record_model(self, model):
     """Record the given model."""
     name = DataConnector.record_model(self, model)
     filename = self.location + "/" + name + ".yml"
     if os.path.exists(filename):
         with open(filename, "r") as file:
             self.read_table(name, file)
     
     self.files[name] = filename
Beispiel #12
0
 def record_model(self, model):
     """Record a single model."""
     DataConnector.record_model(self, model)
     name = get_plural_name(model)
     if name not in self.created_tables:
         self.create_table(name, model)
Beispiel #13
0
 def record_model(self, model):
     """Record a single model."""
     DataConnector.record_model(self, model)
     name = get_plural_name(model)
     if name not in self.created_tables:
         self.create_table(name, model)