Archive for python

pytemplate 1.5

Hello

pytemplate 1.5 is arrived, with 2 new features: daemon capabilities and signal handling. Go straight forward to  pytemplate project page to get it!

I’m also pleased to announce that it should be available on netBSD, thanks to imil.

Have fun.

Posted in python | 2 Comments

News about pytemplate: version 1.4.0 available!

Hello

pytemplate, the python template framework, is now in version 1.4.0. What’s new for this version? it uses optparse to create options, meaning that options can now be created easely from your program and that pytemplate.py does not need to be modified anymore. It also means that this version is really able to be a pythondistributed module.

For more information, to download it,  go to the pytemplate project page.
deb and rpm package to install as a python distributed module are available at this page.
Have fun.

Stephbul

Posted in python | Leave a comment

pytemplate 1.3.1

You are welcome on my new small wiki to download the pytemplate-1.3.1!
If you want to participate to this project, do not hesitate to live a comment.
In the todo list, I have mainly the portability task on windows.
I’ve been using this framework for a few script, and be sure it really helps to go quick and not too durty.

Regards.
Stephane

Posted in python | Leave a comment

pytemplate: a main script template

Hello,

If you want to start a python script and if the developper white page fears you, you are very welcome on this page. I have updated an old project of script template written in python.  You have only to think about what you want to do, the script will handle other stuffs, like parameters, logging function. If you want to dowload the script, you can go on the project page, or download it directly.

Also available a debian building environment, where you will have to replace all the pytemplate references by the name fo your package. Be carefull, using this building environment, I advise you the new debian maintainer’s guide if you are not familiar the debian policies.

Comments are very welcome.

stephbul

Posted in python | 2 Comments

A python script template for main

Hello,

Today, I propose a template for your python scripts. You can use it as you want when you need to create a script. If you want to modify it, go ahead, but let me know…

By default, with this script, you can manage -h for help, -c for config file, -v for verbosity, you can also enter parameters. It will by default use the system stdin and stdout, and will log on error.log the stderr.

If you have trouble to use this script, do not hesitate to contact me through this blog.

To download the main_template.py, go to the project page.

Regards and have fun.

stephbul

Posted in python | Leave a comment

My patch cmd.py pour keyboardinterrupt

--- backuo/cmd.py       2007-10-19 13:54:25.000000000 +0200
+++ cmd.py      2007-10-19 14:19:54.000000000 +0200
@@ -130,6 +130,13 @@
                             line = raw_input(self.prompt)
                         except EOFError:
                             line = 'EOF'
+                        except KeyboardInterrupt:
+                            self.stdout.write('nare you sure you want to exit?
 y/n ')
+                            answer =''
+                            while (answer != 'y') & (answer != 'n'):
+                                answer = raw_input()
+                                if answer == 'y':
+                                    exit(0)    
                     else:
                         self.stdout.write(self.prompt)
                         self.stdout.flush()

Posted in python | Leave a comment

How to create a patch, how to apply it?

Hello,

After having proposed a modification to python.org on the cmd.py lib in order to manage correctly, I have been asked for sending the associated patch… Of course, I will!.. But before, I need to learn how to make a patch. Here is the way to do it:

Let’s imagine I have my old.py file that has a bug, and the new.py that is the old.py with the bug correction. to generate the patch, do:

diff -ruN old.py new.py >mypatch

-r is to do it recursively. In how case, not really useful, but you can create patch on directories.

-u will output 3 lines of unified context. Default is 3. -U4 will put 4 lines...

-N will be used to treat absent files as empty files. Same, in our case not useful, but usefull for patches on directories.

Now, how to apply a patch:

patch < mypatch for a file.
patch -pNUM < mypatch #where NUM is the recursive depth for directories

Here it is…

Let me know, if this helped!

That’s it, you have made a patch.

How to use it

Posted in python | Leave a comment

schemgen V2

Hello,

Do you remember schemgen.py, my small python ldap generator? If you used it, probably, you got some troubles… Not really easy to use and a few bugs! I propose that you use this new version V2.0.

Go on the projects page

Have fun.

Stephbul

Posted in ldap, python | Leave a comment

python lib cmd.py: management of KeyboardInterrupt

Hello all,

You are a python user and you are used to import cmd.py to generate a simple CLI, but disappointed with ctrl-C management that generates a KeyboardInterrupt error, well, I have submitted a proposal. You will be able to read it on http://bugs.python.org/issue1294 .

Have fun

Posted in python | Leave a comment

python multhreading…

Hello,

Python multithreating module is very easy to use. I have created this almost unuseful script to generate with an asterisk equipment calls to every 10 seconds.

For this you have to know that to generate calls with asterisk, you can send 1.call files (x.call) in the /var/spool/asterisk/outgoing directory .

Here is a sample of 1.call file:

Channel: SIP/me

MaxRetries: 1

RetryTime: 60

WaitTime: 30

Context: me

Extension: you

Priority: 1

where me and you are declared channel in sip.conf

I have created the following script that sends every 10 sec the files into the good directory (first process) and notify the second process that a call has been generated.


#!/usr/bin/env python

import thread
import time
from threading import *
import subprocess

class call_gen(Thread):

def __init__(self,condition,sleeptime=10):
    Thread.__init__(self)
    self.cond=condition
    self.sleeptime=sleeptime

def run(self):
    cond=self.cond

    while 1 :
        cond.acquire() #acquire the lock
        b = subprocess.Popen(['./start_call.sh'])
        cond.notifyAll()
        cond.release()
        time.sleep(self.sleeptime)

class Notifier(Thread):

    def __init__(self,condition,sleeptime=2):

        Thread.__init__(self)
        self.cond=condition
        self.sleeptime=sleeptime

    def run(self):
        cond=self.cond

    while 1:
        time.sleep(self.sleeptime)
        cond.acquire()
        cond.wait()
        print 'call has been generated'
        cond.release()

if __name__=="__main__":

    cond=Condition()
    call_gen=call_gen(cond)
    Not=Notifier(cond)
    call_gen.start()
    Not.start()
    while 1: pass

For information start_call.sh is a script that copy the 1.call and send it into the directory /var/spool…

Thanks to http://linuxgazette.net/107/pai.html made by Krishna G Pai that really helped!

Have fun.

Posted in asterisk, python | Leave a comment

Swedish Greys - a WordPress theme from Nordic Themepark.