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

[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 std

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 ? > > Tha

[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 m

[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 f

[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

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, del

[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 a

[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=Tr

[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

[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] 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 cod

[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 'p

[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 dir

[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 - Tu

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 refr

[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

[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

[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 expan

[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

[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 ? Che

[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',

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 > &

[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

[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 h

[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

[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 -- Plea

[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

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 fa

[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 b

[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 ... [l

[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:/

[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 ___ T