parent
fd57940940
commit
ed22afa7fb
|
@ -0,0 +1,5 @@
|
|||
*.a
|
||||
*.so
|
||||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
|
@ -0,0 +1,302 @@
|
|||
package gorrent
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/anacrolix/torrent"
|
||||
"golang.org/x/net/context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TorrentStatus struct {
|
||||
DownloadRate int
|
||||
UploadRate int
|
||||
Seeds int
|
||||
}
|
||||
type FileStatus struct {
|
||||
Name string
|
||||
Url string
|
||||
Progress int
|
||||
Length int
|
||||
}
|
||||
|
||||
type Engine struct {
|
||||
fileIdx int
|
||||
settings *Settings
|
||||
torrCfg *torrent.ClientConfig
|
||||
client *torrent.Client
|
||||
torrent *torrent.Torrent
|
||||
alive bool
|
||||
srv *http.Server
|
||||
srvWg sync.WaitGroup
|
||||
ctx context.Context
|
||||
shutdown context.CancelFunc
|
||||
msgs chan string
|
||||
status struct {
|
||||
lastBytesReadData int
|
||||
lastBytesWrittenData int
|
||||
downRate int
|
||||
upRate int
|
||||
seeds int
|
||||
}
|
||||
}
|
||||
|
||||
func NewEngine(settings *Settings) *Engine {
|
||||
e := &Engine{
|
||||
settings: settings,
|
||||
msgs: make(chan string, 50),
|
||||
}
|
||||
e.ctx, e.shutdown = context.WithCancel(context.Background())
|
||||
return e
|
||||
}
|
||||
func (o *Engine) IsAlive() bool {
|
||||
return o.alive
|
||||
}
|
||||
func (o *Engine) StartTorrent(idx int) error {
|
||||
o.fileIdx = idx
|
||||
var err error
|
||||
o.torrCfg = torrent.NewDefaultClientConfig()
|
||||
o.torrCfg.ListenPort = o.settings.ListenPort
|
||||
o.torrCfg.DataDir = o.settings.DownloadPath
|
||||
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.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() {
|
||||
t := o.torrent
|
||||
<-t.GotInfo()
|
||||
|
||||
file := o.torrent.Files()[idx]
|
||||
|
||||
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++ {
|
||||
t.Piece(int(i)).SetPriority(torrent.PiecePriorityNow)
|
||||
}
|
||||
|
||||
go func() {
|
||||
ticker := time.NewTicker(time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-o.ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
o.updateStats()
|
||||
o.debug(`update stats finished. down: %d KB/s up: %d KB/s seeds: %d`, o.status.downRate, o.status.upRate, o.status.seeds)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
o.srvWg.Add(1)
|
||||
go func() {
|
||||
defer o.srvWg.Done()
|
||||
|
||||
router := http.NewServeMux()
|
||||
router.HandleFunc("/", o.GetFileHandler(file))
|
||||
|
||||
o.srv = &http.Server{Addr: fmt.Sprintf(`%s:%d`, o.settings.HttpBindHost, o.settings.HttpBindPort), Handler: router}
|
||||
|
||||
o.info(`starting http server on port: %d`, o.settings.HttpBindPort)
|
||||
err = o.srv.ListenAndServe()
|
||||
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
o.error(`http listener exit with error: %s`, err.Error())
|
||||
}
|
||||
o.info(`http server stopped successfully`)
|
||||
}()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Engine) updateStats() {
|
||||
stats := o.torrent.Stats()
|
||||
if o.status.lastBytesReadData == 0 {
|
||||
o.status.downRate = 0
|
||||
} else {
|
||||
o.status.downRate = (int(stats.BytesReadData.Int64()) - o.status.lastBytesReadData) / 1024
|
||||
}
|
||||
o.status.lastBytesReadData = int(stats.BytesReadData.Int64())
|
||||
if o.status.lastBytesWrittenData == 0 {
|
||||
o.status.upRate = 0
|
||||
} else {
|
||||
o.status.upRate = (int(stats.BytesWrittenData.Int64()) - o.status.lastBytesWrittenData) / 1024
|
||||
}
|
||||
o.status.lastBytesWrittenData = int(stats.BytesWrittenData.Int64())
|
||||
o.status.seeds = stats.ConnectedSeeders
|
||||
}
|
||||
|
||||
func (o *Engine) Status() TorrentStatus {
|
||||
res := TorrentStatus{}
|
||||
res.DownloadRate = o.status.downRate
|
||||
res.UploadRate = o.status.upRate
|
||||
res.Seeds = o.status.seeds
|
||||
return res
|
||||
}
|
||||
func (o *Engine) FileStatus(i int) (FileStatus, error) {
|
||||
fs := FileStatus{}
|
||||
if i < 0 || i > len(o.torrent.Files())-1 {
|
||||
return fs, fmt.Errorf(`file index out of range: %d`, i)
|
||||
}
|
||||
|
||||
file := o.torrent.Files()[i]
|
||||
|
||||
pathParts := strings.Split(file.DisplayPath(), `/`)
|
||||
fs.Name = file.DisplayPath()
|
||||
for idx := range pathParts {
|
||||
pathParts[idx] = url.QueryEscape(pathParts[idx])
|
||||
}
|
||||
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)
|
||||
fs.Length = int(file.Length())
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
func (o *Engine) Stop() {
|
||||
go func() {
|
||||
httpCtx, cancelHttp := context.WithTimeout(o.ctx, time.Second*5)
|
||||
defer cancelHttp()
|
||||
if err := o.srv.Shutdown(httpCtx); err != nil {
|
||||
o.error(`shutting down http server failed: %s`, err.Error())
|
||||
}
|
||||
|
||||
o.srvWg.Wait()
|
||||
|
||||
o.syncDebug(`dropping torrent`)
|
||||
o.torrent.Drop()
|
||||
o.syncDebug(`closing client`)
|
||||
o.client.Close()
|
||||
<-o.client.Closed()
|
||||
|
||||
if !o.settings.KeepFiles {
|
||||
o.Clean()
|
||||
}
|
||||
|
||||
o.syncDebug(`torrent engine stopped`)
|
||||
close(o.msgs)
|
||||
o.alive = false
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Engine) GetMsg() string {
|
||||
select {
|
||||
case msg, ok := <-o.msgs:
|
||||
if ok {
|
||||
return msg
|
||||
} else {
|
||||
return "__CLOSED__"
|
||||
}
|
||||
default:
|
||||
}
|
||||
return "__NO_MSG__"
|
||||
}
|
||||
func (o *Engine) debug(tmpl string, args ...interface{}) {
|
||||
go o.syncDebug(tmpl, args...)
|
||||
}
|
||||
func (o *Engine) info(tmpl string, args ...interface{}) {
|
||||
go o.syncInfo(tmpl, args...)
|
||||
}
|
||||
func (o *Engine) error(tmpl string, args ...interface{}) {
|
||||
go o.syncError(tmpl, args...)
|
||||
}
|
||||
func (o *Engine) syncError(t string, a ...interface{}) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
fmt.Printf("recovered from panic: %v\n", rec)
|
||||
}
|
||||
}()
|
||||
var result string
|
||||
if len(a) > 0 {
|
||||
result = fmt.Sprintf(t, a...)
|
||||
} else {
|
||||
result = t
|
||||
}
|
||||
o.msgs <- fmt.Sprintf(`[ERROR] %s`, result)
|
||||
}
|
||||
func (o *Engine) syncDebug(t string, a ...interface{}) {
|
||||
if o.settings.Debug {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
fmt.Printf("recovered from panic: %v\n", rec)
|
||||
}
|
||||
}()
|
||||
var result string
|
||||
if len(a) > 0 {
|
||||
result = fmt.Sprintf(t, a...)
|
||||
} else {
|
||||
result = t
|
||||
}
|
||||
o.msgs <- fmt.Sprintf(`[DEBUG] %s`, result)
|
||||
}
|
||||
}
|
||||
func (o *Engine) syncInfo(t string, a ...interface{}) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
fmt.Printf("recovered from panic: %v\n", rec)
|
||||
}
|
||||
}()
|
||||
var result string
|
||||
if len(a) > 0 {
|
||||
result = fmt.Sprintf(t, a...)
|
||||
} else {
|
||||
result = t
|
||||
}
|
||||
o.msgs <- fmt.Sprintf(`[INFO] %s`, result)
|
||||
}
|
||||
|
||||
func (o *Engine) GetFileHandler(target *torrent.File) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
entry := target.NewReader()
|
||||
entry.SetReadahead(target.Length() / 100)
|
||||
entry.SetResponsive()
|
||||
|
||||
defer func() {
|
||||
if err := entry.Close(); err != nil {
|
||||
o.error(`close torrent file in file handler failed: %s`, err.Error())
|
||||
}
|
||||
}()
|
||||
|
||||
pathParts := strings.Split(target.DisplayPath(), `/`)
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=\""+pathParts[len(pathParts)-1]+"\"")
|
||||
http.ServeContent(w, r, target.DisplayPath(), time.Now(), entry)
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Engine) Clean() {
|
||||
fp := path.Join(o.settings.DownloadPath, o.torrent.Name())
|
||||
if err := os.RemoveAll(fp); err != nil {
|
||||
o.syncError(`remove downloaded data failed: %s`, err.Error())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
module gorrent
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/RoaringBitmap/roaring v0.9.4
|
||||
github.com/anacrolix/dht/v2 v2.15.2-0.20220123034220-0538803801cb
|
||||
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8
|
||||
github.com/anacrolix/torrent v1.41.0
|
||||
github.com/go-python/gopy v0.4.0
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/anacrolix/chansync v0.3.0 // indirect
|
||||
github.com/anacrolix/confluence v1.9.0 // indirect
|
||||
github.com/anacrolix/envpprof v1.1.1 // indirect
|
||||
github.com/anacrolix/go-libutp v1.2.0 // indirect
|
||||
github.com/anacrolix/missinggo v1.3.0 // indirect
|
||||
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
|
||||
github.com/anacrolix/missinggo/v2 v2.5.2 // indirect
|
||||
github.com/anacrolix/mmsg v1.0.0 // indirect
|
||||
github.com/anacrolix/multiless v0.2.0 // indirect
|
||||
github.com/anacrolix/stm v0.3.0 // indirect
|
||||
github.com/anacrolix/sync v0.4.0 // indirect
|
||||
github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 // indirect
|
||||
github.com/anacrolix/utp v0.1.0 // indirect
|
||||
github.com/benbjohnson/immutable v0.3.0 // indirect
|
||||
github.com/bits-and-blooms/bitset v1.2.0 // indirect
|
||||
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
||||
github.com/edsrzf/mmap-go v1.0.0 // indirect
|
||||
github.com/google/btree v1.0.1 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/huandu/xstrings v1.3.2 // indirect
|
||||
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||
github.com/mschoch/smat v0.2.0 // indirect
|
||||
github.com/pion/datachannel v1.5.2 // indirect
|
||||
github.com/pion/dtls/v2 v2.1.2 // indirect
|
||||
github.com/pion/ice/v2 v2.1.20 // indirect
|
||||
github.com/pion/interceptor v0.1.7 // indirect
|
||||
github.com/pion/logging v0.2.2 // indirect
|
||||
github.com/pion/mdns v0.0.5 // indirect
|
||||
github.com/pion/randutil v0.1.0 // indirect
|
||||
github.com/pion/rtcp v1.2.9 // indirect
|
||||
github.com/pion/rtp v1.7.4 // indirect
|
||||
github.com/pion/sctp v1.8.2 // indirect
|
||||
github.com/pion/sdp/v3 v3.0.4 // indirect
|
||||
github.com/pion/srtp/v2 v2.0.5 // indirect
|
||||
github.com/pion/stun v0.3.5 // indirect
|
||||
github.com/pion/transport v0.13.0 // indirect
|
||||
github.com/pion/turn/v2 v2.0.6 // indirect
|
||||
github.com/pion/udp v0.1.1 // indirect
|
||||
github.com/pion/webrtc/v3 v3.1.24-0.20220208053747-94262c1b2b38 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/rs/dnscache v0.0.0-20210201191234-295bba877686 // indirect
|
||||
go.etcd.io/bbolt v1.3.6 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220131195533-30dcbda58838 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
modernc.org/libc v1.11.82 // indirect
|
||||
modernc.org/mathutil v1.4.1 // indirect
|
||||
modernc.org/memory v1.0.5 // indirect
|
||||
modernc.org/sqlite v1.14.2-0.20211125151325-d4ed92c0a70f // indirect
|
||||
zombiezen.com/go/sqlite v0.8.0 // indirect
|
||||
)
|
|
@ -0,0 +1,15 @@
|
|||
package gorrent
|
||||
|
||||
var version = `1.0.0`
|
||||
|
||||
func GetMetaFromFile(path string) (*Info, error) {
|
||||
info := &Info{}
|
||||
if err := info.LoadFile(path); err != nil {
|
||||
return info, err
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func Version() string {
|
||||
return version
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package gorrent
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
)
|
||||
|
||||
type FileInfo struct {
|
||||
Length int64
|
||||
Path []string
|
||||
PathUTF8 []string
|
||||
}
|
||||
|
||||
type Info struct {
|
||||
Name string
|
||||
Length int64
|
||||
Source string
|
||||
Files []*FileInfo
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
func (o *Info) LoadFile(path string) error {
|
||||
meta, err := metainfo.LoadFromFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i, err := meta.UnmarshalInfo()
|
||||
o.Name = i.Name
|
||||
o.Length = i.Length
|
||||
o.Source = i.Source
|
||||
for _, fi := range i.Files {
|
||||
o.Files = append(o.Files, &FileInfo{
|
||||
Length: fi.Length,
|
||||
Path: fi.Path,
|
||||
PathUTF8: fi.PathUTF8,
|
||||
})
|
||||
}
|
||||
return err
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
# Makefile for python interface for package gorrent.
|
||||
# File is generated by gopy. Do not edit.
|
||||
# gopy gen --output=py/gorrent gorrent
|
||||
|
||||
GOCMD=go
|
||||
GOBUILD=$(GOCMD) build -mod=mod
|
||||
GOIMPORTS=goimports
|
||||
PYTHON=/usr/bin/python
|
||||
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
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
# build target builds the generated files -- this is what gopy build does..
|
||||
# this will otherwise be built during go build and may be out of date
|
||||
- rm gorrent.c
|
||||
# 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
|
||||
# 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
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
# python build stubs for package gorrent
|
||||
# File is generated by gopy. Do not edit.
|
||||
# gopy gen --output=py/gorrent gorrent
|
||||
|
||||
from pybindgen import retval, param, Function, Module
|
||||
import sys
|
||||
|
||||
class CheckedFunction(Function):
|
||||
def __init__(self, *a, **kw):
|
||||
super(CheckedFunction, self).__init__(*a, **kw)
|
||||
self._failure_expression = kw.get('failure_expression', '')
|
||||
self._failure_cleanup = kw.get('failure_cleanup', '')
|
||||
|
||||
def set_failure_expression(self, expr):
|
||||
self._failure_expression = expr
|
||||
|
||||
def set_failure_cleanup(self, expr):
|
||||
self._failure_cleanup = expr
|
||||
|
||||
def generate_call(self):
|
||||
super(CheckedFunction, self).generate_call()
|
||||
check = "PyErr_Occurred()"
|
||||
if self._failure_expression:
|
||||
check = "{} && {}".format(self._failure_expression, check)
|
||||
failure_cleanup = self._failure_cleanup or None
|
||||
self.before_call.write_error_check(check, failure_cleanup)
|
||||
|
||||
def add_checked_function(mod, name, retval, params, failure_expression='', *a, **kw):
|
||||
fn = CheckedFunction(name, retval, params, *a, **kw)
|
||||
fn.set_failure_expression(failure_expression)
|
||||
mod._add_function_obj(fn)
|
||||
return fn
|
||||
|
||||
def add_checked_string_function(mod, name, retval, params, failure_expression='', *a, **kw):
|
||||
fn = CheckedFunction(name, retval, params, *a, **kw)
|
||||
fn.set_failure_cleanup('if (retval != NULL) free(retval);')
|
||||
fn.after_call.add_cleanup_code('free(retval);')
|
||||
fn.set_failure_expression(failure_expression)
|
||||
mod._add_function_obj(fn)
|
||||
return fn
|
||||
|
||||
mod = Module('_gorrent')
|
||||
mod.add_include('"gorrent_go.h"')
|
||||
mod.add_function('GoPyInit', None, [])
|
||||
mod.add_function('DecRef', None, [param('int64_t', 'handle')])
|
||||
mod.add_function('IncRef', None, [param('int64_t', 'handle')])
|
||||
mod.add_function('NumHandles', retval('int'), [])
|
||||
mod.add_function('Slice_bool_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_bool_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_bool_elem', retval('bool'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_bool_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_bool_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('bool', 'value')])
|
||||
mod.add_function('Slice_bool_append', None, [param('int64_t', 'handle'), param('bool', 'value')])
|
||||
mod.add_function('Slice_byte_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_byte_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_byte_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_byte_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_byte_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint8_t', 'value')])
|
||||
mod.add_function('Slice_byte_append', None, [param('int64_t', 'handle'), param('uint8_t', 'value')])
|
||||
mod.add_function('Slice_float32_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_float32_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_float32_elem', retval('float'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_float32_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_float32_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('float', 'value')])
|
||||
mod.add_function('Slice_float32_append', None, [param('int64_t', 'handle'), param('float', 'value')])
|
||||
mod.add_function('Slice_float64_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_float64_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_float64_elem', retval('double'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_float64_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_float64_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('double', 'value')])
|
||||
mod.add_function('Slice_float64_append', None, [param('int64_t', 'handle'), param('double', 'value')])
|
||||
mod.add_function('Slice_int_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_int_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_int_elem', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_int_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_int_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int64_t', 'value')])
|
||||
mod.add_function('Slice_int_append', None, [param('int64_t', 'handle'), param('int64_t', 'value')])
|
||||
mod.add_function('Slice_int16_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_int16_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_int16_elem', retval('int16_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_int16_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_int16_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int16_t', 'value')])
|
||||
mod.add_function('Slice_int16_append', None, [param('int64_t', 'handle'), param('int16_t', 'value')])
|
||||
mod.add_function('Slice_int32_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_int32_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_int32_elem', retval('int32_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_int32_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_int32_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int32_t', 'value')])
|
||||
mod.add_function('Slice_int32_append', None, [param('int64_t', 'handle'), param('int32_t', 'value')])
|
||||
mod.add_function('Slice_int64_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_int64_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_int64_elem', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_int64_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_int64_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int64_t', 'value')])
|
||||
mod.add_function('Slice_int64_append', None, [param('int64_t', 'handle'), param('int64_t', 'value')])
|
||||
mod.add_function('Slice_int8_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_int8_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_int8_elem', retval('int8_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_int8_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_int8_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int8_t', 'value')])
|
||||
mod.add_function('Slice_int8_append', None, [param('int64_t', 'handle'), param('int8_t', 'value')])
|
||||
mod.add_function('Slice_rune_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_rune_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_rune_elem', retval('int32_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_rune_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_rune_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('int32_t', 'value')])
|
||||
mod.add_function('Slice_rune_append', None, [param('int64_t', 'handle'), param('int32_t', 'value')])
|
||||
mod.add_function('Slice_string_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_string_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_string_elem', retval('char*'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_string_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_string_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('char*', 'value')])
|
||||
mod.add_function('Slice_string_append', None, [param('int64_t', 'handle'), param('char*', 'value')])
|
||||
mod.add_function('Slice_uint_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_uint_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_uint_elem', retval('uint64_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_uint_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_uint_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint64_t', 'value')])
|
||||
mod.add_function('Slice_uint_append', None, [param('int64_t', 'handle'), param('uint64_t', 'value')])
|
||||
mod.add_function('Slice_uint16_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_uint16_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_uint16_elem', retval('uint16_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_uint16_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_uint16_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint16_t', 'value')])
|
||||
mod.add_function('Slice_uint16_append', None, [param('int64_t', 'handle'), param('uint16_t', 'value')])
|
||||
mod.add_function('Slice_uint32_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_uint32_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_uint32_elem', retval('uint32_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_uint32_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_uint32_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint32_t', 'value')])
|
||||
mod.add_function('Slice_uint32_append', None, [param('int64_t', 'handle'), param('uint32_t', 'value')])
|
||||
mod.add_function('Slice_uint64_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_uint64_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_uint64_elem', retval('uint64_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_uint64_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_uint64_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint64_t', 'value')])
|
||||
mod.add_function('Slice_uint64_append', None, [param('int64_t', 'handle'), param('uint64_t', 'value')])
|
||||
mod.add_function('Slice_uint8_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_uint8_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_uint8_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
mod.add_function('Slice_uint8_subslice', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'st'), param('int', 'ed')])
|
||||
mod.add_function('Slice_uint8_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint8_t', 'value')])
|
||||
mod.add_function('Slice_uint8_append', None, [param('int64_t', 'handle'), param('uint8_t', 'value')])
|
||||
mod.add_function('Slice_Ptr_gorrent_FileInfo_CTor', retval('int64_t'), [])
|
||||
mod.add_function('Slice_Ptr_gorrent_FileInfo_len', retval('int'), [param('int64_t', 'handle')])
|
||||
mod.add_function('Slice_Ptr_gorrent_FileInfo_elem', retval('int64_t'), [param('int64_t', 'handle'), param('int', 'idx')])
|
||||
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_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')])
|
||||
mod.add_function('gorrent_FileStatus_Url_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_FileStatus_Url_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_FileStatus_Progress_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_FileStatus_Progress_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_FileStatus_Length_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_FileStatus_Length_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_Info_CTor', retval('int64_t'), [])
|
||||
mod.add_function('gorrent_Info_Name_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Info_Name_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Info_Length_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Info_Length_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_Info_Source_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Info_Source_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Info_Files_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Info_Files_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
add_checked_function(mod, 'gorrent_Info_LoadFile', retval('char*'), [param('int64_t', '_handle'), param('char*', 'path')])
|
||||
mod.add_function('gorrent_Settings_CTor', retval('int64_t'), [])
|
||||
mod.add_function('gorrent_Settings_DownloadPath_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_DownloadPath_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Settings_HttpBindHost_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_HttpBindHost_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Settings_HttpBindPort_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_HttpBindPort_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_Settings_ListenPort_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_ListenPort_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_Settings_MaxConnections_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_MaxConnections_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_Settings_TorrentPath_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_TorrentPath_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Settings_Proxy_Get', retval('char*'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_Proxy_Set', None, [param('int64_t', 'handle'), param('char*', 'val')])
|
||||
mod.add_function('gorrent_Settings_KeepFiles_Get', retval('bool'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_KeepFiles_Set', None, [param('int64_t', 'handle'), param('bool', 'val')])
|
||||
mod.add_function('gorrent_Settings_Debug_Get', retval('bool'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_Settings_Debug_Set', None, [param('int64_t', 'handle'), param('bool', 'val')])
|
||||
mod.add_function('gorrent_TorrentStatus_CTor', retval('int64_t'), [])
|
||||
mod.add_function('gorrent_TorrentStatus_DownloadRate_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
mod.add_function('gorrent_TorrentStatus_DownloadRate_Set', None, [param('int64_t', 'handle'), param('int64_t', 'val')])
|
||||
mod.add_function('gorrent_TorrentStatus_UploadRate_Get', retval('int64_t'), [param('int64_t', 'handle')])
|
||||
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_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'))
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,723 @@
|
|||
|
||||
# python wrapper for package gorrent within overall package gorrent
|
||||
# This is what you import to use the package.
|
||||
# File is generated by gopy. Do not edit.
|
||||
# gopy gen --output=py/gorrent gorrent
|
||||
|
||||
# the following is required to enable dlopen to open the _go.so file
|
||||
import os,sys,inspect,collections
|
||||
try:
|
||||
import collections.abc as _collections_abc
|
||||
except ImportError:
|
||||
_collections_abc = collections
|
||||
|
||||
cwd = os.getcwd()
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
os.chdir(currentdir)
|
||||
from . import _gorrent
|
||||
from . import go
|
||||
|
||||
os.chdir(cwd)
|
||||
|
||||
# to use this code in your end-user python file, import it as follows:
|
||||
# from gorrent import gorrent
|
||||
# and then refer to everything using gorrent. prefix
|
||||
# packages imported by this package listed below:
|
||||
|
||||
|
||||
|
||||
|
||||
# ---- Types ---
|
||||
|
||||
# Python type for slice []*gorrent.FileInfo
|
||||
class Slice_Ptr_gorrent_FileInfo(go.GoClass):
|
||||
""""""
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
handle=A Go-side object is always initialized with an explicit handle=arg
|
||||
otherwise parameter is a python list that we copy from
|
||||
"""
|
||||
self.index = 0
|
||||
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.Slice_Ptr_gorrent_FileInfo_CTor()
|
||||
_gorrent.IncRef(self.handle)
|
||||
if len(args) > 0:
|
||||
if not isinstance(args[0], _collections_abc.Iterable):
|
||||
raise TypeError('Slice_Ptr_gorrent_FileInfo.__init__ takes a sequence as argument')
|
||||
for elt in args[0]:
|
||||
self.append(elt)
|
||||
def __del__(self):
|
||||
_gorrent.DecRef(self.handle)
|
||||
def __str__(self):
|
||||
s = 'gorrent.Slice_Ptr_gorrent_FileInfo len: ' + str(len(self)) + ' handle: ' + str(self.handle) + ' ['
|
||||
if len(self) < 120:
|
||||
s += ', '.join(map(str, self)) + ']'
|
||||
return s
|
||||
def __repr__(self):
|
||||
return 'gorrent.Slice_Ptr_gorrent_FileInfo([' + ', '.join(map(str, self)) + '])'
|
||||
def __len__(self):
|
||||
return _gorrent.Slice_Ptr_gorrent_FileInfo_len(self.handle)
|
||||
def __getitem__(self, key):
|
||||
if isinstance(key, slice):
|
||||
if key.step == None or key.step == 1:
|
||||
st = key.start
|
||||
ed = key.stop
|
||||
if st == None:
|
||||
st = 0
|
||||
if ed == None:
|
||||
ed = _gorrent.Slice_Ptr_gorrent_FileInfo_len(self.handle)
|
||||
return Slice_Ptr_gorrent_FileInfo(handle=_gorrent.Slice_Ptr_gorrent_FileInfo_subslice(self.handle, st, ed))
|
||||
return [self[ii] for ii in range(*key.indices(len(self)))]
|
||||
elif isinstance(key, int):
|
||||
if key < 0:
|
||||
key += len(self)
|
||||
if key < 0 or key >= len(self):
|
||||
raise IndexError('slice index out of range')
|
||||
return FileInfo(handle=_gorrent.Slice_Ptr_gorrent_FileInfo_elem(self.handle, key))
|
||||
else:
|
||||
raise TypeError('slice index invalid type')
|
||||
def __setitem__(self, idx, value):
|
||||
if idx < 0:
|
||||
idx += len(self)
|
||||
if idx < len(self):
|
||||
_gorrent.Slice_Ptr_gorrent_FileInfo_set(self.handle, idx, value.handle)
|
||||
return
|
||||
raise IndexError('slice index out of range')
|
||||
def __iadd__(self, value):
|
||||
if not isinstance(value, _collections_abc.Iterable):
|
||||
raise TypeError('Slice_Ptr_gorrent_FileInfo.__iadd__ takes a sequence as argument')
|
||||
for elt in value:
|
||||
self.append(elt)
|
||||
return self
|
||||
def __iter__(self):
|
||||
self.index = 0
|
||||
return self
|
||||
def __next__(self):
|
||||
if self.index < len(self):
|
||||
rv = _gorrent.Slice_Ptr_gorrent_FileInfo_elem(self.handle, self.index)
|
||||
self.index = self.index + 1
|
||||
return rv
|
||||
raise StopIteration
|
||||
def append(self, value):
|
||||
_gorrent.Slice_Ptr_gorrent_FileInfo_append(self.handle, value.handle)
|
||||
def copy(self, src):
|
||||
""" copy emulates the go copy function, copying elements into this list from source list, up to min of size of each list """
|
||||
mx = min(len(self), len(src))
|
||||
for i in range(mx):
|
||||
self[i] = src[i]
|
||||
|
||||
|
||||
#---- Enums from Go (collections of consts with same type) ---
|
||||
|
||||
|
||||
#---- Constants from Go: Python can only ask that you please don't change these! ---
|
||||
|
||||
|
||||
# ---- Global Variables: can only use functions to access ---
|
||||
|
||||
|
||||
# ---- Interfaces ---
|
||||
|
||||
|
||||
# ---- Structs ---
|
||||
|
||||
# Python type for struct gorrent.FileStatus
|
||||
class FileStatus(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_FileStatus_CTor()
|
||||
_gorrent.IncRef(self.handle)
|
||||
if 0 < len(args):
|
||||
self.Name = args[0]
|
||||
if "Name" in kwargs:
|
||||
self.Name = kwargs["Name"]
|
||||
if 1 < len(args):
|
||||
self.Url = args[1]
|
||||
if "Url" in kwargs:
|
||||
self.Url = kwargs["Url"]
|
||||
if 2 < len(args):
|
||||
self.Progress = args[2]
|
||||
if "Progress" in kwargs:
|
||||
self.Progress = kwargs["Progress"]
|
||||
if 3 < len(args):
|
||||
self.Length = args[3]
|
||||
if "Length" in kwargs:
|
||||
self.Length = kwargs["Length"]
|
||||
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.FileStatus{'
|
||||
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.FileStatus ( '
|
||||
for v in pr:
|
||||
if not callable(v[1]):
|
||||
sv += v[0] + '=' + str(v[1]) + ', '
|
||||
return sv + ')'
|
||||
@property
|
||||
def Name(self):
|
||||
return _gorrent.gorrent_FileStatus_Name_Get(self.handle)
|
||||
@Name.setter
|
||||
def Name(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_FileStatus_Name_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_FileStatus_Name_Set(self.handle, value)
|
||||
@property
|
||||
def Url(self):
|
||||
return _gorrent.gorrent_FileStatus_Url_Get(self.handle)
|
||||
@Url.setter
|
||||
def Url(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_FileStatus_Url_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_FileStatus_Url_Set(self.handle, value)
|
||||
@property
|
||||
def Progress(self):
|
||||
return _gorrent.gorrent_FileStatus_Progress_Get(self.handle)
|
||||
@Progress.setter
|
||||
def Progress(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_FileStatus_Progress_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_FileStatus_Progress_Set(self.handle, value)
|
||||
@property
|
||||
def Length(self):
|
||||
return _gorrent.gorrent_FileStatus_Length_Get(self.handle)
|
||||
@Length.setter
|
||||
def Length(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_FileStatus_Length_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_FileStatus_Length_Set(self.handle, value)
|
||||
|
||||
# Python type for struct gorrent.Info
|
||||
class Info(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_Info_CTor()
|
||||
_gorrent.IncRef(self.handle)
|
||||
if 0 < len(args):
|
||||
self.Name = args[0]
|
||||
if "Name" in kwargs:
|
||||
self.Name = kwargs["Name"]
|
||||
if 1 < len(args):
|
||||
self.Length = args[1]
|
||||
if "Length" in kwargs:
|
||||
self.Length = kwargs["Length"]
|
||||
if 2 < len(args):
|
||||
self.Source = args[2]
|
||||
if "Source" in kwargs:
|
||||
self.Source = kwargs["Source"]
|
||||
if 3 < len(args):
|
||||
self.Files = args[3]
|
||||
if "Files" in kwargs:
|
||||
self.Files = kwargs["Files"]
|
||||
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.Info{'
|
||||
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.Info ( '
|
||||
for v in pr:
|
||||
if not callable(v[1]):
|
||||
sv += v[0] + '=' + str(v[1]) + ', '
|
||||
return sv + ')'
|
||||
@property
|
||||
def Name(self):
|
||||
return _gorrent.gorrent_Info_Name_Get(self.handle)
|
||||
@Name.setter
|
||||
def Name(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Info_Name_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Info_Name_Set(self.handle, value)
|
||||
@property
|
||||
def Length(self):
|
||||
return _gorrent.gorrent_Info_Length_Get(self.handle)
|
||||
@Length.setter
|
||||
def Length(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Info_Length_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Info_Length_Set(self.handle, value)
|
||||
@property
|
||||
def Source(self):
|
||||
return _gorrent.gorrent_Info_Source_Get(self.handle)
|
||||
@Source.setter
|
||||
def Source(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Info_Source_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Info_Source_Set(self.handle, value)
|
||||
@property
|
||||
def Files(self):
|
||||
return Slice_Ptr_gorrent_FileInfo(handle=_gorrent.gorrent_Info_Files_Get(self.handle))
|
||||
@Files.setter
|
||||
def Files(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Info_Files_Set(self.handle, value.handle)
|
||||
else:
|
||||
raise TypeError("supplied argument type {t} is not a go.GoClass".format(t=type(value)))
|
||||
def LoadFile(self, path):
|
||||
"""LoadFile(str path) str"""
|
||||
return _gorrent.gorrent_Info_LoadFile(self.handle, path)
|
||||
|
||||
# Python type for struct gorrent.Settings
|
||||
class Settings(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_Settings_CTor()
|
||||
_gorrent.IncRef(self.handle)
|
||||
if 0 < len(args):
|
||||
self.DownloadPath = args[0]
|
||||
if "DownloadPath" in kwargs:
|
||||
self.DownloadPath = kwargs["DownloadPath"]
|
||||
if 1 < len(args):
|
||||
self.HttpBindHost = args[1]
|
||||
if "HttpBindHost" in kwargs:
|
||||
self.HttpBindHost = kwargs["HttpBindHost"]
|
||||
if 2 < len(args):
|
||||
self.HttpBindPort = args[2]
|
||||
if "HttpBindPort" in kwargs:
|
||||
self.HttpBindPort = kwargs["HttpBindPort"]
|
||||
if 3 < len(args):
|
||||
self.ListenPort = args[3]
|
||||
if "ListenPort" in kwargs:
|
||||
self.ListenPort = kwargs["ListenPort"]
|
||||
if 4 < len(args):
|
||||
self.MaxConnections = args[4]
|
||||
if "MaxConnections" in kwargs:
|
||||
self.MaxConnections = kwargs["MaxConnections"]
|
||||
if 5 < len(args):
|
||||
self.TorrentPath = args[5]
|
||||
if "TorrentPath" in kwargs:
|
||||
self.TorrentPath = kwargs["TorrentPath"]
|
||||
if 6 < len(args):
|
||||
self.Proxy = args[6]
|
||||
if "Proxy" in kwargs:
|
||||
self.Proxy = kwargs["Proxy"]
|
||||
if 7 < len(args):
|
||||
self.KeepFiles = args[7]
|
||||
if "KeepFiles" in kwargs:
|
||||
self.KeepFiles = kwargs["KeepFiles"]
|
||||
if 8 < len(args):
|
||||
self.Debug = args[8]
|
||||
if "Debug" in kwargs:
|
||||
self.Debug = kwargs["Debug"]
|
||||
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.Settings{'
|
||||
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.Settings ( '
|
||||
for v in pr:
|
||||
if not callable(v[1]):
|
||||
sv += v[0] + '=' + str(v[1]) + ', '
|
||||
return sv + ')'
|
||||
@property
|
||||
def DownloadPath(self):
|
||||
return _gorrent.gorrent_Settings_DownloadPath_Get(self.handle)
|
||||
@DownloadPath.setter
|
||||
def DownloadPath(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_DownloadPath_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_DownloadPath_Set(self.handle, value)
|
||||
@property
|
||||
def HttpBindHost(self):
|
||||
return _gorrent.gorrent_Settings_HttpBindHost_Get(self.handle)
|
||||
@HttpBindHost.setter
|
||||
def HttpBindHost(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_HttpBindHost_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_HttpBindHost_Set(self.handle, value)
|
||||
@property
|
||||
def HttpBindPort(self):
|
||||
return _gorrent.gorrent_Settings_HttpBindPort_Get(self.handle)
|
||||
@HttpBindPort.setter
|
||||
def HttpBindPort(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_HttpBindPort_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_HttpBindPort_Set(self.handle, value)
|
||||
@property
|
||||
def ListenPort(self):
|
||||
return _gorrent.gorrent_Settings_ListenPort_Get(self.handle)
|
||||
@ListenPort.setter
|
||||
def ListenPort(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_ListenPort_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_ListenPort_Set(self.handle, value)
|
||||
@property
|
||||
def MaxConnections(self):
|
||||
return _gorrent.gorrent_Settings_MaxConnections_Get(self.handle)
|
||||
@MaxConnections.setter
|
||||
def MaxConnections(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_MaxConnections_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_MaxConnections_Set(self.handle, value)
|
||||
@property
|
||||
def TorrentPath(self):
|
||||
return _gorrent.gorrent_Settings_TorrentPath_Get(self.handle)
|
||||
@TorrentPath.setter
|
||||
def TorrentPath(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_TorrentPath_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_TorrentPath_Set(self.handle, value)
|
||||
@property
|
||||
def Proxy(self):
|
||||
return _gorrent.gorrent_Settings_Proxy_Get(self.handle)
|
||||
@Proxy.setter
|
||||
def Proxy(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_Proxy_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_Proxy_Set(self.handle, value)
|
||||
@property
|
||||
def KeepFiles(self):
|
||||
return _gorrent.gorrent_Settings_KeepFiles_Get(self.handle)
|
||||
@KeepFiles.setter
|
||||
def KeepFiles(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_KeepFiles_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_KeepFiles_Set(self.handle, value)
|
||||
@property
|
||||
def Debug(self):
|
||||
return _gorrent.gorrent_Settings_Debug_Get(self.handle)
|
||||
@Debug.setter
|
||||
def Debug(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_Settings_Debug_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_Settings_Debug_Set(self.handle, value)
|
||||
|
||||
# Python type for struct gorrent.TorrentStatus
|
||||
class TorrentStatus(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_TorrentStatus_CTor()
|
||||
_gorrent.IncRef(self.handle)
|
||||
if 0 < len(args):
|
||||
self.DownloadRate = args[0]
|
||||
if "DownloadRate" in kwargs:
|
||||
self.DownloadRate = kwargs["DownloadRate"]
|
||||
if 1 < len(args):
|
||||
self.UploadRate = args[1]
|
||||
if "UploadRate" in kwargs:
|
||||
self.UploadRate = kwargs["UploadRate"]
|
||||
if 2 < len(args):
|
||||
self.Seeds = args[2]
|
||||
if "Seeds" in kwargs:
|
||||
self.Seeds = kwargs["Seeds"]
|
||||
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.TorrentStatus{'
|
||||
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.TorrentStatus ( '
|
||||
for v in pr:
|
||||
if not callable(v[1]):
|
||||
sv += v[0] + '=' + str(v[1]) + ', '
|
||||
return sv + ')'
|
||||
@property
|
||||
def DownloadRate(self):
|
||||
return _gorrent.gorrent_TorrentStatus_DownloadRate_Get(self.handle)
|
||||
@DownloadRate.setter
|
||||
def DownloadRate(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_TorrentStatus_DownloadRate_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_TorrentStatus_DownloadRate_Set(self.handle, value)
|
||||
@property
|
||||
def UploadRate(self):
|
||||
return _gorrent.gorrent_TorrentStatus_UploadRate_Get(self.handle)
|
||||
@UploadRate.setter
|
||||
def UploadRate(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_TorrentStatus_UploadRate_Set(self.handle, value.handle)
|
||||
else:
|
||||
_gorrent.gorrent_TorrentStatus_UploadRate_Set(self.handle, value)
|
||||
@property
|
||||
def Seeds(self):
|
||||
return _gorrent.gorrent_TorrentStatus_Seeds_Get(self.handle)
|
||||
@Seeds.setter
|
||||
def Seeds(self, value):
|
||||
if isinstance(value, go.GoClass):
|
||||
_gorrent.gorrent_TorrentStatus_Seeds_Set(self.handle, value.handle)
|
||||
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 ---
|
||||
|
||||
|
||||
# ---- Maps ---
|
||||
|
||||
|
||||
# ---- Constructors ---
|
||||
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 ---
|
||||
def Version():
|
||||
"""Version() str"""
|
||||
return _gorrent.gorrent_Version()
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package gorrent
|
||||
|
||||
type Settings struct {
|
||||
DownloadPath string
|
||||
HttpBindHost string
|
||||
HttpBindPort int
|
||||
ListenPort int
|
||||
MaxConnections int
|
||||
TorrentPath string
|
||||
Proxy string
|
||||
KeepFiles bool
|
||||
Debug bool
|
||||
}
|
||||
|
||||
func NewSettings() *Settings {
|
||||
return &Settings{}
|
||||
}
|
Loading…
Reference in New Issue