From b6e3f2f4409ed7aa3a753df4d754ef23b82ed85a Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 11 Mar 2016 14:11:00 -0500 Subject: [PATCH] Added dump flag Former-commit-id: 1c5335ec40ce0b7ee52abb71af58bedd5559ee32 [formerly f6c2c21205c5859ae3972a43e6de8086268d9d88] [formerly f4dfec26467d1e2b994aab8305281364b3029986 [formerly 4d3affefbf993978d8e976d6e6ca6f55eff70094 [formerly ee5c701dd0dee79ce55a47ae2c3790f40dddd204]]] Former-commit-id: 632facfd569da911dd20b0375b4fede77664e32e [formerly 3dc6dbad5fc4d30880af0961fae01c8fac5a113f] Former-commit-id: 577ba1fedacb3cc7a0ecc9fca4cadd896398e8cf Former-commit-id: 12476b03c22651c9e91b8be59827f67fa50e6406 --- main.go | 11 +++++++++++ routes.go | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/main.go b/main.go index 6b6fa1c..bf8814d 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/routes.go b/routes.go index 7bf9129..dc9f875 100644 --- a/routes.go +++ b/routes.go @@ -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 + }) +}