2016-03-21 2 views
1

Aは、TCPプロトコルを開始し、STDINで入力したものをエコーアウトする、死んだ単純なねじれたアプリケーションを作成しました。ツイスト・プラグイン・エラー

私は今、自分のアプリケーションこのように実行することができるようにtwistdプラグインを作成しようとしています:予想通りecho startコマンドを使用しているときecho startかのどちらかが

twistd -n echoすべてを実行している、私はエラーを取得する作品twistd -n echoを:/home/vagrant/.env/bld/bin/echo: Unknown command: echoここで

が私のコードです:

エコー/ plugins.py

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

from twisted.application import internet 
from twisted.internet import endpoints 
from twisted.internet.protocol import Factory 
from twisted.python import usage 

from echo.protocol import EchoProtocol 


class Options(usage.Options): 
    optParameters = [['port', 'p', 1234, 'Service port.']] 


def makeService(options): 
    from twisted.internet import reactor 

    f = Factory() 
    f.protocol = EchoProtocol 

    ep = endpoints.TCP4ServerEndpoint(reactor, int(options['port'])) 
    return internet.StreamServerEndpointService(ep, f) 

エコー/ protocol.py

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

from twisted.internet.protocol import Protocol 


class EchoProtocol(Protocol): 
    def dataReceived(self, data): 
     self.transport.write('You entered: {data}'.format(data=data)) 

エコー/ tap.py

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

import sys 

from twisted.python import usage 
from twisted.scripts import twistd 


class Start(twistd.ServerOptions): 
    def parseOptions(self, args): 
     sys.argv[1:] = self.getArguments(args) 
     print('Starting echo service...') 
     twistd.run() 

    def getArguments(self, args): 
     args.extend(['--pidfile', self.parent.pid]) 
     args.extend(['_bld_echo']) 
     return args 


class Options(usage.Options): 
    pid = '/tmp/echo.pid' 
    subCommands = [['start', None, Start, 'Launch echo service.']] 


def main(argv=None): 
    o = Options() 
    try: 
     o.parseOptions(argv) 
    except usage.UsageError, e: 
     raise SystemExit(str(e)) 

撚り/プラグイン/ echo_plugin.py

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

from twisted.application.service import ServiceMaker 

Finger = ServiceMaker(
    'EchoServiceMaker', # name 
    'echo.plugins', # module 
    'Description blah-blah.', # description 
    '_plgn_echo') # tapname 

setup.pyここ

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

from setuptools import find_packages 
from setuptools import setup 

setup(
    name='Echo', 
    version='0.0.1', 
    packages=find_packages(), 
    entry_points={ 
     'console_scripts': [ 
      '_ep_echo=echo.tap:main', 
     ], 
    }, 
    install_requires=[ 
     'Twisted==16.0.0', 
    ], 
    include_package_data=True, 
    zip_safe=False,) 

私のvirtualenvのセットアップ:私は呼び出すときに1が呼び出されたかわからなかったので、私は_ep__bld_と私の命令を前に付けている

(bld)[email protected]/code/echo $ pip list 
Echo (0.0.1) 
pip (1.4.1) 
setuptools (20.3.1) 
Twisted (16.0.0) 
wsgiref (0.1.2) 
zope.interface (4.1.3) 

プログラムをtwistdまたはentry_pointを直接呼び出してプログラムを実行しますが、成功なしに可能な組み合わせを試しました...

私は_ep_echo startを実行すると、私が手に:私は_ep_echo_bld_echoを置き換える場合

[twistd -help output...] 

twistd reads a twisted.application.service.Application out of a file and runs 
it. 
Commands: 
    conch   A Conch SSH service. 
    dns    A domain name server. 
    ftp    An FTP server. 
    inetd   An inetd(8) replacement. 
    mail    An email service 
    manhole   An interactive remote debugger service accessible via 
        telnet and ssh and providing syntax coloring and basic line 
        editing functionality. 
    manhole-old  An interactive remote debugger service. 
    news    A news server. 
    portforward  A simple port-forwarder. 
    procmon   A process watchdog/supervisor 
    socks   A SOCKSv4 proxy service. 
    telnet   A simple, telnet-based remote debugging service. 
    web    A general-purpose web server which can serve from a 
        filesystem or application resource. 
    words   A modern words server 
    xmpp-router  An XMPP Router server 

/home/vagrant/.env/bld/bin/_ep_echo: Unknown command: _bld_echo 

同じことが行きます。

twistyにはechoサブコマンドが登録されていません。

私はtwistd --helpを実行した場合、私は取得する:あなたがechoコマンドが登録され見ることができます

twistd reads a twisted.application.service.Application out of a file and runs 
it. 
Commands: 
    _plgn_echo  Description blah-blah. 
    conch   A Conch SSH service. 
    dns    A domain name server. 
    ftp    An FTP server. 
    inetd   An inetd(8) replacement. 
    mail    An email service 
    manhole   An interactive remote debugger service accessible via 
        telnet and ssh and providing syntax coloring and basic line 
        editing functionality. 
    manhole-old  An interactive remote debugger service. 
    news    A news server. 
    portforward  A simple port-forwarder. 
    procmon   A process watchdog/supervisor 
    socks   A SOCKSv4 proxy service. 
    telnet   A simple, telnet-based remote debugging service. 
    web    A general-purpose web server which can serve from a 
        filesystem or application resource. 
    words   A modern words server 
    xmpp-router  An XMPP Router server 

