diff -Nru python-utmp-0.7.4/debian/changelog python-utmp-0.8/debian/changelog --- python-utmp-0.7.4/debian/changelog 2009-03-10 03:11:04.000000000 -0400 +++ python-utmp-0.8/debian/changelog 2009-12-16 22:38:18.000000000 -0500 @@ -1,3 +1,21 @@ +python-utmp (0.8-0.1ubuntu1) lucid; urgency=low + + * Merge from debian testing (LP: #496397), remaining changes: + - bumped dh_pysupport to depend on > 0.5.3 + - debian/pyversions now >= 2.5 + - debian/rules removed unnecessary dh_python + - rm debian/pycompat + + -- Scott Howard Wed, 16 Dec 2009 22:38:08 -0500 + +python-utmp (0.8) unstable; urgency=low + + * support for python3 + * __repr__ for UtmpRecord and UtmpEntry + * incorporate Makefile changes by Pierre Habouzit + + -- Radovan Garabík Thu, 06 Aug 2009 17:49:55 +0200 + python-utmp (0.7.4-0.1ubuntu2) jaunty; urgency=low * No-change rebuild for Python 2.6. diff -Nru python-utmp-0.7.4/debian/compat python-utmp-0.8/debian/compat --- python-utmp-0.7.4/debian/compat 1969-12-31 19:00:00.000000000 -0500 +++ python-utmp-0.8/debian/compat 2009-08-09 15:07:00.000000000 -0400 @@ -0,0 +1 @@ +5 diff -Nru python-utmp-0.7.4/debian/control python-utmp-0.8/debian/control --- python-utmp-0.7.4/debian/control 2007-03-19 10:50:24.000000000 -0400 +++ python-utmp-0.8/debian/control 2009-12-16 22:49:23.000000000 -0500 @@ -1,10 +1,10 @@ Source: python-utmp -Section: interpreters +Section: python Priority: optional Maintainer: Ubuntu MOTU Developers XSBC-Original-Maintainer: Radovan Garabík -Standards-Version: 3.7.2 -Build-Depends: debhelper (>= 5.0.37.2), python-all-dev (>= 2.3.5-11), python-support (>= 0.3) +Standards-Version: 3.8.2 +Build-Depends: debhelper (>= 5.0.37.2), python-all-dev (>= 2.3.5-11), python-support (>= 0.5.3) Package: python-utmp Architecture: any diff -Nru python-utmp-0.7.4/debian/pycompat python-utmp-0.8/debian/pycompat --- python-utmp-0.7.4/debian/pycompat 2006-07-01 14:27:52.000000000 -0400 +++ python-utmp-0.8/debian/pycompat 1969-12-31 19:00:00.000000000 -0500 @@ -1 +0,0 @@ -2 diff -Nru python-utmp-0.7.4/debian/pyversions python-utmp-0.8/debian/pyversions --- python-utmp-0.7.4/debian/pyversions 1969-12-31 19:00:00.000000000 -0500 +++ python-utmp-0.8/debian/pyversions 2009-12-16 22:53:08.000000000 -0500 @@ -0,0 +1 @@ +2.5- diff -Nru python-utmp-0.7.4/debian/README.Debian python-utmp-0.8/debian/README.Debian --- python-utmp-0.7.4/debian/README.Debian 2003-01-22 07:38:25.000000000 -0500 +++ python-utmp-0.8/debian/README.Debian 2009-11-05 22:53:04.000000000 -0500 @@ -3,4 +3,4 @@ packaged as native package - -- Radovan Garabík , Wed, 22 Mar 2000 15:22:23 +0100 + -- Radovan Garabík , Wed, 22 Mar 2000 15:22:23 +0100 diff -Nru python-utmp-0.7.4/debian/rules python-utmp-0.8/debian/rules --- python-utmp-0.7.4/debian/rules 2009-03-10 03:03:33.000000000 -0400 +++ python-utmp-0.8/debian/rules 2009-11-05 22:53:04.000000000 -0500 @@ -6,7 +6,7 @@ #export DH_VERBOSE=1 # This is the debhelper compatability version to use. -export DH_COMPAT=5 +#export DH_COMPAT=5 PYVERS := $(subst python,,$(shell pyversions -r)) diff -Nru python-utmp-0.7.4/examples/dumputmp.py python-utmp-0.8/examples/dumputmp.py --- python-utmp-0.7.4/examples/dumputmp.py 1969-12-31 19:00:00.000000000 -0500 +++ python-utmp-0.8/examples/dumputmp.py 2009-08-09 14:12:03.000000000 -0400 @@ -0,0 +1,12 @@ +#!/usr/bin/python +# dump utmp + +import utmp +from UTMPCONST import * + +a = utmp.UtmpRecord() + + +for b in a: + print(b) + diff -Nru python-utmp-0.7.4/examples/finger.py python-utmp-0.8/examples/finger.py --- python-utmp-0.7.4/examples/finger.py 2003-02-04 05:34:36.000000000 -0500 +++ python-utmp-0.8/examples/finger.py 2009-11-05 22:53:04.000000000 -0500 @@ -10,7 +10,7 @@ def getrealname(gec): # get real name from gecos fiels return string.split(gec,",",1)[0] - + def formatidle(t): if t<30: return "" @@ -36,7 +36,7 @@ break if b.ut_type == USER_PROCESS: username = b.ut_user - if user and b.ut_user<>user: + if user and b.ut_user!=user: continue try: pwnam = pwd.getpwnam(username) @@ -61,7 +61,7 @@ tty = b.ut_line try: s = os.stat("/dev/"+tty) - p = s[ST_MODE] & 060 + p = s[ST_MODE] & 0x30 # 060 octal - test executable bit if tnowpids[b.ut_pid]: - print "%-10s %-10s %5i %-25s %-20s" % (b.ut_user, b.ut_line, b.ut_pid, b.ut_host, time.ctime(b.ut_tv[0])) + if (b.ut_pid not in pids) or b.ut_user!=pids[b.ut_pid]: + print ("%-10s %-10s %5i %-25s %-20s" % (b.ut_user, b.ut_line, b.ut_pid, b.ut_host, time.ctime(b.ut_tv[0]))) b.ut_type = DEAD_PROCESS b.ut_host = '' b.ut_tv = (0, 0) diff -Nru python-utmp-0.7.4/INSTALL python-utmp-0.8/INSTALL --- python-utmp-0.7.4/INSTALL 2001-02-21 15:40:47.000000000 -0500 +++ python-utmp-0.8/INSTALL 2009-11-05 22:53:04.000000000 -0500 @@ -3,5 +3,7 @@ Select suitable Makefile.target, where target is one of dumb, bsd, glibc, hpux, sunos, check DEFINES for your system. -type make -f Makefile.target -type make install +type +$ make -f Makefile.target +# make install + diff -Nru python-utmp-0.7.4/Makefile python-utmp-0.8/Makefile --- python-utmp-0.7.4/Makefile 2001-02-19 10:36:35.000000000 -0500 +++ python-utmp-0.8/Makefile 2009-11-05 22:53:04.000000000 -0500 @@ -1,4 +1,3 @@ include Makefile.common - \ No newline at end of file diff -Nru python-utmp-0.7.4/Makefile.common python-utmp-0.8/Makefile.common --- python-utmp-0.7.4/Makefile.common 2006-07-01 14:29:22.000000000 -0400 +++ python-utmp-0.8/Makefile.common 2009-11-05 22:53:04.000000000 -0500 @@ -1,4 +1,4 @@ -PYTHONVER?=2.3 +PYTHONVER?=3.1 PYTHONDIR=$(DESTDIR)/usr/lib/python$(PYTHONVER)/site-packages/ PYTHONINCLUDE=/usr/include/python$(PYTHONVER)/ @@ -19,9 +19,9 @@ ./makeconst.sh $(CFLAGS) clean: - rm -f *~ *.o utmpmodule.so *.pyc UTMPCONST.py makeconst + rm -f *~ *.o utmpaccessmodule.so *.pyc UTMPCONST.py makeconst install: mkdir -p $(PYTHONDIR) cp -f utmpaccessmodule.so utmp.py UTMPCONST.py $(PYTHONDIR) - + diff -Nru python-utmp-0.7.4/README python-utmp-0.8/README --- python-utmp-0.7.4/README 2003-02-04 07:18:00.000000000 -0500 +++ python-utmp-0.8/README 2009-11-05 22:53:04.000000000 -0500 @@ -1,5 +1,5 @@ -http://melkor.dnp.fmph.uniba.sk/~garabik/python-utmp -garabik@melkor.dnp.fmph.uniba.sk +http://kassiopeia.juls.savba.sk/~garabik/software/python-utmp +garabik @ kassiopeia.juls.savba.sk ==================================================== python-utmp consists of three modules, providing access to utmp records. @@ -14,7 +14,23 @@ linux with glibc2.0, glibc2.1, glibc2.2, glibc2.3; SunOS 5.6; HP-UX B.10.20; NetBSD 1.4.2; OpenBSD 2.9 -There was a big API change in version 0.7 - old interface has +Python 3.X support +------------------ +Starting from version 0.8, there is now a partial python3 support. +In particular, ut_line, ut_id, ut_user, ut_host are strings, not bytes. +If any of these fields contain non-ASCII characters, utmpaccess module +will try to convert them into strings using the default system encoding +(usually utf-8). If the field happens to contain invalid utf-8 sequences, +this will raise an exception. +However, this should not happen under normal circumstances – strings in +utmp should be ASCII only, so this indicates a pathological situation, +probably a damage to the utmp file. +Correct solution would be for utmpaccess to return bytes, and let +utmp.py deal with it, by indicating that we want either bytes or strings. +Some of the examples work with python3, converting others will be trivial. + + +There was a big API change in version 0.7 – old interface has been kept for backward portability, but may be removed in the future. Usually, system provides functions for accessing utmp, but on *BSD @@ -189,3 +205,4 @@ You pass filename for utmpname() when creating instance of the class, e.g. a=Utmp.UtmpRecord("/var/log/wtmp") + diff -Nru python-utmp-0.7.4/utmpaccessmodule.c python-utmp-0.8/utmpaccessmodule.c --- python-utmp-0.7.4/utmpaccessmodule.c 2000-10-16 13:04:23.000000000 -0400 +++ python-utmp-0.8/utmpaccessmodule.c 2009-11-05 22:53:04.000000000 -0500 @@ -533,7 +533,7 @@ PyObject *args; { if (!PyArg_ParseTuple(args, "")) - return NULL; + return NULL; my_endutent(); Py_INCREF(Py_None); return Py_None; @@ -541,18 +541,38 @@ static PyMethodDef UtmpMethods[] = { - {"utmpname", utmp_utmpname, METH_VARARGS}, - {"setutent", utmp_setutent, METH_VARARGS}, - {"getutent", utmp_getutent, METH_VARARGS}, - {"endutent", utmp_endutent, METH_VARARGS}, - {"getutid", utmp_getutid, METH_VARARGS}, + {"utmpname", utmp_utmpname, METH_VARARGS}, + {"setutent", utmp_setutent, METH_VARARGS}, + {"getutent", utmp_getutent, METH_VARARGS}, + {"endutent", utmp_endutent, METH_VARARGS}, + {"getutid", utmp_getutid, METH_VARARGS}, {"getutline", utmp_getutline, METH_VARARGS}, {"pututline", utmp_pututline, METH_VARARGS}, {NULL, NULL} /* Sentinel */ }; +#if PY_MAJOR_VERSION >= 3 +static struct PyModuleDef utmpaccessmodule = { + PyModuleDef_HEAD_INIT, + "utmpaccess", /* name of module */ + NULL, /* module documentation, may be NULL */ + -1, /* size of per-interpreter state of the module, + or -1 if the module keeps state in global variables. */ + UtmpMethods +}; + +PyMODINIT_FUNC +PyInit_utmpaccess(void) +{ + return PyModule_Create(&utmpaccessmodule); +} + +#else void initutmpaccess() { (void) Py_InitModule("utmpaccess", UtmpMethods); } +#endif + + diff -Nru python-utmp-0.7.4/utmp.py python-utmp-0.8/utmp.py --- python-utmp-0.7.4/utmp.py 2003-01-22 07:32:35.000000000 -0500 +++ python-utmp-0.8/utmp.py 2009-11-05 22:53:04.000000000 -0500 @@ -8,12 +8,12 @@ self.clear() if len(arg)==1: arg = arg[0] - if (type(arg)==types.TupleType or type(arg)==types.ListType) and arg: + if (type(arg)==tuple or type(arg)==list) and arg: self.ut_type, self.ut_pid, self.ut_line, \ self.ut_id, self.ut_user, self.ut_host, \ self.ut_exit, self.ut_session, self.ut_tv, \ self.ut_addr_v6 = arg - elif type(arg)==types.DictType: + elif type(arg)==dict: for i in arg.keys(): self[i] = arg[i] elif type(arg)==types.InstanceType: @@ -26,7 +26,7 @@ arg.ut_addr_v6 for i in dictarg.keys(): self[i] = dictarg[i] - + def clear(self): self.ut_type = EMPTY self.ut_pid = 0 @@ -38,7 +38,7 @@ self.ut_session = 0 self.ut_tv = (0, 0) self.ut_addr_v6 = (0, 0, 0, 0) - + def _as_tuple(self): return (self.ut_type, self.ut_pid, self.ut_line, \ self.ut_id, self.ut_user, self.ut_host, \ @@ -67,8 +67,8 @@ elif item=='ut_addr_v6' or item==9: return self.ut_addr_v6 else: - raise IndexError, "Bad key used to access UtmpEntry: "+repr(item) - + raise IndexError("Bad key used to access UtmpEntry: "+repr(item)) + def __setitem__(self, item, val): if item=='ut_type' or item==0: self.ut_type=val @@ -91,26 +91,37 @@ elif item=='ut_addr_v6' or item==9: self.ut_addr_v6=val else: - raise IndexError, "Bad key used to access UtmpEntry: "+repr(item) - - + raise IndexError("Bad key used to access UtmpEntry: "+repr(item)) + + def __repr__(self): + fs = [] + for key in 'ut_type', 'ut_pid', 'ut_line', \ + 'ut_id', 'ut_user', 'ut_host', \ + 'ut_exit', 'ut_session', 'ut_tv', \ + 'ut_addr_v6': + fs.append( key+'='+repr(self[key]) ) + fs = ', '.join(fs) + r = fs + r = 'utmp.UtmpEntry( %s )' % fs + return r class UtmpRecord: def __init__(self, fname=None): if fname: utmpaccess.utmpname(fname) + self.fname = fname self.setutent() - + def _makeclass(self, a): if not a: return None return UtmpEntry(a) - + def setutent(self): "rewinds the file pointer to the beginning of the utmp file." utmpaccess.setutent() - + def endutent(self): "closes the utmp file." utmpaccess.endutent() @@ -123,12 +134,14 @@ def __iter__(self): return self - def next(self): + def __next__(self): r = self.getutent() - if not r: - raise StopIteration + if not r: + raise StopIteration return r - + + next = __next__ + def pututline(self, *ut, **dictut): """writes the UtmpEntry provided as parameter into the utmp file. It uses getutid() to search for the proper place in the file to insert the new entry. If it cannot find an @@ -138,8 +151,8 @@ else: u = ut u = UtmpEntry(u, **dictut) - apply(utmpaccess.pututline, u._as_tuple()) - + utmpaccess.pututline(*u._as_tuple()) + def getutid(self, ut_type, ut_id=''): """searches forward from the current file position in the utmp file based upon ut_type. If ut_type is RUN_LVL, BOOT_TIME, @@ -161,8 +174,11 @@ pututline_dict = pututline getutid_dict = getutid getutline_dict = getutline - + def __del__(self): self.endutent() - - + + def __repr__(self): + if not self.fname: + fname = '' + return 'utmp.UtmpRecord(%s)' % fname