예제 #1
0
파일: entity.py 프로젝트: gldnspud/schevo
 def t_clone(self, **kw):
     """Return a Clone transaction."""
     # First create a Create transaction based on this entity's
     # fields.
     tx = self._Create(self)
     # Apply keyword arguments.
     for name, value in kw.iteritems():
         setattr(tx, name, value)
     # Relabel the transaction.
     relabel(tx, 'Clone')
     return tx
예제 #2
0
파일: test_label.py 프로젝트: Schevo/schevo
 def test_database_decoration(self):
     # This label is assigned automatically.
     assert label.label(db) == u'Schevo Database'
     # It can be easily overridden.
     label.relabel(db, 'Custom Label')
     assert label.label(db) == u'Custom Label'
     # When reopening the database, the label persists.
     self.reopen()
     assert label.label(db) == u'Custom Label'
     # Cannot change the label during a transaction.
     def fn(db):
         label.relabel(db, u'Custom Label 2')
     tx = transaction.CallableWrapper(fn)
     raises(error.DatabaseExecutingTransaction,
            db.execute, tx)
예제 #3
0
파일: database.py 프로젝트: gldnspud/schevo
def create(filename, backend_name, backend_args={},
           schema_source=None, schema_version=None, initialize=True,
           format=None, label=u'Schevo Database'):
    """Create a new database and return it.

    - `filename`: Filename of the new database.
    - `backend_name`: Name of the backend to use when creating the
      database.
    - `backend_args`: (optional) Arguments to pass to the backend.
    - `schema_source`: (optional) Schema source code to synchronize
      the new database with. If `None` is given, the database will
      exist but will contain no extents.
    - `schema_version`: (optional) Version of the schema being used to
      create the database.  If `None` is given, `1` is assumed.
    - `initialize`: `True` (default) if the new database should be
      populated with initial values defined in the schema.
    - `format`: (optional) Internal structure format to use.  If
      `None` is given, the latest format will be used.
    - `label`: (optional) The label to give the new database.
    """
    backend = new_backend(filename, backend_name, backend_args)
    # Make sure the database doesn't already exist.
    root = backend.get_root()
    if 'SCHEVO' in root:
        backend.close()
        raise DatabaseAlreadyExists(filename)
    # Continue creating the new database.
    Database = format_dbclass[format]
    db = Database(backend)
    db._sync(
        schema_source=schema_source,
        schema_version=schema_version,
        initialize=initialize,
        )
    # Apply label.
    relabel(db, label)
    # Install icon support.
    icon.install(db)
    return db
예제 #4
0
파일: entity.py 프로젝트: gldnspud/schevo
 def setup_transactions(cls, class_name, class_dict, t_spec):
     """Create standard transaction classes."""
     # Fields in a transaction class defined in the schema appear
     # below the fields that come from the entity field spec.
     for name in dir(cls):
         # Skip namespace names so we do not access them.
         if len(name) == 1 or name == 'sys':
             continue
         OldClass = getattr(cls, name)
         if not isinstance(OldClass, type):
             continue
         if not issubclass(OldClass, (transaction.Create,
                                      transaction.Delete,
                                      transaction.Update)):
             continue
         NewClass = type(name, (OldClass,), {})
         NewClass._EntityClass = cls
         NewClass._extent_name = class_name
         NewClass._fget_fields = cls._fget_fields
         field_spec = NewClass._field_spec = t_spec.copy()
         field_spec.update(OldClass._field_spec, reorder=True)
         field_spec.reorder_all()
         # Perform any class-level initialization.
         if hasattr(NewClass, '_init_class'):
             NewClass._init_class()
         setattr(cls, name, NewClass)
     # Special case for DeleteSelected.  It needs to be subclassed
     # so that its ._db is set properly, but it does not need the
     # field copying performed above.
     if (isinstance(cls._DeleteSelected, type)
         and issubclass(cls._DeleteSelected, transaction.DeleteSelected)
         ):
         NewClass = type(name, (cls._DeleteSelected,), {})
         NewClass._EntityClass = cls
         NewClass._extent_name = class_name
         if hasattr(NewClass, '_init_class'):
             NewClass._init_class()
         relabel(NewClass, label(cls._DeleteSelected))
         cls._DeleteSelected = NewClass
예제 #5
0
파일: test_label.py 프로젝트: Schevo/schevo
 def fn(db):
     label.relabel(db, u'Custom Label 2')