pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/devel/py-sysctl



Module Name:    pkgsrc
Committed By:   maya
Date:           Mon Sep  9 07:09:47 UTC 2019

Modified Files:
        pkgsrc/devel/py-sysctl: Makefile PLIST distinfo
Added Files:
        pkgsrc/devel/py-sysctl/patches: patch-setup.py patch-sysctlmodule.c
            patch-test.py

Log Message:
py-sysctl: port to python 3.

One remaining test fails, but it seems it failed before.
PR pkg/54530


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 pkgsrc/devel/py-sysctl/Makefile
cvs rdiff -u -r1.1.1.1 -r1.2 pkgsrc/devel/py-sysctl/PLIST
cvs rdiff -u -r1.2 -r1.3 pkgsrc/devel/py-sysctl/distinfo
cvs rdiff -u -r0 -r1.1 pkgsrc/devel/py-sysctl/patches/patch-setup.py \
    pkgsrc/devel/py-sysctl/patches/patch-sysctlmodule.c \
    pkgsrc/devel/py-sysctl/patches/patch-test.py

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/devel/py-sysctl/Makefile
diff -u pkgsrc/devel/py-sysctl/Makefile:1.6 pkgsrc/devel/py-sysctl/Makefile:1.7
--- pkgsrc/devel/py-sysctl/Makefile:1.6 Sun Jan  4 05:43:31 2015
+++ pkgsrc/devel/py-sysctl/Makefile     Mon Sep  9 07:09:47 2019
@@ -1,8 +1,8 @@
-# $NetBSD: Makefile,v 1.6 2015/01/04 05:43:31 dholland Exp $
+# $NetBSD: Makefile,v 1.7 2019/09/09 07:09:47 maya Exp $
 
 DISTNAME=      py-sysctl-0.1
 PKGNAME=       ${PYPKGPREFIX}-sysctl-0.1
-PKGREVISION=   1
+PKGREVISION=   2
 CATEGORIES=    devel python
 MASTER_SITES=  ftp://ftp.NetBSD.org/pub/NetBSD/misc/cherry/
 

Index: pkgsrc/devel/py-sysctl/PLIST
diff -u pkgsrc/devel/py-sysctl/PLIST:1.1.1.1 pkgsrc/devel/py-sysctl/PLIST:1.2
--- pkgsrc/devel/py-sysctl/PLIST:1.1.1.1        Sun Apr 11 06:48:41 2010
+++ pkgsrc/devel/py-sysctl/PLIST        Mon Sep  9 07:09:47 2019
@@ -1,2 +1,2 @@
-@comment $NetBSD: PLIST,v 1.1.1.1 2010/04/11 06:48:41 cherry Exp $
-${PYSITELIB}/sysctlmodule.so
+@comment $NetBSD: PLIST,v 1.2 2019/09/09 07:09:47 maya Exp $
+${PYSITELIB}/sysctl.so

Index: pkgsrc/devel/py-sysctl/distinfo
diff -u pkgsrc/devel/py-sysctl/distinfo:1.2 pkgsrc/devel/py-sysctl/distinfo:1.3
--- pkgsrc/devel/py-sysctl/distinfo:1.2 Tue Nov  3 03:29:16 2015
+++ pkgsrc/devel/py-sysctl/distinfo     Mon Sep  9 07:09:47 2019
@@ -1,6 +1,9 @@
-$NetBSD: distinfo,v 1.2 2015/11/03 03:29:16 agc Exp $
+$NetBSD: distinfo,v 1.3 2019/09/09 07:09:47 maya Exp $
 
 SHA1 (py-sysctl-0.1.tar.gz) = 120483a57fc85790702223317b1e29ece62f5bb0
 RMD160 (py-sysctl-0.1.tar.gz) = 053144711e41f5518efc418795eec5e6e06750a1
 SHA512 (py-sysctl-0.1.tar.gz) = 4b6123625a212364ef5a2a367f13ec32194503b8881248e3909f5958adac05149ed2c22aa49b67468c3d1fc23386c16d97af747b8045b322c749f37d1a086005
 Size (py-sysctl-0.1.tar.gz) = 6746 bytes
