Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44094
| Date | 2013-04-22 17:32 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: error importing modules |
| References | <CABRP1o-iZ1SzUakm4yvDaeRrh1MkqZh0X4Lob8dtn0Nx-SzDYQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.930.1366648529.3114.python-list@python.org> (permalink) |
On 22/04/2013 15:54, Rodrick Brown wrote:
> I'm using the fabric api (fabfile.org <http://fabfile.org>)
>
> I’m executing my fab script like the following:
>
> $ fab -H server set_nic_buffers -f set_nic_buffers.py
> Traceback (most recent call last):
> File "/usr/lib/python2.7/site-packages/fabric/main.py", line 739, in main
> *args, **kwargs
> File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 316, in
> execute
> multiprocessing
> File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 213, in
> _execute
> return task.run(*args, **kwargs)
> File "/usr/lib/python2.7/site-packages/fabric/tasks.py", line 123, in run
> return self.wrapped(*args, **kwargs)
> File "/home/rbrown/repos/unix-tools/tools/fabfiles/nb.py", line 5, in
> set_nic_buffers
> f_exec = modules.Fabexec('set_nic_buffers',
> '/var/tmp/unix-tools/tools/set_nic_buffers.sh')
> TypeError: 'module' object is not callable
>
> My paths all seem to be fine not sure what’s going on
>
> $ python -c 'import modules.Fabexec; print (modules.Fabexec)'
> <module 'modules.Fabexec' from 'modules/Fabexec.pyc'>
>
> Fabfiles
>
> |-- modules
> | |-- Fabexec.py
> | |-- Fabexec.pyc
> | |-- __init__.py
> | `-- __init__.pyc
> |-- systune.py
> |-- systune.pyc
> `-- set_nic_buffers.py
>
> --- set_nic_buffers.py ---
> import modules
> from modules import Fabexec
> def set_nic_buffers():
> f_exec = modules.Fabexec('set_nic_buffers',
> '/var/tmp/unix-tools/tools/set_nic_buffers.sh')
> f_exec.run()
>
'modules.Fabexec' is the module/script 'Fabexec'. What you want is the
'Fabexec' class within the 'Fabexec' module.
> --- Fabexec.py ---
> from fabric.api import run, cd, sudo, env
> from fabric.contrib import files
> from fabric.colors import green
>
> class Fabexec(object):
>
> repobase='/var/tmp/unix-tools'
>
> def __init__(self,script_name,install_script):
> self.script_name = script_name
> self.install_script = install_script
>
> def run(self):
> if files.exists(self.install_script):
> with cd(self.repobase):
> result = sudo(self.install_script + ' %s ' % env.host)
> if result.return_code != 0:
> print(red('Error occured executing %s' %
> self.install_script))
> else:
> print(green('%s executed successfully'))
> else:
> print(red('Error no such dir %s try running repo deploy
> script to host %s' % (self.repobase, env.host)))
> raise SystemExit()
>
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: error importing modules MRAB <python@mrabarnett.plus.com> - 2013-04-22 17:32 +0100
csiph-web