Ejemplo n.º 1
0
 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]
     # 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.
     icon_path = None
     schema_path = None
     if options.app_path:
         app_path = package_path(options.app_path)
         icon_path = os.path.join(app_path, 'icons')
         schema_path = os.path.join(app_path, 'schema')
     if options.icon_path:
         icon_path = package_path(options.icon_path)
     if options.schema_path:
         schema_path = package_path(options.schema_path)
     if schema_path is None:
         parser.error('Please specify either the --app or --schema option.')
     # Open the database.
     if not os.path.isfile(db_filename):
         parser.error('DBFILE must be an existing database.')
     print 'Opening database...'
     db = schevo.database.open(
         filename=db_filename,
         backend_name=options.backend_name,
         backend_args=options.backend_args,
         )
     print 'Current database version is %i.' % db.version
     try:
         schema_source = schevo.schema.read(schema_path, version=db.version)
     except schevo.error.SchemaFileIOError:
         parser.error('Could not read schema source for version %i.'
                      % db.version)
     print 'Syncing database with new schema source...'
     db._sync(schema_source, initialize=False)
     # Import icons.
     if icon_path and os.path.exists(icon_path):
         print 'Importing icons...'
         schevo.icon.install(db, icon_path)
     if options.pack:
         # Pack the database.
         print 'Packing the database...'
         db.pack()
     # Done.
     db.close()
     print 'Database updated.'
Ejemplo n.º 2
0
 def main(self, arg0, args):
     print
     print
     parser = _parser()
     options, args = parser.parse_args(list(args))
     if len(args) != 2:
         parser.error('Please specify both DBFILE and VERSION.')
     db_filename, final_version = args
     final_version = final_version.lower()
     if final_version != 'latest':
         try:
             final_version = int(final_version)
         except ValueError:
             parser.error('Please specify a version number or "latest".')
     # 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.
     icon_path = None
     schema_path = None
     if options.app_path:
         app_path = package_path(options.app_path)
         icon_path = os.path.join(app_path, 'icons')
         schema_path = os.path.join(app_path, 'schema')
     if options.icon_path:
         icon_path = package_path(options.icon_path)
     if options.schema_path:
         schema_path = package_path(options.schema_path)
     if schema_path is None:
         parser.error('Please specify either the --app or --schema option.')
     # Open the database.
     if not os.path.isfile(db_filename):
         parser.error('DBFILE must be an existing database.')
     db = schevo.database.open(
         filename=db_filename,
         backend_name=options.backend_name,
         backend_args=options.backend_args,
         )
     print 'Current database version is %i.' % db.version
     if final_version == 'latest':
         final_version = schevo.schema.latest_version(schema_path)
     evolve_db(parser, schema_path, db, final_version)
     # Import icons.
     if icon_path and os.path.exists(icon_path):
         print 'Importing icons...'
         schevo.icon.install(db, icon_path)
     # Pack the database.
     print 'Packing the database...'
     db.pack()
     # Done.
     db.close()
     print 'Database evolution complete.'
Ejemplo n.º 3
0
 def schemata_from_package(pkg_name, final_version):
     schemata = []
     schema_path = package_path(pkg_name)
     version = 0
     while True:
         if version == final_version:
             break
         version += 1
         source = schevo.schema.read(schema_path, version=version)
         schemata.append(source)
     return schemata
