コード例 #1
0
ファイル: conftest.py プロジェクト: charlesjkwanin/omegaup
    def mysql_auth(self):
        '''Gets the authentication string for MySQL.'''

        return database_utils.authentication(
            config_file=self.options.mysql_config_file,
            username=self.options.username,
            password=self.options.password)
コード例 #2
0
ファイル: policy-tool.py プロジェクト: yoshoo90/omegaup
def main():
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--database', default='omegaup', help='MySQL database')
    parser.add_argument('--username',
                        default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for development.
    parser_validate = subparsers.add_parser(
        'validate', help='Validates that the versioning is sane')
    parser_validate.set_defaults(func=validate)

    parser_upgrade = subparsers.add_parser('upgrade',
                                           help='Generates the upgrade script')
    parser_upgrade.set_defaults(func=upgrade)

    args = parser.parse_args()
    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password)
    args.func(args, auth)
コード例 #3
0
ファイル: policy-tool.py プロジェクト: categulario/omegaup
def main():
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--database', default='omegaup', help='MySQL database')
    parser.add_argument('--username', default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for development.
    parser_validate = subparsers.add_parser(
        'validate', help='Validates that the versioning is sane')
    parser_validate.set_defaults(func=validate)

    parser_upgrade = subparsers.add_parser(
        'upgrade', help='Generates the upgrade script')
    parser_upgrade.set_defaults(func=upgrade)

    args = parser.parse_args()
    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password)
    args.func(args, auth)
コード例 #4
0
def _main() -> None:
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--skip-container-check',
                        action='store_true',
                        help='Skip the container check')
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--database', default='omegaup', help='MySQL database')
    parser.add_argument('--hostname',
                        default=None,
                        type=str,
                        help='Hostname of the MySQL server')
    parser.add_argument('--port',
                        default=13306,
                        type=int,
                        help='Port of the MySQL server')
    parser.add_argument('--username',
                        default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for development.
    parser_validate = subparsers.add_parser(
        'validate', help='Validates that the versioning is sane')
    parser_validate.set_defaults(func=validate)

    parser_upgrade = subparsers.add_parser('upgrade',
                                           help='Generates the upgrade script')
    parser_upgrade.set_defaults(func=upgrade)

    args = parser.parse_args()

    if not args.skip_container_check:
        database_utils.check_inside_container()

    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password,
                                         hostname=args.hostname,
                                         port=args.port)
    args.func(args, auth)
