Learning python 系列7

今天首先讨论daemon.py这个文件。
这里有几个base class以及一些设计方法
VMCDaemon,它的__init__(self,freq,device,notification_manager)
有member:
frequency:
device:
loop:
manager:上述除了loop初始化为none,其他都来自初始化参数。
方法:
start:如果loop为None或者loop没有运行,self.loop=LoopingCall(self.funtion).而后
调用loop.start(self.frequency).
stop:是如果loop.running,调用loop.stop停止。
function:这里没有实现。但是LoopingCall()是什么意思呢?

SignalQuanlityDaemon是继承VMCDaemon,它定义了function.
为self.device.sconn.get_signal_level()的d添加 addcallback.而这个callback是
由UnsolicitedNoticaiton构造一个notification,然后交由manager.on_notification_received()处理。
type为SIG_RSSI,arg为rssi。

CellTypeDaemon和上一个类似,不果调用sconn.get_network_info()返回d,添加callback,
这个callback构造同样的类对象,不过参数是SIG_NEW_CONN_MODE,netinfo[1].

NetworkSpeedDaemon稍微复杂,也是继承VMCDeamon().它比父类多一个netspeed有NetwrokSpeed()构造。
重载方法:
start:netspeed.start(),添加self.function作为LoopingCall().然后调用loop.start().
stop:先把loop停掉,然后停掉netspeed.stop().
function:同样构造UnsolicitedNotification,然后调用manager.on_notifiacation_received().

VMCDaemonCollection是一个基类。有member 字典变量daemons={}。
append_deamon(self,name,daemon):
has_daemon(self,name)
remove_daemon(self,name)
start_daemons(self):对于每一个self.daemons.values(),调用deamon.start().
stop_daemon(self,name),
stop_deamons(self).

而VMCDaemonFactory()这是一个工厂的设计。至于collection,或者是factory,等在设计模式中详细讨论之。有一个方法:build_daemon_collection(cls,device,notification_,manager)
首先构造一个collection由上面的类构造。对于不同的设置不同的freq.
建SignalQuanlityDaemon(),CellTypeDaemon如果条件允许,也即是在device的能力范围内。Append them
(signal,...),(conn_mode,...).

再来看看CLICollaborator和CLICollaboratorFactory类。先看Factory
他是为了实现ICollaboratorFactory的interface,which:声明了get_collaborator(self,device,view).
重新定义了接口参数:
get_collaborator(cls,device,*args,**kwds):返回CLICollaborator(device,*args,**kwds).

而这个CLICollaborator()的类是实现ICollaborator,which:单个接口:get_pin,get_puk,get_puk2.
有成员:__init__(self,device,config=None)
keyring:
config:
device:
pin:
puk:
puk2:除了device,和config来自参数,其他都是None.
有方法:
get_pin(self):如果self.config并且self.config['pin']存在,直接返回。否则,构造defer,
调用deferToThread()让用户输入。
get_puk(self):首先要输入pin,调用deferToThread(),并且用返回值作为waitForDeferred()的参数。
yield pin,什么意思?由pin.getResult()返回the pin.同样等待puk,yield it,取得the puk.
yield他们两个,返回。
get_puk = deferredGenerator(get_puk)什么意思啊?晕晕晕。
get_puk2(self):
和上面一样,只是puk换成puk2.

这里有很多机制并不了解,来自于twisted.internet.threads和defer这两个模块。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2016新书,和另一个Learning Python(最新第5版)不是同一个,书面相同 Paperback: 140 pages Publisher: Packt Publishing - ebooks Account (January 1, 2016) Language: English ISBN-10: 178528424X ISBN-13: 978-1785284243 Key Features Find out how to interact with Jenkins from within Eclipse, NetBeans, and IntelliJ IDEA Develop custom solutions that act upon Jenkins information in real time A step-by-step, practical guide to help you learn about extension points in existing plugins and how to build your own plugin Book Description Jenkins CI is the leading open source continuous integration server. It is written in Java and has a wealth of plugins to support the building and testing of virtually any project. Jenkins supports multiple Software Configuration Management tools such as Git, Subversion, and Mercurial. This book explores and explains the many extension points and customizations that Jenkins offers its users, and teaches you how to develop your own Jenkins extensions and plugins. First, you will learn how to adapt Jenkins and leverage its abilities to empower DevOps, Continuous Integration, Continuous Deployment, and Agile projects. Next, you will find out how to reduce the cost of modern software development, increase the quality of deliveries, and thereby reduce the time to market. We will also teach you how to create your own custom plugins using Extension points. Finally, we will show you how to combine everything you learned over the course of the book into one real-world scenario.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值