Beispiel #1
0
 def run(self, args):
     check_options_consistency(self.config)
     print('\n' + underline_title('Initializing the system database'))
     from cubicweb.server import init_repository
     appid = args[0]
     config = ServerConfiguration.config_for(appid)
     try:
         system = config.system_source_config
         extra_args = system.get('db-extra-arguments')
         extra = extra_args and {'extra_args': extra_args} or {}
         get_connection(system['db-driver'],
                        database=system['db-name'],
                        host=system.get('db-host'),
                        port=system.get('db-port'),
                        user=system.get('db-user') or '',
                        password=system.get('db-password') or '',
                        schema=system.get('db-namespace'),
                        **extra)
     except Exception as ex:
         raise ConfigurationError(
             'You seem to have provided wrong connection information in '
             'the %s file. Resolve this first (error: %s).' %
             (config.sources_file(), str(ex).strip()))
     init_repository(config, drop=self.config.drop)
     if not self.config.automatic:
         while ASK.confirm('Enter another source ?', default_is_yes=False):
             CWCTL.run([
                 'source-add', '--config-level',
                 str(self.config.config_level), config.appid
             ])
Beispiel #2
0
 def postcreate(self, automatic=False, inputlevel=0):
     if automatic:
         CWCTL.run(['db-create', '--automatic', self.config.appid])
     elif ASK.confirm('Run db-create to create the system database ?'):
         CWCTL.run([
             'db-create', '--config-level',
             str(inputlevel), self.config.appid
         ])
     else:
         print('-> nevermind, you can do it later with '
               '"cubicweb-ctl db-create %s".' % self.config.appid)
Beispiel #3
0
 def run(self, args):
     appid, backupfile = args
     if self.config.format == 'portable':
         # we need to ensure a DB exist before restoring from portable format
         if not self.config.no_drop:
             try:
                 CWCTL.run(['db-create', '--automatic', appid])
             except SystemExit as exc:
                 # continue if the command exited with status 0 (success)
                 if exc.code:
                     raise
     _local_restore(appid,
                    backupfile,
                    drop=not self.config.no_drop,
                    format=self.config.format)
     if self.config.format == 'portable':
         try:
             CWCTL.run(['db-rebuild-fti', appid])
         except SystemExit as exc:
             if exc.code:
                 raise
Beispiel #4
0
                      if cwconfig['base-url'].startswith('https') else 'http')
        repo = app.application.registry['cubicweb.repository']
        try:
            waitress.serve(app,
                           host=host,
                           port=port,
                           url_scheme=url_scheme,
                           clear_untrusted_proxy_headers=True)
        finally:
            repo.shutdown()
        if self._needreload:
            return 3
        return 0


CWCTL.register(PyramidStartHandler)


def _turn_sigterm_into_systemexit():
    """Attempts to turn a SIGTERM exception into a SystemExit exception."""
    try:
        import signal
    except ImportError:
        return

    def handle_term(signo, frame):
        raise SystemExit

    signal.signal(signal.SIGTERM, handle_term)

Beispiel #5
0
            etype = self['show-etype']
            visitor = s2d.OneHopESchemaVisitor(schema[etype],
                                               skiptypes=skiptypes)
            propshdlr = s2d.SchemaDotPropsHandler(visitor)
            backend = DotBackend('schema',
                                 'BT',
                                 ratio='compress',
                                 size=None,
                                 renderer='dot',
                                 additionnal_param={
                                     'overlap': 'false',
                                     'splines': 'true',
                                     'sep': '0.2'
                                 })
            generator = s2d.GraphGenerator(backend)
            generator.generate(visitor, propshdlr, out)

        if viewer:
            p = Popen((viewer, out))
            p.wait()


for cmdcls in (
        UpdateCubicWebCatalogCommand,
        UpdateCubeCatalogCommand,
        NewCubeCommand,
        ExamineLogCommand,
        GenerateSchema,
):
    CWCTL.register(cmdcls)
Beispiel #6
0
class WebUpgradeHandler(CommandHandler, GenStaticDataDirMixIn):
    cmdname = 'upgrade'

    def postupgrade(self, repo):
        config = self.config
        if not config['generate-staticdir']:
            return
        self.generate_static_dir(config, ask_clean=True, repo=repo)


class GenStaticDataDir(Command, GenStaticDataDirMixIn):
    """Create a directory merging all data directory content from cubes and CW.
    """
    name = 'gen-static-datadir'
    arguments = '<instance> [dirpath]'
    min_args = 1
    max_args = 2

    options = ()

    def run(self, args):
        appid = args.pop(0)
        config = cwcfg.config_for(appid)
        dest = None
        if args:
            dest = args[0]
        self.generate_static_dir(config, dest)