コード例 #5
0
ファイル: db-migrate.py プロジェクト: mjayalam/omegaup
def main() -> None:
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--mysql-config-file',
        default=database_utils.default_config_file(),
        help='.my.cnf file that stores credentials')
    parser.add_argument(
        '--username', default='root', help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    parser.add_argument('--verbose', action='store_true')
    parser.add_argument(
        '--aws-username',
        default='omegaup-rds-deploy',
        help='The name of the AWS user to change the RDS timeout')
    parser.add_argument(
        '--aws-rds-region',
        default='us-east-1',
        help='The region of the RDS database')
    parser.add_argument(
        '--aws-rds-parameter-group-name',
        default='omegaup-frontend',
        help='The name of the Parameter Group name')
    parser.add_argument(
        '--lower-timeout',
        default='mysql',
        choices=('no', 'mysql', 'aws'),
        help='Temporarily lower the wait timeout.')
    parser.add_argument(
        '--kill-other-connections',
        action='store_true',
        help='Kill all connections to MySQL.')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for puppet.
    parser_exists = subparsers.add_parser(
        'exists', help='Checks if the migration table exists')
    parser_exists.set_defaults(func=exists)

    parser_latest = subparsers.add_parser(
        'latest', help='Checks if the database is at the latest revision')
    parser_latest.set_defaults(func=latest)

    parser_migrate = subparsers.add_parser(
        'migrate', help='Migrates the database to the latest revision')
    parser_migrate.add_argument(
        '--noop',
        action='store_true',
        help=('Only print scripts that would be '
              'installed'))
    parser_migrate.add_argument(
        '--development-environment',
        dest='development_environment',
        action='store_true',
        help='Installs scripts flagged as for testing')
    parser_migrate.add_argument(
        '--databases',
        default='omegaup,omegaup-test',
        help='Comma-separated list of databases')
    parser_migrate.add_argument(
        '--limit', type=int, help='Last revision to include')
    parser_migrate.set_defaults(func=migrate)

    # Commands for development.
    parser_validate = subparsers.add_parser(
        'validate', help='Validates that the versioning is sane')
    parser_validate.set_defaults(func=validate)

    parser_ensure = subparsers.add_parser(
        'ensure', help='Ensures that the migration table exists')
    parser_ensure.set_defaults(func=ensure)

    parser_reset = subparsers.add_parser(
        'reset', help='Resets the migration table to a particular revision')
    parser_reset.add_argument(
        'revision', help='The desired revision', type=int)
    parser_reset.set_defaults(func=reset)

    parser_revision = subparsers.add_parser(
        'revision', help='Gets the current revision')
    parser_revision.set_defaults(func=print_revision)

    parser_purge = subparsers.add_parser(
        'purge', help='Start from scratch - Drop & Create empty databases')
    parser_purge.add_argument(
        '--databases',
        default=('omegaup,omegaup-test,'
                 '_omegaup_metadata'),
        help='Comma-separated list of databases')
    parser_purge.set_defaults(func=purge)

    parser_schema = subparsers.add_parser(
        'schema',
        help=('Show the database schema. Does not actually '
              'read/write from the database'))
    parser_schema.add_argument(
        '--limit', type=int, help='Last revision to include')
    parser_schema.set_defaults(func=schema)

    args = parser.parse_args()

    if args.verbose:
        logging.getLogger().setLevel('DEBUG')

    auth = database_utils.authentication(
        config_file=args.mysql_config_file,
        username=args.username,
        password=args.password)
    args.func(args, auth)
コード例 #6
0
def main():
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--username',
                        default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for puppet.
    parser_exists = subparsers.add_parser(
        'exists', help='Checks if the migration table exists')
    parser_exists.set_defaults(func=exists)

    parser_latest = subparsers.add_parser(
        'latest', help='Checks if the database is at the latest revision')
    parser_latest.set_defaults(func=latest)

    parser_migrate = subparsers.add_parser(
        'migrate', help='Migrates the database to the latest revision')
    parser_migrate.add_argument('--noop',
                                action='store_true',
                                help=('Only print scripts that would be '
                                      'installed'))
    parser_migrate.add_argument('--development-environment',
                                dest='development_environment',
                                action='store_true',
                                help='Installs scripts flagged as for testing')
    parser_migrate.add_argument('--databases',
                                default='omegaup,omegaup-test',
                                help='Comma-separated list of databases')
    parser_migrate.add_argument('--limit',
                                type=int,
                                help='Last revision to include')
    parser_migrate.set_defaults(func=migrate)

    # Commands for development.
    parser_ensure = subparsers.add_parser(
        'ensure', help='Ensures that the migration table exists')
    parser_ensure.set_defaults(func=ensure)

    parser_reset = subparsers.add_parser(
        'reset', help='Resets the migration table to a particular revision')
    parser_reset.add_argument('revision',
                              help='The desired revision',
                              type=int)
    parser_reset.set_defaults(func=reset)

    parser_revision = subparsers.add_parser('revision',
                                            help='Gets the current revision')
    parser_revision.set_defaults(func=print_revision)

    parser_purge = subparsers.add_parser(
        'purge', help='Start from scratch - Drop & Create empty databases')
    parser_purge.add_argument('--databases',
                              default=('omegaup,omegaup-test,'
                                       '_omegaup_metadata'),
                              help='Comma-separated list of databases')
    parser_purge.set_defaults(func=purge)

    parser_schema = subparsers.add_parser(
        'schema',
        help=('Show the database schema. Does not actually '
              'read/write from the database'))
    parser_schema.add_argument('--limit',
                               type=int,
                               help='Last revision to include')
    parser_schema.set_defaults(func=schema)

    args = parser.parse_args()
    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password)
    args.func(args, auth)
