<commit_before>package commands

import (
	"time"

	"code.google.com/p/go.crypto/bcrypt"

	"github.com/aymerick/kowa/models"
	"github.com/aymerick/kowa/server"
	"github.com/spf13/cobra"
	"gopkg.in/mgo.v2/bson"
)

var bootstrapCmd = &cobra.Command{
	Use:   "bootstrap",
	Short: "Bootstrap Kowa",
	Long:  `Creates records in database`,
	Run:   bootstrap,
}

func bootstrap(cmd *cobra.Command, args []string) {
	// @todo Check that we are NOT in production

	// Insert oauth client
	oauthStorage := server.NewOAuthStorage()
	oauthStorage.SetupDefaultClient()

	db := models.NewDBSession()

	password, err := bcrypt.GenerateFromPassword([]byte("test"), bcrypt.DefaultCost)
	if err != nil {
		panic("Arg")
	}

	// Insert users
	userJeanClaude := models.User{
		Id:        "test",
		CreatedAt: time.Now(),
		Email:     "<EMAIL>",
		FirstName: "Jean-Claude",
		LastName:  "Trucmush",
		Password:  string(password),
	}
	db.UsersCol().Insert(&userJeanClaude)

	userHenry := models.User{
		Id:        "hkanan",
		CreatedAt: time.Now(),
		Email:     "<EMAIL>",
		FirstName: "Henry",
		LastName:  "Kanan",
		Password:  string(password),
	}
	db.UsersCol().Insert(&userHenry)

	// Insert sites
	siteJC1 := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userJeanClaude.Id,
		CreatedAt:   time.Now(),
		Name:        "My site",
		Tagline:     "So powerfull !",
		Description: "You will be astonished by what my site is about",
	}
	db.SitesCol().Insert(&siteJC1)

	siteJC2 := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userJeanClaude.Id,
		CreatedAt:   time.Now(),
		Name:        "My second site",
		Tagline:     "Very interesting",
		Description: "Our projects are so importants, please help us",
	}
	db.SitesCol().Insert(&siteJC2)

	siteH := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userHenry.Id,
		CreatedAt:   time.Now(),
		Name:        "Ultimate petanque",
		Tagline:     "La petanque comme vous ne l'avez jamais vu",
		Description: "C'est vraiment le sport du futur. Messieurs, preparez vos boules !",
	}
	db.SitesCol().Insert(&siteH)

	// Insert posts
	var post models.Post

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
		SiteId:      siteJC1.Id,
		PublishedAt: time.Now(),
		Title:       "My first post",
		Body:        "Let's talk and me myself and I. Blablablablabla",
	}
	db.PostsCol().Insert(&post)

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
		SiteId:      siteJC1.Id,
		PublishedAt: time.Now(),
		Title:       "My second post",
		Body:        "I haven't finished, let's talk about me again.",
	}
	db.PostsCol().Insert(&post)

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
		SiteId:      siteJC2.Id,
		PublishedAt: time.Now(),
		Title:       "This is a lonely",
		Body:        "It appears on my second website.",
	}
	db.PostsCol().Insert(&post)

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),<commit_msg>Generates more posts fixtures<commit_after>package commands

import (
	"fmt"
	"time"

	"code.google.com/p/go.crypto/bcrypt"

	"github.com/aymerick/kowa/models"
	"github.com/aymerick/kowa/server"
	"github.com/spf13/cobra"
	"gopkg.in/mgo.v2/bson"
)

var bootstrapCmd = &cobra.Command{
	Use:   "bootstrap",
	Short: "Bootstrap Kowa",
	Long:  `Creates records in database`,
	Run:   bootstrap,
}

func bootstrap(cmd *cobra.Command, args []string) {
	// @todo Check that we are NOT in production

	// Insert oauth client
	oauthStorage := server.NewOAuthStorage()
	oauthStorage.SetupDefaultClient()

	db := models.NewDBSession()

	password, err := bcrypt.GenerateFromPassword([]byte("<PASSWORD>"), bcrypt.DefaultCost)
	if err != nil {
		panic("Arg")
	}

	// Insert users
	userJeanClaude := models.User{
		Id:        "test",
		CreatedAt: time.Now(),
		Email:     "<EMAIL>",
		FirstName: "Jean-Claude",
		LastName:  "Trucmush",
		Password:  string(password),
	}
	db.UsersCol().Insert(&userJeanClaude)

	userHenry := models.User{
		Id:        "hkanan",
		CreatedAt: time.Now(),
		Email:     "<EMAIL>",
		FirstName: "Henry",
		LastName:  "Kanan",
		Password:  string(password),
	}
	db.UsersCol().Insert(&userHenry)

	// Insert sites
	siteJC1 := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userJeanClaude.Id,
		CreatedAt:   time.Now(),
		Name:        "My site",
		Tagline:     "So powerfull !",
		Description: "You will be astonished by what my site is about",
	}
	db.SitesCol().Insert(&siteJC1)

	siteJC2 := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userJeanClaude.Id,
		CreatedAt:   time.Now(),
		Name:        "My second site",
		Tagline:     "Very interesting",
		Description: "Our projects are so importants, please help us",
	}
	db.SitesCol().Insert(&siteJC2)

	siteH := models.Site{
		Id:          bson.NewObjectId(),
		UserId:      userHenry.Id,
		CreatedAt:   time.Now(),
		Name:        "Ultimate petanque",
		Tagline:     "La petanque comme vous ne l'avez jamais vu",
		Description: "C'est vraiment le sport du futur. Messieurs, preparez vos boules !",
	}
	db.SitesCol().Insert(&siteH)

	// Insert posts
	var post models.Post

	for i := 0; i < 30; i++ {
		post = models.Post{
			Id:          bson.NewObjectId(),
			CreatedAt:   time.Now(),
			UpdatedAt:   time.Now(),
			SiteId:      siteJC1.Id,
			PublishedAt: time.Now(),
			Title:       fmt.Sprintf("Post %d", i),
			Body:        fmt.Sprintf("This is my post numner %d. Blablablablabla", i),
		}
		db.PostsCol().Insert(&post)
	}

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
		SiteId:      siteJC2.Id,
		PublishedAt: time.Now(),
		Title:       "This is a lonely",
		Body:        "It appears on my second website.",
	}
	db.PostsCol().Insert(&post)

	post = models.Post{
		Id:          bson.NewObjectId(),
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
{'fraction_non_alphanumeric': 0.148664343786295, 'fraction_numerical': 0.0036502405840384933, 'mean_word_length': 2.9815059445178336, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7181404', 'n_tokens_mistral': 2370, 'n_tokens_neox': 2171, 'n_words': 503}