class='something' as kwarg

2007-11-17 Thread Vladimir Rusinov
Hello!

I'm using beautiful soup html parser, and I need to get all '...' tags.
It can be done by:

import BeautifulSoup as BSoup

...

soup = BSoup(page)
for div in soup.findAll('div', class='g'):


But how can I use `class` as kwarg name?

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

python safe scripting

2007-11-21 Thread Vladimir Rusinov
Hello!

In one my project (it's logfile manager) I want to implement 'smart'
configuration files, e.g.

logfile("/var/log/messages")
if (size() > 10*1024*1024) and (lavg() < 5):
   execute("my_log_alerter")
   rotate(save=10, compress='bzip2')

how can I safely do this?

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: python safe scripting

2007-11-22 Thread Vladimir Rusinov
On 11/21/07, Guilherme Polo <[EMAIL PROTECTED]> wrote:
>
> 2007/11/21, Vladimir Rusinov <[EMAIL PROTECTED]>:
> > Hello!
> >
> > In one my project (it's logfile manager) I want to implement 'smart'
> > configuration files, e.g.
> >
> > logfile("/var/log/messages")
> > if (size() > 10*1024*1024) and (lavg() < 5):
> > execute("my_log_alerter")
> >rotate(save=10, compress='bzip2')
> >
> > how can I safely do this?
> >
> logging already provides the rotating
>

Yes, but apache, nginx and others does not uses logger.
I wanna write an application which would handle all my (Linux) logs:
rotating, compressing, analysing and so on (logrotate replacement), it would
require some nontrivial configuration, something like "If size of this log
bigger then 2Mb or today is sunday. If size of this log bigger then 30 Mb,
and today is not sunday, then rotate it, and make alert".
Is there any module to parse such configuration files?

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rss Feed Creator

2007-11-27 Thread Vladimir Rusinov
On 11/27/07, James Matthews <[EMAIL PROTECTED]> wrote:
>
> I am looking for a library that will create Rss/Atom feeds in python. It
> needs to format the XML in a readable format! Does anyone have any
> suggestions?


You can also use some xml-based template engine (Kid or Genshi).

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: a strange SyntaxError

2007-12-10 Thread Vladimir Rusinov
>   self.numlines = self.config['numlines']
>
>   self.w = 520
>   self.h = 12*self.numfeeds*(self.numlines+1)

why extra ident here?

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: sqlite weirdness

2007-12-12 Thread Vladimir Rusinov
On 12/12/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> "SELECT SUM(reg), SUM(ot), SUM(ce), SUM(hol), SUM(sklv), SUM(vac),
> SUM(ct), SUM(conv), SUM(misc) FROM tbl_TimeEntries WHERE dateworked >=
> '12/31/2006' AND dateworked <= '01/13/2007' AND empid = 281"




The first and third return the correct sums. The middle one returns a
> list of null values.


Run sqlite  and check, if there is any NULLs in rows
WHERE dateworked >=
'12/31/2006' AND dateworked <= '01/13/2007' AND empid = 281"

AFAIR if any row in sum have null value, the sum would be null.

If I select everything in the database for that user, I get this:
>
> [(u'12/18/2006', 281, 8.0, u'', u'', u'', u'', u'', u'', u'', u'',
> u''), (u'12/19/2006', 281, 8.0, u'', u'', u'', u'', u'', u'', u'',
> u'', u''), (u'12/20/2006', 281, 8.0, u'', u'', u'', u'', u'', u'',
> u'', u'', u''), (u'12/21/2006', 281, 8.0, u'', u'', u'', u'', u'',
> u'', u'', u'', u''), (u'12/22/2006', 281, 8.0, u'', u'', u'', u'',
> u'', u'', u'', u'', u''), (u'12/25/2006', 281, 8.0, u'', u'', u'',
> u'', u'', u'', u'', u'', u''), (u'12/26/2006', 281, 8.0, u'', u'',
> u'', u'', u'', u'', u'', u'', u''), (u'12/27/2006', 281, 8.0, u'',
> u'', u'', u'', u'', u'', u'', u'', u''), (u'12/28/2006', 281, 8.0,
> u'', u'', u'', u'', u'', u'', u'', u'', u''), (u'12/29/2006', 281,
> 8.0, u'', u'', u'', u'', u'', u'', u'', u'', u''), (u'01/01/2007',
> 281, 8.0, u'', u'', u'', u'', u'', u'', u'', u'', u''),
> (u'01/02/2007', 281, 8.0, u'', u'', u'', u'', u'', u'', u'', u'',
> u''), (u'01/03/2007', 281, 8.0, u'', u'', u'', u'', u'', u'', u'',
> u'', u''), (u'01/04/2007', 281, 8.0, u'', u'', u'', u'', u'', u'',
> u'', u'', u''), (u'01/05/2007', 281, 8.0, u'', u'', u'', u'', u'',
> u'', u'', u'', u''), (u'01/08/2007', 281, 8.0, u'', u'', u'', u'',
> u'', u'', u'', u'', u''), (u'01/09/2007', 281, 8.0, u'', u'', u'',
> u'', u'', u'', u'', u'', u''), (u'01/10/2007', 281, 8.0, u'', u'',
> u'', u'', u'', u'', u'', u'', u''), (u'01/11/2007', 281, 8.0, u'',
> u'', u'', u'', u'', u'', u'', u'', u''), (u'01/12/2007', 281, 8.0,
> u'', u'', u'', u'', u'', u'', u'', u'', u''), (u'01/15/2007', 281,
> 8.0, u'', u'', u'', u'', u'', u'', u'', u'', u''), (u'01/16/2007',
> 281, 8.0, u'', u'', u'', u'', u'', u'', u'', u'', u''),
> (u'01/17/2007', 281, 8.0, u'', u'', u'', u'', u'', u'', u'', u'',
> u''), (u'01/18/2007', 281, 8.0, u'', u'', u'', u'', u'', u'', u'',
> u'', u''), (u'01/19/2007', 281, 8.0, u'', u'', u'', u'', u'', u'',
> u'', u'', u''), (u'01/22/2007', 281, 8.0, u'', u'', u'', u'', u'',
> u'', u'', u'', u''), (u'01/23/2007', 281, 8.0, u'', u'', u'', u'',
> u'', u'', u'', u'', u''), (u'01/24/2007', 281, 8.0, u'', u'', u'',
> u'', u'', u'', u'', u'', u''), (u'01/25/2007', 281, 8.0, u'', u'',
> u'', u'', u'', u'', u'', u'', u''), (u'01/26/2007', 281, 8.0, u'',
> u'', u'', u'', u'', u'', u'', u'', u'')]
> [(80.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)]
>

Sorry, but this is unreadable.
Try to execute your queries via sqlite shell.

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Monitoring the output of an external program

2007-12-13 Thread Vladimir Rusinov
On 12/13/07, Caleb Marcus <[EMAIL PROTECTED]> wrote:
>
>  I'm writing something that has to invoke an external program, and every
> time the external program prints something, update a UI. How would I go
> about doing this?
>

Use sys.popen or pexpect module.
With pexpect you can even use single thread.

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

listdir() with mask

2007-12-14 Thread Vladimir Rusinov
Hello!

Is there any easy way to list files using bash-like patterns? Something like
listfiles("/var/log/*.log"), listfiles("/var/{cache,run}/*").

Also, I'll need something like listfiles("/tmp/**/*.tmp"), where ** is
unlimited number of folders (like is zsh).

Thanks and sorry for my English.

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: listdir() with mask

2007-12-14 Thread Vladimir Rusinov
On 12/14/07, Jeff McNeil <[EMAIL PROTECTED]> wrote:
>
> Sure is.. check out the glob module:
> http://www.python.org/doc/current/lib/module-glob.html (Official)
> http://blog.doughellmann.com/2007/07/pymotw-glob.html (PyMOTW)
>

Thanks a lot!

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Deleting lines from a file

2007-12-17 Thread Vladimir Rusinov
On 12/17/07, Horacius ReX <[EMAIL PROTECTED]> wrote:
>
> and regardless of the speed, what do you think would be the best
> method to do this ?
>

use sqlite

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rounding

2007-12-18 Thread Vladimir Rusinov
On 12/15/07, katie smith <[EMAIL PROTECTED]> wrote:
>
> if i have a number 6.345 and i wanted it to be 6 without subtracting .345
> because it won't always be .345 what do i do?
>
> how do i round to the nearest whole number. Or in this case round down. Is
> there an easy way to round down to the nearest whole number?


init() ?


-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Rounding

2007-12-18 Thread Vladimir Rusinov
On 12/18/07, Lars Johansen <[EMAIL PROTECTED]> wrote:
>
> that does not round up..
>

Yep, this is truncation. I'd read the question better.

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

distutils: troubles with install

2007-12-28 Thread Vladimir Rusinov
Hello!

I've written a small app, succesfully packaged it and trying to install.
I'm getting following error:
# python setup.py install -n
running install
running build
running build_py
running build_scripts
running install_lib
creating /usr/lib/python2.4/site-packages/logmanager
creating /usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/core/logfile.py ->
/usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/core/logfiles.py ->
/usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/core/config.py ->
/usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/core/fs.py ->
/usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/core/__init__.py ->
/usr/lib/python2.4/site-packages/logmanager/core
copying build/lib/logmanager/__init__.py ->
/usr/lib/python2.4/site-packages/logmanager
byte-compiling /usr/lib/python2.4/site-packages/logmanager/core/logfile.py
to logfile.pyc
byte-compiling /usr/lib/python2.4/site-packages/logmanager/core/logfiles.py
to logfiles.pyc
byte-compiling /usr/lib/python2.4/site-packages/logmanager/core/config.py to
config.pyc
byte-compiling /usr/lib/python2.4/site-packages/logmanager/core/fs.py to
fs.pyc
byte-compiling /usr/lib/python2.4/site-packages/logmanager/core/__init__.py
to __init__.pyc
byte-compiling /usr/lib/python2.4/site-packages/logmanager/__init__.py to
__init__.pyc
running install_scripts
copying build/scripts-2.4/logmanager.py -> /usr/bin
changing mode of /usr/bin/logmanager.py to 755
running install_data
error: can't copy 'f': doesn't exist or not a regular file

What the 'f'???

Here is my setup.py:
#!/usr/bin/env python
"""
bla-bla-bla
"""

from distutils.core import setup
setup(name='logmanager',
  version='0.1.0',
  description='Log Management tool',
  author='Vladimir Rusinov',
  author_email='[EMAIL PROTECTED]',
  url='http://greenmice.info/',
  packages=[
'logmanager',
'logmanager.core'
],
scripts=['logmanager.py'],
data_files=[
('/etc/', 'files/etc/logmanager.conf'),
('/etc/logmanager.d/', 'files/etc/logmanager.d/portage.py')
],

long_description="""
bla-bla-bla
""",
classifiers=[
'many'
]
 )

File structure:
$ ls -R
.:
AUTHORS  CHANGELOG  dist  files  LICENSE  logmanager  logmanager.e3p
logmanager.e3t  logmanager.py  make_distribution.sh  MANIFEST  MANIFEST.in
setup.py

./dist:
logmanager-0.1.0.tar.bz2

./files:
etc

./files/etc:
logmanager.conf  logmanager.d

./files/etc/logmanager.d:
portage.py

./logmanager:
core  __init__.py  __init__.pyc

./logmanager/core:
config.py  config.pyc  fs.py  fs.pyc  __init__.py  __init__.pyc  logfile.py
logfile.pyc  logfiles.py  logfiles.pyc

$ tar tf dist/logmanager-0.1.0.tar.bz2
logmanager-0.1.0/
logmanager-0.1.0/PKG-INFO
logmanager-0.1.0/logmanager/
logmanager-0.1.0/logmanager/core/
logmanager-0.1.0/logmanager/core/logfile.py
logmanager-0.1.0/logmanager/core/logfiles.py
logmanager-0.1.0/logmanager/core/config.py
logmanager-0.1.0/logmanager/core/fs.py
logmanager-0.1.0/logmanager/core/__init__.py
logmanager-0.1.0/logmanager/__init__.py
logmanager-0.1.0/files/
logmanager-0.1.0/files/etc/
logmanager-0.1.0/files/etc/logmanager.conf
logmanager-0.1.0/files/etc/logmanager.d/
logmanager-0.1.0/files/etc/logmanager.d/portage.py
logmanager-0.1.0/LICENSE
logmanager-0.1.0/setup.py
logmanager-0.1.0/AUTHORS
logmanager-0.1.0/CHANGELOG
logmanager-0.1.0/logmanager.py

Please, help.

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: problem with gethostbyaddr with intranet addresses on MAC

2008-01-25 Thread Vladimir Rusinov
On 1/25/08, shailesh <[EMAIL PROTECTED]> wrote:
>
> apples-computer:~ apple$ ping 192.168.4.123
> PING 192.168.4.123 (192.168.4.123): 56 data bytes
> 64 bytes from 192.168.4.123: icmp_seq=0 ttl=64 time=0.328 ms
> 64 bytes from 192.168.4.123: icmp_seq=1 ttl=64 time=0.236 ms
> 64 bytes from 192.168.4.123: icmp_seq=2 ttl=64 time= 0.255 ms
> ^C
> --- 192.168.4.123 ping statistics ---
> 3 packets transmitted, 3 packets received, 0% packet loss
> round-trip min/avg/max/stddev = 0.236/0.273/0.328/0.040 ms
> apples-computer:~ apple$ python2.4
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from socket import *
> >>> x = gethostbyname('google.com')
> >>> x
> '64.233.167.99'
> >>> gethostbyaddr(x)
> ('py-in-f99.google.com', [], ['64.233.167.99'])
> >>> e = '192.168.4.123'
> >>> gethostbyaddr(e)
> Traceback (most recent call last):
>   File "", line 1, in ?
> socket.herror: (1, 'Unknown host')
> >>>
>

I'm sure your dns server have no reverse records for ' 192.168.4.123'.
So, it can't resolve it (123.4.168.192.in-addr.arpa).

-- 
Vladimir Rusinov
GreenMice Solutions: IT-решения на базе Linux
http://greenmice.info/
-- 
http://mail.python.org/mailman/listinfo/python-list