Ejemplo n.º 4
0
 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]
     # 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.
     icon_path = None
     schema_path = None
     if options.app_path:
         app_path = package_path(options.app_path)
         icon_path = os.path.join(app_path, 'icons')
         schema_path = os.path.join(app_path, 'schema')
     if options.icon_path:
         icon_path = package_path(options.icon_path)
     if options.schema_path:
         schema_path = package_path(options.schema_path)
     if schema_path is None:
         parser.error('Please specify either the --app or --schema option.')
     # Delete the database file if one exists.
     if options.delete_existing_database:
         if os.path.isfile(db_filename):
             print 'Deleting existing file:', db_filename
             os.remove(db_filename)
     # Use a default backend if one was not specified on the
     # command-line.
     if options.backend_name is None:
         options.backend_name = os.environ.get(
             'SCHEVO_DEFAULT_BACKEND', 'durus')
     # Create the database.
     if os.path.isfile(db_filename):
         parser.error(
             'Use "schevo db update" or "schevo db evolve" commands to '
             'update or evolve an existing database.')
     final_version = options.schema_version.lower()
     if final_version != 'latest':
         try:
             final_version = int(final_version)
         except ValueError:
             parser.error(
                 'Please specify a version number or "latest" '
                 'for the --version option.')
     else:
         final_version = schevo.schema.latest_version(schema_path)
     evolve_from_version = options.evolve_from_version.lower()
     if evolve_from_version != 'latest':
         try:
             evolve_from_version = int(evolve_from_version)
         except ValueError:
             parser.error(
                 'Please specify a version number or "latest" '
                 'for the --evolve-from-version option.')
     else:
         evolve_from_version = schevo.schema.latest_version(schema_path)
     if evolve_from_version > final_version:
         # Respect the version number given by --version over the
         # version number given by --evolve-from-version.
         evolve_from_version = final_version
     print 'Creating new database at version %r.' % evolve_from_version
     schema_source = schevo.schema.read(
         schema_path, version=evolve_from_version)
     db = schevo.database.create(
         filename=db_filename,
         backend_name=options.backend_name,
         backend_args=options.backend_args,
         schema_source=schema_source,
         schema_version=evolve_from_version,
         )
     # Evolve if necessary.
     if final_version > evolve_from_version:
         print 'Evolving database...'
         evolve_db(parser, schema_path, db, final_version)
     # Import icons.
     if icon_path and os.path.exists(icon_path):
         print 'Importing icons...'
         schevo.icon.install(db, icon_path)
     # Create sample data.
     if options.create_sample_data:
         print 'Populating with sample data...'
         db.populate()
     # Pack the database.
     print 'Packing the database...'
     db.pack()
     # Done.
     print 'Database version is now at %i.' % db.version
     db.close()
     print 'Database created.'
Ejemplo n.º 5
0
 def main(self, arg0, args):
     print
     print
     parser = _parser()
     options, args = parser.parse_args(list(args))
     if len(args) != 1:
         parser.error('Please specify URL.')
     url = args[0]
     # 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.
     icon_path = None
     schema_path = None
     if options.app_path:
         app_path = package_path(options.app_path)
         icon_path = os.path.join(app_path, 'icons')
         schema_path = os.path.join(app_path, 'schema')
     if options.icon_path:
         icon_path = package_path(options.icon_path)
     if options.schema_path:
         schema_path = package_path(options.schema_path)
     if schema_path is None:
         parser.error('Please specify either the --app or --schema option.')
     # Use a default backend if one was not specified on the
     # command-line.
     if '://' not in url:
         url = 'durus:///%s' % url
     # Create the database.
     final_version = options.schema_version.lower()
     if final_version != 'latest':
         try:
             final_version = int(final_version)
         except ValueError:
             parser.error(
                 'Please specify a version number or "latest" '
                 'for the --version option.')
     else:
         final_version = schevo.schema.latest_version(schema_path)
     evolve_from_version = options.evolve_from_version.lower()
     if evolve_from_version != 'latest':
         try:
             evolve_from_version = int(evolve_from_version)
         except ValueError:
             parser.error(
                 'Please specify a version number or "latest" '
                 'for the --evolve-from-version option.')
     else:
         evolve_from_version = schevo.schema.latest_version(schema_path)
     if evolve_from_version > final_version:
         # Respect the version number given by --version over the
         # version number given by --evolve-from-version.
         evolve_from_version = final_version
     print 'Creating new database at version %r.' % evolve_from_version
     schema_source = schevo.schema.read(
         schema_path, version=evolve_from_version)
     try:
         db = schevo.database.create(
             url,
             schema_source=schema_source,
             schema_version=evolve_from_version,
             )
     except schevo.error.DatabaseAlreadyExists:
         print 'ERROR: Database already exists.'
         print 'Use "schevo db update" or "schevo db evolve" commands to'
         print 'update or evolve an existing database.'
         return 1
     # Evolve if necessary.
     if final_version > evolve_from_version:
         print 'Evolving database...'
         evolve_db(parser, schema_path, db, final_version)
     # Import icons.
     if icon_path and os.path.exists(icon_path):
         print 'Importing icons...'
         schevo.icon.install(db, icon_path)
     # Create sample data.
     if options.create_sample_data:
         print 'Populating with sample data...'
         db.populate()
     # Pack the database.
     print 'Packing the database...'
     db.pack()
     # Done.
     print 'Database version is now at %i.' % db.version
     db.close()
     print 'Database created.'