CWCTL.register(GenStaticDataDir)
Beispiel #7
0
 def run(self, args):
     """run the command with its specific arguments"""
     check_options_consistency(self.config)
     automatic = self.get('automatic')
     appid = args.pop()
     config = ServerConfiguration.config_for(appid)
     source = config.system_source_config
     dbname = source['db-name']
     driver = source['db-driver']
     helper = get_db_helper(driver)
     if driver == 'sqlite':
         if os.path.exists(dbname) and (automatic or ASK.confirm(
                 'Database %s already exists. Drop it?' % dbname)):
             os.unlink(dbname)
     elif self.config.create_db:
         print('\n' + underline_title('Creating the system database'))
         # connect on the dbms system base to create our base
         dbcnx = _db_sys_cnx(source,
                             'CREATE/DROP DATABASE and / or USER',
                             interactive=not automatic)
         cursor = dbcnx.cursor()
         try:
             if helper.users_support:
                 user = source['db-user']
                 if not helper.user_exists(cursor, user) and (
                         automatic
                         or ASK.confirm('Create db user %s ?' % user,
                                        default_is_yes=False)):
                     helper.create_user(source['db-user'],
                                        source.get('db-password'))
                     print('-> user %s created.' % user)
             if dbname in helper.list_databases(cursor):
                 if automatic or ASK.confirm(
                         'Database %s already exists -- '
                         'do you want to drop it ?' % dbname):
                     cursor.execute('DROP DATABASE "%s"' % dbname)
                 else:
                     print('you may want to run "cubicweb-ctl db-init '
                           '--drop %s" manually to continue.' %
                           config.appid)
                     return
             createdb(helper, source, dbcnx, cursor)
             dbcnx.commit()
             print('-> database %s created.' % dbname)
         except BaseException:
             dbcnx.rollback()
             raise
     cnx = system_source_cnx(source,
                             special_privs='CREATE LANGUAGE/SCHEMA',
                             interactive=not automatic)
     cursor = cnx.cursor()
     helper.init_fti_extensions(cursor)
     namespace = source.get('db-namespace')
     if namespace and ASK.confirm('Create schema %s in database %s ?' %
                                  (namespace, dbname)):
         helper.create_schema(cursor, namespace)
     cnx.commit()
     # postgres specific stuff
     if driver == 'postgres':
         # install plpythonu/plpgsql languages
         langs = ('plpythonu', 'plpgsql')
         for extlang in langs:
             if automatic or ASK.confirm('Create language %s ?' % extlang):
                 try:
                     helper.create_language(cursor, extlang)
                 except Exception as exc:
                     print('-> ERROR:', exc)
                     print('-> could not create language %s, '
                           'some stored procedures might be unusable' %
                           extlang)
                     cnx.rollback()
                 else:
                     cnx.commit()
     print(
         '-> database for instance %s created and necessary extensions installed.'
         % appid)
     print()
     if automatic:
         CWCTL.run([
             'db-init', '--automatic', '--config-level', '0', config.appid
         ])
     elif ASK.confirm('Run db-init to initialize the system database ?'):
         CWCTL.run([
             'db-init', '--config-level',
             str(self.config.config_level), config.appid
         ])
     else:
         print('-> nevermind, you can do it later with '
               '"cubicweb-ctl db-init %s".' % config.appid)
Beispiel #8
0
        CreateInstanceDBCommand,
        InitInstanceCommand,
        GrantUserOnInstanceCommand,
        ResetAdminPasswordCommand,
        DBDumpCommand,
        DBRestoreCommand,
        DBCopyCommand,
        DBIndexSanityCheckCommand,
        AddSourceCommand,
        CheckRepositoryCommand,
        RebuildFTICommand,
        SynchronizeSourceCommand,
        SchemaDiffCommand,
        RepositorySchedulerCommand,
):
    CWCTL.register(cmdclass)

# extend configure command to set options in sources config file ###############

db_options = (('db', {
    'short':
    'd',
    'type':
    'named',
    'metavar':
    '[section1.]key1:value1,[section2.]key2:value2',
    'default':
    None,
    'help':
    '''set <key> in <section> to <value> in "source" configuration file. If
<section> is not specified, it defaults to "system".
Beispiel #9
0
    arguments = '<instance id> <fs file or directory>...'
    options = (
        ("map-folders",
         {'short': 'F', 'action' : 'store_true',
          'default': False,
          'help': 'map file-system directories as Folder entities (requires the `folder` cube).',
          }),
        ("filed-under",
         {'short': 'u', 'type' : 'int',
          'help': 'put imported file into the folder entity of the given eid.',
          }),
        )

    def run(self, args):
        """run the command with its specific arguments"""
        from cubicweb.server.serverconfig import ServerConfiguration
        from cubicweb.server.serverctl import repo_cnx
        from cubes.file.fsimport import fsimport
        appid = args.pop(0)
        config = ServerConfiguration.config_for(appid)
        repo, cnx = repo_cnx(config)
        repo.hm.call_hooks('server_maintenance', repo=repo)
        session = repo._get_session(cnx.sessionid, setcnxset=True)
        fsimport(session, args, parenteid=self.config.filed_under,
                 mapfolders=self.config.map_folders,
                 bfss='data' in repo.system_source._storages.get('File', ()),
                 )
        session.commit()

CWCTL.register(FSImportCommand)