+SHA1 (patch-setup.py) = eef1ae1e7a6d60f332514670ebcd1ee08dece131
+SHA1 (patch-sysctlmodule.c) = 55c7cec28080a936022e17f6e599f00b6825011c
+SHA1 (patch-test.py) = ff610e1eb2371147454861dd80e4d31878ec0ae7

Added files:

Index: pkgsrc/devel/py-sysctl/patches/patch-setup.py
diff -u /dev/null pkgsrc/devel/py-sysctl/patches/patch-setup.py:1.1
--- /dev/null   Mon Sep  9 07:09:47 2019
+++ pkgsrc/devel/py-sysctl/patches/patch-setup.py       Mon Sep  9 07:09:47 2019
@@ -0,0 +1,11 @@
+$NetBSD: patch-setup.py,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+--- setup.py.orig      2010-04-10 17:41:18.000000000 +0000
++++ setup.py
+@@ -2,5 +2,5 @@
+ from distutils.core import setup, Extension
+ 
+-module1 = Extension('sysctlmodule',
++module1 = Extension('sysctl',
+                     sources = ['sysctlmodule.c'])
+ 
Index: pkgsrc/devel/py-sysctl/patches/patch-sysctlmodule.c
diff -u /dev/null pkgsrc/devel/py-sysctl/patches/patch-sysctlmodule.c:1.1
--- /dev/null   Mon Sep  9 07:09:47 2019
+++ pkgsrc/devel/py-sysctl/patches/patch-sysctlmodule.c Mon Sep  9 07:09:47 2019
@@ -0,0 +1,202 @@
+$NetBSD: patch-sysctlmodule.c,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+Port to python 3
+
+--- sysctlmodule.c.orig        2010-04-10 17:41:18.000000000 +0000
++++ sysctlmodule.c
+@@ -33,6 +33,21 @@
+ #include <errno.h>
+ #include <sys/sysctl.h>
+ 
++struct module_state {
++    PyObject *error;
++};
++
++#if PY_MAJOR_VERSION >= 3
++#define PyInt_AsLong                  PyLong_AsLong
++#define PyInt_CheckExact              PyLong_CheckExact
++#define PyString_CheckExact(val)      PyUnicode_CheckExact(val)
++#define PyString_FromStringAndSize    PyUnicode_FromStringAndSize
++#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
++#else
++#define GETSTATE(m) (&_state)
++static struct module_state _state;
++#endif
++
+ /* 
+  * create Python object of type similar to the MIB node 'name'
+  * This is basically the laziest way to do this, as we outsource the
+@@ -104,14 +119,12 @@ nodetype(char *nodepath)
+ 
+       int rv;
+       char cname[SYSCTL_NAMELEN];
+-      int csz;
++      size_t csz = SYSCTL_NAMELEN;
+ 
+       struct sysctlnode *rnode = NULL;
+ 
+       assert (nodepath != NULL);
+ 
+-      csz = SYSCTL_NAMELEN;
+-
+       rv = sysctlgetmibinfo(nodepath, NULL, NULL, cname, &csz, &rnode, SYSCTL_VERSION);
+ 
+       if (rv == -1 || rnode == NULL) {
+@@ -149,7 +162,7 @@ write_sysctl_string(char *name, char *va
+       size_t nodelen;
+ 
+       char cname[SYSCTL_NAMELEN];
+-      int csz = SYSCTL_NAMELEN;
++      size_t csz = SYSCTL_NAMELEN;
+ 
+       /* Sanity checks */
+ 
+@@ -237,7 +250,7 @@ read_sysctl(PyObject *self, PyObject *ar
+ {
+       PyObject *o;
+       void *val;
+-      size_t len;
++      size_t len = 0;
+       const char *name;
+       int rv;
+ 
+@@ -245,9 +258,7 @@ read_sysctl(PyObject *self, PyObject *ar
+               return NULL;
+ 
+ getbyname:
+-      val = NULL;
+-      len = 0;
+-
++      len += 4;
+       rv = sysctlbyname(name, NULL, &len, NULL, 0);
+ 
+       if (rv == -1) {
+@@ -256,7 +267,7 @@ getbyname:
+       }
+ 
+       val = malloc(len);
+-      if (val ==NULL) {
++      if (val == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+@@ -309,7 +320,7 @@ write_sysctl(PyObject *self, PyObject *a
+ 
+       /* Arrange to obtain the oldvalue */
+       oldval = NULL;
+-      len = 0;
++      len = 4;
+ 
+       rv = sysctlbyname(name, NULL, &len, NULL, 0);
+ 
+@@ -445,7 +456,7 @@ create_node(const char *name, int ctl_ty
+ {
+ 
+       int mib[CTL_MAXNAME];
+-      u_int miblen = CTL_MAXNAME;
++      size_t miblen = CTL_MAXNAME;
+ 
+       char cname[SYSCTL_NAMELEN]; /* Canonical name */
+       char pname[SYSCTL_NAMELEN]; /* The Canonical prefix */
+@@ -456,6 +467,7 @@ create_node(const char *name, int ctl_ty
+       struct sysctlnode node;
+       size_t nodelen;
+ 
++
+       /* Check for NULL ptr dereference */
+       assert (value != NULL || vlen == 0);
+ 
+@@ -533,7 +545,7 @@ create_sysctl(PyObject *self, PyObject *
+       const char *typename = NULL;
+       size_t typelen = 0;
+ 
+-      int len, rv;
++      int rv;
+ 
+       /* XXX: Royal mess... needs more thought */
+       if (!PyArg_ParseTuple(args, "s|s#O: Incorrect values passed to sysctl.write", &name, &typename, &typelen, &value)) {
+@@ -546,7 +558,7 @@ create_sysctl(PyObject *self, PyObject *
+       }
+ 
+       /* XXX: Arrange to obtain the oldvalue */
+-      len = 0;
++      /*len = 4;*/
+ 
+       if ((typename == NULL && typelen == 0)
+           || (!strncmp(typename, "CTLTYPE_NODE", typelen)) ) {
+@@ -593,7 +605,12 @@ create_sysctl(PyObject *self, PyObject *
+                               PyErr_SetString(PyExc_TypeError, "Value passed is of wrong type");
+                               return NULL;
+                       }
++#if PY_MAJOR_VERSION >= 3
++                      strval = PyUnicode_AsUTF8AndSize(value, &vlen);
++                      if (strval == NULL) {
++#else
+                       if (-1 == PyString_AsStringAndSize(value, &strval, &vlen)) {
++#endif
+                               PyErr_SetString(PyExc_TypeError, "Error decoding string from buffer \n");
+                               return NULL;
+                       }
+@@ -694,8 +711,61 @@ static PyMethodDef sysctl_methods[] = {
+ };
+ 
+ 
++
++#if PY_MAJOR_VERSION >= 3
++
++static int sysctl_traverse(PyObject *m, visitproc visit, void *arg) {
++    Py_VISIT(GETSTATE(m)->error);
++    return 0;
++}
++
++static int sysctl_clear(PyObject *m) {
++    Py_CLEAR(GETSTATE(m)->error);
++    return 0;
++}
++
++
++static struct PyModuleDef moduledef = {
++        PyModuleDef_HEAD_INIT,
++        "sysctl",
++        NULL,
++        sizeof(struct module_state),
++        sysctl_methods,
++        NULL,
++        sysctl_traverse,
++        sysctl_clear,
++        NULL
++};
++
++#define INITERROR return NULL
++
+ PyMODINIT_FUNC
++PyInit_sysctl(void)
++
++#else
++#define INITERROR return
++
++void
+ initsysctl(void)
++#endif
+ {
+-      (void) Py_InitModule("sysctl", sysctl_methods);
++#if PY_MAJOR_VERSION >= 3
++    PyObject *module = PyModule_Create(&moduledef);
++#else
++    PyObject *module = Py_InitModule("sysctl", sysctl_methods);
++#endif
++
++    if (module == NULL)
++        INITERROR;
++    struct module_state *st = GETSTATE(module);
++
++    st->error = PyErr_NewException("sysctl.Error", NULL, NULL);
++    if (st->error == NULL) {
++        Py_DECREF(module);
++        INITERROR;
++    }
++
++#if PY_MAJOR_VERSION >= 3
++    return module;
++#endif
+ }
Index: pkgsrc/devel/py-sysctl/patches/patch-test.py
diff -u /dev/null pkgsrc/devel/py-sysctl/patches/patch-test.py:1.1
--- /dev/null   Mon Sep  9 07:09:47 2019
+++ pkgsrc/devel/py-sysctl/patches/patch-test.py        Mon Sep  9 07:09:47 2019
@@ -0,0 +1,304 @@
+$NetBSD: patch-test.py,v 1.1 2019/09/09 07:09:47 maya Exp $
+
+Port to python 3.
+
+--- test.py.orig       2010-04-10 17:41:18.000000000 +0000
++++ test.py
+@@ -9,111 +9,111 @@ import sysctl
+ 
+ # Invalid node
+ try:
+-    print "Testing invalid node: sysctl.read(\"unknown\")"
++    print("Testing invalid node: sysctl.read(\"unknown\")")
+     sysctl.read("unknown")
+ except OSError as detail:
+-    print detail
+-    print "PASSED"
++    print(detail)
++    print("PASSED")
+ else:
+-    print "FAILED"
++    print("FAILED")
+ 
+ # Node with Struct/Table val.
+ tmp = 666 #Variable Declaration
+ try:
+-    print "Testing (integer) node sysctl.read(\"kern.maxproc\")"
++    print("Testing (integer) node sysctl.read(\"kern.maxproc\")")
+     tmp = sysctl.read("kern.maxproc")
+ except ValueError as detail:
+-    print detail
+-    print "FAILED"
++    print(detail)
++    print("FAILED")
+ else:
+-    print "kern.maxproc == %i" % tmp
+-    print "PASSED"
++    print("kern.maxproc == %i" % tmp)
++    print("PASSED")
+ 
+ # Node with String.
+ try:
+-    print "Testing (string) node sysctl.read(\"kern.ostype\")"
++    print("Testing (string) node sysctl.read(\"kern.ostype\")")
+     tmp = sysctl.read("kern.ostype")
+ except ValueError as detail:
+-    print detail
+-    print "FAILED"
++    print(detail)
++    print("FAILED")
+ else:
+-    print "kern.ostype = %s" % tmp
+-    print "PASSED"
++    print("kern.ostype = %s" % tmp)
++    print("PASSED")
+ 
+ # Node with long integer.
+ try:
+-    print "Testing read (long integer) node sysctl.read(\"kern.osrevision\")"
++    print("Testing read (long integer) node sysctl.read(\"kern.osrevision\")")
+     tmp = sysctl.read("kern.osrevision")
+ except ValueError as detail:
+-    print detail
+-    print "FAILED"
++    print(detail)
++    print("FAILED")
+ else:
+-    print "kern.osrevision = %li" % tmp
+-    print "PASSED"
++    print("kern.osrevision = %li" % tmp)
++    print("PASSED")
+ 
+ 
+ # Write a read-only node.
+ osrev = 0
+ try:
+-    print "Testing write to read only node sysctl.write(\"kern.osrevision\", 2)"
++    print("Testing write to read only node sysctl.write(\"kern.osrevision\", 2)")
+     osrev = sysctl.write("kern.osrevision", 2)
+ except OSError as detail:
+-    print detail
+-    print "sysctl.write() failed."
+-    print "PASSED"
++    print(detail)
++    print("sysctl.write() failed.")
++    print("PASSED")
+ else:
+     if osrev == sysctl.read("kern.osrevision"):
+-        print "FAILED: write succeed to read-only node! (review test? )"
++        print("FAILED: write succeed to read-only node! (review test? )")
+     else:
+-        print "FAILED"
++        print("FAILED")
+ 
+ # Write an integer to a writeable node.
+ # Create a writeable node of type integer.
+ try:
+     node="mynode"
+-    print "Testing write (integer) to node %s ..." % node
++    print("Testing write (integer) to node %s ..." % node)
+     subprocess.call(["sysctl", "-w", "//create=%s,type=int" % node])
+     oldval = sysctl.read(node)
+     oldval1 = sysctl.write(node, oldval + 1)
+ except ValueError as detail:
+-    print detail
++    print(detail)
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-    print "FAILED"
++    print("FAILED")
+ else:
+     if oldval != oldval1:
+-        print "FAILED: sysctl.write() returns incorrect old value"
++        print("FAILED: sysctl.write() returns incorrect old value")
+     else:
+         if (oldval1 + 1) != sysctl.read(node):
+-            print "FAILED: update failed."
++            print("FAILED: update failed.")
+         else:
+             sysctl.write(node, oldval1);
+             subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-            print "PASSED"
++            print("PASSED")
+ 
+ # Write a string to a writeable node.
+ # Create a writeable node of type string.
+ try:
+     node="mynode"
+-    print "Testing write (string) to node %s ..." % node
++    print("Testing write (string) to node %s ..." % node)
+     subprocess.call(["sysctl", "-w", "//create=%s,type=string,value=\"nothing\"" % node])
+     oldstring = sysctl.read(node)
+-    print "oldstring == %s" % oldstring
++    print("oldstring == %s" % oldstring)
+     oldstring1 = sysctl.write(node, "FOOBAR")
+-    print "write read oldstring1 == %s" % oldstring1
++    print("write read oldstring1 == %s" % oldstring1)
+ except ValueError as detail:
+-    print detail
++    print(detail)
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-    print "FAILED"
++    print("FAILED")
+ else:
+     if oldstring != oldstring1:
+-        print "FAILED: sysctl.write() returns incorrect old string value"
++        print("FAILED: sysctl.write() returns incorrect old string value")
+     else:
+         if "FOOBAR" != sysctl.read(node):
+-            print "FAILED: update failed."
++            print("FAILED: update failed.")
+         else:
+             sysctl.write(node, oldstring1);
+             subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-            print "PASSED"
++            print("PASSED")
+ 
+ # Write a string to a writeable 2-level node.
+ # Create a writeable node of type string.
+@@ -121,35 +121,35 @@ try:
+     node="mynode"
+     leaf="myleaf"
+     branch = node + '.' + leaf
+-    print "Testing write (string) to node %s ..." % branch
++    print("Testing write (string) to node %s ..." % branch)
+     subprocess.call(["sysctl", "-w", "//create=%s,type=node,value=\"nothing\"" % node])
+     subprocess.call(["sysctl", "-w", "//create=%s,type=string,value=\"nothing\"" % branch])
+     oldstring = sysctl.read(branch)
+-    print "oldstring == %s" % oldstring
++    print("oldstring == %s" % oldstring)
+     oldstring1 = sysctl.write(branch, "FOOBAR")
+-    print "write read oldstring1 == %s" % oldstring1
++    print("write read oldstring1 == %s" % oldstring1)
+ except ValueError as detail:
+-    print detail
++    print(detail)
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % branch])
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-    print "FAILED"
++    print("FAILED")
+ else:
+     if oldstring != oldstring1:
+-        print "FAILED: sysctl.write() returns incorrect old string value"
++        print("FAILED: sysctl.write() returns incorrect old string value")
+     else:
+         if "FOOBAR" != sysctl.read(branch):
+-            print "FAILED: update failed."
++            print("FAILED: update failed.")
+         else:
+             sysctl.write(branch, oldstring1);
+             subprocess.call(["sysctl", "-w", "//destroy=%s" % branch])
+             subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-            print "PASSED"
++            print("PASSED")
+ 
+ # Create a 3-level node using sysctl.create() and delete it using
+ # sysctl.destroy() 
+ 
+ try:
+-    print "Testing sysctl.create()"
++    print("Testing sysctl.create()")
+     node="mynode"
+     digit=node + "." + "mydigit"
+     leaf=digit + "." + "myleaf"
+@@ -159,7 +159,7 @@ try:
+     sysctl.create(leaf, "CTLTYPE_STRING")
+ # XXX: read/readwrite/permanent 
+ except OSError as detail:
+-    print "FAILED"
++    print("FAILED")
+ 
+ else:
+     try:
+@@ -172,10 +172,10 @@ else:
+         sysctl.destroy(node)
+ 
+     except OSError as detail:
+-        print "FAILED"
++        print("FAILED")
+ 
+     else:
+-        print "PASSED"
++        print("PASSED")
+ 
+ # Create a 3-level node and delete it using sysctl.delete()
+ 
+@@ -183,12 +183,12 @@ try:
+     node="mynode"
+     digit=node + "." + "mydigit"
+     leaf=digit + "." + "myleaf"
+-    print "Testing write (string) to node %s ..." % leaf
++    print("Testing write (string) to node %s ..." % leaf)
+     subprocess.call(["sysctl", "-w", "//create=%s,type=node,value=\"nothing\"" % node])
+     subprocess.call(["sysctl", "-w", "//create=%s,type=node,value=\"nothing\"" % digit])
+     subprocess.call(["sysctl", "-w", "//create=%s,type=string,value=\"nothing\"" % leaf])
+     oldstring = sysctl.read(leaf)
+-    print "oldstring == %s" % oldstring
++    print("oldstring == %s" % oldstring)
+ 
+     sysctl.destroy(leaf)
+ 
+@@ -197,51 +197,51 @@ try:
+         sysctl.destroy(node)
+     except OSError as detail:
+         # Should fail
+-        print "continue test with %s" % detail
++        print("continue test with %s" % detail)
+     else: 
+-        print "FAILED"
++        print("FAILED")
+ 
+     sysctl.destroy(digit)
+     sysctl.destroy(node)
+-    print "PASSED"
++    print("PASSED")
+ 
+ except ValueError as detail:
+-    print detail
++    print(detail)
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % leaf])
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % digit])
+     subprocess.call(["sysctl", "-w", "//destroy=%s" % node])
+-    print "FAILED"
++    print("FAILED")
+ 
+ def createdestroy(nodename, type, value):
+ 
+     if type == "CTLTYPE_STRING":
+-        print "Testing string: " + value
++        print("Testing string: " + value)
+     else:
+         if type == "CTLTYPE_INT":
+-            print "Testing integer: %d" % value
++            print("Testing integer: %d" % value)
+         else:
+-            print "Unknown type requested"
++            print("Unknown type requested")
+             return
+ 
+     try:
+         sysctl.create(nodename, type, value)
+     except OSError as detail:
+-        print "Failed to create node " + nodename + detail
++        print("Failed to create node " + nodename + detail)
+ 
+     newval = sysctl.read(nodename)
+ 
+     if newval != value:
+-        print "FAILED Value read mismatch", newval
++        print("FAILED Value read mismatch", newval)
+     else:
+-        print "PASSED"
++        print("PASSED")
+ 
+     try:
+         sysctl.destroy(nodename)
+     except OSError as detail:
+-        print "Failed to destroy node " + nodename + detail
++        print("Failed to destroy node " + nodename + detail)
+ 
+ 
+ # Try creating and verifying different types of nodes.
+-print "Testing writing to different types of nodes"
++print("Testing writing to different types of nodes")
+ createdestroy("tnode", "CTLTYPE_STRING", "TESTSTRING")
+ createdestroy("tnode", "CTLTYPE_INT", 65535)



Home | Main Index | Thread Index | Old Index