Access to sysctl on FreeBSD?

2008-05-20 Thread Skye
How do I access the sysctl(3) call from Python on BSD?

Specifically I want to retrieve:

$ sysctl -d net.inet.ip.stats
net.inet.ip.stats: IP statistics (struct ipstat, netinet/ip_var.h)

So I'll need some way of getting to struct ipstat from Python as well

Thanks,
Skye

--
http://mail.python.org/mailman/listinfo/python-list


Re: Access to sysctl on FreeBSD?

2008-05-20 Thread Skye
Great, thanks for the help (I'm fairly new to Python, didn't know
about ctypes)

from ctypes import *
libc = CDLL("libc.so.7")
size = c_uint(0)
libc.sysctlbyname("net.inet.ip.stats", None, byref(size), None, 0)
buf = c_char_p(" " * size.value)
libc.sysctlbyname("net.inet.ip.stats", buf, byref(size), None, 0)

So now that I've got the data, can you point me towards docs
explaining how to layout struct ipstat?

Thanks,
Skye

--
http://mail.python.org/mailman/listinfo/python-list


Re: Access to sysctl on FreeBSD?

2008-05-20 Thread Skye
Nevermind, I seem to have found it on my own =]

http://python.org/doc/2.5/lib/module-struct.html

This module performs conversions between Python values and C structs
represented as Python strings. It uses format strings (explained
below) as compact descriptions of the lay-out of the C structs and the
intended conversion to/from Python values. This can be used in
handling binary data stored in files or from network connections,
among other sources.

I freakin' love Python!!

Skye

--
http://mail.python.org/mailman/listinfo/python-list


Newb question: underscore

2008-06-05 Thread Skye
What is this doing?

print >> fd, _(__doc__)


I'm guessing line-splitting __doc__ into a list, but what's that
leading underscore do?

Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newb question: underscore

2008-06-05 Thread Skye
Ohh, it's a function _() call.  Now it makes sense.

Of course Python would be consistent... I was expecting trickery!

It's actually from the Mailman source, def _(s) is a string function
for i18n

Thanks,
Skye

--
http://mail.python.org/mailman/listinfo/python-list


Question by someone coming from C...

2008-06-09 Thread Skye
Writing this app in Python, not sure what the "best practice" would
be.

I want a bitfield global logging level that allows me to turn specific
debugging modules on and off.  If I was doing this in C, I'd just use
some globals like:

unsigned int debug_level = 0;
#define DEBUG_GENERAL 0x0001
#define DEBUG_CONFIG 0x0002
#define DEBUG_OPTIONS 0x0004
etc etc

So I guess my questions are:

1. there doesn't seem to be a way to define global constants like in
other languages?
2. any  special voodoo to use bitfields in Python?

Thanks!
Skye

--
http://mail.python.org/mailman/listinfo/python-list


Re: Question by someone coming from C...

2008-06-09 Thread Skye
OK, sounds good.  So if not bitfields, what would be a good Python-y
way to do it?
Flip booleans in a "debug config" dictionary or something?

Skye

--
http://mail.python.org/mailman/listinfo/python-list


Re: Question by someone coming from C...

2008-06-09 Thread Skye
On Jun 9, 2:35 pm, Matimus <[EMAIL PROTECTED]> wrote:
> The only time to do that sort of thing (in python) is when interacting
> with something else that isn't written in Python though. In general,
> for logging, just use the standard logging 
> module:http://docs.python.org/lib/module-logging.html

Thanks!  It looks like subclassing the logging module would be a much
better idea :)

Skye

--
http://mail.python.org/mailman/listinfo/python-list


Re: Question by someone coming from C...

2008-06-09 Thread Skye
Very cool - I'm liking the pythonic way of doing things more and
more.
The logger namespace/singleton idea makes great sense!

I see how the module variables make globals irrelevant, thanks!

Skye

--
http://mail.python.org/mailman/listinfo/python-list


Finding email threads with mailbox.mbox

2010-09-23 Thread Skye
Hello,

I'm working on a script to read large numbers of mail list archives in
mbox format and dump them into a database.  I was happy to find
mailbox.mbox because I like writing Python =)

However I need to find email threads (replies, quoted test, Re:
subjects etc) and it doesn't look like anything in the standard Python
library will help me with that.

I suppose I could yank some code from Mailman's pipermail or something
for identifying discussion threads, but I was wondering if anyone had
any other suggestions before I reinvent the wheel.

Thanks,
Skye
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Am I doing this wrong? Why does this seem so clumsy (time, datetime vs. DateTime)

2009-09-19 Thread Skye sh...@#$
On Sep 19, 7:22 pm, Schif Schaf  wrote:
> The other day I needed to convert a date like "August 2009" into a
> "seconds-since-epoch" value (this would be for the first day of that
> month, at the first second of that day).

You could use Time::Piece:

[ss...@localhost ~]$ perl -lMTime::Piece -e'$t=Time::Piece->strptime
("August 2009","%b %Y"); print $t->epoch'
1249084800
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get quote enclosed field in a line

2008-04-17 Thread Skye [EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
> > is there a simple way in perl, python, or awk/shell/pipe, that gets
> > the user agent field in a apache log?

> Something like:
> # cut -d '"' -f 6 < httpd-access.log
> ?
> --
> mph

Doesn't it feel like autosplit mode never gets any run time?

perl -laF'"' -ne'print $F[5]' access_log

-- 
http://mail.python.org/mailman/listinfo/python-list