Example #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 = {}
Example #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] = {}
Example #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 = {}
Example #4
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] = {}
Example #5
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)
Example #6
0
 def record_models(self, models):
     """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_models(self, models)
     self.connection.commit()
Example #7
0
 def record_models(self, models):
     """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_models(self, models)
     self.connection.commit()
Example #8
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)
Example #9
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"
Example #10
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"
Example #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
Example #12
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
Example #13
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:]
     
     location_dir = os.path.split(location)[0]
     if location_dir and not os.path.exists(location_dir):
         # Try to create it
         os.makedirs(location_dir)
     
     DataConnector.__init__(self)
     self.location = location
     self.connection = sqlite3.connect(self.location)
Example #14
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:]

        location_dir = os.path.split(location)[0]
        if location_dir and not os.path.exists(location_dir):
            # Try to create it
            os.makedirs(location_dir)

        DataConnector.__init__(self)
        self.location = location
        self.connection = sqlite3.connect(self.location)
Example #15
0
 def setup(self, host=None, port=None, dbname=None, dbuser=None,
         dbpass=""):
     """Setup the data connector."""
     if host is None:
         raise exceptions.InsufficientConfiguration(
                 "the database host was not specified for " \
                 "the postgresql data connector")
     
     if port is None:
         raise exceptions.InsufficientConfiguration(
                 "the database port was not specified for " \
                 "the postgresql data connector")
     
     if dbname is None:
         raise exceptions.InsufficientConfiguration(
                 "the database name was not specified for " \
                 "the postgresql data connector")
     
     if dbuser is None:
         raise exceptions.InsufficientConfiguration(
                 "the database user was not specified for " \
                 "the postgresql data connector")
     
     DataConnector.__init__(self)
     if dbpass is None:
         dbpass = ""
     else:
         dbpass = str(dbpass)
     
     self.db_host = host
     self.db_port = port
     self.db_name = dbname
     self.db_user = dbuser
     self.db_pass = dbpass
     self.connection = postgresql.open(
             "pq://{user}:{password}@{host}:{port}/{database}".format(
             user=dbuser, password=dbpass, host=host, port=port,
             database=dbname))
Example #16
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)
Example #17
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)
Example #18
0
 def record_models(self, models):
     """Record the tables."""
     query = "SELECT table_name FROM information_schema.tables"
     statement = self.connection.prepare(query)
     self.created_tables = tuple(row[0] for row in statement())
     DataConnector.record_models(self, models)