From a07d4c89f3928aae1845d89bae89d68f9d570079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=BE=D0=B4=D0=B8=D0=BD=20=D0=A0=D0=BE?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD?= Date: Mon, 21 Mar 2022 23:46:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B5=20=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=D1=89=D0=B0=20=D1=81=D0=BE=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D1=8F=20=D1=87=D0=B0=D1=81=D1=82=D0=B5=D0=B9?= =?UTF-8?q?=20=D1=82=D0=BE=D1=80=D1=80=D0=B5=D0=BD=D1=82=D0=B0=20sqlite=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D0=B0=D1=81=D1=82=D1=80=D0=BE=D1=84=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=20=D1=83=D0=B2=D0=B5=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=B8=D0=B2=D0=B0=D0=B5=D1=82=20=D0=B2=D1=80=D0=B5=D0=BC?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine.go | 24 ++-- py/gorrent/Makefile | 15 ++- py/gorrent/build.py | 32 ++--- py/gorrent/gorrent.go | 288 ++++++++++++++++++++--------------------- py/gorrent/gorrent.py | 290 +++++++++++++++++++++--------------------- 5 files changed, 330 insertions(+), 319 deletions(-) diff --git a/engine.go b/engine.go index 1a298b5..a2ff3c9 100644 --- a/engine.go +++ b/engine.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/anacrolix/torrent" + "github.com/anacrolix/torrent/storage" "golang.org/x/net/context" "net/http" "net/url" @@ -14,6 +15,8 @@ import ( "time" ) +const boltDbDir = `piece_complete_db` + type TorrentStatus struct { DownloadRate int UploadRate int @@ -64,29 +67,23 @@ func (o *Engine) StartTorrent(idx int) error { o.torrCfg = torrent.NewDefaultClientConfig() o.torrCfg.ListenPort = o.settings.ListenPort o.torrCfg.DataDir = o.settings.DownloadPath + o.torrCfg.DefaultStorage = storage.NewFileWithCompletion(o.settings.DownloadPath, storage.NewMapPieceCompletion()) if o.settings.Proxy != "" { if u, err := url.Parse(o.settings.Proxy); err != nil { o.torrCfg.HTTPProxy = func(request *http.Request) (*url.URL, error) { return u, nil } } - } o.client, err = torrent.NewClient(o.torrCfg) if err != nil { return fmt.Errorf(`create torrent client failed: %s`, err.Error()) } - o.debug(`got new client for torrent file: %s`, o.settings.TorrentPath) - if o.torrent, err = o.client.AddTorrentFromFile(o.settings.TorrentPath); err != nil { - return fmt.Errorf(`add torrent file failed: %s`, err.Error()) + o.error(`add torrent file failed: %s`, err.Error()) } - o.debug(`added torrent file: %s`, o.settings.TorrentPath) - o.torrent.SetMaxEstablishedConns(o.settings.MaxConnections) - o.debug(`set max connections: %d`, o.settings.MaxConnections) - o.alive = true go func() { @@ -95,9 +92,12 @@ func (o *Engine) StartTorrent(idx int) error { file := o.torrent.Files()[idx] + // отключаем загрузку всех файлов + o.torrent.CancelPieces(0, o.torrent.NumPieces()-1) + // + firstPieceIndex := file.Offset() * int64(t.NumPieces()) / t.Length() endPieceIndex := (file.Offset() + file.Length()) * int64(t.NumPieces()) / t.Length() - o.torrent.DownloadPieces(int(firstPieceIndex), int(endPieceIndex)) for i := firstPieceIndex; i <= endPieceIndex*5/100; i++ { @@ -178,7 +178,13 @@ func (o *Engine) FileStatus(i int) (FileStatus, error) { } fs.Url = fmt.Sprintf(`http://%s:%d/files/%s`, o.settings.HttpBindHost, o.settings.HttpBindPort, strings.Join(pathParts, `/`)) fs.Progress = int(float64(file.BytesCompleted()) / float64(file.Length()) * 100.0) + if fs.Progress < 0 { + fs.Progress *= -1 + } fs.Length = int(file.Length()) + if fs.Length < 0 { + fs.Length *= -1 + } return fs, nil } diff --git a/py/gorrent/Makefile b/py/gorrent/Makefile index c8e9ca3..62db4f4 100644 --- a/py/gorrent/Makefile +++ b/py/gorrent/Makefile @@ -10,10 +10,13 @@ LIBEXT=.so # get the CC and flags used to build python: GCC = $(shell $(GOCMD) env CC) -CFLAGS = $(shell python3-config --includes) -LDFLAGS = -L/usr/lib64 $(BOOST_ROOT)/stage/lib/libboost_python*.a -lpthread -ldl -lutil -lm -lm +CFLAGS = -I/usr/include/python3.9 +LDFLAGS = -L/usr/lib64 -lpython3.9 -lpthread -ldl -lutil -lm -lm -all: build +all: gen build + +gen: + gopy gen -no-make -gorrent build: # build target builds the generated files -- this is what gopy build does.. @@ -22,12 +25,14 @@ build: # goimports is needed to ensure that the imports list is valid $(GOIMPORTS) -w gorrent.go # generate gorrent_go$(LIBEXT) from gorrent.go -- the cgo wrappers to go functions - $(GOBUILD) -buildmode=c-archive -o gorrent_go.a gorrent.go + $(GOBUILD) -buildmode=c-shared -o gorrent_go$(LIBEXT) gorrent.go # use pybindgen to build the gorrent.c file which are the CPython wrappers to cgo wrappers.. # note: pip install pybindgen to get pybindgen if this fails $(PYTHON) build.py # build the _gorrent$(LIBEXT) library that contains the cgo and CPython wrappers # generated gorrent.py python wrapper imports this c-code package - $(GCC) gorrent.c gorrent_go.a -o _gorrent$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared -w + $(GCC) gorrent.c gorrent_go$(LIBEXT) -o _gorrent$(LIBEXT) $(CFLAGS) $(LDFLAGS) -fPIC --shared -w + + diff --git a/py/gorrent/build.py b/py/gorrent/build.py index 6df02ac..d16a9ff 100644 --- a/py/gorrent/build.py +++ b/py/gorrent/build.py @@ -147,6 +147,21 @@ mod.add_function('Slice_Ptr_gorrent_FileInfo_elem', retval('int64_t'), [param('i mod.add_function('Slice_Ptr_gorrent_FileInfo_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')]) mod.add_function('Slice_Ptr_gorrent_FileInfo_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int64_t', 'value')]) mod.add_function('Slice_Ptr_gorrent_FileInfo_append', None, [param('int64_t', 'handle'), param('int64_t', 'value')]) +mod.add_function('gorrent_Engine_CTor', retval('int64_t'), []) +add_checked_function(mod, 'gorrent_Engine_IsAlive', retval('bool'), [param('int64_t', '_handle')]) +add_checked_function(mod, 'gorrent_Engine_StartTorrent', retval('char*'), [param('int64_t', '_handle'), param('int64_t', 'idx')]) +add_checked_function(mod, 'gorrent_Engine_Status', retval('int64_t'), [param('int64_t', '_handle')]) +add_checked_function(mod, 'gorrent_Engine_FileStatus', retval('int64_t'), [param('int64_t', '_handle'), param('int64_t', 'i')]) +add_checked_function(mod, 'gorrent_Engine_Stop', None, [param('int64_t', '_handle'), param('bool', 'goRun')]) +add_checked_string_function(mod, 'gorrent_Engine_GetMsg', retval('char*'), [param('int64_t', '_handle')]) +add_checked_function(mod, 'gorrent_Engine_Clean', None, [param('int64_t', '_handle'), param('bool', 'goRun')]) +mod.add_function('gorrent_FileInfo_CTor', retval('int64_t'), []) +mod.add_function('gorrent_FileInfo_Length_Get', retval('int64_t'), [param('int64_t', 'handle')]) +mod.add_function('gorrent_FileInfo_Length_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) +mod.add_function('gorrent_FileInfo_Path_Get', retval('int64_t'), [param('int64_t', 'handle')]) +mod.add_function('gorrent_FileInfo_Path_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) +mod.add_function('gorrent_FileInfo_PathUTF8_Get', retval('int64_t'), [param('int64_t', 'handle')]) +mod.add_function('gorrent_FileInfo_PathUTF8_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) mod.add_function('gorrent_FileStatus_CTor', retval('int64_t'), []) mod.add_function('gorrent_FileStatus_Name_Get', retval('char*'), [param('int64_t', 'handle')]) mod.add_function('gorrent_FileStatus_Name_Set', None, [param('int64_t', 'handle'), param('char*', 'val')]) @@ -192,24 +207,9 @@ mod.add_function('gorrent_TorrentStatus_UploadRate_Get', retval('int64_t'), [par mod.add_function('gorrent_TorrentStatus_UploadRate_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) mod.add_function('gorrent_TorrentStatus_Seeds_Get', retval('int64_t'), [param('int64_t', 'handle')]) mod.add_function('gorrent_TorrentStatus_Seeds_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) -mod.add_function('gorrent_Engine_CTor', retval('int64_t'), []) -add_checked_function(mod, 'gorrent_Engine_IsAlive', retval('bool'), [param('int64_t', '_handle')]) -add_checked_function(mod, 'gorrent_Engine_StartTorrent', retval('char*'), [param('int64_t', '_handle'), param('int64_t', 'idx')]) -add_checked_function(mod, 'gorrent_Engine_Status', retval('int64_t'), [param('int64_t', '_handle')]) -add_checked_function(mod, 'gorrent_Engine_FileStatus', retval('int64_t'), [param('int64_t', '_handle'), param('int64_t', 'i')]) -add_checked_function(mod, 'gorrent_Engine_Stop', None, [param('int64_t', '_handle'), param('bool', 'goRun')]) -add_checked_string_function(mod, 'gorrent_Engine_GetMsg', retval('char*'), [param('int64_t', '_handle')]) -add_checked_function(mod, 'gorrent_Engine_Clean', None, [param('int64_t', '_handle'), param('bool', 'goRun')]) -mod.add_function('gorrent_FileInfo_CTor', retval('int64_t'), []) -mod.add_function('gorrent_FileInfo_Length_Get', retval('int64_t'), [param('int64_t', 'handle')]) -mod.add_function('gorrent_FileInfo_Length_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) -mod.add_function('gorrent_FileInfo_Path_Get', retval('int64_t'), [param('int64_t', 'handle')]) -mod.add_function('gorrent_FileInfo_Path_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) -mod.add_function('gorrent_FileInfo_PathUTF8_Get', retval('int64_t'), [param('int64_t', 'handle')]) -mod.add_function('gorrent_FileInfo_PathUTF8_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')]) +add_checked_function(mod, 'gorrent_NewEngine', retval('int64_t'), [param('int64_t', 'settings')]) add_checked_function(mod, 'gorrent_GetMetaFromFile', retval('int64_t'), [param('char*', 'path')]) add_checked_function(mod, 'gorrent_NewSettings', retval('int64_t'), []) -add_checked_function(mod, 'gorrent_NewEngine', retval('int64_t'), [param('int64_t', 'settings')]) add_checked_string_function(mod, 'gorrent_Version', retval('char*'), []) mod.generate(open('gorrent.c', 'w')) diff --git a/py/gorrent/gorrent.go b/py/gorrent/gorrent.go index c1029b9..56dd73f 100644 --- a/py/gorrent/gorrent.go +++ b/py/gorrent/gorrent.go @@ -1246,6 +1246,144 @@ func handleFromPtr_gorrent_TorrentStatus(p interface{}) CGoHandle { // ---- Structs --- +// --- wrapping struct: gorrent.Engine --- +//export gorrent_Engine_CTor +func gorrent_Engine_CTor() CGoHandle { + return CGoHandle(handleFromPtr_gorrent_Engine(&gorrent.Engine{})) +} + +//export gorrent_Engine_IsAlive +func gorrent_Engine_IsAlive(_handle CGoHandle) C.char { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return boolGoToPy(false) + } + return boolGoToPy(gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).IsAlive()) + +} + +//export gorrent_Engine_StartTorrent +func gorrent_Engine_StartTorrent(_handle CGoHandle, idx C.longlong) *C.char { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return C.CString("") + } + __err = gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).StartTorrent(int(idx)) + + if __err != nil { + estr := C.CString(__err.Error()) + C.PyErr_SetString(C.PyExc_RuntimeError, estr) + return estr + } + return C.CString("") +} + +//export gorrent_Engine_Status +func gorrent_Engine_Status(_handle CGoHandle) CGoHandle { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return handleFromPtr_gorrent_TorrentStatus(nil) + } + cret := gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Status() + + return handleFromPtr_gorrent_TorrentStatus(&cret) +} + +//export gorrent_Engine_FileStatus +func gorrent_Engine_FileStatus(_handle CGoHandle, i C.longlong) CGoHandle { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return handleFromPtr_gorrent_FileStatus(nil) + } + cret, __err := gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).FileStatus(int(i)) + + if __err != nil { + estr := C.CString(__err.Error()) + C.PyErr_SetString(C.PyExc_RuntimeError, estr) + C.free(unsafe.Pointer(estr)) + return handleFromPtr_gorrent_FileStatus(nil) + } + return handleFromPtr_gorrent_FileStatus(&cret) +} + +//export gorrent_Engine_Stop +func gorrent_Engine_Stop(_handle CGoHandle, goRun C.char) { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return + } + if boolPyToGo(goRun) { + go gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Stop() + } else { + gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Stop() + } +} + +//export gorrent_Engine_GetMsg +func gorrent_Engine_GetMsg(_handle CGoHandle) *C.char { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return C.CString("") + } + return C.CString(gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).GetMsg()) + +} + +//export gorrent_Engine_Clean +func gorrent_Engine_Clean(_handle CGoHandle, goRun C.char) { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") + if __err != nil { + return + } + if boolPyToGo(goRun) { + go gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Clean() + } else { + gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Clean() + } +} + +// --- wrapping struct: gorrent.FileInfo --- +//export gorrent_FileInfo_CTor +func gorrent_FileInfo_CTor() CGoHandle { + return CGoHandle(handleFromPtr_gorrent_FileInfo(&gorrent.FileInfo{})) +} +//export gorrent_FileInfo_Length_Get +func gorrent_FileInfo_Length_Get(handle CGoHandle) C.longlong { + op := ptrFromHandle_gorrent_FileInfo(handle) + return C.longlong(op.Length) +} + +//export gorrent_FileInfo_Length_Set +func gorrent_FileInfo_Length_Set(handle CGoHandle, val C.longlong) { + op := ptrFromHandle_gorrent_FileInfo(handle) + op.Length = int64(val) +} + +//export gorrent_FileInfo_Path_Get +func gorrent_FileInfo_Path_Get(handle CGoHandle) CGoHandle { + op := ptrFromHandle_gorrent_FileInfo(handle) + return handleFromPtr_Slice_string(&op.Path) +} + +//export gorrent_FileInfo_Path_Set +func gorrent_FileInfo_Path_Set(handle CGoHandle, val CGoHandle) { + op := ptrFromHandle_gorrent_FileInfo(handle) + op.Path = deptrFromHandle_Slice_string(val) +} + +//export gorrent_FileInfo_PathUTF8_Get +func gorrent_FileInfo_PathUTF8_Get(handle CGoHandle) CGoHandle { + op := ptrFromHandle_gorrent_FileInfo(handle) + return handleFromPtr_Slice_string(&op.PathUTF8) +} + +//export gorrent_FileInfo_PathUTF8_Set +func gorrent_FileInfo_PathUTF8_Set(handle CGoHandle, val CGoHandle) { + op := ptrFromHandle_gorrent_FileInfo(handle) + op.PathUTF8 = deptrFromHandle_Slice_string(val) +} + + // --- wrapping struct: gorrent.FileStatus --- //export gorrent_FileStatus_CTor func gorrent_FileStatus_CTor() CGoHandle { @@ -1526,144 +1664,6 @@ func gorrent_TorrentStatus_Seeds_Set(handle CGoHandle, val C.longlong) { } -// --- wrapping struct: gorrent.Engine --- -//export gorrent_Engine_CTor -func gorrent_Engine_CTor() CGoHandle { - return CGoHandle(handleFromPtr_gorrent_Engine(&gorrent.Engine{})) -} - -//export gorrent_Engine_IsAlive -func gorrent_Engine_IsAlive(_handle CGoHandle) C.char { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return boolGoToPy(false) - } - return boolGoToPy(gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).IsAlive()) - -} - -//export gorrent_Engine_StartTorrent -func gorrent_Engine_StartTorrent(_handle CGoHandle, idx C.longlong) *C.char { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return C.CString("") - } - __err = gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).StartTorrent(int(idx)) - - if __err != nil { - estr := C.CString(__err.Error()) - C.PyErr_SetString(C.PyExc_RuntimeError, estr) - return estr - } - return C.CString("") -} - -//export gorrent_Engine_Status -func gorrent_Engine_Status(_handle CGoHandle) CGoHandle { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return handleFromPtr_gorrent_TorrentStatus(nil) - } - cret := gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Status() - - return handleFromPtr_gorrent_TorrentStatus(&cret) -} - -//export gorrent_Engine_FileStatus -func gorrent_Engine_FileStatus(_handle CGoHandle, i C.longlong) CGoHandle { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return handleFromPtr_gorrent_FileStatus(nil) - } - cret, __err := gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).FileStatus(int(i)) - - if __err != nil { - estr := C.CString(__err.Error()) - C.PyErr_SetString(C.PyExc_RuntimeError, estr) - C.free(unsafe.Pointer(estr)) - return handleFromPtr_gorrent_FileStatus(nil) - } - return handleFromPtr_gorrent_FileStatus(&cret) -} - -//export gorrent_Engine_Stop -func gorrent_Engine_Stop(_handle CGoHandle, goRun C.char) { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return - } - if boolPyToGo(goRun) { - go gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Stop() - } else { - gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Stop() - } -} - -//export gorrent_Engine_GetMsg -func gorrent_Engine_GetMsg(_handle CGoHandle) *C.char { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return C.CString("") - } - return C.CString(gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).GetMsg()) - -} - -//export gorrent_Engine_Clean -func gorrent_Engine_Clean(_handle CGoHandle, goRun C.char) { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Engine") - if __err != nil { - return - } - if boolPyToGo(goRun) { - go gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Clean() - } else { - gopyh.Embed(vifc, reflect.TypeOf(gorrent.Engine{})).(*gorrent.Engine).Clean() - } -} - -// --- wrapping struct: gorrent.FileInfo --- -//export gorrent_FileInfo_CTor -func gorrent_FileInfo_CTor() CGoHandle { - return CGoHandle(handleFromPtr_gorrent_FileInfo(&gorrent.FileInfo{})) -} -//export gorrent_FileInfo_Length_Get -func gorrent_FileInfo_Length_Get(handle CGoHandle) C.longlong { - op := ptrFromHandle_gorrent_FileInfo(handle) - return C.longlong(op.Length) -} - -//export gorrent_FileInfo_Length_Set -func gorrent_FileInfo_Length_Set(handle CGoHandle, val C.longlong) { - op := ptrFromHandle_gorrent_FileInfo(handle) - op.Length = int64(val) -} - -//export gorrent_FileInfo_Path_Get -func gorrent_FileInfo_Path_Get(handle CGoHandle) CGoHandle { - op := ptrFromHandle_gorrent_FileInfo(handle) - return handleFromPtr_Slice_string(&op.Path) -} - -//export gorrent_FileInfo_Path_Set -func gorrent_FileInfo_Path_Set(handle CGoHandle, val CGoHandle) { - op := ptrFromHandle_gorrent_FileInfo(handle) - op.Path = deptrFromHandle_Slice_string(val) -} - -//export gorrent_FileInfo_PathUTF8_Get -func gorrent_FileInfo_PathUTF8_Get(handle CGoHandle) CGoHandle { - op := ptrFromHandle_gorrent_FileInfo(handle) - return handleFromPtr_Slice_string(&op.PathUTF8) -} - -//export gorrent_FileInfo_PathUTF8_Set -func gorrent_FileInfo_PathUTF8_Set(handle CGoHandle, val CGoHandle) { - op := ptrFromHandle_gorrent_FileInfo(handle) - op.PathUTF8 = deptrFromHandle_Slice_string(val) -} - - // ---- Slices --- @@ -1673,6 +1673,12 @@ func gorrent_FileInfo_PathUTF8_Set(handle CGoHandle, val CGoHandle) { // ---- Constructors --- +//export gorrent_NewEngine +func gorrent_NewEngine(settings CGoHandle) CGoHandle { + return handleFromPtr_Ptr_gorrent_Engine(gorrent.NewEngine(ptrFromHandle_Ptr_gorrent_Settings(settings))) + +} + //export gorrent_GetMetaFromFile func gorrent_GetMetaFromFile(path *C.char) CGoHandle { cret, __err := gorrent.GetMetaFromFile(C.GoString(path)) @@ -1692,12 +1698,6 @@ func gorrent_NewSettings() CGoHandle { } -//export gorrent_NewEngine -func gorrent_NewEngine(settings CGoHandle) CGoHandle { - return handleFromPtr_Ptr_gorrent_Engine(gorrent.NewEngine(ptrFromHandle_Ptr_gorrent_Settings(settings))) - -} - // ---- Functions --- diff --git a/py/gorrent/gorrent.py b/py/gorrent/gorrent.py index 7b92191..dbd7f73 100644 --- a/py/gorrent/gorrent.py +++ b/py/gorrent/gorrent.py @@ -127,6 +127,148 @@ class Slice_Ptr_gorrent_FileInfo(go.GoClass): # ---- Structs --- +# Python type for struct gorrent.Engine +class Engine(go.GoClass): + """""" + def __init__(self, *args, **kwargs): + """ + handle=A Go-side object is always initialized with an explicit handle=arg + otherwise parameters can be unnamed in order of field names or named fields + in which case a new Go object is constructed first + """ + if len(kwargs) == 1 and 'handle' in kwargs: + self.handle = kwargs['handle'] + _gorrent.IncRef(self.handle) + elif len(args) == 1 and isinstance(args[0], go.GoClass): + self.handle = args[0].handle + _gorrent.IncRef(self.handle) + else: + self.handle = _gorrent.gorrent_Engine_CTor() + _gorrent.IncRef(self.handle) + def __del__(self): + _gorrent.DecRef(self.handle) + def __str__(self): + pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] + sv = 'gorrent.Engine{' + first = True + for v in pr: + if callable(v[1]): + continue + if first: + first = False + else: + sv += ', ' + sv += v[0] + '=' + str(v[1]) + return sv + '}' + def __repr__(self): + pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] + sv = 'gorrent.Engine ( ' + for v in pr: + if not callable(v[1]): + sv += v[0] + '=' + str(v[1]) + ', ' + return sv + ')' + def IsAlive(self): + """IsAlive() bool""" + return _gorrent.gorrent_Engine_IsAlive(self.handle) + def StartTorrent(self, idx): + """StartTorrent(int idx) str""" + return _gorrent.gorrent_Engine_StartTorrent(self.handle, idx) + def Status(self): + """Status() object""" + return TorrentStatus(handle=_gorrent.gorrent_Engine_Status(self.handle)) + def FileStatus(self, i): + """FileStatus(int i) object, str""" + return FileStatus(handle=_gorrent.gorrent_Engine_FileStatus(self.handle, i)) + def Stop(self, goRun=False): + """Stop() """ + _gorrent.gorrent_Engine_Stop(self.handle, goRun) + def GetMsg(self): + """GetMsg() str""" + return _gorrent.gorrent_Engine_GetMsg(self.handle) + def Clean(self, goRun=False): + """Clean() """ + _gorrent.gorrent_Engine_Clean(self.handle, goRun) + +# Python type for struct gorrent.FileInfo +class FileInfo(go.GoClass): + """""" + def __init__(self, *args, **kwargs): + """ + handle=A Go-side object is always initialized with an explicit handle=arg + otherwise parameters can be unnamed in order of field names or named fields + in which case a new Go object is constructed first + """ + if len(kwargs) == 1 and 'handle' in kwargs: + self.handle = kwargs['handle'] + _gorrent.IncRef(self.handle) + elif len(args) == 1 and isinstance(args[0], go.GoClass): + self.handle = args[0].handle + _gorrent.IncRef(self.handle) + else: + self.handle = _gorrent.gorrent_FileInfo_CTor() + _gorrent.IncRef(self.handle) + if 0 < len(args): + self.Length = args[0] + if "Length" in kwargs: + self.Length = kwargs["Length"] + if 1 < len(args): + self.Path = args[1] + if "Path" in kwargs: + self.Path = kwargs["Path"] + if 2 < len(args): + self.PathUTF8 = args[2] + if "PathUTF8" in kwargs: + self.PathUTF8 = kwargs["PathUTF8"] + def __del__(self): + _gorrent.DecRef(self.handle) + def __str__(self): + pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] + sv = 'gorrent.FileInfo{' + first = True + for v in pr: + if callable(v[1]): + continue + if first: + first = False + else: + sv += ', ' + sv += v[0] + '=' + str(v[1]) + return sv + '}' + def __repr__(self): + pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] + sv = 'gorrent.FileInfo ( ' + for v in pr: + if not callable(v[1]): + sv += v[0] + '=' + str(v[1]) + ', ' + return sv + ')' + @property + def Length(self): + return _gorrent.gorrent_FileInfo_Length_Get(self.handle) + @Length.setter + def Length(self, value): + if isinstance(value, go.GoClass): + _gorrent.gorrent_FileInfo_Length_Set(self.handle, value.handle) + else: + _gorrent.gorrent_FileInfo_Length_Set(self.handle, value) + @property + def Path(self): + return go.Slice_string(handle=_gorrent.gorrent_FileInfo_Path_Get(self.handle)) + @Path.setter + def Path(self, value): + if isinstance(value, go.GoClass): + _gorrent.gorrent_FileInfo_Path_Set(self.handle, value.handle) + else: + raise TypeError("supplied argument type {t} is not a go.GoClass".format(t=type(value))) + @property + def PathUTF8(self): + return go.Slice_string(handle=_gorrent.gorrent_FileInfo_PathUTF8_Get(self.handle)) + @PathUTF8.setter + def PathUTF8(self, value): + if isinstance(value, go.GoClass): + _gorrent.gorrent_FileInfo_PathUTF8_Set(self.handle, value.handle) + else: + raise TypeError("supplied argument type {t} is not a go.GoClass".format(t=type(value))) + # Python type for struct gorrent.FileStatus class FileStatus(go.GoClass): """""" @@ -554,148 +696,6 @@ class TorrentStatus(go.GoClass): else: _gorrent.gorrent_TorrentStatus_Seeds_Set(self.handle, value) -# Python type for struct gorrent.Engine -class Engine(go.GoClass): - """""" - def __init__(self, *args, **kwargs): - """ - handle=A Go-side object is always initialized with an explicit handle=arg - otherwise parameters can be unnamed in order of field names or named fields - in which case a new Go object is constructed first - """ - if len(kwargs) == 1 and 'handle' in kwargs: - self.handle = kwargs['handle'] - _gorrent.IncRef(self.handle) - elif len(args) == 1 and isinstance(args[0], go.GoClass): - self.handle = args[0].handle - _gorrent.IncRef(self.handle) - else: - self.handle = _gorrent.gorrent_Engine_CTor() - _gorrent.IncRef(self.handle) - def __del__(self): - _gorrent.DecRef(self.handle) - def __str__(self): - pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] - sv = 'gorrent.Engine{' - first = True - for v in pr: - if callable(v[1]): - continue - if first: - first = False - else: - sv += ', ' - sv += v[0] + '=' + str(v[1]) - return sv + '}' - def __repr__(self): - pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] - sv = 'gorrent.Engine ( ' - for v in pr: - if not callable(v[1]): - sv += v[0] + '=' + str(v[1]) + ', ' - return sv + ')' - def IsAlive(self): - """IsAlive() bool""" - return _gorrent.gorrent_Engine_IsAlive(self.handle) - def StartTorrent(self, idx): - """StartTorrent(int idx) str""" - return _gorrent.gorrent_Engine_StartTorrent(self.handle, idx) - def Status(self): - """Status() object""" - return TorrentStatus(handle=_gorrent.gorrent_Engine_Status(self.handle)) - def FileStatus(self, i): - """FileStatus(int i) object, str""" - return FileStatus(handle=_gorrent.gorrent_Engine_FileStatus(self.handle, i)) - def Stop(self, goRun=False): - """Stop() """ - _gorrent.gorrent_Engine_Stop(self.handle, goRun) - def GetMsg(self): - """GetMsg() str""" - return _gorrent.gorrent_Engine_GetMsg(self.handle) - def Clean(self, goRun=False): - """Clean() """ - _gorrent.gorrent_Engine_Clean(self.handle, goRun) - -# Python type for struct gorrent.FileInfo -class FileInfo(go.GoClass): - """""" - def __init__(self, *args, **kwargs): - """ - handle=A Go-side object is always initialized with an explicit handle=arg - otherwise parameters can be unnamed in order of field names or named fields - in which case a new Go object is constructed first - """ - if len(kwargs) == 1 and 'handle' in kwargs: - self.handle = kwargs['handle'] - _gorrent.IncRef(self.handle) - elif len(args) == 1 and isinstance(args[0], go.GoClass): - self.handle = args[0].handle - _gorrent.IncRef(self.handle) - else: - self.handle = _gorrent.gorrent_FileInfo_CTor() - _gorrent.IncRef(self.handle) - if 0 < len(args): - self.Length = args[0] - if "Length" in kwargs: - self.Length = kwargs["Length"] - if 1 < len(args): - self.Path = args[1] - if "Path" in kwargs: - self.Path = kwargs["Path"] - if 2 < len(args): - self.PathUTF8 = args[2] - if "PathUTF8" in kwargs: - self.PathUTF8 = kwargs["PathUTF8"] - def __del__(self): - _gorrent.DecRef(self.handle) - def __str__(self): - pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] - sv = 'gorrent.FileInfo{' - first = True - for v in pr: - if callable(v[1]): - continue - if first: - first = False - else: - sv += ', ' - sv += v[0] + '=' + str(v[1]) - return sv + '}' - def __repr__(self): - pr = [(p, getattr(self, p)) for p in dir(self) if not p.startswith('__')] - sv = 'gorrent.FileInfo ( ' - for v in pr: - if not callable(v[1]): - sv += v[0] + '=' + str(v[1]) + ', ' - return sv + ')' - @property - def Length(self): - return _gorrent.gorrent_FileInfo_Length_Get(self.handle) - @Length.setter - def Length(self, value): - if isinstance(value, go.GoClass): - _gorrent.gorrent_FileInfo_Length_Set(self.handle, value.handle) - else: - _gorrent.gorrent_FileInfo_Length_Set(self.handle, value) - @property - def Path(self): - return go.Slice_string(handle=_gorrent.gorrent_FileInfo_Path_Get(self.handle)) - @Path.setter - def Path(self, value): - if isinstance(value, go.GoClass): - _gorrent.gorrent_FileInfo_Path_Set(self.handle, value.handle) - else: - raise TypeError("supplied argument type {t} is not a go.GoClass".format(t=type(value))) - @property - def PathUTF8(self): - return go.Slice_string(handle=_gorrent.gorrent_FileInfo_PathUTF8_Get(self.handle)) - @PathUTF8.setter - def PathUTF8(self, value): - if isinstance(value, go.GoClass): - _gorrent.gorrent_FileInfo_PathUTF8_Set(self.handle, value.handle) - else: - raise TypeError("supplied argument type {t} is not a go.GoClass".format(t=type(value))) - # ---- Slices --- @@ -704,15 +704,15 @@ class FileInfo(go.GoClass): # ---- Constructors --- +def NewEngine(settings): + """NewEngine(object settings) object""" + return Engine(handle=_gorrent.gorrent_NewEngine(settings.handle)) def GetMetaFromFile(path): """GetMetaFromFile(str path) object, str""" return Info(handle=_gorrent.gorrent_GetMetaFromFile(path)) def NewSettings(): """NewSettings() object""" return Settings(handle=_gorrent.gorrent_NewSettings()) -def NewEngine(settings): - """NewEngine(object settings) object""" - return Engine(handle=_gorrent.gorrent_NewEngine(settings.handle)) # ---- Functions ---