1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Merge pull request #29 from schollz/dump

Added dump flag to dump all the pages to markdown files

Former-commit-id: 102c9d852456b64d1a365242c9b6521a729adf2a [formerly 921def6205cd6c9223d8c5a8502f7be40ce377d5] [formerly c2c0c0d87425d13583d7e148a017a3d5400a7c2f [formerly 3513926cf8]]
Former-commit-id: 4df0fc273fa1c007c431eeba98fc1507dd07a3d8 [formerly 396764512eeb27e2cf179b150849803acf71af60]
Former-commit-id: e9e8a138a49277f1e5170bcb0e881c488620d0eb
This commit is contained in:
Zack 2016-03-11 14:13:52 -05:00
commit 9eff989504
2 changed files with 31 additions and 0 deletions

11
main.go
View File

@ -45,6 +45,7 @@ func main() {
flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt")
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key")
flag.StringVar(&RuntimeArgs.WikiName, "w", "AwwKoala", "custom name for wiki")
dumpDataset := flag.Bool("dump", false, "flag to dump all data to 'dump' directory")
flag.CommandLine.Usage = func() {
fmt.Println(`AwwKoala (version ` + VersionNum + `): A Websocket Wiki and Kind Of A List Application
run this to start the server and then visit localhost at the port you specify
@ -57,11 +58,21 @@ Options:`)
flag.CommandLine.PrintDefaults()
}
flag.Parse()
if *dumpDataset {
fmt.Println("Dumping data to 'dump' folder...")
Open(RuntimeArgs.DatabaseLocation)
dumpEverything()
Close()
os.Exit(1)
}
RuntimeArgs.ExternalIP = flag.Arg(0)
if RuntimeArgs.ExternalIP == "" {
RuntimeArgs.ExternalIP = GetLocalIP() + RuntimeArgs.Port
}
RuntimeArgs.SourcePath = cwd
Open(RuntimeArgs.DatabaseLocation)
defer Close()

View File

@ -5,6 +5,7 @@ import (
"html/template"
"io/ioutil"
"net/http"
"os"
"path"
"regexp"
"strconv"
@ -328,3 +329,22 @@ func listEverything() string {
})
return everything
}
func dumpEverything() {
err := os.MkdirAll("dump", 0777)
if err != nil {
fmt.Println("Already exists")
}
db.View(func(tx *bolt.Tx) error {
// Assume bucket exists and has keys
b := tx.Bucket([]byte("datas"))
c := b.Cursor()
for k, _ := c.First(); k != nil; k, _ = c.Next() {
var p WikiData
p.load(string(k))
fmt.Println(string(k), len(p.CurrentText))
ioutil.WriteFile(path.Join("dump", string(k)+".md"), []byte(p.CurrentText), 0644)
}
return nil
})
}