コード例 #7
0
ファイル: db-migrate.py プロジェクト: AlejandroGY/OmegaUp
def main() -> None:
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--skip-container-check',
                        action='store_true',
                        help='Skip the container check')
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--hostname',
                        default=None,
                        type=str,
                        help='Hostname of the MySQL server')
    parser.add_argument('--port',
                        default=13306,
                        type=int,
                        help='Port of the MySQL server')
    parser.add_argument('--username',
                        default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    parser.add_argument('--aws-rds-parameter-group-name',
                        default='omegaup-frontend',
                        help=('The name of the Parameter Group name. '
                              'Required with --lower-timeout and --aws.'))
    parser.add_argument('--lower-timeout',
                        action='store_true',
                        help='Temporarily lower the wait timeout.')
    parser.add_argument('--kill-blocking-connections',
                        action='store_true',
                        help='Kill all connections that hold a lock.')
    parser.add_argument('--aws',
                        action='store_true',
                        help='Use AWS-specific commands.')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for puppet.
    parser_exists = subparsers.add_parser(
        'exists', help='Checks if the migration table exists')
    parser_exists.set_defaults(func=exists)

    parser_latest = subparsers.add_parser(
        'latest', help='Checks if the database is at the latest revision')
    parser_latest.set_defaults(func=latest)

    parser_migrate = subparsers.add_parser(
        'migrate', help='Migrates the database to the latest revision')
    parser_migrate.add_argument('--noop',
                                action='store_true',
                                help=('Only print scripts that would be '
                                      'installed'))
    parser_migrate.add_argument('--development-environment',
                                dest='development_environment',
                                action='store_true',
                                help='Installs scripts flagged as for testing')
    parser_migrate.add_argument('--databases',
                                default='omegaup,omegaup-test',
                                help='Comma-separated list of databases')
    parser_migrate.add_argument('--limit',
                                type=int,
                                help='Last revision to include')
    parser_migrate.set_defaults(func=migrate)

    # Commands for development.
    parser_validate = subparsers.add_parser(
        'validate', help='Validates that the versioning is sane')
    parser_validate.set_defaults(func=validate)

    parser_ensure = subparsers.add_parser(
        'ensure', help='Ensures that the migration table exists')
    parser_ensure.set_defaults(func=ensure)

    parser_reset = subparsers.add_parser(
        'reset', help='Resets the migration table to a particular revision')
    parser_reset.add_argument('revision',
                              help='The desired revision',
                              type=int)
    parser_reset.set_defaults(func=reset)

    parser_revision = subparsers.add_parser('revision',
                                            help='Gets the current revision')
    parser_revision.set_defaults(func=print_revision)

    parser_purge = subparsers.add_parser(
        'purge', help='Start from scratch - Drop & Create empty databases')
    parser_purge.add_argument('--databases',
                              default=('omegaup,omegaup-test,'
                                       '_omegaup_metadata'),
                              help='Comma-separated list of databases')
    parser_purge.set_defaults(func=purge)

    parser_schema = subparsers.add_parser(
        'schema',
        help=('Show the database schema. Does not actually '
              'read/write from the database'))
    parser_schema.add_argument('--limit',
                               type=int,
                               help='Last revision to include')
    parser_schema.set_defaults(func=schema)

    lib.logs.configure_parser(parser)

    args = parser.parse_args()
    lib.logs.init(parser.prog, args)

    if not args.skip_container_check:
        database_utils.check_inside_container()

    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password,
                                         hostname=args.hostname,
                                         port=args.port)
    args.func(args, auth)
コード例 #8
0
ファイル: db-migrate.py プロジェクト: rcxr/omegaup
def main():
    '''Main entrypoint.'''

    parser = argparse.ArgumentParser()
    parser.add_argument('--mysql-config-file',
                        default=database_utils.default_config_file(),
                        help='.my.cnf file that stores credentials')
    parser.add_argument('--username', default='root',
                        help='MySQL root username')
    parser.add_argument('--password', default='omegaup', help='MySQL password')
    subparsers = parser.add_subparsers(dest='command')
    subparsers.required = True

    # Commands for puppet.
    parser_exists = subparsers.add_parser(
        'exists', help='Checks if the migration table exists')
    parser_exists.set_defaults(func=exists)

    parser_latest = subparsers.add_parser(
        'latest', help='Checks if the database is at the latest revision')
    parser_latest.set_defaults(func=latest)

    parser_migrate = subparsers.add_parser(
        'migrate', help='Migrates the database to the latest revision')
    parser_migrate.add_argument('--noop', action='store_true',
                                help=('Only print scripts that would be '
                                      'installed'))
    parser_migrate.add_argument('--development-environment',
                                dest='development_environment',
                                action='store_true',
                                help='Installs scripts flagged as for testing')
    parser_migrate.add_argument('--databases', default='omegaup,omegaup-test',
                                help='Comma-separated list of databases')
    parser_migrate.add_argument('--limit', type=int,
                                help='Last revision to include')
    parser_migrate.set_defaults(func=migrate)

    # Commands for development.
    parser_ensure = subparsers.add_parser(
        'ensure', help='Ensures that the migration table exists')
    parser_ensure.set_defaults(func=ensure)

    parser_reset = subparsers.add_parser(
        'reset',
        help='Resets the migration table to a particular revision')
    parser_reset.add_argument('revision', help='The desired revision',
                              type=int)
    parser_reset.set_defaults(func=reset)

    parser_revision = subparsers.add_parser(
        'revision', help='Gets the current revision')
    parser_revision.set_defaults(func=print_revision)

    parser_purge = subparsers.add_parser(
        'purge', help='Start from scratch - Drop & Create empty databases')
    parser_purge.add_argument('--databases',
                              default=('omegaup,omegaup-test,'
                                       '_omegaup_metadata'),
                              help='Comma-separated list of databases')
    parser_purge.set_defaults(func=purge)

    parser_schema = subparsers.add_parser(
        'schema', help=('Show the database schema. Does not actually '
                        'read/write from the database'))
    parser_schema.add_argument('--limit', type=int,
                               help='Last revision to include')
    parser_schema.set_defaults(func=schema)

    args = parser.parse_args()
    auth = database_utils.authentication(config_file=args.mysql_config_file,
                                         username=args.username,
                                         password=args.password)
    args.func(args, auth)
コード例 #9
0
ファイル: conftest.py プロジェクト: rcxr/omegaup
    def mysql_auth(self):
        '''Gets the authentication string for MySQL.'''

        return database_utils.authentication(
            config_file=self.options.mysql_config_file,
            username=self.options.username, password=self.options.password)