Use native bindings instead of string parsing
darkdragon-001 opened this issue · 3 comments
darkdragon-001 commented
Use gopy to create the bindings to restic/cmd/cmd_backup.go#runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Terminal, args []string)
. The same should be done for the other commands of course as well.
Structs and string arrays should work out of the box, for termstatus.Terminal.New(wr io.Writer, errWriter io.Writer, disableStatus bool)
one needs to implement io.Writer
interface which only needs a simple Write(p []byte) (n int, err error)
which should call the python logger callback.
darkdragon-001 commented
I wrote the go wrapper:
package gopythonlogger
type PythonLogger struct {
Fun func(str string)
}
func (logger *PythonLogger) Write(p []byte) (n int, err error) {
logger.Fun(string(p))
return len(p), nil
}
func New(fun func(str string)) *PythonLogger {
return &PythonLogger { Fun: fun }
}
In Python, one can call it with
import go, gopythonlogger
ioWriter = gopythonlogger.New(lambda s : logger.debug(s))
andreasnuesslein commented
andreasnuesslein commented
Will use the API then, restic/restic#2403 once that is implemented