Ejemplo n.º 1
0
def main(argv=sys.argv):
    logging.basicConfig()
    logging.getLogger('karl').setLevel(logging.INFO)

    parser = optparse.OptionParser(description=__doc__)
    parser.add_option('-C', '--config', dest='config',
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('-c', '--communities', dest='communities',
        default='10',
        help='Number of communities to add (default 10)')
    parser.add_option('--dry-run', dest='dryrun',
        action='store_true', default=False,
        help="Don't actually commit the transaction")
    options, args = parser.parse_args(argv[1:])
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    try:
        add_sample_users(root)
        for i in range(int(options.communities)):
            add_sample_community(root, more_files=i==0)
    except:
        transaction.abort()
        raise
    else:
        if options.dryrun:
            transaction.abort()
        else:
            transaction.commit()
Ejemplo n.º 2
0
def main(argv=sys.argv):
    parser = create_karl_argparser(
        description='Generate sample content in the database.'
        )
    parser.add_argument('-c', '--communities', dest='communities',
        help='Number of communities to add (default 10)', default=10)
    parser.add_argument('--dry-run', dest='dryrun',
        action='store_true',
        help="Don't actually commit the transaction")
    parser.add_argument('-m', '--more-files', dest='more_files',
        action='store_true',
        help="Create many files in the first community (default false)")
    args = parser.parse_args(argv[1:])
    env = args.bootstrap(args.config_uri)
    root, closer = env['root'], env['closer']
    try:
        add_sample_users(root)
        for i in range(int(args.communities)):
            try:
                add_sample_community(
                    root,
                    more_files=(args.more_files and i==0)
                    )
            except TypeError:
                # fall back for old versions that do not support more_files
                add_sample_community(root)
    except:
        transaction.abort()
        raise
    else:
        if args.dryrun:
            transaction.abort()
        else:
            transaction.commit()
Ejemplo n.º 3
0
    def test_add_users(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IProfile
        registerContentFactory(testing.DummyModel, IProfile)

        site = testing.DummyModel()
        site['profiles'] = testing.DummyModel()
        site.users = karl.testing.DummyUsers()

        from karl.utilities.samplegen import add_sample_users
        add_sample_users(site)
        self.assert_('staff1' in site.users._by_id)
        self.assert_('staff1' in site['profiles'])
Ejemplo n.º 4
0
    def test_add_users(self):
        from repoze.lemonade.testing import registerContentFactory
        from karl.models.interfaces import IProfile
        registerContentFactory(testing.DummyModel, IProfile)

        site = testing.DummyModel()
        site['profiles'] = testing.DummyModel()
        site.users = karl.testing.DummyUsers()

        from karl.utilities.samplegen import add_sample_users
        add_sample_users(site)
        self.assert_('staff1' in site.users._by_id)
        self.assert_('staff1' in site['profiles'])
Ejemplo n.º 5
0
def samplegen(args, instance):
    root, closer = args.get_root(instance)
    set_current_instance(instance)
    try:
        add_sample_users(root)
        for i in range(int(args.communities)):
            add_sample_community(root)
    except:
        transaction.abort()
        raise
    else:
        if args.dryrun:
            transaction.abort()
        else:
            transaction.commit()
Ejemplo n.º 6
0
def samplegen(args, instance):
    root, closer = args.get_root(instance)
    set_current_instance(instance)
    try:
        add_sample_users(root)
        for i in range(int(args.communities)):
            try:
                add_sample_community(root, more_files=(args.more_files and i==0))
            except TypeError:
                # fall back for old versions that do not support more_files
                add_sample_community(root)
    except:
        transaction.abort()
        raise
    else:
        if args.dryrun:
            transaction.abort()
        else:
            transaction.commit()
Ejemplo n.º 7
0
def main(argv=sys.argv):
    logging.basicConfig()
    logging.getLogger('karl').setLevel(logging.INFO)

    parser = optparse.OptionParser(description=__doc__)
    parser.add_option(
        '-C',
        '--config',
        dest='config',
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('-c',
                      '--communities',
                      dest='communities',
                      default='10',
                      help='Number of communities to add (default 10)')
    parser.add_option('--dry-run',
                      dest='dryrun',
                      action='store_true',
                      default=False,
                      help="Don't actually commit the transaction")
    options, args = parser.parse_args(argv[1:])
    if args:
        parser.error("Too many parameters: %s" % repr(args))

    config = options.config
    if config is None:
        config = get_default_config()
    root, closer = open_root(config)

    try:
        add_sample_users(root)
        for i in range(int(options.communities)):
            add_sample_community(root, more_files=i == 0)
    except:
        transaction.abort()
        raise
    else:
        if options.dryrun:
            transaction.abort()
        else:
            transaction.commit()
Ejemplo n.º 8
0
def main(argv=sys.argv):
    parser = create_karl_argparser(
        description='Generate sample content in the database.')
    parser.add_argument('-c',
                        '--communities',
                        dest='communities',
                        help='Number of communities to add (default 10)',
                        default=10)
    parser.add_argument('--dry-run',
                        dest='dryrun',
                        action='store_true',
                        help="Don't actually commit the transaction")
    parser.add_argument(
        '-m',
        '--more-files',
        dest='more_files',
        action='store_true',
        help="Create many files in the first community (default false)")
    args = parser.parse_args(argv[1:])
    env = args.bootstrap(args.config_uri)
    root, closer = env['root'], env['closer']
    try:
        add_sample_users(root)
        for i in range(int(args.communities)):
            try:
                add_sample_community(root,
                                     more_files=(args.more_files and i == 0))
            except TypeError:
                # fall back for old versions that do not support more_files
                add_sample_community(root)
    except:
        transaction.abort()
        raise
    else:
        if args.dryrun:
            transaction.abort()
        else:
            transaction.commit()