diff --git a/py/Makefile b/py/Makefile index f549867..4d31bca 100644 --- a/py/Makefile +++ b/py/Makefile @@ -18,7 +18,7 @@ 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 + - rm -f 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 diff --git a/py/gorrent/Makefile b/py/gorrent/Makefile index f549867..4d31bca 100644 --- a/py/gorrent/Makefile +++ b/py/gorrent/Makefile @@ -18,7 +18,7 @@ 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 + - rm -f 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 diff --git a/py/gorrent/build.py b/py/gorrent/build.py index 412394a..233133a 100644 --- a/py/gorrent/build.py +++ b/py/gorrent/build.py @@ -147,16 +147,6 @@ 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_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')]) @@ -207,9 +197,19 @@ mod.add_function('gorrent_FileStatus_Progress_Get', retval('int64_t'), [param('i 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')]) -add_checked_function(mod, 'gorrent_GetMetaFromFile', retval('int64_t'), [param('char*', 'path')]) +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')]) add_checked_function(mod, 'gorrent_NewSettings', retval('int64_t'), []) 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_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 9128369..5341a2a 100644 --- a/py/gorrent/gorrent.go +++ b/py/gorrent/gorrent.go @@ -1246,76 +1246,6 @@ func handleFromPtr_gorrent_TorrentStatus(p interface{}) CGoHandle { // ---- Structs --- -// --- wrapping struct: gorrent.Info --- -//export gorrent_Info_CTor -func gorrent_Info_CTor() CGoHandle { - return CGoHandle(handleFromPtr_gorrent_Info(&gorrent.Info{})) -} -//export gorrent_Info_Name_Get -func gorrent_Info_Name_Get(handle CGoHandle) *C.char { - op := ptrFromHandle_gorrent_Info(handle) - return C.CString(op.Name) -} - -//export gorrent_Info_Name_Set -func gorrent_Info_Name_Set(handle CGoHandle, val *C.char) { - op := ptrFromHandle_gorrent_Info(handle) - op.Name = C.GoString(val) -} - -//export gorrent_Info_Length_Get -func gorrent_Info_Length_Get(handle CGoHandle) C.longlong { - op := ptrFromHandle_gorrent_Info(handle) - return C.longlong(op.Length) -} - -//export gorrent_Info_Length_Set -func gorrent_Info_Length_Set(handle CGoHandle, val C.longlong) { - op := ptrFromHandle_gorrent_Info(handle) - op.Length = int64(val) -} - -//export gorrent_Info_Source_Get -func gorrent_Info_Source_Get(handle CGoHandle) *C.char { - op := ptrFromHandle_gorrent_Info(handle) - return C.CString(op.Source) -} - -//export gorrent_Info_Source_Set -func gorrent_Info_Source_Set(handle CGoHandle, val *C.char) { - op := ptrFromHandle_gorrent_Info(handle) - op.Source = C.GoString(val) -} - -//export gorrent_Info_Files_Get -func gorrent_Info_Files_Get(handle CGoHandle) CGoHandle { - op := ptrFromHandle_gorrent_Info(handle) - return handleFromPtr_Slice_Ptr_gorrent_FileInfo(&op.Files) -} - -//export gorrent_Info_Files_Set -func gorrent_Info_Files_Set(handle CGoHandle, val CGoHandle) { - op := ptrFromHandle_gorrent_Info(handle) - op.Files = deptrFromHandle_Slice_Ptr_gorrent_FileInfo(val) -} - - -//export gorrent_Info_LoadFile -func gorrent_Info_LoadFile(_handle CGoHandle, path *C.char) *C.char { - vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Info") - if __err != nil { - return C.CString("") - } - __err = gopyh.Embed(vifc, reflect.TypeOf(gorrent.Info{})).(*gorrent.Info).LoadFile(C.GoString(path)) - - if __err != nil { - estr := C.CString(__err.Error()) - C.PyErr_SetString(C.PyExc_RuntimeError, estr) - return estr - } - return C.CString("") -} - // --- wrapping struct: gorrent.Settings --- //export gorrent_Settings_CTor func gorrent_Settings_CTor() CGoHandle { @@ -1664,6 +1594,76 @@ func gorrent_FileStatus_Length_Set(handle CGoHandle, val C.longlong) { } +// --- wrapping struct: gorrent.Info --- +//export gorrent_Info_CTor +func gorrent_Info_CTor() CGoHandle { + return CGoHandle(handleFromPtr_gorrent_Info(&gorrent.Info{})) +} +//export gorrent_Info_Name_Get +func gorrent_Info_Name_Get(handle CGoHandle) *C.char { + op := ptrFromHandle_gorrent_Info(handle) + return C.CString(op.Name) +} + +//export gorrent_Info_Name_Set +func gorrent_Info_Name_Set(handle CGoHandle, val *C.char) { + op := ptrFromHandle_gorrent_Info(handle) + op.Name = C.GoString(val) +} + +//export gorrent_Info_Length_Get +func gorrent_Info_Length_Get(handle CGoHandle) C.longlong { + op := ptrFromHandle_gorrent_Info(handle) + return C.longlong(op.Length) +} + +//export gorrent_Info_Length_Set +func gorrent_Info_Length_Set(handle CGoHandle, val C.longlong) { + op := ptrFromHandle_gorrent_Info(handle) + op.Length = int64(val) +} + +//export gorrent_Info_Source_Get +func gorrent_Info_Source_Get(handle CGoHandle) *C.char { + op := ptrFromHandle_gorrent_Info(handle) + return C.CString(op.Source) +} + +//export gorrent_Info_Source_Set +func gorrent_Info_Source_Set(handle CGoHandle, val *C.char) { + op := ptrFromHandle_gorrent_Info(handle) + op.Source = C.GoString(val) +} + +//export gorrent_Info_Files_Get +func gorrent_Info_Files_Get(handle CGoHandle) CGoHandle { + op := ptrFromHandle_gorrent_Info(handle) + return handleFromPtr_Slice_Ptr_gorrent_FileInfo(&op.Files) +} + +//export gorrent_Info_Files_Set +func gorrent_Info_Files_Set(handle CGoHandle, val CGoHandle) { + op := ptrFromHandle_gorrent_Info(handle) + op.Files = deptrFromHandle_Slice_Ptr_gorrent_FileInfo(val) +} + + +//export gorrent_Info_LoadFile +func gorrent_Info_LoadFile(_handle CGoHandle, path *C.char) *C.char { + vifc, __err := gopyh.VarFromHandleTry((gopyh.CGoHandle)(_handle), "*gorrent.Info") + if __err != nil { + return C.CString("") + } + __err = gopyh.Embed(vifc, reflect.TypeOf(gorrent.Info{})).(*gorrent.Info).LoadFile(C.GoString(path)) + + if __err != nil { + estr := C.CString(__err.Error()) + C.PyErr_SetString(C.PyExc_RuntimeError, estr) + return estr + } + return C.CString("") +} + // ---- Slices --- @@ -1673,6 +1673,18 @@ func gorrent_FileStatus_Length_Set(handle CGoHandle, val C.longlong) { // ---- Constructors --- +//export gorrent_NewSettings +func gorrent_NewSettings() CGoHandle { + return handleFromPtr_Ptr_gorrent_Settings(gorrent.NewSettings()) + +} + +//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)) @@ -1686,18 +1698,6 @@ func gorrent_GetMetaFromFile(path *C.char) CGoHandle { return handleFromPtr_Ptr_gorrent_Info(cret) } -//export gorrent_NewSettings -func gorrent_NewSettings() CGoHandle { - return handleFromPtr_Ptr_gorrent_Settings(gorrent.NewSettings()) - -} - -//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 90ae902..292a14f 100644 --- a/py/gorrent/gorrent.py +++ b/py/gorrent/gorrent.py @@ -127,102 +127,6 @@ class Slice_Ptr_gorrent_FileInfo(go.GoClass): # ---- Structs --- -# 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): """""" @@ -696,6 +600,102 @@ class FileStatus(go.GoClass): 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) + # ---- Slices --- @@ -704,15 +704,15 @@ class FileStatus(go.GoClass): # ---- 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)) +def GetMetaFromFile(path): + """GetMetaFromFile(str path) object, str""" + return Info(handle=_gorrent.gorrent_GetMetaFromFile(path)) # ---- Functions ---