|
@@ -45,6 +45,7 @@ import (
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"os"
|
|
"os"
|
|
|
|
+ "path"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
@@ -294,7 +295,9 @@ func handleServerCommandLine(gm *graph.Manager) bool {
|
|
var ecalConsole *bool
|
|
var ecalConsole *bool
|
|
|
|
|
|
importDb := flag.String("import", "", "Import a database from a zip file")
|
|
importDb := flag.String("import", "", "Import a database from a zip file")
|
|
|
|
+ importDbLS := flag.String("import-ls", "", "Large scale import from a directory")
|
|
exportDb := flag.String("export", "", "Export the current database to a zip file")
|
|
exportDb := flag.String("export", "", "Export the current database to a zip file")
|
|
|
|
+ exportDbLS := flag.String("export-ls", "", "Large scale export to a directory")
|
|
|
|
|
|
if config.Bool(config.EnableECALScripts) {
|
|
if config.Bool(config.EnableECALScripts) {
|
|
ecalConsole = flag.Bool("ecal-console", false, "Start an interactive interpreter console for ECAL")
|
|
ecalConsole = flag.Bool("ecal-console", false, "Start an interactive interpreter console for ECAL")
|
|
@@ -319,6 +322,62 @@ func handleServerCommandLine(gm *graph.Manager) bool {
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ err = handleSimpleImportExport(importDb, exportDb, gm)
|
|
|
|
+
|
|
|
|
+ err = handleLargeScaleImportExport(importDbLS, exportDbLS, gm)
|
|
|
|
+
|
|
|
|
+ if ecalConsole != nil && *ecalConsole && err == nil {
|
|
|
|
+ var term termutil.ConsoleLineTerminal
|
|
|
|
+
|
|
|
|
+ isExitLine := func(s string) bool {
|
|
|
|
+ return s == "exit" || s == "q" || s == "quit" || s == "bye" || s == "\x04"
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ term, err = termutil.NewConsoleLineTerminal(os.Stdout)
|
|
|
|
+ if err == nil {
|
|
|
|
+ term, err = termutil.AddHistoryMixin(term, "", isExitLine)
|
|
|
|
+ if err == nil {
|
|
|
|
+ tid := api.SI.Interpreter.RuntimeProvider.NewThreadID()
|
|
|
|
+
|
|
|
|
+ runECALConsole := func(delay int) {
|
|
|
|
+ defer term.StopTerm()
|
|
|
|
+
|
|
|
|
+ time.Sleep(time.Duration(delay) * time.Millisecond)
|
|
|
|
+
|
|
|
|
+ term.WriteString(fmt.Sprintln("Type 'q' or 'quit' to exit the shell and '?' to get help"))
|
|
|
|
+
|
|
|
|
+ line, err := term.NextLine()
|
|
|
|
+ for err == nil && !isExitLine(line) {
|
|
|
|
+ trimmedLine := strings.TrimSpace(line)
|
|
|
|
+
|
|
|
|
+ api.SI.Interpreter.HandleInput(term, trimmedLine, tid)
|
|
|
|
+
|
|
|
|
+ line, err = term.NextLine()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err = term.StartTerm(); err == nil {
|
|
|
|
+ if *noServ {
|
|
|
|
+ runECALConsole(0)
|
|
|
|
+ } else {
|
|
|
|
+ go runECALConsole(3000)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err.Error())
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return *noServ
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func handleSimpleImportExport(importDb, exportDb *string, gm *graph.Manager) error {
|
|
|
|
+ var err error
|
|
|
|
+
|
|
if *importDb != "" {
|
|
if *importDb != "" {
|
|
var zipFile *zip.ReadCloser
|
|
var zipFile *zip.ReadCloser
|
|
|
|
|
|
@@ -346,7 +405,7 @@ func handleServerCommandLine(gm *graph.Manager) bool {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if *exportDb != "" {
|
|
|
|
|
|
+ if *exportDb != "" && err == nil {
|
|
var zipFile *os.File
|
|
var zipFile *os.File
|
|
|
|
|
|
fmt.Println("Exporting to:", *exportDb)
|
|
fmt.Println("Exporting to:", *exportDb)
|
|
@@ -375,52 +434,62 @@ func handleServerCommandLine(gm *graph.Manager) bool {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if ecalConsole != nil && *ecalConsole {
|
|
|
|
- var term termutil.ConsoleLineTerminal
|
|
|
|
|
|
+ return err
|
|
|
|
+}
|
|
|
|
|
|
- isExitLine := func(s string) bool {
|
|
|
|
- return s == "exit" || s == "q" || s == "quit" || s == "bye" || s == "\x04"
|
|
|
|
- }
|
|
|
|
|
|
+type directoryFactory struct {
|
|
|
|
+ pathPrefix string
|
|
|
|
+}
|
|
|
|
|
|
- term, err = termutil.NewConsoleLineTerminal(os.Stdout)
|
|
|
|
- if err == nil {
|
|
|
|
- term, err = termutil.AddHistoryMixin(term, "", isExitLine)
|
|
|
|
- if err == nil {
|
|
|
|
- tid := api.SI.Interpreter.RuntimeProvider.NewThreadID()
|
|
|
|
|
|
+func (tf *directoryFactory) Readers() ([]string, error) {
|
|
|
|
+ var files []string
|
|
|
|
|
|
- runECALConsole := func(delay int) {
|
|
|
|
- defer term.StopTerm()
|
|
|
|
|
|
+ fileInfos, err := ioutil.ReadDir(tf.pathPrefix)
|
|
|
|
|
|
- time.Sleep(time.Duration(delay) * time.Millisecond)
|
|
|
|
|
|
+ if err == nil {
|
|
|
|
+ for _, fi := range fileInfos {
|
|
|
|
+ if !fi.IsDir() && strings.HasPrefix(fi.Name(), "db-") {
|
|
|
|
+ name := fi.Name()[3:]
|
|
|
|
+ files = append(files, strings.TrimSuffix(name, path.Ext(name)))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- term.WriteString(fmt.Sprintln("Type 'q' or 'quit' to exit the shell and '?' to get help"))
|
|
|
|
|
|
+ return files, err
|
|
|
|
+}
|
|
|
|
|
|
- line, err := term.NextLine()
|
|
|
|
- for err == nil && !isExitLine(line) {
|
|
|
|
- trimmedLine := strings.TrimSpace(line)
|
|
|
|
|
|
+func (tf *directoryFactory) CreateWriter(name string) (io.Writer, error) {
|
|
|
|
+ return os.Create(path.Join(tf.pathPrefix, "db-"+name+".ndjson"))
|
|
|
|
+}
|
|
|
|
|
|
- api.SI.Interpreter.HandleInput(term, trimmedLine, tid)
|
|
|
|
|
|
+func (tf *directoryFactory) CreateReader(name string) (io.Reader, error) {
|
|
|
|
+ return os.Open(path.Join(tf.pathPrefix, "db-"+name+".ndjson"))
|
|
|
|
+}
|
|
|
|
|
|
- line, err = term.NextLine()
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+func handleLargeScaleImportExport(importDbLS, exportDbLS *string, gm *graph.Manager) error {
|
|
|
|
+ var err error
|
|
|
|
|
|
- if err = term.StartTerm(); err == nil {
|
|
|
|
|
|
+ if *importDbLS != "" {
|
|
|
|
+ stat, err := os.Stat(*importDbLS)
|
|
|
|
|
|
- if *noServ {
|
|
|
|
- runECALConsole(0)
|
|
|
|
- } else {
|
|
|
|
- go runECALConsole(3000)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if err == nil && stat.IsDir() {
|
|
|
|
+ fmt.Println("Importing from:", *importDbLS)
|
|
|
|
+
|
|
|
|
+ fac := &directoryFactory{*importDbLS}
|
|
|
|
+
|
|
|
|
+ err = graph.LargeScaleImportPartition(fac, gm)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if err != nil {
|
|
|
|
- fmt.Println(err.Error())
|
|
|
|
- return true
|
|
|
|
|
|
+ if *exportDbLS != "" && err == nil {
|
|
|
|
+ fmt.Println("Exporting to:", *exportDbLS)
|
|
|
|
+
|
|
|
|
+ err = os.MkdirAll(*exportDbLS, 0777)
|
|
|
|
+
|
|
|
|
+ fac := &directoryFactory{*exportDbLS}
|
|
|
|
+
|
|
|
|
+ err = graph.LargeScaleExportPartition(fac, gm)
|
|
}
|
|
}
|
|
|
|
|
|
- return *noServ
|
|
|
|
|
|
+ return err
|
|
}
|
|
}
|