そして、そこを。

これは私を夢中にしています、何が問題なのかここで何か考えていますか?私はpython setup.py installなくpython setup.py develop、後者のコマンドの動作を実行するが、私はaxiomatic startが働いた理由を検索した後にその生産の


EDIT

[OK]を実行したくない

お知らせそして私のecho start私は私が私が聞くのが大好きだ、これは解決策であると主張していない(私が見つけたものをここでインストールしてから、すべての不要なコードを除去することにより、理由を見つけません@この上のグリフの回答)

公理エコー間の主な違いはsetup.pyにこの行です:

packages=find_packages() + ['twisted.plugins']

私はpackages lineから+ ['twisted.plugins']追加を持っていなかったと今では動作しますが、まだこのエラーが発生しています:

Unexpected error while writing cache file 
Traceback (most recent call last): 
    File "/home/vagrant/.env/bld/lib/python2.7/site-packages/Twisted-16.0.0-py2.7-linux-x86_64.egg/twisted/application/app.py", line 579, in parseOptions 
    usage.Options.parseOptions(self, options) 
    File "/home/vagrant/.env/bld/lib/python2.7/site-packages/Twisted-16.0.0-py2.7-linux-x86_64.egg/twisted/python/usage.py", line 262, in parseOptions 
    for (cmd, short, parser, doc) in self.subCommands: 
    File "/home/vagrant/.env/bld/lib/python2.7/site-packages/Twisted-16.0.0-py2.7-linux-x86_64.egg/twisted/application/app.py", line 596, in subCommands 
    for plug in sorted(plugins, key=attrgetter('tapname')): 
    File "/home/vagrant/.env/bld/lib/python2.7/site-packages/Twisted-16.0.0-py2.7-linux-x86_64.egg/twisted/plugin.py", line 213, in getPlugins 
    allDropins = getCache(package) 
--- <exception caught here> --- 
    File "/home/vagrant/.env/bld/lib/python2.7/site-packages/Twisted-16.0.0-py2.7-linux-x86_64.egg/twisted/plugin.py", line 185, in getCache 
    dropinPath.setContent(pickle.dumps(dropinDotCache)) 
exceptions.AttributeError: 'ZipPath' object has no attribute 'setContent' 

プラグイン作品が、私は本当に

+0

うまくいけば、 'エコー/プラグイン/ py'実際'エコー/ plugins.py'を指し?それを反映させるために質問を編集します。 (もしそうでなければ:それはあなたの問題です:)) – Glyph

答えて

1

があなたの問題の非常に完全な説明をありがとう...それをインストールする私の元の方法が機能しなかった理由を知るのが大好きです。私は(それ適切なパッケージにするために__init__.pyecho/の内側を作成する)唯一のマイナーな微調整を正確にそれを再現することができました。

まず、ここでの修正です:

diff --git a/echo/tap.py b/echo/tap.py 
index d23571f..8e1ea84 100644 
--- a/echo/tap.py 
+++ b/echo/tap.py 
@@ -15,7 +15,7 @@ class Start(twistd.ServerOptions): 

    def getArguments(self, args): 
     args.extend(['--pidfile', self.parent.pid]) 
-  args.extend(['_bld_echo']) 
+  args.extend(['_plgn_echo']) 
     return args 

これが機能することの理由は、あなたがこのようなコマンドを書いているとき、あなたがやっていることは、あなたがツイストプラグインの実行を包むあるであることですargs.extendによって構築された合成コマンドライン上にあるものが、twistdのコマンドラインにあるのと同じものである、Twistedプラグインのtapnameであることを意味します。これは_plgn_echoである理由

うまくいけば、それは明らかです。

を明確に理解するために、これらのプレフィックスを追加することをお勧めします。の名前は、特にコードの各領域で参照されています。この答えがあなたにとって理にかなっていると仮定すると、たとえそれが最初にうまくいったとしても、echoを貼り付けたばかりの場合よりも、コードの理解を深めることができます。

+0

私は完全に理解していますが、私はまだ同じエラーがあります... '/home/vagrant/.env/bld/bin/_ep_echo:不明なコマンド:_plgn_echo'、私は試しました** ARGV **リストを記録し、ここではそれがあるために: '[ '/home/vagrant/.env/bld/bin/_ep_echo'、 '--pidfile'、 '/tmp/echo.pid'、 '_plgn_echo' ] '。 'twistd' helpコマンドは、私が書いた' _ * _ echo'コマンドをまだ表示していません。 – kitensei

+0

私は何が失敗したのかを見つけました。私の編集を見て、あなたのサポートに感謝します:) – kitensei

関連する問題