использование в качестве хранилища состояния частей торрента sqlite катастрофически увеличивает время запуска

master
Роман Бородин 2022-03-21 23:46:57 +03:00
parent ed22afa7fb
commit a07d4c89f3
5 changed files with 330 additions and 319 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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'))

View File

@ -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 ---

View File

@ -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 ---