コード例 #1
0
 def test_check_open_empty(self):
     name = mktemp()
     f = open(name, 'w')
     f.close()
     s = FileStorage(name)
     s.close()
     unlink(name)
コード例 #2
0
ファイル: db_inject.py プロジェクト: gldnspud/schevo
 def main(self, arg0, args):
     print
     print
     parser = _parser()
     options, args = parser.parse_args(list(args))
     if len(args) != 1:
         parser.error('Please specify DBFILE.')
     db_filename = args[0]
     if not os.path.isfile(db_filename):
         parser.error('Please specify a DBFILE that exists.')
     # Process paths.  Start with app_path option and populate
     # schema_path and icon_path based on it if it is set, then use
     # icon_path and schema_path options to override.
     def path(pkg_or_path):
         """If pkg_or_path is a module, return its path; otherwise,
         return pkg_or_path."""
         from_list = pkg_or_path.split('.')[:1]
         try:
             pkg = __import__(pkg_or_path, {}, {}, from_list)
         except ImportError:
             return pkg_or_path
         if '__init__.py' in pkg.__file__:
             # Package was specified; return the dir it's in.
             return os.path.dirname(pkg.__file__)
         else:
             # Module was specified; return its filename.
             return pkg.__file__
     schema_path = None
     if options.app_path:
         app_path = path(options.app_path)
         schema_path = os.path.join(app_path, 'schema')
     if options.schema_path:
         schema_path = path(options.schema_path)
     # Inspect the database file to get its schema version.
     fs = FileStorage(db_filename)
     schema_version = Connection(fs).get_root()['SCHEVO']['version']
     fs.close()
     print 'Database is at version %i.' % schema_version
     # Inject the schema.
     schema_source = schevo.schema.read(schema_path, version=schema_version)
     schevo.database.inject(
         filename=db_filename,
         backend_name=options.backend_name,
         backend_args=options.backend_args,
         schema_source=schema_source,
         version=schema_version,
         )
     print 'Schema injected as version %i.' % schema_version
コード例 #3
0
 def _check_file_storage(self, storage):
     b = storage
     assert b.new_oid() == p64(1)
     assert b.new_oid() == p64(2)
     try:
         b.load(p64(0))
         assert 0
     except KeyError: pass
     record = pack_record(p64(0), 'ok', '')
     b.store(p64(0), record)
     b.begin()
     b.end()
     b.sync()
     b.begin()
     b.store(p64(1), pack_record(p64(1), 'no', ''))
     b.end()
     assert len(list(b.gen_oid_record())) == 2
     b.pack()
     import schevo.store.file_storage
     if schevo.store.file_storage.RENAME_OPEN_FILE:
         schevo.store.file_storage.RENAME_OPEN_FILE = False
         b.pack()
         c = FileStorage(b.get_filename(), readonly=True)
         try:
             c.pack()
             assert 0
         except IOError: # read-only storage
             pass
     b.close()
     try:
         b.pack()
         assert 0
     except IOError: # storage closed
         pass
     try:
         b.load(0)
         assert 0
     except IOError: # storage closed
         pass