[Tutor] os.popen3 > subprocess.Popen but nohup.out won't go

2009-04-04 Thread dave selby
Hi,

I have upgraded to python 2.6 and was getting depreciation warnings
about os.popen3 etc so I changed over to subprocess.

os.popen3('nohup %s/core/kmotion_hkd2.py &> /dev/null &' % kmotion_dir)

becomes ..

subprocess.Popen('nohup %s/core/kmotion_hkd2.py &> /dev/null &' %
kmotion_dir, shell=True)

all is well except I now get

nohup: appending output to `nohup.out'

on the terminal which '&> /dev/null' used to ditch to /dev/null. I
think this is because subprocess simulates the
shell differently. Any idea how to ditch to /dev/null in subprocess ?

Cheers

Dave







-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pythons xf86misc documentation ?

2007-09-23 Thread dave selby
Can anyone tell me where the documentation for pythons xf86misc module
is, ie what methods are avalible ?

Many thanks

Dave





-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Q1: Any way for script to intercept a HUP signal ?

2007-11-16 Thread dave selby
Is there a way for a Python script to intercept a HUP signal sent to it ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Q2: logging not working as expected

2007-11-16 Thread dave selby
I am trying to use the python logging module. At first glance it looks
pretty complicated but having Ggooled a lot I have come up with a
trial script of  ...

logging.config.fileConfig("logging.conf")
logger = logging.getLogger()
logger.critical("Test Message")

Where 'loggin.conf' contains ...

[loggers]
keys=root,hdk1,hkd2

[handlers]
keys=SysLog,hand02

[formatters]
keys=SysLog

[logger_root]
level=NOTSET
handlers=SysLog

[logger_hkd1]
level=DEBUG
propagate=1
qualname=hkd1
handlers=SysLog
channel=hkd1
parent=(root)

[logger_hkd2]
level=DEBUG
propagate=1
qualname=hkd2
handlers=hand02
channel=hkd2
parent=(root)

[handler_hand02]
class=FileHandler
level=DEBUG
formatter=SysLog
args=('python.log', 'w')

[handler_SysLog]
class=handlers.SysLogHandler
level=DEBUG
formatter=SysLog
args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)

[formatter_SysLog]
format=%(filename)s[%(process)d]: %(levelname)s: %(message)s

I was trying to get logging to report to Syslog, that failed so I
changed it to write to a file 'python.log' .  When I execute my test
script 'python.log' appears but contains no messages and no error
messages are generated.

Anybody any ideas as to what I am doing wrong ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] More logging probs ...

2007-11-17 Thread dave selby
Im having a bad day. The logging module refused to send anything to
syslog no matter what I did, so discovering the syslog module &
thought, for what I need I will write a simple class to do the job.

 class kmotion_logger:

def __init__(self, ident, min_priority):
# min_priority must be one of ...
# EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG

self.case = {'EMERG': syslog.LOG_EMERG,
'ALERT': syslog.LOG_ALERT,
'CRIT': syslog.LOG_CRIT,
'ERR': syslog.LOG_ERR,
'WARNING': syslog.LOG_WARNING,
'NOTICE': syslog.LOG_NOTICE,
'INFO': syslog.LOG_INFO,
'DEBUG': syslog.LOG_DEBUG}

self.ident = ident
print 'log up to & inclusive of ... ', self.case[min_priority]
syslog.setlogmask(syslog.LOG_UPTO(self.case[min_priority]))

def log(self, msg, priority):
print 'sending message at level ...',  self.case[priority]
syslog.openlog(self.ident , syslog.LOG_PID,
(self.case[priority] | syslog.LOG_USER))
syslog.syslog(msg)
syslog.closelog()

And call it with ...

import kmotion_logger
# EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG
logger = kmotion_logger.kmotion_logger("kmotion", "DEBUG")
logger.log("TESTING", "ALERT")

And it worked as I wanted, it logs to syslog (cheers, jumps for joy) :)

Then I noticed several inconsistencys, the following also works AOK ...

import kmotion_logger
# EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG
logger = kmotion_logger.kmotion_logger("kmotion", "INFO")
logger.log("TESTING", "ALERT")

But the next one fails to log ...

import kmotion_logger
# EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO, DEBUG
logger = kmotion_logger.kmotion_logger("kmotion", "NOTICE")
logger.log("TESTING", "ALERT")
ALERT is above NOTICE & should log  I am suspicious of
'(self.case[priority] | syslog.LOG_USER)' although it looks right and
have tried LOG_LOCAL6 etc but still no joy

I have even tried explaining it to my cat, no joy

Any ideas anyone ?

Cheers

A very log frustrated programmer

Dave




-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] More logging probs ...

2007-11-17 Thread dave selby
OK so to condense the problem the following works at LOG_INFO default
priority ...

def log(self, msg, priority):
syslog.openlog(self.ident , syslog.LOG_PID)
syslog.syslog('testing message')
syslog.closelog()

But as soon as I try to set a priority API syslog docs, it fails to log ...

def log(self, msg, priority):
syslog.openlog(self.ident , syslog.LOG_PID)
syslog.syslog((syslog.LOG_ALERT | syslog.LOG_USER), 'testing message')
syslog.closelog()

PS tried LOG_LOCAL6 etc, same result.

Trying to change the priority in openlog() logs but does not appear to
change the priority since syslog.setlogmask() indicate it is stuck at
LOG_INFO

def log(self, msg, priority):
syslog.openlog(self.ident , syslog.LOG_PID, (syslog.LOG_ALERT
| syslog.LOG_LOCAL6))
syslog.syslog('testing message')
syslog.closelog()

Still stuck

Dave
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unexpected signal behaviour

2007-11-24 Thread dave selby
Hi all,

I have written a daemon as part of a larger project, if it recieves a
SIGHUP signal it needs to re-read its config file. It works in that I
get 'signal HUP detected, re-reading config file' in syslog but then
the script exits ... mmm  first time I have used signal catching
... thought it would continue its infinate loop. Any idea anyone ?

Cheers

Dave




import os,  sys, time, signal, ConfigParser, kmotion_logger

class Kmotion_Hkd2:

def __init__(self):
self.snap_init = [ 0 for i in xrange(16) ]
self.snap_count = [ 0 for i in xrange(16) ]
self.video_dir = ''
self.motion_feeds = ''
self.logger = kmotion_logger.Logger('kmotion_hdk2', 'DEBUG')
signal.signal(signal.SIGHUP, self.signal_hup)
self.read_config()

def start_daemon(self):
self.logger.log('daemon starting ...', 'DEBUG')
 Start the house keeping 2 daemon """
while(True):
target_date = time.strftime('%Y%m%d')
# Scan the feeds
for feed in xrange(self.motion_feeds):
target_tmp = '%s/%s/%02i/tmp/' % (self.video_dir,
target_date, (feed + 1))
target_video = '%s/%s/%02i/video/' % (self.video_dir,
target_date, (feed + 1))

# If target_date or target_tmp don't exist they will
shortly as motion auto generates them
# If target_video doesn't exist, could be just no
motion so add dir
if not(os.path.isdir(self.video_dir + '/' +
target_date)) or not(os.path.isdir(target_tmp)): continue
if not(os.path.isdir(target_video)): os.mkdir(target_video)

jpeg_list = os.listdir(target_tmp)
jpeg_list.sort()

while (len(jpeg_list) >= 3):
jpeg = jpeg_list[:1][0]
self.snap_count[feed] = self.snap_count[feed] - 1

if  self.snap_count[feed]:
# Still counting down the snap_count[], so
delete the snapshot
self.logger.log('deleteing snapshot %s' %
(target_tmp + jpeg), 'DEBUG')
os.remove(target_tmp + jpeg)

else:  # snap_count[] = 0, reset it & do something
with the snapshot
self.snap_count[feed] = self.snap_init[feed]

if os.path.isdir(target_video + jpeg[:-4]) or
not(self.snap_init[feed]):
# If there is a video file dir or if
snap_init[feed] = 0, we dont need a snapshot so remove it
self.logger.log('remove snapshot due to
video clash %s/tmp/%s' % (self.video_dir, jpeg), 'DEBUG')
os.remove(target_tmp + jpeg)

else:  # No video file dir, move the snapshot
self.logger.log('rename %s %s' %
(target_tmp + jpeg, target_video + jpeg), 'DEBUG')
os.rename(target_tmp + jpeg, target_video + jpeg)

jpeg_list = jpeg_list[1:]
time.sleep(2)

def read_config(self):
""" Read config file from '~/.kde/share/apps/kmotion/kmotion.rc' """
parser = ConfigParser.SafeConfigParser()
parsed =
parser.read(os.path.expanduser('~/.kde/share/apps/kmotion/kmotion.rc'))
if parsed[0][-10:] != 'kmotion.rc':
emsg = 'Can\'t open config file %s - killing motion & all
daemon processes' % (parsed[0][-10:])
self.logger.log(emsg, 'CRIT')
self.kill_daemons()
sys.exit()

try:
self.video_dir = parser.get('misc', 'video_dir')
self.motion_feeds = 0  # Get ready to count the live feeds
for i in xrange(0, 16):
self.snap_init[i] = int(parser.get('feed%s' %
(str(i)), 'snapshot_interval'))
if parser.get('feed%s' % (str(i)), 'live') == "yes" :
self.motion_feeds = self.motion_feeds + 1
except:
emsg = 'Corrupt config %s - Killing motion & all daemons
processes' %  (sys.exc_info()[1])
self.logger.log(emsg, 'CRIT')
self.kill_daemons()
sys.exit()

for i in xrange(16):  # Force an immediate snapshot on all feeds
self.snap_count[i] = 1

def kill_daemons(self):
""" Kill motion & all daemons """
os.system('killall -q motion')
os.system('pkill -f \'python.+kmotion_hkd1.py\'')

def signal_hup(self, signum, frame):
""" Re-read the config file on SIGHUP """
self.logger.log('signal HUP detected, re-reading config
file', 'DEBUG')
self.read_config()

if __name__ == '__main__':
Hkd2 = Kmotion_Hkd2()
Hkd2.start_daemon()



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cant write new line at end of file append

2007-12-21 Thread dave selby
Hi all,

I need to write a newline at the end of a string I am appending to a
file. I tried ...

journal.write('%s#%s\n' % (jpeg[:-4], self.snap_init[feed]))

The text is all there but no new line at the end  any idea what I
am doing wrong ? ... thought \n would do it.

Cheers

Dave


-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] os.system() problem

2008-02-03 Thread dave selby
Hi all,

I am not sure if this is a Python or bash issue :).

In bash if I execute 'motion' with the following ...

[EMAIL PROTECTED]:~/.kde/share/apps/kmotion$ motion &> /dev/null &
[1] 10734
[EMAIL PROTECTED]:~/.kde/share/apps/kmotion$

I get what I expect, a background job, however if I execute it from
Python with an os.system ...

os.system('motion &> /dev/null &')

I get tons of output to the BASH shell ...

[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Processing config file /etc/motion/motion.1.conf
[0] Processing config file /etc/motion/motion.2.conf
[1] Thread is from /etc/motion/motion.1.conf
[2] Thread is from /etc/motion/motion.2.conf
[1] Thread started
[2] Thread started
[1] File of type 2 saved to: /var/lib/motion/20080203/01/tmp/175253.jpg
...etc ...

I just can't work out why this is happening & how to stop it ?. Any ideas ?

Cheers

Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] if ... else shorthand form ?

2008-02-09 Thread dave selby
Hi all,

Returning to python after a brief affair with C++, I have the following code ...

if (items.has_keys('snapshot_interval')):
self.snap_init[i] = items['snapshot_interval']
else:
self.snap_init[i] = 0

I thought Python had a shorthand version of something like 

self.snap_init[i] =
(items.has_keys('snapshot_interval'))?items['snapshot_interval']:0

Googled but no luck ... or is it my poor overloaded brain getting confused ?

Cheers

Dave













-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I destroy class instances ?

2008-02-24 Thread dave selby
I have created a list of class instances, works a treat. I need to be
able to re __init__ the instances on a SIGHUP so I guess the best way
is to destroy them & re make them.

err ... how do I destroy an instance ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I destroy class instances ?

2008-02-24 Thread dave selby
On 24/02/2008, Dave Kuhlman <[EMAIL PROTECTED]> wrote:
> On Sun, Feb 24, 2008 at 04:14:02PM +0000, dave selby wrote:
>  > I have created a list of class instances, works a treat. I need to be
>  > able to re __init__ the instances on a SIGHUP so I guess the best way
>  > is to destroy them & re make them.
>  >
>  > err ... how do I destroy an instance ?
>
>
> It is not likely that you need to.
>
>  When your instances are no longer referenced (nothing points to
>  them, so to speak), they will be garbage collected.  Here is an
>  illustraction -- This code collects three instances of class
>  MyClass in a list, then later "forgets" them:
>
> myinstances = []
> myinstances.append(MyClass())
> myinstances.append(MyClass())
> myinstances.append(MyClass())
> o
> o
> o
> myinstances = []
>
>  Or, if there are resources that are held onto by each instance and
>  need to be cleaned up, for example an open file.  Then do something
>  like the following:
>
> for inst in myinstances:
> inst.cleanup()
> myinstances = []
>
>  where "cleanup" is a method implemented in each class that needs to
>  cleanup/release resources.
>
>  But, remember that, if there are objects that are referred to by
>  your instances and *only* your instances, then when your instances
>  go away (are garbage collected), those other things will also
>  automatically go away, too.  No extra work is needed.
>
>  It takes a little thought before you will figure out that this is
>  something that needs (almost) no thought.

Thanks for replying, I have been away from Python for quite a while,
being dabbleing in C++ on a KDE4 app. I Forgot just how friendly
Python is :)

Cheers

Dave



>
>  Hope this helps.
>
>  - Dave
>
>
>  --
>  Dave Kuhlman
>  http://www.rexx.com/~dkuhlman
>
> ___
>  Tutor maillist  -  Tutor@python.org
>  http://mail.python.org/mailman/listinfo/tutor
>


-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems with ConfigParser set method

2008-03-08 Thread dave selby
Hi All,

I am using the ConfigParser module, I can 'get' from a config file
fine, when I try to set it, it silently fails. the code.

parser = ConfigParser.SafeConfigParser()
parser.read('./daemon.rc')
print parser.get('feeds', 'number')
parser.set('feeds', 'number',  '99')
print parser.get('feeds', 'number')

there is a section [feeds], and option number, it is set to 1. If I
execute the script I get ...

[EMAIL PROTECTED]:/var/lib/kmotion/daemons$ ./daemon_start.py
1
99
[EMAIL PROTECTED]:/var/lib/kmotion/daemons$ ./daemon_start.py
1
99
[EMAIL PROTECTED]:/var/lib/kmotion/daemons$


The first call returns as expected, the second should return 99, 99
not 1, 99. On opening daemons.rc the 'number' option is not changed.

Any ideas ?

Cheers

Dave














-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] signal trapping in a class instance

2008-03-15 Thread dave selby
Hi all,

I have a series of class instances saved in an array. I need the
instances to respond to a SIGKILL by writing to a file and
sys.exit()-ing.

Am I right in codeing it as below ? ... does the sys.exit() kill the
instance or the instance & the instance holding array definition above
it ?

Cheers

Dave


  def signal_kill(self, signum, frame):
"""
On SIGKILL update journal_snap with a special #$86400 'no snapshot' string
"""
now_secs =  time.strftime('%H') * 60 * 60
now_secs =  time.strftime('%M') * 60 + now_secs
now_secs =  time.strftime('%S') + now_secs
update_journal(self,  time.strftime('%Y%m%d'), self.feed,
now_secs, 86400)
sys.exit()



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need suggestion / advice - controlling remote server

2008-04-17 Thread dave selby
Hi all,

I am after some advice / suggestions. I have written web interface for
viewing CCTV images http://code.google.com/p/kmotion/wiki/ScreenShots
its called 'kmotion'. Underneath its all Python daemons. It usually
runs stand alone on headless servers. Now I am about to write a KDE
interface in Python & QT4 for config & local viewing.

The question is how to communicate with the remote kmotion servers
Python daemons. I could access the images via port 80, no prob but I
need the KDE interface to change configs etc and restart services. I
am thinking of getting the KDE interface to ssh in and do the changes
via shell commands, ie change config files, restarts deamons etc,
should work OK. Is this acceptable ? How would you guys do it ?

Thanks in advance

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] doc string format ?

2008-06-08 Thread dave selby
Hi All,

I am trying to improve my code quality and have started using doc
strings. What format do you guys use for your doc strings ?
I have 'made up' the following general format ...

Cheers

Dave



def gen_vhost(kmotion_dir):
"""
Generate the kmotion vhost file from vhost_template expanding %directory%
strings to their full paths as defined in kmotion.rc

arguments :
kmotion_dir ... the 'root' directory of kmotion

exceptions:
exit ... if kmotion.rc cannot be read

returns:
"""
parser = ConfigParser.SafeConfigParser()
parsed = parser.read('%s/core/kmotion.rc' % kmotion_dir)
try:
images_dbase_dir = parser.get('dirs', 'images_dbase_dir')
port = parser.get('misc', 'port')
LDAP_enabled = parser.get('LDAP', 'enabled') in ['true',
'True',  'yes',  'Yes']
LDAP_url = parser.get('LDAP', 'AuthLDAPUrl')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] clipping file to size ?

2008-06-09 Thread dave selby
Hi All,

I need to read parse and re-write the parsed file. I am opening with

f = open(file_rc, 'r+')

reading file 

f.seek(0)

resetting file pointer ...

print >> f, section

writing smaller file...

and I end up with the remnants of the old larger file at the end.
any idea how to clip the file to the newer smaller size without
closing it and reopening it as a 'w' ?

Cheers

Dave


-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] do I need f.close()

2008-06-10 Thread dave selby
Hi All,

Up to now I when I need to write some data to a file I have been
purposely using close()

f = open(conf, 'w')
f.writelines(lines)
f.close()

Is it as safe to use the following 

open(conf, 'w').writelines(lines)

ie no close() to flush the data, but also not assigned an object name
so am I right in thinking that as the object is 'reclaimed' close() is
automatically called ?

Cheers

Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] do I need f.close()

2008-06-11 Thread dave selby
Thanks for all your help guys, I am getting a strong consensus that
f.close() should be used everywhere, reading files as well as writing
files and not to rely on the PVM to do clean-up for you.

The whole topic came up because I just finished reading 'learning
python' 3rd edition OReilly as a refresher where there are multiple
instances of suggesting that you do the exact opposite eg ...

[line.rstrip() for line in open('myfile')] ... p361
for line in open('script1.py') ... p261& p276 where it is described as
'best practice' for reading files line by line
etc ...


Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Split string on 2 delimiters ?

2008-08-07 Thread dave selby
Hi all,

Is there a neat way to split a string on either of two delimiters ie
space and comma

Cheers

Dave


-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] importing path question

2008-08-09 Thread dave selby
Hi all,

I have a main directory 'kmotion2' where python scripts live. They
access a library of scripts in 'kmotion2/core'  as 'kmotion2/core' has
a __init__.py file. However I now need to create a new directory
'utilities' inside 'kmotion2' that also needs to access scripts in
'core'

kmotion2 directory
|   |
core utilities

So I need to import up the tree then back down. Is this possible ?

Dave






-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pwd lib probs

2008-08-18 Thread dave selby
Hi all,

I am using the pwd lib where I am codeing things like ...

gid = pwd.getpwnam(apache2_user)[3]

where as I would like to code it as ...

gid = pwd.getpwnam(apache2_user)[pwd.pw_gid]

but I get

gid = pwd.getpwnam(apache2_user)[pwd.pw_gid]
AttributeError: 'module' object has no attribute 'pw_gid'
[EMAIL PROTECTED]:~/kmotion2$ sudo ./install.py

What am I missing ?

Dave





-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] named pipe problem

2008-08-20 Thread dave selby
Hi All,


I am trying to get a named pipe working, I have already made a fifo

[EMAIL PROTECTED]:/usr/local/bin$ ls -al /home/dave/kmotion2/www/pipe_func
prw-rw 1 dave www-data 0 2008-08-20 20:25 /home/dave/kmotion2/www/pipe_func
[EMAIL PROTECTED]:/usr/local/bin$

but when I execute my test code to add an item to the fifo ...

func = '199'
www_dir = '/home/dave/kmotion2/www'
print '%s/pipe_func' % www_dir
pipeout = os.open('%s/pipe_func' % www_dir, os.O_WRONLY)
print 'xxx'
os.write(pipeout, func)
os.close(pipeout)

I get the path printed out & then the script hangs silently on pipeout
= os.open('%s/pipe_func' % www_dir, os.O_WRONLY)

Can anyone tell me why ? I expected it to return immediately

Cheers

Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] stopping threads ?

2008-11-03 Thread dave selby
Hi All,

Why when I use threads in my app (I know they are evil ...lol) does it
not stop with ctrl-c, I have to use ctrl-z ?

Cheers

Dave


-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] totally stumped on signal code, wont work in this instance

2009-02-06 Thread dave selby
Hi,

I have been hitting my head on a brick wall on a bit of code that
refuses to work. I have similar code in other scripts that works AOK
I have commented out all functionality except the core problem ...


import sys, threading, time, os.path, urllib, time, signal, ConfigParser, logger


def main():
#logger.log('daemon starting ...', 'CRIT')
#read_config()
#thread1 = Thread1_PTZ()
#thread1.setDaemon(True)
#thread1.start()
#thread2 = Thread2_PTZ_Park()
#thread2.setDaemon(True)
#thread2.start()
#thread3 = Thread3_PTZ_Preset()
#thread3.setDaemon(True)
#thread3.start()

while True: # sleep to keep daemons alive :)
time.sleep(60 * 60 * 24)


def signal_hup(signum, frame):
"""
SIGHUP, unlike all other daemons SIGHUP causes this daemon to exit killing
all its daemon threads. This is a workaround. Because 'kmotion_ptzd' is
threaded the only way to get the threads to reliably reload their config
is to kill and restart else they languish in a sleep state for ? secs.

args: discarded
excepts :
return  : none
"""

print 'sighup :)'
#logger.log('signal SIGHUP detected, shutting down due to
threading', 'CRIT')
#sys.exit()

...
main()

So main just sits there AOK. I send a sighup to the script with

pkill -SIGHUP -f python.+kmotion_ptzd.py

and I get ...

d...@main-system:~/kmotion2/core$ ./kmotion_ptzd.py
Hangup
d...@main-system:~/kmotion2/core$

OK so I would have expected signal_hup to have intercepted the signal
and printed 'sighup :)'
and also not have exited in this case.

Any ideas, I can solve most of my python probs but this one has me stumped.

Cheers

Dave










-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] I am trying to read and decode an emails PDF attachment via python,

2011-08-20 Thread dave selby
I am trying to read and decode an emails PDF attachment via python,
its a dedicated mailbox, anything emailed there is to be read by the
script, deleted from the mailbox and processed.

http://pastebin.com/VA1gwWH3

def get_next_mail() works AOK, I get a nice long string containing the
next email and PDF data block but when I execute

msg.is_multipart()
I get False ???

And when I execute
msg.get_payload()
I get nothing

Any ideas anyone, at a guess its because my string is not formatted
correctly, can anyone advise ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am trying to read and decode an emails PDF attachment via python,

2011-08-20 Thread dave selby
Did a lot more digging and finally sorted it, sorry for bothering you guys,

Cheers

Dave

On 20 August 2011 10:58, dave selby  wrote:
> I am trying to read and decode an emails PDF attachment via python,
> its a dedicated mailbox, anything emailed there is to be read by the
> script, deleted from the mailbox and processed.
>
> http://pastebin.com/VA1gwWH3
>
> def get_next_mail() works AOK, I get a nice long string containing the
> next email and PDF data block but when I execute
>
> msg.is_multipart()
> I get False ???
>
> And when I execute
> msg.get_payload()
> I get nothing
>
> Any ideas anyone, at a guess its because my string is not formatted
> correctly, can anyone advise ?
>
> Cheers
>
> Dave
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html
>



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] \x00T\x00r\x00i\x00a\x00 ie I get \x00 breaking up every character ?

2011-11-20 Thread dave selby
Hi All,

I have a long string which is an HTML file, I strip the HTML tags away
and make a list with

text = re.split('<.*?>', HTML)

I then tried to search for a string with text.index(...) but it was
not found, printing HTML to a terminal I get what I expect, a block of
tags and text, I split the HTML and print text and I get loads of

\x00T\x00r\x00i\x00a\x00  ie I get \x00 breaking up every character.

Any idea what is happening and how to get back to a list of ascii strings ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Trying to send a cursor down key press string to a device

2012-03-17 Thread dave selby
HI,

I have an attatched mymobiler device which I can send string to, I
need to send a cursor down command but am having problems,

I need to send ... 224 followed by 80 I found this by monitering msvcrt.getch()

However I do not know how to construct this, chr(224) + chr(80)
returns a loud bleep from my mymobiler device instead of moving the
highlighte down one line

Any ideas

Cheers

Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Threads, ok to access parent script methods by passing 'self' ?

2012-06-05 Thread dave selby
Hi All,

If a thread is started and 'self' is passed as a parameter, is it
acceptable to access methods of the calling class via
'self.updateGrid()' etc from within the thread or does everything have
to be done via wx.lib.pubsub and publisher calls ?

Cheers

Dave







-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Threads, ok to access parent script methods by passing 'self' ?

2012-06-05 Thread dave selby
On 5 June 2012 12:05, dave selby  wrote:
> I was running the thread by instantiating a separate class but this
> will make the very neat CallAfter() difficult, is it OK to call a
> method in the main class as a thread in which case the CallAfter()
> should work OK ?
>
> Thanks Again
>
> Dave



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Subprocess.Popen process seems to be outputting to stdout even though redirected ?

2012-06-10 Thread dave selby
I have a simple script to tail a log file for an error string, it
works AOK but there is an unexpected side effect, when I run it in a
shell.

if I

echo "ERROR TEST" >> LOG

in a separate shell, I get the following from the script

ERROR TEST
GOT YA :)
ERROR TEST

So it looks like I am getting stdout from the tail -f, and two copies
of it ?, stdout should be piped to subprocess.stdout

tail = subprocess.Popen(['tail', '-f', LOG_FILE], shell=False,
stdout=subprocess.PIPE)

for out in iter(tail.stdout.readline, ''):

out_str = out.rstrip('\n')

if out_str.find('ERROR') != -1:
print 'GOT YA :)'

time.sleep(1)

Any ideas anyone ?

Cheers

Dave

-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Subprocess.Popen process seems to be outputting to stdout even though redirected ?

2012-06-10 Thread dave selby
This list is amazing, I scratch my head, think and think then finally
post a question, maybe its the act of spelling it out, ps ax showed 2
x 'tail' processes, I am guessing zombies of previous attempts, killed
them, all works AOK now


On 10 June 2012 10:06, dave selby  wrote:
> I have a simple script to tail a log file for an error string, it
> works AOK but there is an unexpected side effect, when I run it in a
> shell.
>
> if I
>
> echo "ERROR TEST" >> LOG
>
> in a separate shell, I get the following from the script
>
> ERROR TEST
> GOT YA :)
> ERROR TEST
>
> So it looks like I am getting stdout from the tail -f, and two copies
> of it ?, stdout should be piped to subprocess.stdout
>
> tail = subprocess.Popen(['tail', '-f', LOG_FILE], shell=False,
> stdout=subprocess.PIPE)
>
> for out in iter(tail.stdout.readline, ''):
>
>        out_str = out.rstrip('\n')
>
>        if out_str.find('ERROR') != -1:
>                print 'GOT YA :)'
>
>        time.sleep(1)
>
> Any ideas anyone ?
>
> Cheers
>
> Dave
>
> --
>
> Please avoid sending me Word or PowerPoint attachments.
> See http://www.gnu.org/philosophy/no-word-attachments.html



-- 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor