[ANN] pyKook 0.7.0 - task automation tool for Python, similar to Rake or Ant

Makoto Kuwata kwa at kuwata-lab.com
Sat Nov 5 02:06:55 EDT 2011


Hi,

I have released pyKook 0.7.0.
http://pypi.python.org/pypi/Kook/
http://www.kuwata-lab.com/kook/
http://www.kuwata-lab.com/kook/pykook-users-guide.html

In this release, you can run commands on remote machines using ssh.
This is very useful to deploy your application.


pyKook Overview
---------------

pyKook is a task automation tool for Python, similar to Rake or Ant.

(Kookbook.py):

    kookbook.default = 'build'

    ## task
    @recipe(None, ['hello'])
    def build(c):
        """build all"""
        pass

    ## file
    @recipe('hello', ['hello.o'])
    def file_hello(c):
        """build 'hello' from 'hello.o'"""
        system(c%'gcc -o $(product) $(ingred)')

    ## rule
    @recipe('*.o', ['$(1).c', '$(1).h'])
    def file_o(c):
        system(c%'gcc -c $(ingred)')


Command-line:

    bash> kk     # or pykook
    $ gcc -c hello.c
    ### *** hello.o (recipe=file_o)
    $ gcc -c hello.c
    ### ** hello (recipe=file_hello)
    $ gcc -o hello hello.o
    ### * build (recipe=build)

See http://www.kuwata-lab.com/kook/pykook-users-guide.html for details.


Enhancements in this release
----------------------------

* (EXPERIMENTAL!!) Remote command execution (ssh and sftp) is available.
  This is very useful to deploy your application into servers.

  Ex (Kookbook.py)::

	from kook.remote import Remote
	remote = Remote(
	    hosts    = ['www1', 'www2', 'user3 at www3:10022'],
	    port     = 22,
	    user     = 'user1',
	    #password = None,      # for login, '~/.ssh/id_rsa' and sudo
	    passphrase = None,     # only for '~/.ssh/id_rsa'
	    sudo_password = 'xxx', # only for sudo command
	)

	@recipe
	@remotes(remote)
	def hostinfo(c):
	    """show hostname"""
	    ssh = c.ssh
	    ssh('hostname')        # run command with ssh
	    ssh('whomai')          # run command with ssh
	    ssh.sudo('whoami')     # run command with sudo

	@recipe
	@remotes(remote)
	def exchange(c):
	    """upload and download files"""
	    ssh = c.ssh
	    with ssh.pushd('work/apps'):
	        ssh.get('file.remote')    # download a file
	        ssh.put('file.local')     # upload a file
	        ssh.mget('remote.*')      # download files
	        ssh.mput('local.*')       # upload files

  Notice that you must configure ssh at first and confirm that
  you can log into servers without typing password::

	bash> ssh user1 at www1
	bash> ssh user1 at www2
	bash> ssh -p 10022 user3 at www3
	bash> kk hostinfo
	### * showinfo (recipe=showinfo)
	[user1 at www1]$ hostame
	www1
	[user1 at www1]$ whoami
	user1
	[user1 at www1]$ sudo whoami
	root
	[user2 at www2]$ hostame
	www2
	[user2 at www2]$ whoami
	user2
	[user2 at www2]$ sudo whoami
	root
	[user3 at www3]$ hostame
	www3
	[user3 at www3]$ whami
	user3
	[user3 at www3]$ sudo whoami
	root

  Currently commands are executed sequencially (not in parallel).

* (EXPERIMENTAL!!) Password object supported.
  Password object asks you to enter password in prompt when necessary.

  Ex (Kookbook.py)::

	from kook.remote import Remote, Password
	remote = Remote(
	    hosts         = ['user1 at www1:22'],
	    #password     = Password('login'),
	    passphrase    = Password('~/.ssh/id_rsa'),
	    sudo_password = Password('sudo command')
	)
	#
	@recipe
	@remotes(remote)
	def remote_test(c):
	    ssh = c.ssh
	    ssh.sudo('whoami')

  Output example::

	bash> kk remote_test
	### * remote_test (recipe=remote_test)
	Password for ~/.ssh/id_rsa:
	Password for sudo command:
	[user1 at www1]$ sudo whoami
	root

  It is easy to share password object.

  Ex (Kookbook.py)::

	from kook.remote import Remote, Password
	passwd = Password()
	remote = Remote(
	    hosts         = ['user1 at www1:22'],
	    password      = passwd,
	    passphrase    = passwd,
	    sudo_password = passwd,
	)


Changes in this release
-----------------------

* Category class is changed to convers all instance methods into staticmethods.

  Ex (Kookbook.py):

	class apache(Category):
	    @recipe
	    def start(c):
	       system('apachectl start')

	## start() is converted into staticmethod
	assert type(apache.__dict__['start']) == staticmethod
	from types import FunctionType
	assert type(apache.start) == FuntionType

  This makes execution of other recipes in category easier::

	class apache(Category):
	    @recipe
	    def start(c):
	       ...
	    @recipe
	    def stop(c):
	       ...
	    @recipe
	    def restart(c):
	       apache.start(c)    # execute other recipe
	       apache.stop(c)     # execute other recipe

* (internal) kook.config.stdout and kook.config.stderr are removed.



See http://www.kuwata-lab.com/kook/pykook-CHANGES.txt for details.


Have fun!

--
regards,
makoto kuwata



More information about the Python-list mailing list