<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>蒙卓&#38;博客 &#187; Linux软件</title>
	<atom:link href="http://mengzhuo.org/blog/tag/linux%e8%bd%af%e4%bb%b6/feed" rel="self" type="application/rss+xml" />
	<link>http://mengzhuo.org/blog</link>
	<description>Just The Way It Was</description>
	<lastBuildDate>Fri, 27 Jan 2012 16:46:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>安装fakeshell最小化ssh用户权限</title>
		<link>http://mengzhuo.org/blog/%e5%ae%89%e8%a3%85fakeshell%e6%9c%80%e5%b0%8f%e5%8c%96ssh%e7%94%a8%e6%88%b7%e6%9d%83%e9%99%90.html</link>
		<comments>http://mengzhuo.org/blog/%e5%ae%89%e8%a3%85fakeshell%e6%9c%80%e5%b0%8f%e5%8c%96ssh%e7%94%a8%e6%88%b7%e6%9d%83%e9%99%90.html#comments</comments>
		<pubDate>Wed, 18 Jan 2012 16:08:11 +0000</pubDate>
		<dc:creator>mz</dc:creator>
				<category><![CDATA[阴]]></category>
		<category><![CDATA[雨]]></category>
		<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[折腾]]></category>
		<category><![CDATA[网站]]></category>

		<guid isPermaLink="false">http://mengzhuo.org/blog/?p=1444</guid>
		<description><![CDATA[因为新买的VPS跑网站（nginx+php-fastcgi）很吃力，可能是我配置得不好，配置邮件服务器我试了2次，都不行，所以干脆把新服务器改成了ssh代理站，至于用来干什么大家都很清楚哈。 但是Linux下新建的用户权限还是相当高，网上搜到的教程都是把shell指到/bin/false下的，文章连标点符号都一样，可见国内互联网环境有多差！抄就抄的吧，可我要是用这个方法链接刚开始就会自动退出了，所以，在github上找到个源码： github.com/xxlmira/fakeshell 完全符合我的要求，用户能登入，不需要其他动作，只需要添加即可。 这么方便？就看下面的教程吧。如果你知道什么是编译、用过make这种东西，下面的就不用看啦，哈哈。 安装fakeshell 因为是源码安装，所以肯定要有build-essential，然后下载上面的代码到自己的服务器上，并修改Makefile …… PROG= fakeshell SRCS= fakeshell.c BANNER= banner PREFIX= #原来是/usr/local 这里我喜欢用空值 PROVIDER= "mengzhuo.org" #改成你要的网站标题 ADMINS= "mengzhuo1203@gmail.com" #改成你要的管理员邮箱 CC= gcc …… 然后输入make &#038;&#038; make install即可，很容易吧。 配置用户 因为我只是想分发少量的帐号，毕竟这个服务器也不知道能撑到什么时候，所以就手动输入 useradd -s /bin/fakeshell test添加一个test用户 passwd test给test用户添加密码 到这里就好了，不敢相信吧~ 后记 登入后显示： Welcome to mengzhuo.org service on x200s! In case of any urgency, do not hesitate [...]]]></description>
			<content:encoded><![CDATA[<p>因为新买的VPS跑网站（nginx+php-fastcgi）很吃力，可能是我配置得不好，配置邮件服务器我试了2次，都不行，所以干脆把新服务器改成了ssh代理站，至于用来干什么大家都很清楚哈。<br />
但是Linux下新建的用户权限还是相当高，网上搜到的教程都是把shell指到/bin/false下的，文章连标点符号都一样，可见国内互联网环境有多差！抄就抄的吧，可我要是用这个方法链接刚开始就会自动退出了，所以，在github上找到个源码：<br />
<a href="https://github.com/xxlmira/fakeshell">github.com/xxlmira/fakeshell</a><br />
完全符合我的要求，用户能登入，不需要其他动作，只需要添加即可。<br />
这么方便？就看下面的教程吧。如果你知道什么是编译、用过make这种东西，下面的就不用看啦，哈哈。</p>
<h4>安装fakeshell</h4>
<p>因为是源码安装，所以肯定要有build-essential，然后下载上面的代码到自己的服务器上，并修改Makefile<br />
……</p>
<pre style="background:#F1F1F1">
PROG=		fakeshell
SRCS=		fakeshell.c
BANNER=		banner
PREFIX=		#原来是/usr/local 这里我喜欢用空值
PROVIDER=	"mengzhuo.org" #改成你要的网站标题
ADMINS=		"mengzhuo1203@gmail.com" #改成你要的管理员邮箱
CC=		gcc
</pre>
<p>……<span id="more-1444"></span><br />
然后输入<code>make &#038;&#038; make install</code>即可，很容易吧。</p>
<h4>配置用户</h4>
<p>因为我只是想分发少量的帐号，毕竟这个服务器也不知道能撑到什么时候，所以就手动输入<br />
<code>useradd -s /bin/fakeshell test</code>添加一个test用户<br />
<code>passwd test</code>给test用户添加密码</p>
<p>到这里就好了，不敢相信吧~</p>
<h4>后记</h4>
<p>登入后显示：</p>
<pre style="background:#F1F1F1">
Welcome to mengzhuo.org service on x200s!
In case of any urgency, do not hesitate to contact us at mengzhuo1203@gmail.com.
ls
What do you think I am, a shell?
^C
</pre>
<p>这个fakeshell确实很好，而且我还想给这个fakeshell加个uptime的功能，敬请期待<br />
<a href="https://github.com/mengzhuo/fakeshell">github.com/mengzhuo/fakeshell</a></p>
<blockquote><a title="安装fakeshell最小化ssh用户权限" href="http://mengzhuo.org/blog/%e5%ae%89%e8%a3%85fakeshell%e6%9c%80%e5%b0%8f%e5%8c%96ssh%e7%94%a8%e6%88%b7%e6%9d%83%e9%99%90.html">安装fakeshell最小化ssh用户权限</a> | <a title="蒙卓的博客，东西很杂" href="http://mengzhuo.org/blog/feed">订阅博客</a></blockquote><blockquote><small><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="保留权利声明">署名-非商业性使用-相同方式共享</a></small><blockquote>]]></content:encoded>
			<wfw:commentRss>http://mengzhuo.org/blog/%e5%ae%89%e8%a3%85fakeshell%e6%9c%80%e5%b0%8f%e5%8c%96ssh%e7%94%a8%e6%88%b7%e6%9d%83%e9%99%90.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>[python]豆瓣小组沙发机器人</title>
		<link>http://mengzhuo.org/blog/python%e8%b1%86%e7%93%a3%e5%b0%8f%e7%bb%84%e6%b2%99%e5%8f%91%e6%9c%ba%e5%99%a8%e4%ba%ba.html</link>
		<comments>http://mengzhuo.org/blog/python%e8%b1%86%e7%93%a3%e5%b0%8f%e7%bb%84%e6%b2%99%e5%8f%91%e6%9c%ba%e5%99%a8%e4%ba%ba.html#comments</comments>
		<pubDate>Sat, 03 Sep 2011 14:46:36 +0000</pubDate>
		<dc:creator>mz</dc:creator>
				<category><![CDATA[晴]]></category>
		<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[折腾]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://mengzhuo.org/blog/?p=1204</guid>
		<description><![CDATA[这玩意quick and dirty 点我下载 运行前参数要自己改源代码（CTRL+F搜索「#设置区域」） 如何获得小组ID？ 例如：B组的URL http://m.douban.com/group/17947/ group后面那串数字就是ID了。 运行前要修改代码 group_id = &#8216;小组ID填这里&#8217; #set refresh_interval refresh_interval = 1 #刷新的秒数（不过会有随机延迟，毕竟豆娘也不容易） #set sofa Content sofa_content = &#8216;沙发内容&#8217; data = {&#8216;form_email&#8217;:'注册邮件地址&#8217;, &#8216;form_password&#8217;:'密码&#8217;, &#8216;action&#8217;:'/&#8217;} 然后在终端输入：python douban.py，吼吼，就可以啦～ [python]豆瓣小组沙发机器人 &#124; 订阅博客署名-非商业性使用-相同方式共享]]></description>
			<content:encoded><![CDATA[<p><a href="http://mengzhuo.org/blog/wp-content/uploads/2011/09/2011-09-03-220616_1280x800_scrot1.png"><img class="size-large wp-image-1215 alignnone" title="2011-09-03-220616_1280x800_scrot" src="http://mengzhuo.org/blog/wp-content/uploads/2011/09/2011-09-03-220616_1280x800_scrot1-610x168.png" alt="" width="610" height="168" /></a><br />
这玩意quick and dirty</p>
<p><a href="http://mengzhuo.org/lab/file/douban_group_sofa_bot.py">点我下载</a><br />
运行前参数要自己改源代码（CTRL+F搜索「#设置区域」）<br />
如何获得小组ID？<br />
例如：B组的URL</p>
<blockquote><p>http://m.douban.com/group/17947/</p></blockquote>
<p>group后面那串数字就是ID了。</p>
<p>运行前要修改代码</p>
<blockquote><p>group_id = &#8216;小组ID填这里&#8217;<br />
#set refresh_interval<br />
refresh_interval = 1 #刷新的秒数（不过会有随机延迟，毕竟豆娘也不容易）<br />
#set sofa Content<br />
sofa_content = &#8216;沙发内容&#8217;<br />
data = {&#8216;form_email&#8217;:'注册邮件地址&#8217;, &#8216;form_password&#8217;:'密码&#8217;, &#8216;action&#8217;:'/&#8217;}</p></blockquote>
<p>然后在终端输入：<code>python douban.py</code>，吼吼，就可以啦～</p>
<blockquote><a title="[python]豆瓣小组沙发机器人" href="http://mengzhuo.org/blog/python%e8%b1%86%e7%93%a3%e5%b0%8f%e7%bb%84%e6%b2%99%e5%8f%91%e6%9c%ba%e5%99%a8%e4%ba%ba.html">[python]豆瓣小组沙发机器人</a> | <a title="蒙卓的博客，东西很杂" href="http://mengzhuo.org/blog/feed">订阅博客</a></blockquote><blockquote><small><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="保留权利声明">署名-非商业性使用-相同方式共享</a></small><blockquote>]]></content:encoded>
			<wfw:commentRss>http://mengzhuo.org/blog/python%e8%b1%86%e7%93%a3%e5%b0%8f%e7%bb%84%e6%b2%99%e5%8f%91%e6%9c%ba%e5%99%a8%e4%ba%ba.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>如何让Ubuntu启动提速50%与Upstart使用</title>
		<link>http://mengzhuo.org/blog/%e5%a6%82%e4%bd%95%e8%ae%a9ubuntu%e5%90%af%e5%8a%a8%e6%8f%90%e9%80%9f50%e4%b8%8eupstart%e4%bd%bf%e7%94%a8.html</link>
		<comments>http://mengzhuo.org/blog/%e5%a6%82%e4%bd%95%e8%ae%a9ubuntu%e5%90%af%e5%8a%a8%e6%8f%90%e9%80%9f50%e4%b8%8eupstart%e4%bd%bf%e7%94%a8.html#comments</comments>
		<pubDate>Thu, 18 Aug 2011 13:59:35 +0000</pubDate>
		<dc:creator>mz</dc:creator>
				<category><![CDATA[雨]]></category>
		<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[折腾]]></category>

		<guid isPermaLink="false">http://mengzhuo.org/blog/?p=1171</guid>
		<description><![CDATA[不得不说10.04以后的Canonical为了让Ubuntu启动速度加快下了相当大的功夫：不惜去掉传统的rc.X，init.d等，换成能并行启动处理的Upstart，还单独开发了ureadahead这个软件来预加载所有可能读到的文件。我觉得还是应该还真面目以正视听。我的机子按2011年的配置来说是相当老爷机和落伍了，可是启动经过调整后可以达到32秒 而且蓝牙、HAL、WIFI必须的程序没有移出启动队列。 首先得说说我的基本配置： ThinkPad X200s CPU：Intel Core2 SU3500-1.40GHz[单核] 内存：DDR3 1333 4GB 硬盘：HDD WDC WD2500BEVS 250GB 5400RPM 软件与平台： Ubuntu 10.04.3 LTS ureadahead 0.100.0 那么怎么做到的呢？ 了解Upstart 也许你也发现在10.04以后版本的Ubuntu中每次通过init.d启动程序，例如 /etc/init.d/mysql start Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service mysql start Since the script you are attempting to invoke has been converted to an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/x200s-lucid-20110818-6.png" alt="" title="x200s-lucid-20110818-6" width="473" height="99" class="size-full wp-image-1192" /><br />
不得不说10.04以后的Canonical为了让Ubuntu启动速度加快下了相当大的功夫：不惜去掉传统的rc.X，init.d等，换成能并行启动处理的Upstart，还单独开发了ureadahead这个软件来预加载所有可能读到的文件。我觉得还是应该还真面目以正视听。我的机子按2011年的配置来说是相当老爷机和落伍了，可是启动经过调整后可以<strong>达到32秒</strong><br />
而且<strong>蓝牙、HAL、WIFI必须的程序没有移出启动队列</strong>。<br />
首先得说说我的基本配置：</p>
<blockquote><p>ThinkPad X200s<br />
CPU：Intel Core2 SU3500-1.40GHz[单核]<br />
内存：DDR3 1333 4GB<br />
硬盘：HDD WDC WD2500BEVS 250GB 5400RPM
</p></blockquote>
<p>软件与平台：</p>
<blockquote><p>Ubuntu 10.04.3 LTS<br />
ureadahead 0.100.0
</p></blockquote>
<p>那么怎么做到的呢？<br />
<span id="more-1171"></span></p>
<h4>了解Upstart</h4>
<p>也许你也发现在10.04以后版本的Ubuntu中每次通过init.d启动程序，例如</p>
<blockquote><p>/etc/init.d/mysql start<br />
Rather than invoking init scripts through /etc/init.d, use the service(8)<br />
utility, e.g. service mysql start</p>
<p>Since the script you are attempting to invoke has been converted to an<br />
Upstart job, you may also use the start(8) utility, e.g. start mysql</p></blockquote>
<p>这是因为Ubuntu使用Upstart作为「启动控制器」，这样的好处就是可以「<strong>并行</strong>」启动，而以往的启动是是单一「线性」的，就好比老的启动方法是单行线，而Upstart是六车道。但是，太多程序在打包进源的时候，并没有将配置文件改写成Upstart使用的样式——继续用老式的启动方法，Upstart因为兼容老式方法，被拖累后并背黑锅。那么怎么分析启动项呢？那么就得搬出神器bootchart</p>
<h4>使用bootchart分析启动项</h4>
<p><a href="http://mengzhuo.org/blog/wp-content/uploads/2011/08/x200s-lucid-20110818-1.png"><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/x200s-lucid-20110818-1.png" alt="" title="x200s-lucid-20110818-1" width="491" height="217" class="alignnone size-full wp-image-1177" /></a><br />
（注：中间绿色部分是为了排版方便而缩小的，两端为正常分辨率）<br />
可以看出我原来的启动时间是65秒左右，自从内核加载以来的粉红色的Disk Thoughout(磁盘读写总量)一直是满的，即磁盘在启动后一直没停过小文件的读写，上面还有磁盘的峰值读写速度为44MB/s。而后下面长长的列表中发现一些网站调试使用的apache、mysql之类平时不需要的项，但是<strong>使用老的管理器已经无法停止其启动的程序</strong>。那么要停止它启动载入才行，由于网上以讹传讹地是要注释掉/etc/init/*.conf中启动的那几行就可以了，但是我觉得这真TM是胡说！应该查明当前的启动等级，例如</p>
<blockquote><p>$ runlevel<br />
N 2
</p></blockquote>
<p>说明我目前以启动等级2启动，N(Normal)属于正常启动。<br />
再进行修改Upstart配置文件才行。</p>
<h4>Upstart配置文件部分分析</h4>
<p>启动部分是本文重点，因此举个常见的，「很难」去除的Mysql作为例子：</p>
<blockquote><p>start on (net-device-up<br />
          and local-filesystems<br />
	  and runlevel [345])<br />
stop on runlevel [016]</p></blockquote>
<p>和你的<code>/etc/init/mysql.conf</code>比较一下，我只是去掉了2这个runlevel中的数字，多简单啊！mysql就不会在正常启动的时候运行了。</p>
<p>而且这个配置文件还可以安排启动顺序，例如我的hald <code>/etc/init/hald.conf</code>启动项：</p>
<blockquote><p>start on (local-filesystems<br />
	  and started dbus<br />
	  and runlevel [2345])<br />
stop on runlevel [016]</p>
<p>exec /usr/sbin/hald &#8211;daemon=yes</p>
</blockquote>
<p>这样在dbus启动后并行启动hald，启动等级是[2345]，这样就不必在rc.local中拖Upstart的后腿了。<br />
注：
<ul>
<li>可以删除一些/etc/init/tty*.conf来减少tty的量，也加快一些加载速度。</li>
<li>调整一些程序的启动顺序，比如让mysql、gdm也在dbus之后启动的话，对于多线程的CPU应该会更快点</li>
<li>删除plymouth(加载的画面主题)也是个好办法</li>
</ul>
<h4>为ureadahead正名</h4>
<p>很多人认为ureadahead只是为SSD准备的，但是事实如图（为方便排版已缩小）：<a href="http://mengzhuo.org/blog/wp-content/uploads/2011/08/x200s-lucid-20110818-3.png"><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/x200s-lucid-20110818-3.png" alt="" title="x200s-lucid-20110818-3" width="576" height="189" class="alignnone size-full wp-image-1185" /></a><br />
<a href="http://mengzhuo.org/blog/wp-content/uploads/2011/08/5.png"><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/5.png" alt="" title="5" width="160" height="60" class="alignright size-full wp-image-1189" /></a><br />
可以看出ureadahead启动之完成后，磁盘的读写顿时下降，而且峰值已经从之前的44MB/s增至77MB/s，速度瞬间少了20秒，当然……取而代之的是CPU的用量猛增。要注意修改内核或启动项之后，下一次的启动会相当慢，但是想想这种机会应该比较少吧。</p>
<h4>小总结</h4>
<p>可见技术在发展，速度自然是越来越快的，欢迎大家提出优化得更好的启动方案。</p>
<blockquote><a title="如何让Ubuntu启动提速50%与Upstart使用" href="http://mengzhuo.org/blog/%e5%a6%82%e4%bd%95%e8%ae%a9ubuntu%e5%90%af%e5%8a%a8%e6%8f%90%e9%80%9f50%e4%b8%8eupstart%e4%bd%bf%e7%94%a8.html">如何让Ubuntu启动提速50%与Upstart使用</a> | <a title="蒙卓的博客，东西很杂" href="http://mengzhuo.org/blog/feed">订阅博客</a></blockquote><blockquote><small><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="保留权利声明">署名-非商业性使用-相同方式共享</a></small><blockquote>]]></content:encoded>
			<wfw:commentRss>http://mengzhuo.org/blog/%e5%a6%82%e4%bd%95%e8%ae%a9ubuntu%e5%90%af%e5%8a%a8%e6%8f%90%e9%80%9f50%e4%b8%8eupstart%e4%bd%bf%e7%94%a8.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rhythmbox插件编写教程指北</title>
		<link>http://mengzhuo.org/blog/rhythmbox%e6%8f%92%e4%bb%b6%e7%bc%96%e5%86%99%e6%95%99%e7%a8%8b%e6%8c%87%e5%8c%97.html</link>
		<comments>http://mengzhuo.org/blog/rhythmbox%e6%8f%92%e4%bb%b6%e7%bc%96%e5%86%99%e6%95%99%e7%a8%8b%e6%8c%87%e5%8c%97.html#comments</comments>
		<pubDate>Fri, 12 Aug 2011 07:58:39 +0000</pubDate>
		<dc:creator>mz</dc:creator>
				<category><![CDATA[阴]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Rhythmbox]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[折腾]]></category>

		<guid isPermaLink="false">http://mengzhuo.org/blog/?p=1093</guid>
		<description><![CDATA[写了个Rhythmbox的插件以后才发现这方面的中文教程简直是0的状态（百度连鸟语的都不知道），介于我是python新手，C语言全部还给老师了，所以不敢说这篇文章是指南，权当这是中文关于Rhythmbox插件编写的0.5篇文章吧。具体的最好还要参考Rhythmbox官方的指南 ++++++++++++++ 示例的源代码 ++++++++++++++ 首先，想好一个插件名字吧 教程里，我就用「RB_notify」。 要清楚用python写Rhythmbox的插件机制其实很简单——写好两个文件就可以成个插件 RB_notify.rb-plugin和__init__.py 前者负责解释你这插件叫啥、作者是谁等，后者是程序的入口，把他们放到$HOME/.gnome2/rhythmbox/plugins/notify里面就可以运行了，很简单是吧。 翻翻notify.rb-plugin [RB Plugin] Loader=python Module=RB_notify IAge=1 Name=RB Plugin Example Name[zh_CN]=RB插件例子 Description=This is an example of RB Plugin Description[zh_CN]=这是个RB插件例子 Authors=Meng Zhuo Copyright=2011 © Meng Zhuo Website=http://mengzhuo.org/blog/ 这个是插件描述文件，由于我们插件是python写的，所以前面的4个参数都不能修改，而Module后面的跟的是需要加载模块，这里和项目同名就好了。后面几个都不言自明了，所以很简单吧。光说你的插件是干啥的自然是不行，得用程序让Rhythmbox听话。 __init.py__程序登场 写过python程序的同学都清楚，大部分程序第一步是导入一定量的库，这样才能正常运行，我们的Rhythmbox程序也一样： import rb 这个语句是必须的，因为这个库是Rhythmbox的缩写。其他的库像 gconf（需要配置的话）【教程】 gtk（需要图形的话）教程 gettext（推荐import，国际化用）教程同上 这里我们就只使用rb吧，这时候程序应该是这个样子的： __init__函数是入口函数，每次插件运行的时候都先运行一遍里面的程序，里面一般第一句是添加self为RB插件的类。rb.Plugin.__init__(self) activate函数是插件启动的时候执行的程序，这里就用简单的print吧 deactivate函数是插件关闭或者Rhythmbox退出的时候执行的程序，理论上之前创建了什么东西，就得销毁掉（用del命令)，不赘述了。 检验成果的时候到了！ 运行Rhythmbox -D RB_notify 打开插件栏，这时候就可以看见你的插件了。 启动插件后就会在刚才运行命令的终端里出现 (15:36:44) [0x6ea040] [...]]]></description>
			<content:encoded><![CDATA[<p>写了个Rhythmbox的插件以后才发现这方面的中文教程简直是0的状态（百度连鸟语的都不知道），介于我是python新手，C语言全部还给老师了，所以不敢说这篇文章是指南，权当这是中文关于Rhythmbox插件编写的0.5篇文章吧。<a href="http://live.gnome.org/RhythmboxPlugins/WritingGuide">具体的最好还要参考Rhythmbox官方的指南</a><br />
++++++++++++++<br />
<a href='http://mengzhuo.org/lab/file/RB_notify.tar.gz' >示例的源代码</a><br />
++++++++++++++</p>
<h4>首先，想好一个插件名字吧</h4>
<p>教程里，我就用「RB_notify」。<br />
要清楚用python写Rhythmbox的插件机制其实很简单——写好两个文件就可以成个插件<br />
<code>RB_notify.rb-plugin</code>和<code>__init__.py</code><br />
前者负责解释你这插件叫啥、作者是谁等，后者是程序的入口，把他们放到$HOME/.gnome2/rhythmbox/plugins/notify里面就可以运行了，很简单是吧。</p>
<h4>翻翻notify.rb-plugin</h4>
<blockquote><p>[RB Plugin]<br />
Loader=python<br />
Module=RB_notify<br />
IAge=1<br />
Name=RB Plugin Example<br />
Name[zh_CN]=RB插件例子<br />
Description=This is an example of RB Plugin<br />
Description[zh_CN]=这是个RB插件例子<br />
Authors=Meng Zhuo <mengzhuo1203 @gmail.com><br />
Copyright=2011 © Meng Zhuo<br />
Website=http://mengzhuo.org/blog/</mengzhuo1203></p></blockquote>
<p>这个是插件描述文件，由于我们插件是python写的，所以前面的4个参数都不能修改，而Module后面的跟的是需要加载模块，这里和项目同名就好了。后面几个都不言自明了，所以很简单吧。光说你的插件是干啥的自然是不行，得用程序让Rhythmbox听话。</p>
<h4>__init.py__程序登场</h4>
<p>写过python程序的同学都清楚，大部分程序第一步是导入一定量的库，这样才能正常运行，我们的Rhythmbox程序也一样：</p>
<blockquote><p>import rb</p></blockquote>
<p>这个语句是必须的，因为这个库是Rhythmbox的缩写。其他的库像
<ul>
<li>gconf（需要配置的话）<del datetime="2011-08-12T02:28:03+00:00">【教程】</del></li>
<li>gtk（需要图形的话）<a href="http://qixinglu.com/archives/python_and_glade_file_i18n_guide" target="_blank">教程</a></li>
<li>gettext（推荐import，国际化用）教程同上</li>
</ul>
<p>这里我们就只使用rb吧，这时候程序应该是这个样子的：<a href="http://mengzhuo.org/blog/wp-content/uploads/2011/08/Screenshot-__init__.py-.gnome2-rhythmbox-plugins-RB_notify-gedit.png"><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/Screenshot-__init__.py-.gnome2-rhythmbox-plugins-RB_notify-gedit-300x164.png" alt="" title="Screenshot-*__init__.py (~-.gnome2-rhythmbox-plugins-RB_notify) - gedit" width="300" height="164" class="alignnone size-medium wp-image-1121" /></a></p>
<ul>
<li>__init__函数是入口函数，每次插件运行的时候都先运行一遍里面的程序，里面一般第一句是添加self为RB插件的类。<code>rb.Plugin.__init__(self)</code></li>
<li>activate函数是插件启动的时候执行的程序，这里就用简单的print吧</li>
<li>deactivate函数是插件关闭或者Rhythmbox退出的时候执行的程序，理论上之前创建了什么东西，就得销毁掉（用del命令)，不赘述了。</li>
</ul>
<h4>检验成果的时候到了！</h4>
<p>运行<code>Rhythmbox -D RB_notify</code><br />
打开插件栏，这时候就可以看见你的插件了。<a href="http://mengzhuo.org/blog/wp-content/uploads/2011/08/Screenshot-配置插件.png"><img src="http://mengzhuo.org/blog/wp-content/uploads/2011/08/Screenshot-配置插件-300x183.png" alt="" title="Screenshot-配置插件" width="300" height="183" class="alignnone size-medium wp-image-1122" /></a><br />
启动插件后就会在刚才运行命令的终端里出现<br />
<code>(15:36:44) [0x6ea040] [RB_notify.activate] .gnome2/rhythmbox/plugins/RB_notify/__init__.py:15: Hello, This is a Example<br />
</code></p>
<h4>做些有用的事</h4>
<p>光是在终端里输出一些字符可不是什么有趣的事，所以要介绍RB牛X的地方，在于它的shell。在刚才的print后面添加<br />
<code>shell.props.shell_player.playpause(0)</code><br />
这样，每次启动插件，这个RB就会暂停或者是播放。<br />
当然这个shell没有这么简单，不只能控制播放、音量等，还能UI什么的，大家可以去<a href="http://developer.gnome.org/rhythmbox/unstable/RBShellPlayer.html">他们的官网</a>围观哈</p>
<blockquote><a title="Rhythmbox插件编写教程指北" href="http://mengzhuo.org/blog/rhythmbox%e6%8f%92%e4%bb%b6%e7%bc%96%e5%86%99%e6%95%99%e7%a8%8b%e6%8c%87%e5%8c%97.html">Rhythmbox插件编写教程指北</a> | <a title="蒙卓的博客，东西很杂" href="http://mengzhuo.org/blog/feed">订阅博客</a></blockquote><blockquote><small><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="保留权利声明">署名-非商业性使用-相同方式共享</a></small><blockquote>]]></content:encoded>
			<wfw:commentRss>http://mengzhuo.org/blog/rhythmbox%e6%8f%92%e4%bb%b6%e7%bc%96%e5%86%99%e6%95%99%e7%a8%8b%e6%8c%87%e5%8c%97.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rhythmbox小插件-耳机意外防止器</title>
		<link>http://mengzhuo.org/blog/rhythmbox%e5%b0%8f%e6%8f%92%e4%bb%b6-%e8%80%b3%e6%9c%ba%e6%84%8f%e5%a4%96%e9%98%b2%e6%ad%a2%e5%99%a8.html</link>
		<comments>http://mengzhuo.org/blog/rhythmbox%e5%b0%8f%e6%8f%92%e4%bb%b6-%e8%80%b3%e6%9c%ba%e6%84%8f%e5%a4%96%e9%98%b2%e6%ad%a2%e5%99%a8.html#comments</comments>
		<pubDate>Wed, 29 Jun 2011 07:39:33 +0000</pubDate>
		<dc:creator>mz</dc:creator>
				<category><![CDATA[雨]]></category>
		<category><![CDATA[Linux软件]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[技术]]></category>

		<guid isPermaLink="false">http://mengzhuo.org/blog/?p=1069</guid>
		<description><![CDATA[不知道Rhythmbox是什么的童鞋，请无视这篇发布文章 用途请看图（画了1个小时……木有美术细胞没办法），其实这个问题我一直想找个插件，可是就是没有，只好自己做了。DEB下载地址 重新插上耳机的时候会自动地恢复播放 惯例一些废话： 这个插件用的是Python+dbus，所以，如果你的耳机插孔没有被系统识别那我也没办法，目前我的X200上一切正常，理论上应该是支持所有耳机插孔的。 插件有时会导致Rhythmbox卡死（原因未知……但不是BUG……），请清除插件目录下的.pyc文件，重启Rhythmbox。 至于名字嘛……我真的想不出更好的了，有好的名字可以请发到我邮箱 Rhythmbox小插件-耳机意外防止器 &#124; 订阅博客署名-非商业性使用-相同方式共享]]></description>
			<content:encoded><![CDATA[<p>不知道Rhythmbox是什么的童鞋，请无视这篇发布文章<br />
用途请看图（画了1个小时……木有美术细胞没办法），其实这个问题我一直想找个插件，可是就是没有，只好自己做了。<a href="http://mengzhuo.org/lab/EP4Rhythmbox/rhythmbox-plugin-earphone_last_version_all.deb">DEB下载地址</a><br />
<img class="alignnone" title="EP4Rhythmbox" src="http://mengzhuo.org/lab/EP4Rhythmbox/top.png" alt="" width="550" height="311" /></p>
<p><strong>重新插上耳机的时候会自动地恢复播放</strong></p>
<p>惯例一些废话：
<ul>
<li>这个插件用的是Python+dbus，所以，如果你的耳机插孔没有被系统识别那我也没办法，目前我的X200上一切正常，理论上应该是支持所有耳机插孔的。</li>
<li>插件有时会导致Rhythmbox卡死（原因未知……但不是BUG……），请清除插件目录下的.pyc文件，重启Rhythmbox。</li>
<li>至于名字嘛……我真的想不出更好的了，有好的名字可以请发到我邮箱</li>
</ul>
<blockquote><a title="Rhythmbox小插件-耳机意外防止器" href="http://mengzhuo.org/blog/rhythmbox%e5%b0%8f%e6%8f%92%e4%bb%b6-%e8%80%b3%e6%9c%ba%e6%84%8f%e5%a4%96%e9%98%b2%e6%ad%a2%e5%99%a8.html">Rhythmbox小插件-耳机意外防止器</a> | <a title="蒙卓的博客，东西很杂" href="http://mengzhuo.org/blog/feed">订阅博客</a></blockquote><blockquote><small><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/deed.zh" title="保留权利声明">署名-非商业性使用-相同方式共享</a></small><blockquote>]]></content:encoded>
			<wfw:commentRss>http://mengzhuo.org/blog/rhythmbox%e5%b0%8f%e6%8f%92%e4%bb%b6-%e8%80%b3%e6%9c%ba%e6%84%8f%e5%a4%96%e9%98%b2%e6%ad%a2%e5%99%a8.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

