<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5542064418961639741</atom:id><lastBuildDate>Sat, 21 Sep 2024 12:29:40 +0000</lastBuildDate><category>Python</category><category>Mac</category><category>Emacs</category><category>Linux</category><category>Greasemonkey</category><category>database</category><category>Firefox</category><category>Mercurial</category><category>Twitter</category><category>iPhone</category><category>misc</category><category>Blogger</category><category>Common Lisp</category><category>Google</category><category>数学</category><category>Zsh</category><category>JavaScript</category><category>Terminal</category><category>Visualization</category><category>ecto</category><category>munin</category><category>Django</category><category>Erlang</category><category>GUI</category><category>Git</category><category>Java</category><category>XML</category><category>nginx</category><category>Android</category><category>Book</category><category>Cassandra</category><category>Dell</category><category>Facebook</category><category>Haskell</category><category>JBoss</category><category>LaTeX</category><category>Leopard</category><category>MarsEdit</category><category>MongoDB</category><category>MySQL</category><category>Programming</category><category>Qt</category><category>Riak</category><category>Scala</category><category>Tumblr</category><category>identi.ca</category><category>ifttt</category><category>screen</category><category>tmux</category><category>不採用</category><title>技術的生存報告記</title><description>このblogは、著者である「&lt;a href=&quot;http://sakito.jp&quot;&gt;sakito&lt;/a&gt;」が技術的に生存している事を報告するために存在します&lt;br&gt;&#xa;タイトルを「紹介マニアどらふと版」から変更しました</description><link>http://www.sakito.com/</link><managingEditor>noreply@blogger.com (sakito)</managingEditor><generator>Blogger</generator><openSearch:totalResults>164</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-2805048959756103101</guid><pubDate>Fri, 08 Apr 2016 14:01:00 +0000</pubDate><atom:updated>2016-04-08T23:01:47.180+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">misc</category><title>タイトル変更</title><description>&lt;p&gt;
タイトル変更しました。&lt;br /&gt;
ついでに、一部bootstrapを利用してレイアウト崩れを防ぐようにしてみました。&lt;br /&gt;
記事はまた思いついた時にでも投稿してみます。
&lt;/p&gt;</description><link>http://www.sakito.com/2016/04/blog-post_8.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-3241909587479547820</guid><pubDate>Sun, 08 Feb 2015 21:39:00 +0000</pubDate><atom:updated>2015-02-10T05:56:43.569+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mac</category><category domain="http://www.blogger.com/atom/ns#">Terminal</category><title>Mac OS X で porg を使って &amp;quot;make install&amp;quot;したソフトを管理する</title><description>&lt;p&gt;
&lt;a href=&quot;http://porg.sourceforge.net/&quot;&gt;Porg&lt;/a&gt;は「make install」でインストールされるファイルの記録を取り、後で削除したりするのを簡単にするためのソフトです。&lt;br&gt;
以前は Paco と言う名前でしたので、Paco に関する記事を見ると良いです。&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://d.hatena.ne.jp/rx7/20081011/p2&quot;&gt;&amp;quot;make install&amp;quot;したソフトウェアを管理できる超便利ツール「Paco」 - 元RX-7乗りの適当な日々&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;こういうのは MacPortsとかHomebrewとかを使うのが普通なのですが、make install も結構してしまうので使うと便利です。&lt;/p&gt;
&lt;h4&gt;porgのインストール&lt;/h4&gt;
&lt;p&gt;
porg の最新版をダウンロードします。この記事を記述している時点だと「0.7」です。
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;curl -LO http://downloads.sourceforge.net/project/porg/porg-0.7.tar.gz
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
Mac で正常に動作させるにはパッチが必要ですのでダウンロードします。
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;curl -LO https://trac.macports.org/raw-attachment/ticket/46702/adapt-to-osx.patch
curl -LO https://trac.macports.org/raw-attachment/ticket/46702/patch-doubleDESTDIR.diff
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;コンパイルします。gropというGUIツールを一緒にインストールしようとしますが、わたしは使わないのでdisable しておきます。ためしたい人は gtkmm をインストールすると使えるはずです。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;tar xvf porg-0.7.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;porg-0.7

&lt;span class=&quot;c&quot;&gt;# パッチを当てます&lt;/span&gt;
patch -p0 &amp;lt; ../adapt-to-osx.patch
patch -p0 &amp;lt; ../patch-doubleDESTDIR.diff

&lt;span class=&quot;c&quot;&gt;# disable-grop します&lt;/span&gt;
./configure --disable-grop
make
sudo make install
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;
「/usr/local/bin」にインストールされるので PATH を通しておいてください。
&lt;/p&gt;
&lt;p&gt;
動作確認をします。動作確認には、porg に porg 自身を登録します。
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo make logme
porg -a
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
「-a」で管理パッケージ一覧が表示できます。無事 porg 自身が表示できていればインストールに問題ないです。&lt;br&gt;
パッチを当てれば Mac でも動作します。
&lt;/p&gt;
&lt;h4&gt;2015/02/09 追記&lt;/h4&gt;
&lt;p&gt;どうやら上手く追加できない物が結構あるみたいなので確認中。&lt;/p&gt;
&lt;p&gt;パッチを追記。&lt;/p&gt;
</description><link>http://www.sakito.com/2015/02/mac-os-x-porg-install.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-6163593860115953757</guid><pubDate>Sat, 07 Feb 2015 14:15:00 +0000</pubDate><atom:updated>2015-02-07T23:15:22.327+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Git</category><title>github から https 経由の clone 時にエラーが発生する場合の対処</title><description>&lt;p&gt;
github で git clone 等を実施した時に以下のようなエラーが発生した場合の対処。
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;fatal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unable&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;access&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://github.com/xxxx/yyyy&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SSL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;certificate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;problem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Invalid&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;certificate&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;chain&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;キーチェンアクセスの確認&lt;/h4&gt;
&lt;p&gt;
「アプリケーション」-&gt;「ユーティリティ」-&gt;「キーチェンアクセス」を起動。
&lt;/p&gt;
&lt;p&gt;
「システムルール」の中から「DigiCert High Assurance EV Root CA」を探して「有効期限」を確認します。
&lt;/p&gt;
&lt;p&gt;
おそらく有効期限が切れていると思います。
&lt;/p&gt;
&lt;h4&gt;証明書の更新&lt;/h4&gt;
&lt;p&gt;
以下のサイトにアクセスします。&lt;br&gt;
&lt;a href=&quot;https://www.digicert.com/digicert-root-certificates.htm#roots&quot;&gt;https://www.digicert.com/digicert-root-certificates.htm#roots&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
「DigiCert High Assurance EV Root CA」の「Download」リンク先を「右クリック」で保存してください。リンクを単純にクリックすると、ブラウザにインストールしようとしていまい、エラーが出てしまうので注意。
&lt;/p&gt;
&lt;p&gt;
ダウンロードできた「crt」ファイルをダブルクリックすると、証明書が更新されます。有効期限が更新された事を確認してください。
&lt;/p&gt;
&lt;p&gt;
git clone を実施して、問題ない事を確認してください。
&lt;/p&gt;
&lt;p&gt;
以上です。
&lt;/p&gt;
</description><link>http://www.sakito.com/2015/02/github-https-clone.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-4599064482148286009</guid><pubDate>Sun, 21 Apr 2013 21:00:00 +0000</pubDate><atom:updated>2013-04-22T06:00:02.951+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">Tumblr</category><title>Tumblr API v2 を利用する</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;TumblrのAPIを突然利用したくなったので、利用方法をメモする。&lt;/p&gt;

&lt;h4&gt;OAuth Key の取得&lt;/h4&gt;
&lt;p&gt;API を利用するには Twitter 等と同様 アプリケーションを登録して OAuth Keyを取得する必要がある。&lt;br /&gt;
プリの登録は、「&lt;a href=&quot;http://www.tumblr.com/oauth/apps&quot;&gt;http://www.tumblr.com/oauth/apps&lt;/a&gt;」で行なう。&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://lh6.ggpht.com/-mIcWpgtmHK8/UXOCRoTkt-I/AAAAAAAAAG8/Sf4JRXJFOo4/tumblr_reg_app.png?imgmax=800&quot; alt=&quot;Tumblr Register application&quot; title=&quot;tumblr_reg_app.png&quot; border=&quot;0&quot; width=&quot;500&quot; height=&quot;508&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;「Register application」ボタンで登録。&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://lh6.ggpht.com/-Uxq92VMYKqo/UXOCSPEm1gI/AAAAAAAAAHE/W-0BHk1ev4c/tumblr_reg_app_name.png?imgmax=800&quot; alt=&quot;Tumblr reg app name&quot; title=&quot;tumblr_reg_app_name.png&quot; border=&quot;0&quot; width=&quot;298&quot; height=&quot;518&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;「Application name」、「Administrative contact email」、「Default callback URL」が必須なので入力する。&lt;br /&gt;
登録内容は後でも変更できる。callback URL はとりあえず自分のサイト等にしておけば良い。&lt;/p&gt;
&lt;p&gt;登録が完了すると、「OAuth Consumer Key」、「Secret Key」が取れる。&lt;/p&gt;

&lt;h4&gt;クライアントアプリケーション作成&lt;/h4&gt;
&lt;p&gt;クライアントアプリケーショを作成する。&lt;br /&gt;
Python で rauth を利用して認証と表示までしたサンプルが以下。実際に利用する場合は「OAuth Consumer Key」、「Secret Key」を自分の物に変更する。&lt;br /&gt;
rauth は OAuth を簡単に処理する外部ライブラリでかなり便利。「pip install rauth」などであらかじめインストールしておくこと。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unittest&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;re&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;webbrowser&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ConfigParser&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SafeConfigParser&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;rauth&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OAuth1Service&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TumblrClientTest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Tumblr クライアントサンプルテスト&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        テスト&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TumblrClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# sessin の取得&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# user/info 取得&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;user/info&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;meta&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;meta&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;msg&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;OK&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# blog/info 取得&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;blog/scipsy.tumblr.com/info?api_key={api_key}&amp;#39;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;api_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_api_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;meta&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;status&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;meta&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;msg&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;OK&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;response&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;blog&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;scipsy&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TumblrClient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    Tumblr クライアントサンプル&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_api_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        API key = OAuth Consumer Key&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;OAuth Consumer Key&amp;#39;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_consumer_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        Secret Key&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Secret Key&amp;#39;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;get_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        session の取得&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# 設定ファイルのパス&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;abspath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dirname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__file__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;tumblr.cfg&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OAuth1Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;tumblr&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;consumer_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_api_key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;consumer_secret&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_consumer_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;request_token_url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;https://www.tumblr.com/oauth/request_token&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;access_token_url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;https://www.tumblr.com/oauth/access_token&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;authorize_url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;https://www.tumblr.com/oauth/authorize&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;base_url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;https://api.tumblr.com/v2/&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;c&quot;&gt;# 設定ファイルが存在する場合、設定ファイル読み込み&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SafeConfigParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;access_token&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;access_token_secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;account&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;access_token_secret&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;access_token_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;c&quot;&gt;# 設定ファイルが存在しない場合、初回認証&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

            &lt;span class=&quot;c&quot;&gt;# 設定ファイル出力&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SafeConfigParser&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;sec_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;account&amp;#39;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_section&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sec_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sec_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;access_token&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sec_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;access_token_secret&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                       &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;wb&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;configfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;configfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        ブラウザでの初回認証&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;request_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request_token_secret&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_request_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;authorize_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_authorize_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;表示されたURLをブラウザで開きます: &amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;authorize_url&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;webbrowser&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;authorize_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;authed_url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;ブラウザアドレスバーのURLをペースとしてください: &amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;verifier&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r&amp;#39;\oauth_verifier=([^#]*)&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;authed_url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# session 取得&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tumblr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get_auth_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;request_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;request_token_secret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;POST&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;oauth_verifier&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;verifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;session&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;
正しく認証されていると、設定画面の「Apps」に登録したアプリが表示される。
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://lh6.ggpht.com/-iEsl8JaMfXw/UXOCSvH44CI/AAAAAAAAAHM/JD8A3hZNvvg/tumblr_apps.png?imgmax=800&quot; alt=&quot;Tumblr apps&quot; title=&quot;tumblr_apps.png&quot; border=&quot;0&quot; width=&quot;513&quot; height=&quot;316&quot; /&gt;
&lt;/p&gt;
&lt;h4&gt;API のドキュメント&lt;/h4&gt;
&lt;p&gt;公式 APIドキュメントが「&lt;a href=&quot;http://www.tumblr.com/docs/en/api/v2&quot;&gt;http://www.tumblr.com/docs/en/api/v2&lt;/a&gt;」に存在するので、あとは必要な物を利用するだけ。&lt;/p&gt;</description><link>http://www.sakito.com/2013/04/tumblr-api-v2.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/-mIcWpgtmHK8/UXOCRoTkt-I/AAAAAAAAAG8/Sf4JRXJFOo4/s72-c/tumblr_reg_app.png?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-8346923470327024347</guid><pubDate>Mon, 01 Apr 2013 21:00:00 +0000</pubDate><atom:updated>2013-04-02T06:00:00.580+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>matplotlib 1.2.1 コンパイル時に Tk 8.5 must be compiled with tcl.h from Tcl 8.5 のエラー</title><description>&lt;h4&gt;現象&lt;/h4&gt;
&lt;p&gt;「Tk 8.5 must be compiled with tcl.h from Tcl 8.5」のエラーは Tcl 8.4 と 8.5 が同居している場合に発生する。&lt;br /&gt;
Mac OS X の場合、MacPorts や Homebrew、ActiveTck なんかをインストールしている環境で発生しやすい。&lt;br /&gt;
Linux 系の場合、パスの設定が変になっている可能性がある。&lt;/p&gt;
&lt;h4&gt;対処&lt;/h4&gt;
&lt;p&gt;Mac OS X の場合は、tkagg を利用しないのが一番簡単だと思う。&lt;br /&gt;
setup.cfg に以下のように設定してコンパイルすれば良い。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gui_support&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;tkagg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;本来は根源的に解決すべきだが、とりあえずはこれでも大体の場合は困らない。&lt;br /&gt;
ただ tkagg を必要とする場合は、別途考える必要があるかも。&lt;/p&gt;</description><link>http://www.sakito.com/2013/04/matplotlib-121-tk-85-must-be-compiled.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-2814663720991112895</guid><pubDate>Tue, 04 Dec 2012 21:00:00 +0000</pubDate><atom:updated>2012-12-05T06:00:05.535+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Erlang</category><category domain="http://www.blogger.com/atom/ns#">Riak</category><title>Riak コンパイルメモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Erlang で実装されたNoSQL系のデータベース「&lt;a href=&quot;http://basho.com/products/riak-overview/&quot;&gt;Riak&lt;/a&gt;」の先端をコンパイルする手順メモ。&lt;/p&gt;
&lt;h4&gt;手順&lt;/h4&gt;
&lt;p&gt;コンパイルする場合 Erlang と Git コマンドが必須なのでパスに存在するか確認しておく。&lt;/p&gt;
&lt;p&gt;Riak はビルドに「&lt;a href=&quot;https://github.com/basho/rebar&quot;&gt;rebar&lt;/a&gt;」を利用している。最新である必要は特にないが、これもコンパイルしておく。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git cline git://github.com/basho/rebar.git
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;rebar
./bootstrap
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Mac OS Xでコンパイルしているが、環境変数に UNICODE が含まれていると認識されコンパイルエラーになった。&lt;br /&gt;
「&lt;a href=&quot;https://github.com/l4u/rebar-1/commit/61c353dcfdafb87107cc5472709d229c26a8cb6c&quot;&gt;Support environment vars with unicode characters · 61c353d · l4u/rebar-1 · GitHub&lt;/a&gt;」のパッチをあてたら通過した。&lt;/p&gt;
&lt;p&gt;Riak 本体をコンパイルする。rebar のコピーを忘れないようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/basho/riak.git
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;riak
cp /path/to/rebar .
make rel
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;関連ライブラリが Git で clone されてコンパイルされるので、環境によっては時間かかる。&lt;br /&gt;
途中でコンパイルエラーにたまになったので、rebarのバイナリコピーしてから再度 make するとちゃんと継続してコンパイルしてくれた。&lt;br /&gt;
「rel」ディレクトリの下にコンパイルされた。&lt;/p&gt;
&lt;p&gt;使い方は確認中なので、また後で書く。&lt;/p&gt;</description><link>http://www.sakito.com/2012/12/riak.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-3046821101370529492</guid><pubDate>Mon, 03 Dec 2012 21:00:00 +0000</pubDate><atom:updated>2012-12-04T06:00:00.356+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">XML</category><title>XML ファイルから PO ファイル を作成する</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;XML ファイルを翻訳することがそれなりの頻度である。翻訳するなら PO ファイルを生成するのが便利。&lt;br /&gt;
XML から PO ファイルを生成するには「xml2po」か、「&lt;a href=&quot;http://itstool.org/&quot;&gt;ITS Tool&lt;/a&gt;」を使う。両方ともGnomeのドキュメント国際化でも使われている Python で作成されたツール。&lt;br /&gt;
両方とも XML から PO を生成したり、PO から XML に戻したりできる。&lt;br /&gt;
ITS Tool の方が新しい。&lt;/p&gt;
&lt;h4&gt;xml2po&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo port install gnome-doc-utils
xml2po --version
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;POファイルの作成と、XMLへの戻しは以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;xml2po -o sample.pot sample.xml
cp sample.pot ja.po
mkdir ja
xml2po -p ja.po sample.xml &amp;gt; ja/sample.xml
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;ITS Tool&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;# 依存ライブラリインストール&lt;/span&gt;
pip install ftp://xmlsoft.org/libxml2/python/libxml2-python-2.6.21.tar.gz
&lt;span class=&quot;c&quot;&gt;# ダウンロード&lt;/span&gt;
curl -O http://files.itstool.org/itstool/itstool-1.2.0.tar.bz2
tar xvfz itstool-1.2.0.tar.bz2
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;itstool-1.2.0
./configure
sudo make install
&lt;span class=&quot;c&quot;&gt;# バージョン確認&lt;/span&gt;
itstool --version
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;POファイルの作成と、XMLへの戻しは以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;itstool sample.xml -o sample.pot
cp sample.pot ja.po
msgfmt -o ja.mo ja.po
mkdir ja
itstool -m ja.mo -o ja/ sample.xml
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;翻訳対象の XML にもよるだろうが、自分は xml2po の方を普段は利用している。&lt;/p&gt;</description><link>http://www.sakito.com/2012/12/xml-po.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-7705909064428237405</guid><pubDate>Sun, 02 Dec 2012 21:00:00 +0000</pubDate><atom:updated>2012-12-03T06:00:02.274+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Emacs</category><category domain="http://www.blogger.com/atom/ns#">Erlang</category><title>Erlang を Emacs でコーディングするための設定</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;プログラミング言語&lt;a href=&quot;http://www.erlang.org/&quot;&gt;Erlang&lt;/a&gt;を Emacs でコーディングするための設定。&lt;/p&gt;
&lt;h4&gt;Erlangインストール&lt;/h4&gt;
&lt;p&gt;Mac の場合は dmg、MacPorts、Homebrew でインストールする方法がある。&lt;/p&gt;
&lt;p&gt;dmgの場合&lt;/p&gt;
&lt;p&gt;あまり知られていないみたいだが、ちゃんと dmg によるバイナリが配布されている。&lt;br /&gt;
以下からダウンロード可能。&lt;br /&gt;
&lt;a href=&quot;https://www.erlang-solutions.com/downloads/download-erlang-otp&quot;&gt;https://www.erlang-solutions.com/downloads/download-erlang-otp&lt;/a&gt;&lt;br /&gt;
アクセスするとブラウザの設定で自動でOperating Systemが選択されるはずだが、Operating Systemが適切でない場合は選択しなおせば dmg がダウンロードできる。&lt;br /&gt;
バイナリは通常は 64bit を選択すれば良い。
&lt;/p&gt;
&lt;p&gt;MacPortsの場合&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo port install erlang
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Homebrewの場合&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;brew install erlang
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;動作確認&lt;/h4&gt;
&lt;p&gt;ターミナルから動作するか確認する。「erl」コマンドで Erlang Shell が起動する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;% erl
1 &amp;gt; 2 + 4.
6
2 &amp;gt; halt().
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「.」を忘れないように。「halt()」で終了する。&lt;/p&gt;
&lt;h4&gt;Emacsの設定&lt;/h4&gt;
&lt;p&gt;erlang-modeとdistelを設定する。&lt;br /&gt;
erlang-mode は Erlang と同時にインストールされる。&lt;/p&gt;
&lt;p&gt;MacPorts だと「/opt/local/lib/erlang/lib/tools-*/emacs/」に存在する。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/jixiuf/distel&quot;&gt;distel&lt;/a&gt;は補完とか、その他いろいろ便利なので設定している。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/jixiuf/distel.git
cd distel
make
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;init.el の設定は以下。path 関連の設定が必要だけど、略。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;setq&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;erlang-root-dir&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;/opt/local/lib/erlang&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;erlang-start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;erlang-flymake&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;distel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;distel-setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Erlang でのプログラム経験がかなり少ないので、ほとんど設定してない。&lt;/p&gt;

</description><link>http://www.sakito.com/2012/12/erlang-emacs.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-4193169734291879219</guid><pubDate>Sun, 18 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-19T06:00:03.987+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Cassandra</category><title>Cassandra 1.1 簡易メモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;「&lt;a href=&quot;http://cassandra.apache.org/&quot;&gt;Apache Cassandra&lt;/a&gt;」の 1.1.6 をとりあえず試すためのメモ。&lt;br /&gt;
ネット上の記事が結構古い物しかない印象なので、公開しておく。&lt;br /&gt;
触りだけで、深い所までは書いてない。&lt;/p&gt;
&lt;h4&gt;設置から起動&lt;/h4&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;curl -O http://ftp.riken.jp/net/apache/cassandra/1.1.6/apache-cassandra-1.1.6-bin.tar.gz
tar xvf apache-cassandra-1.1.6-bin.tar.gz
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;apache-cassandra-1.1.6

&lt;span class=&quot;c&quot;&gt;# conf の中で利用しているディレクトリを作成&lt;/span&gt;
sudo mkdir -p /var/log/cassandra
sudo chown -R &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;whoami&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; /var/log/cassandra
sudo mkdir -p /var/lib/cassandra
sudo chown -R &lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt;whoami&lt;span class=&quot;sb&quot;&gt;`&lt;/span&gt; /var/lib/cassandra

&lt;span class=&quot;c&quot;&gt;# 起動&lt;/span&gt;
bin/cassandra -f
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;
デフォルトでは Messaging Service が 7000 ポート、thrift server が 9160 ポートを利用する。
&lt;/p&gt;
&lt;h4&gt;アクセス&lt;/h4&gt;
&lt;p&gt;
標準クライアントは依然から存在する「bin/cassandra-cli」か、新しい「bin/cqlsh」を利用する。&lt;br /&gt;
ネットや README だと cassandra-cli を利用しているが、cqlsh の方が使いやすいのでそちらを利用する。
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;bin/cqlsh localhost
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;keyspaceの作成&lt;/h4&gt;
&lt;p&gt;最初に RDB のデータベース相当 である keyspace を作成する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;KEYSPACE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Keyspace1&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;WITH&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strategy_class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;SimpleStrategy&amp;#39;&lt;/span&gt; 
   &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strategy_options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replication_factor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;keyspace に移動&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;cqlsh&amp;gt; use Keyspace1;
cqlsh:Keyspace1&amp;gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;column family の作成&lt;/h4&gt;
&lt;p&gt;RDB のテーブル相当である column family を作成する。cqlshを利用すると、「CREATE COLUMNFAMILY」、「CREATE TABLE」のいずれでも作成できる。&lt;br /&gt;
「CREATE TABLE」を利用すると 従来の RDB 的に column も同時に作成できる。とりあえずこちらを利用したサンプル。&lt;br /&gt;
Snappy による圧縮を指定して作成する場合は以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;TABLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;PRIMARY&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;KEY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;varchar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;WITH&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;comparator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LongType&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compression_parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sstable_compression&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;SnappyCompressor&amp;#39;&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;AND&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;compression_parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;chunk_length_kb&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;確認は「DESCRIBE」コマンド。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;DESCRIBE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;KEYSPACE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Keyspace1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;DESCRIBE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;COLUMNFAMILIE&lt;/span&gt; 
&lt;span class=&quot;k&quot;&gt;DESCRIBE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;COLUMNFAMILY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;データ挿入&lt;/h4&gt;
&lt;p&gt;データを挿入してみる。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;John Smith&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;INTO&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;VALUES&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;日本語 挿入&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;33&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;FROM&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;INSERT は UPDATE と同じ動作をするので、prymary key が重複するデータを挿入すると上書きする。&lt;/p&gt;

&lt;h4&gt;データ参照&lt;/h4&gt;
&lt;p&gt;SELECT文を発行する。&lt;br /&gt;
まず count で行数を取得してみる。古いバージョンでは count は Row 中の column 数を表示している時もあったが、現在は Row の数を返すようになっている。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;普通に SELECT文が発行できる。暗黙に「limit = 10000」が付与される。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;age&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;データ削除&lt;/h4&gt;
&lt;p&gt;DELETE文を発行する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Users&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「PRIMARY KEY」を設定していると、「PRIMARY KEY」以外の値が消えるだけで「PRIMARY KEY」の値が残るので、論理削除とかにした方が良い場合もある。&lt;/p&gt;

&lt;h4&gt;ソート&lt;/h4&gt;
&lt;p&gt;ORDER BY したい場合は、PRIMARY KEY を複合キーで作る必要があるので、PRIMARY KEY を複合キーで作成できる場合にしか使えない。&lt;/p&gt;

&lt;h4&gt;参考サイト&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.datastax.com/docs/1.1/references/cql/index&quot;&gt;CQL 3 Language Reference | DataStax Cassandra 1.1 Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://kaworu.jpn.org/kaworu/2012-05-27-1.php&quot;&gt;Cassandra CQLとは&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://www.sakito.com/2012/11/cassandra-11.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-5064118176257263896</guid><pubDate>Mon, 12 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-13T06:00:00.995+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Emacs</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Emacs で Python の補完を強化する jedi を設定してみた</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Emacs の Python 補完はいろいろあるが、どれもいまいち遅い。「&lt;a href=&quot;https://github.com/tkf/emacs-jedi&quot;&gt;emacs-jedi&lt;/a&gt;」は結構高速に補完してくれるみたいなので、設定してみた。&lt;/p&gt;
&lt;h4&gt;設定&lt;/h4&gt;
&lt;p&gt;Python のライブラリをインストール&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip install epc
pip install jedi
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Emacs のライブラリを取得。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/kiwanami/emacs-deferred.git
git clone git://github.com/kiwanami/emacs-ctable.git
git clone git://github.com/kiwanami/emacs-epc.git
git clone git://github.com/tkf/emacs-jedi.git
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;init.el の設定&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;jedi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;add-hook&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;python-mode-hook&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;jedi:ac-setup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで auto-complete を利用して補完が可能。eldoc が有効になっていると、関数の引数説明も表示される。&lt;br /&gt;
結構高速に動作してくれるのでしばらく利用してみる。&lt;/p&gt;</description><link>http://www.sakito.com/2012/11/emacs-python-jedi.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-5963395544364584361</guid><pubDate>Mon, 12 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-13T06:00:01.720+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Emacs</category><title>Emacs で似ている文字列を一度に選択して一括編集可能な mark-multiple.el の導入</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;簡単に複数の同じ様な文字列を選択して、一括編集可能な「&lt;a href=&quot;https://github.com/magnars/mark-multiple.el&quot;&gt;mark-multiple.el&lt;/a&gt;」を導入してみた。&lt;br /&gt;
機能に関しては、「&lt;a href=&quot;http://emacsrocks.com/&quot;&gt;説明動画&lt;/a&gt;」参照。&lt;/p&gt;

&lt;h4&gt;設定&lt;/h4&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/magnars/mark-multiple.el.git
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;init.el には以下を設定。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;mark-more-like-this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;global-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;C-&amp;lt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;mark-previous-like-this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;global-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;C-&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;mark-next-like-this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「C-&amp;lt;」で前方一致選択。「C-&amp;gt;」で後方一致選択。&lt;/p&gt;
&lt;p&gt;矩形選択の機能もあるので設定しておくと便利。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;inline-string-rectangle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;global-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;C-x r t&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;inline-string-rectangle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;</description><link>http://www.sakito.com/2012/11/emacs-mark-multipleel.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-3847508983542882425</guid><pubDate>Sun, 11 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-12T06:00:03.754+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Emacs</category><title>Emacs の region 関連機能をカスタマイズできる expand-region.el の導入</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Emacs で範囲選択をいろいろカスタマイズできる、「&lt;a href=&quot;https://github.com/magnars/expand-region.el&quot;&gt;expand-region.el&lt;/a&gt;」を導入してみた。&lt;br /&gt;
機能に関しては文章読むより、「&lt;a href=&quot;http://emacsrocks.com/e09.html&quot;&gt;解説動画&lt;/a&gt;」を見た方が良い。&lt;/p&gt;
&lt;h4&gt;設定&lt;/h4&gt;
&lt;p&gt;比較的変更が頻繁にはいっているので、git でソースを clone する方がよさそう。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/magnars/expand-region.el.git
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;init.el への設定は以下。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;;; 選択ができるようにしておく&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;transient-mark-mode&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;expand-region&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;;; リージョンを広げる&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;global-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;C-@&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;er/expand-region&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;;; リージョンを狭める&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;global-set-key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;kbd&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;C-M-@&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;&amp;#39;er/contract-region&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;「C-@」で選択範囲を広げる。「C-M-@」で選択範囲を狭める。&lt;br /&gt;
その他選択中に「C-Shift-p」で選択範囲の上移動、「C-Shift-n」で選択範囲の下移動、「C-Shift-x」で選択範囲の先頭、末尾移動が可能。&lt;/p&gt;

&lt;p&gt;動作をカスタマイズしたい場合は、言語ごとの「-expansions.el」のファイルが沢山はいっているので、参考にすればとりあえず作成できる。&lt;/p&gt;
&lt;h4&gt;参考サイト&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://d.hatena.ne.jp/syohex/20120117/1326814127&quot;&gt;expand-region.elの紹介 - Life is very short&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://www.sakito.com/2012/11/emacs-region-expand-regionel.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-4579586307632894434</guid><pubDate>Tue, 06 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-07T06:00:01.008+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python の pip コマンドでライブラリの更新状況を確認する</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Python の pip コマンド最新バージョン 1.2.1 では、ライブラリの更新状況が確認できない。&lt;br /&gt;
確認する方法をメモする。&lt;/p&gt;
&lt;h4&gt;コマンドの設定&lt;/h4&gt;
&lt;p&gt;pip コマンドは「site-packages/pip/commands/」以下にコマンドが存在し、このディレクトリにコマンドプログラムを配置することで、様々な拡張が可能。&lt;/p&gt;
&lt;p&gt;listコマンドを追加する「&lt;a href=&quot;https://github.com/rafaelcaricio/pip/blob/list_command/pip/commands/list.py&quot;&gt;list.py&lt;/a&gt;」が公開されているので、ダウンロードして、配置する。&lt;br /&gt;
利用可能か確認したり、利用方法を確認するには、以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip list --help
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ライブラリの更新状況を確認する場合は以下。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip list -o
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;インストールしているライブラリの量にもよるが、結構時間がかかるので注意。&lt;/p&gt;
</description><link>http://www.sakito.com/2012/11/python-pip.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-535880611617261636</guid><pubDate>Mon, 05 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-06T06:00:03.645+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Linux</category><category domain="http://www.blogger.com/atom/ns#">Mac</category><title>アスキーアートロゴを作成してみる</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;現在「&lt;a href=&quot;https://bitbucket.org/sakito/tweepy/overview&quot;&gt;tweepy のAPI 1.1 対応フォーク&lt;/a&gt;」を作成している。&lt;br /&gt;
変な所が無いか知人に見てもらった時、いくつかの指摘の中で、READMEファイルのアスキーアートロゴに関して質問があった。&lt;br /&gt;
そこで、このようなアスキーアートロゴの作成方法に関してメモしておく。&lt;/p&gt;
&lt;h4&gt;bannerコマンド&lt;/h4&gt;
&lt;p&gt;Mac OS Xで標準的に利用できるコマンドだと「banner」が存在する。「-w」オプションで幅を指定する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;banner -w 30 Hello
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「banner」コマンドは自由度がほとんど無いので、あまり便利ではない。&lt;/p&gt;

&lt;h4&gt;FIGlet&lt;/h4&gt;
&lt;p&gt;「&lt;a href=&quot;http://www.figlet.org/&quot;&gt;FIGlet&lt;/a&gt;」はこの分野でかなり利用されていると思われる。MacPorts や Homebrew で簡単にインストールできる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo port install figlet

brew install figlet
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;使い方は簡単。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;figlet Hello
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;フォントの変更も可能なので、参考サイト参照。&lt;/p&gt;
&lt;p&gt;FIGletのPython実装「&lt;a href=&quot;http://pypi.python.org/pypi/pyfiglet/&quot;&gt;pyfiglet&lt;/a&gt;」が存在する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip install pyfiglet
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;pyfigletはモジューで提供されて、コマンドがインストールされない。&lt;br /&gt;
以下のようにするとコマンドでも利用できるが、普通は import して利用する物だと思われる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;/path/to/pyfiglet/__init__.py &lt;span class=&quot;s2&quot;&gt;&amp;quot;Hello&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;TOIlet&lt;/h4&gt;
&lt;p&gt;色付きでアスキーアートロゴが生成できる。名前やサイトデザインが結構酷いが、品質に問題はないようだ。&lt;br /&gt;
これも MacPorts や Homebrew で簡単にインストールできる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;sudo port install TOIlet

brew install TOIlet
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;使い方は FIGlet とほとんど同じで、色を付けるパターンが存在している。&lt;/p&gt;
&lt;h4&gt;参考サイト&lt;/h4&gt;
&lt;p&gt;以下のサイトが詳しい。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://blog.azumakuniyuki.org/2011/05/figlet.html&quot;&gt;/var/log/azumakuniyuki: サーバ管理に役立つ(かもしれない)FIGletというツール&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://99blues.dyndns.org/blog/2011/01/ascii_art_logo/&quot;&gt;アスキーアートなロゴを作る « Stop Making Sense&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://www.sakito.com/2012/11/blog-post.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-881289147245947790</guid><pubDate>Sun, 04 Nov 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-05T06:00:01.628+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Mac</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>pyobjc 2.4 のインストール</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Python の Objective-C ブリッジライブラリ「&lt;a href=&quot;http://pypi.python.org/pypi/pyobjc/&quot;&gt;pyobjc&lt;/a&gt;」の 2.4 が 2012/11/01 にリリースされたのでインストールメモ。&lt;/p&gt;
&lt;h4&gt;インストール&lt;/h4&gt;
&lt;p&gt;以下は pip でのインストール手順。core を先にインストールしないと依存性が解消されないので注意。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip install -U pyobjc-core
pip install -U pyobjc
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;ドキュメント&lt;/h4&gt;
&lt;p&gt;各種ドキュメントは以下にある。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://pyobjc.sourceforge.net/documentation/index.html&quot;&gt;PyObjC - Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;サンプルソース&lt;/h4&gt;
&lt;p&gt;pip でインストールするとサンプルがインストールされないので、以下のURLから取得する。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://svn.red-bean.com/pyobjc/trunk/pyobjc/&quot;&gt;http://svn.red-bean.com/pyobjc/trunk/pyobjc/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;サンプルの内容は Mac での Objective-C の知識が無いと意図が理解はできないと思われる。&lt;br /&gt;
Python から Objective-C の API が簡単に利用できるというのが便利。&lt;/p&gt;</description><link>http://www.sakito.com/2012/11/pyobjc-24.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-6517439243446401241</guid><pubDate>Wed, 31 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-11-01T06:00:04.534+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python モジュールバージョン番号フォマットに関してのメモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Python モジュールを開発する際のバージョン番号のフォーマットに関してのメモ。&lt;/p&gt;
&lt;h4&gt;ドキュメント&lt;/h4&gt;
&lt;p&gt;PEPが存在する。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.python.org/dev/peps/pep-0386/&quot;&gt;PEP 386 -- Changing the version comparison module in Distutils&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.python.org/dev/peps/pep-0396/&quot;&gt;PEP 396 -- Module Version Numbers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;形式&lt;/h4&gt;
&lt;p&gt;形式は以下。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;N.N[.N]+[{a|b|c|rc}N[.N]+][.postN][.devN]
&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;major&lt;/li&gt;
&lt;li&gt;minor&lt;/li&gt;
&lt;li&gt;micro&lt;/li&gt;
&lt;li&gt;releaselevel&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;dev&lt;/li&gt;
&lt;li&gt;alpha&lt;/li&gt;
&lt;li&gt;beta&lt;/li&gt;
&lt;li&gt;candidate&lt;/li&gt;
&lt;li&gt;final&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;serial&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;バージョン番号表示&lt;/h4&gt;
&lt;p&gt;setup.py でバージョン番号が表示できるように作成する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;python setup.py --version
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;関連プログラム&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/django/django/blob/master/django/utils/version.py&quot;&gt;django/django/utils/version.py at master · django/django · GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</description><link>http://www.sakito.com/2012/11/python.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-3831092945114212937</guid><pubDate>Tue, 30 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-31T06:00:00.450+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">misc</category><title>とりあえず10月も毎日更新してみた</title><description>&lt;p&gt;ほぼ前日の予約投稿だけれども、10月も毎日更新してみた。&lt;br /&gt;
やはり多少の時間がかかるのと、記事の内容が薄くなったりしてしまう。&lt;br /&gt;
11月は、更新毎日はやめる事にして、気が向いた時に更新してみる。&lt;br /&gt;
更新に利用していた時間を開発に回す予定。
&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/10.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-7574991284586141680</guid><pubDate>Mon, 29 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-30T06:00:00.146+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><category domain="http://www.blogger.com/atom/ns#">Twitter</category><title>Twitter 関連のライブラリを API 1.1 に対応させるのは結構大変</title><description>&lt;p&gt;
Python から Twitter API を扱うライブラリに「&lt;a href=&quot;https://github.com/tweepy/tweepy&quot;&gt;tweepy&lt;/a&gt;」があるが、これは API 1.1 に対応していない。&lt;br /&gt;
そこで、API 1.1 の調査を兼ねていろいろ変更してみている「&lt;a href=&quot;https://bitbucket.org/sakito/tweepy/changesets&quot;&gt;sakito / tweepy — Bitbucket&lt;/a&gt;」。
&lt;/p&gt;
&lt;p&gt;単純に endpoint を 1.1 にするだけでも大丈夫そうな感じがするが、細かい所まで対応しようとするとかなり大変。&lt;br /&gt;
使う機能以外を気にすると時間がかかりすぎる気がするので主要な機能だけ、徐々に対応してみようと思う。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/twitter-api-11.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-3962860083867113259</guid><pubDate>Sun, 28 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-29T06:00:02.749+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python の in 演算子</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Python の in 演算子に関して詳細に記述してある「&lt;a href=&quot;http://kracekumar.com/post/22512660850/python-in-operator-use-cases&quot;&gt;python `in` operator use cases&lt;/a&gt;」という記事を見つけた。&lt;br /&gt;
日本語を使うとどうなるかとりあえず試してみた。&lt;/p&gt;
&lt;h4&gt;ソース&lt;/h4&gt;
&lt;p&gt;いつも通り unittest で記述した。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unittest&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        list&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;あ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;い&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;う&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;え&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;お&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;あ&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertFalse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;か&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_nested_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        nested list&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;あ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;い&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;う&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;え&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;お&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;さ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;し&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;す&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;せ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;そ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;[],&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertFalse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;あ&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;あ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;い&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;う&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;え&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;お&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([]&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        dict&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;dct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;名前&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;サンプル&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;国&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;日本&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;OS&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Mac&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
               &lt;span class=&quot;s&quot;&gt;&amp;#39;言語&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;web&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;python&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;名前&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertFalse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;web&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_dict_class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        dict class&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;pass&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({},&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;名前&amp;#39;&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        set&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;stlst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;bar&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;bar&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stlst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;foo&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;stlst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_generator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        generator&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        string&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;Python はシンプルで強力な言語です&amp;#39;&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;Python&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertTrue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;強力&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;Python&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;強力&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;当然のように日本語でも特に問題はない。in はそれほど複雑ではないが、いろいろと応用が効いて便利。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/python-in.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-2629413864118150628</guid><pubDate>Sat, 27 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-28T06:00:01.327+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>多言語対応テンプレート言語 mustache を試してみた</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;「&lt;a href=&quot;http://mustache.github.com/&quot;&gt;{{ mustache }}&lt;/a&gt;」は多言語対応のテンプレート言語。各種エディタの plugin も提供されていて便利そうなので、試してみた。&lt;/p&gt;
&lt;h4&gt;ドキュメント&lt;/h4&gt;
&lt;p&gt;文法は「&lt;a href=&quot;http://mustache.github.com/mustache.5.html&quot;&gt;mustache&lt;/a&gt;」を参照。&lt;/p&gt;
&lt;h4&gt;Python で試してみる&lt;/h4&gt;
&lt;p&gt;とりあえずPython で試してみる。「&lt;a href=&quot;https://github.com/defunkt/pystache&quot;&gt;Pystache&lt;/a&gt;」を使う。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip install Pystache
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「pystache」コマンドがインストールされるので、簡単なサンプルを試してみる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pystache &lt;span class=&quot;s1&quot;&gt;&amp;#39;Hello {{name}}&amp;#39;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;{&amp;quot;name&amp;quot;: &amp;quot;World&amp;quot;}&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;普通はテンプレートファイルを作成する。以下のような内容で「sample.txt」として作成。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;こんにちは {{name}}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
サンプル
{{#lists}}
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;b&amp;gt;&lt;/span&gt;{{name}}&lt;span class=&quot;nt&quot;&gt;&amp;lt;/b&amp;gt;&lt;/span&gt;
{{/lists}}
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これを利用するソースは以下。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unittest&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pystache.loader&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Loader&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pystache&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Renderer&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestPystache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_file&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;DATA_DIR&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;./data&amp;#39;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;loader&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Loader&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search_dirs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DATA_DIR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;file_encoding&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;txt&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;template&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loader&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;sample&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;World&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                   &lt;span class=&quot;s&quot;&gt;&amp;#39;lists&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;b&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;c&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
                   &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;renderer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Renderer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;actual&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;renderer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;html&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;head&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;title&amp;gt;こんにちは World&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;サンプル&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;  &amp;lt;b&amp;gt;a&amp;lt;/b&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;  &amp;lt;b&amp;gt;b&amp;lt;/b&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;  &amp;lt;b&amp;gt;c&amp;lt;/b&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;
                         &lt;span class=&quot;s&quot;&gt;&amp;#39;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;utf-8&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
                         &lt;span class=&quot;n&quot;&gt;actual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;多言語対応なのは利点。&lt;br /&gt;
Python だと &lt;a href=&quot;http://jinja.pocoo.org/docs/&quot;&gt;Jinja2&lt;/a&gt; という強力なテンプレートエンジンがあるので、それほど利点がないかもしれない。&lt;br /&gt;
テンプレートエンジンの選択肢が少ないような言語だとかなり便利かもしれない。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/mustache.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-4288065070080541103</guid><pubDate>Fri, 26 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-27T06:00:01.570+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python 標準ロギングモジュール logging の使い方メモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;logging を利用してみる。&lt;/p&gt;
&lt;p&gt;ドキュメント&lt;/p&gt;
&lt;p&gt;モジュールの使い方は、公式ドキュメント「&lt;a href=&quot;http://docs.python.org/library/logging.html&quot;&gt;logging — Logging facility for Python&lt;/a&gt;」に概要が書いてある。
また「&lt;a href=&quot;http://docs.python.org/howto/logging.html&quot;&gt;Logging HOWTO&lt;/a&gt;」が具体的な使い方に関して書いてある。&lt;/p&gt;
&lt;h4&gt;使い方&lt;/h4&gt;
&lt;p&gt;以下が一番簡単な例。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;わーにんぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;いんふぉ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;実行すると以下のようになる。これはデフォルトレベルが「WARNING」以上だから。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;WARNING:root:わーにんぐ
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ログのレベルは以下のようになる。&lt;/p&gt;
&lt;table style=&quot;border-width: 2px; border-style: solid&quot;&gt;
&lt;tr&gt;
&lt;th&gt;レベル&lt;/th&gt;
&lt;th&gt;関数&lt;/th&gt;
&lt;th&gt;数値&lt;/th&gt;
&lt;th&gt;概要&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CRITICAL&lt;/td&gt;
&lt;td&gt;logging.critical()&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;停止してしまうような致命的な問題用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ERROR&lt;/td&gt;
&lt;td&gt;logging.error()&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;td&gt;重大な問題用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WARNING&lt;/td&gt;
&lt;td&gt;logging.warning()&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;実行機能で問題が発生した場合用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;INFO&lt;/td&gt;
&lt;td&gt;logging.info()&lt;/td&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;動作情報表示用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DEBUG&lt;/td&gt;
&lt;td&gt;logging.debug()&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;詳細な情報表示用&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;NOTSET&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;全てを出力。基本的に設定用の値&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;h4&gt;ファイルへの出力&lt;/h4&gt;
&lt;p&gt;エラーをファイルに出したい場合があるが以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;basicConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;example.log&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;でばっぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;いんふぉ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;わーにんぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「sample.log」ファイルに以下のように出力される。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;DEBUG:root:でばっぐ
INFO:root:いんふぉ
WARNING:root:わーにんぐ
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;ログ出力形式の指定&lt;/h4&gt;
&lt;p&gt;ログの出力形式はいろいろ変更できる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;basicConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%(asctime)s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%(levelname)s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%(message)s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;n&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;でばっぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;いんふぉ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;わーにんぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;以下のように出力される。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;2012-10-01 11:21:46,999:DEBUG:でばっぐ
2012-10-01 11:21:46,999:INFO:いんふぉ
2012-10-01 11:21:47,000:WARNING:わーにんぐ
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;使えるフォーマットは「&lt;a href=&quot;http://docs.python.org/library/logging.html#logrecord-attributes&quot;&gt;LogRecord attributes&lt;/a&gt;」に一覧がある。主な物は以下。&lt;/p&gt;

&lt;table style=&quot;border-width: 2px; border-style: solid&quot;&gt;
&lt;tr&gt;
&lt;th&gt;フォーマット&lt;/th&gt;
&lt;th&gt;概要&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(asctime)s&lt;/td&gt;
&lt;td&gt;実行時刻&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(filename)s&lt;/td&gt;
&lt;td&gt;ファイル名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(funcName)s&lt;/td&gt;
&lt;td&gt;関数名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(levelname)s&lt;/td&gt;
&lt;td&gt;DEBUG、INFO等のレベル名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(lineno)d&lt;/td&gt;
&lt;td&gt;行番号&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(name)s&lt;/td&gt;
&lt;td&gt;呼びだしたログの定義名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(module)s&lt;/td&gt;
&lt;td&gt;モジュール名&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(message)s&lt;/td&gt;
&lt;td&gt;ログメッセージ&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(process)d&lt;/td&gt;
&lt;td&gt;プロセスID&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;%(thread)d&lt;/td&gt;
&lt;td&gt;スレッドID&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;


&lt;h4&gt;設定ファイルの利用&lt;/h4&gt;
&lt;p&gt;フォーマットやログレベルの設定は、通常は設定ファイルを書いて利用する。設定ファイルのファイル名な何でも良い。ここでは以下の内容で「logging.conf」として作成する。&lt;br /&gt;
以下の例だと、コンソールとファイルに「DEBUG」レベルでログを出力する。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;[loggers]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;root, logExample&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[handlers]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;consoleHandler, fileHandler&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[formatters]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;logFormatter&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[logger_root]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DEBUG&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;handlers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;consoleHandler&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[logger_logExample]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DEBUG&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;handlers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;consoleHandler, fileHandler&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;qualname&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;logExample&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;propagate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;0&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[handler_consoleHandler]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;StreamHandler&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DEBUG&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;formatter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;logFormatter&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(sys.stdout,)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[handler_fileHandler]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;handlers.RotatingFileHandler&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;level&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;DEBUG&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;formatter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;logFormatter&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;(&amp;#39;example.log&amp;#39;,)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;[formatter_logFormatter]&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;format&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;%(asctime)s - %(name)s - %(levelname)s - %(message)s&lt;/span&gt;
&lt;span class=&quot;na&quot;&gt;datefmt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;利用するソースは以下。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;logging.config&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fileConfig&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;logging.conf&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getLogger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;logExample&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debug&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;でばっぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;いんふぉ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;わーにんぐ&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Handlerの利用&lt;/h4&gt;
&lt;p&gt;上記のサンプルだと「RotatingFileHandler」を利用している。これはファイルが一定量になると回転するハンドラ。&lt;br /&gt;
標準のハンドラでも十分な場合もあるが、&lt;a href=&quot;http://pypi.python.org/pypi&quot;&gt;PyPI&lt;/a&gt;で探すと他にもいろいろなハンドラが存在している。&lt;br /&gt;
以下とか便利かもしれない。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://pypi.python.org/pypi/log4mongo/&quot;&gt;log4mongo&lt;/a&gt;：mongoDB にログを出力&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://pypi.python.org/pypi/python-redis-log/&quot;&gt;python-redis-log&lt;/a&gt;：Redis にログを出力&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://pypi.python.org/pypi/td-logger/&quot;&gt;td-logger&lt;/a&gt;：Treasure Dataにログを出力&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://pypi.python.org/pypi/fluent-logger/&quot;&gt;fluent-logger&lt;/a&gt;：Fluentdにログを出力&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;存在しない Handler は上記を参考に自作してみると良いかもしれない。&lt;/p&gt;

&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;logging は障害対処時に非常に有効。多用することになるので、使い方に慣れておくと良い。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/python-logging.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-7416109201928305930</guid><pubDate>Thu, 25 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-26T06:00:00.969+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python で標準添付の Debuggerのpdb を利用してデバッグするメモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;pdb を利用してみる。&lt;/p&gt;
&lt;h4&gt;ドキュメント&lt;/h4&gt;
&lt;p&gt;公式ドキュメント「&lt;a href=&quot;http://docs.python.org/library/pdb.html&quot;&gt;pdb — The Python Debugger&lt;/a&gt;」に概要が書いてある。&lt;/p&gt;
&lt;h4&gt;使い方&lt;/h4&gt;
&lt;p&gt;スクリプトを直接起動してデバッグする方法と、インタラクティブshell で起動する方法があるが、ここでは、スクリプトを起動してデバッグする方法で書く。&lt;br /&gt;
以下がデバッグするスクリプトのサンプル「even.py」。&lt;br /&gt;
自分の場合、スクリプトを直接デバッグすることがあまりなく、デバッグするのはライブラリとかをunittest経由でデバッグすることがが多いのでサンプルは unittest で書いている。&lt;br /&gt;
以下の例はクラス内の関数が偶数だけ返す所でバグがあり、奇数を返すようになっている。そんなに良い例ではないかも。&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unittest&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    テスト対象のクラス&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;to_even&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        リストを渡すと、偶数だけにして返す&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# 意図的にバグらせていて、奇数しか返さない&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;evenlst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;evenlst&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestSample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;sd&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    テストクラス&lt;/span&gt;
&lt;span class=&quot;sd&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;clazz&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Sample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;#  0 から 10 のリストを生成 [0, 1, 2, .....]&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;xrange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;evenlst&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clazz&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_even&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# 偶数かテストする&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;evenlst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;とりあえず実行してみると以下のようにエラーになる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&amp;gt; python even.py 
F
======================================================================
FAIL: test_main (__main__.TestSample)
----------------------------------------------------------------------
Traceback (most recent call last):
  File &amp;quot;even.py&amp;quot;, line 33, in test_main
    self.assertEqual(0, num)
AssertionError: 0 != 1

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;pdbを起動してみる。起動は以下のようにする。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;python -m pdb even.py
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;起動すると pdb プロンプトが起動する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&amp;gt; /path/to/even.py(3)&amp;lt;module&amp;gt;()
-&amp;gt; import unittest
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;上記の出力から「3行目」の「import」で実行が停止しているのがわかる。&lt;br /&gt;
「list」で停止位置の周辺ソースが表示される。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) list
  1     #!/usr/bin/env python
  2     # -*- coding: utf-8 -*-
  3  -&amp;gt; import unittest
  4  
  5  
  6     class Sample(object):
  7         &amp;quot;&amp;quot;&amp;quot;
  8         テスト対象のクラス
  9         &amp;quot;&amp;quot;&amp;quot;
 10         def to_even(self, lst):
 11             &amp;quot;&amp;quot;&amp;quot;
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;行数とともに、現在の停止場所に「-&amp;gt;」がある。&lt;/p&gt;
&lt;p&gt;「list」のようにデバッグに利用できるコマンドの主な物は以下になる。コマンドには省略形が存在する物もある。&lt;/p&gt;
&lt;table style=&quot;border-width: 2px; border-style: solid&quot;&gt;
&lt;tr&gt;
&lt;th&gt;コマンド&lt;/th&gt;
&lt;th&gt;省略形&lt;/th&gt;
&lt;th&gt;概要&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;help&lt;/td&gt;
&lt;td&gt;h&lt;/td&gt;
&lt;td&gt;コマンドのヘルプを表示。&lt;br /&gt;
「help」でコマンド一覧、&lt;br /&gt;
「help コマンド名」でコマンドのヘルプ&lt;br /&gt;
が表示される。&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;where&lt;/td&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;スタックトレースを表示&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;down&lt;/td&gt;
&lt;td&gt;d&lt;/td&gt;
&lt;td&gt;スタックトレース中に1レベル下げる&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;up&lt;/td&gt;
&lt;td&gt;u&lt;/td&gt;
&lt;td&gt;スタックトレース中に1レベル上げる&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;step&lt;/td&gt;
&lt;td&gt;s&lt;/td&gt;
&lt;td&gt;現在行を実行し、次の行に進む&lt;br /&gt;
次の行が関数の場合、関数内で停止&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;next&lt;/td&gt;
&lt;td&gt;n&lt;/td&gt;
&lt;td&gt;現在行を実行し、次の行に進む&lt;br /&gt;
次の行が関数でも、関数内では停止しない&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;return&lt;/td&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;現在の関数から抜ける&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;list&lt;/td&gt;
&lt;td&gt;l&lt;/td&gt;
&lt;td&gt;現在行周辺のソースを表示&lt;br /&gt;
デフォルトは11行表示する&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;args&lt;/td&gt;
&lt;td&gt;a&lt;/td&gt;
&lt;td&gt;現在関数の引数一覧を表示&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;p 式&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;式内容を表示&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pp 式&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;式内容を pprint で表示&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;quit&lt;/td&gt;
&lt;td&gt;q&lt;/td&gt;
&lt;td&gt;デバッガ終了&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;現在行が「import」なので「n(ext)」で進める。&lt;br /&gt;
間違えて「s(tep)」すると「import」を実行する Python のライブラリ内に入る。その場合は「r(eturn)」とかすると戻ってこれる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) n
&amp;gt; /path/to/even.py(6)&amp;lt;module&amp;gt;()
-&amp;gt; class Sample(object):
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;class の行になるが、実行されるわけではない。&lt;br /&gt;
再度「n」するが、この「n」は一度実行すると次回は「リターンキー」で同じ事を実行する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) 
&amp;gt; /path/to/even.py(18)&amp;lt;module&amp;gt;()
-&amp;gt; class TestSample(unittest.TestCase):
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「c(ontinue)」すると、停止するまで実行する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) c
F
======================================================================
FAIL: test_main (__main__.TestSample)
----------------------------------------------------------------------
Traceback (most recent call last):
  File &amp;quot;even.py&amp;quot;, line 33, in test_main
    self.assertEqual(0, num)
AssertionError: 0 != 1

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
The program exited via sys.exit(). Exit status:  True
&amp;gt; /path/to/even.py(3)&amp;lt;module&amp;gt;()
-&amp;gt; import unittest
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;ブレークポイント&lt;/h4&gt;
&lt;p&gt;通常 step 実行とかしないで、ブレークポイントを利用する。ブレークポイント関連のコマンドは以下。&lt;/p&gt;
&lt;table style=&quot;border-width: 2px; border-style: solid&quot;&gt;
&lt;tr&gt;
&lt;th&gt;コマンド&lt;/th&gt;
&lt;th&gt;省略形&lt;/th&gt;
&lt;th&gt;概要&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;break 行数 or 関数名&lt;/td&gt;
&lt;td&gt;b&lt;/td&gt;
&lt;td&gt;指定行数にブレークポイントを付ける&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;tbreak 行数 or 関数名&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;一時的ブレークポイントを付ける&lt;br /&gt;
一回通過すると消える&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;clear 行数 or bp番号&lt;/td&gt;
&lt;td&gt;cl&lt;/td&gt;
&lt;td&gt;ブレークポイントを削除&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;disable bp番号&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;ブレークポイントを停止&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;enable bp番号&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;ブレークポイントを有効化&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ignore bp番号 回数&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;ブレークポイントを回数分無視する&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;condition bp番号&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;ブレークポイントの状態を確認&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;commands bp番号&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;ブレークポイントを表示&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;continue&lt;/td&gt;
&lt;td&gt;c&lt;/td&gt;
&lt;td&gt;ブレークポイントで停止してる場合、実行を継続&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;p&gt;「33行目」にブレークポイントを設定し「c」して「l」で確認してみる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) b 33
Breakpoint 1 at /path/to/even.py:33
(Pdb) c
&amp;gt; /path/to/even.py(33)test_main()
-&amp;gt; for item in evenlst:
(Pdb) l
 28             #  0 から 10 のリストを生成 [0, 1, 2, .....]
 29             lst = xrange(10)
 30             evenlst = clazz.to_even(lst)
 31  
 32             # 偶数かテストする
 33 B-&amp;gt;         for item in evenlst:
 34                 num = item % 2
 35                 self.assertEqual(0, num)
 36  
 37  
 38     if __name__ == &amp;#39;__main__&amp;#39;:
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ここで「evenlst」の内容を表示してみる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) p evenlst
[1, 3, 5, 7, 9]
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;バグっている事がわかる。&lt;/p&gt;
&lt;p&gt;「n」を2回して「l」して「p」してみる。「p」で複数表示の場合はカンマで区切る。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(Pdb) p item,num
(1, 1)
(Pdb) 
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;バグ原因が判明したら「q」などで終了すれば良い。&lt;/p&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;他者の作成したライブラリ等はソース修正するとまずいので、 print を入れることができない場合が多く、そういう場合は pdb は便利。&lt;br /&gt;
本当はライブラリ内で Exception が発生したりするので、結構デバッグは大変だったりする。&lt;br /&gt;
自作のスクリプトの場合は、普通は pdb を使うよりも、いかに良くテストを書くかの方が重要な気がしている。pdbを使わなければいけないのはテストが下手だと思った方が良い。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/python-debuggerpdb.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-2762933718196028160</guid><pubDate>Tue, 23 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-24T06:00:03.079+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Emacs</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>pyregexp を利用して Emacs の検索置換に Python の正規表現を利用してみる</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;Emacs の正規表現は結構使いずらくて、覚えられないので、「&lt;a href=&quot;https://github.com/benma/pyregexp&quot;&gt;pyregexp&lt;/a&gt;」を利用して、Python の正規表現を利用してみる。&lt;/p&gt;
&lt;h4&gt;pyregexpに関して&lt;/h4&gt;
&lt;p&gt;Python を利用して Emacs 内の検索・置換の処理で Python の正規表現を利用できるようにする Emacs Lisp。動作には Python が必要。&lt;/p&gt;
&lt;h4&gt;設定&lt;/h4&gt;
&lt;p&gt;ソースを取得して、pathの通った所に配置。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;git clone git://github.com/benma/pyregexp.git
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;init.el 等で以下のように設定する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;(require &amp;#39;pyregexp)
(define-key global-map (kbd &amp;quot;C-c r&amp;quot;) &amp;#39;pyregexp-replace)
(define-key global-map (kbd &amp;quot;C-c q&amp;quot;) &amp;#39;pyregexp-query-replace)
(define-key esc-map (kbd &amp;quot;C-r&amp;quot;) &amp;#39;pyregexp-isearch-backward)
(define-key esc-map (kbd &amp;quot;C-s&amp;quot;) &amp;#39;pyregexp-isearch-forward)
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;使い方&lt;/h4&gt;
&lt;p&gt;公式サイト「&lt;a href=&quot;https://github.com/benma/pyregexp&quot;&gt;pyregexp&lt;/a&gt;」の一部をそのまま引用する。&lt;/p&gt;
&lt;p&gt;以下のようなテキストを用意。これの重複した文字を検索して、重複を削除してみる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;We we can delete double double words
by by using backreferences.
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「C-c r」して入力を開始すると、「Regexp」になるので、「(?i)(\w+) \1」を入力。一致箇所がハイライトされるる。3箇所一致しているはず。一番最後の文字は「いち」なので間違わないように。&lt;br /&gt;
置換する場合は「enter」をすると「Replace」になるので、「\1」を入力。置換結果が「We we =&gt; We」のように表示される。問題なければ、enter することで置換される。&lt;/p&gt;
&lt;p&gt;Python の式を利用することも可能。&lt;/p&gt;
&lt;p&gt;以下のようなファイルを用意。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hoge
foo
bar
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;「C-c r」して「^」を入力すると、文字列の先頭が一致する。enter して Replace にして「C-c C-c」すると「Replace (using expression)」になるので「str(i+1) + &quot;: &quot;」を入力すると、先頭に「1： 2： 3：」のような文字が入力される。&lt;/p&gt;
&lt;p&gt;str だけでなく、int等も利用できるのでかなり便利。&lt;/p&gt;
&lt;p&gt;「wdired-change-to-wdired-mode」でも利用可能。かなり高度な置換ができる。&lt;/p&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;まだ使いはじめたばかりだが、自分は Python に慣れているので、かなり便利に利用できている。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/pyregexp-emacs-python.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-2574552286442222280</guid><pubDate>Mon, 22 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-23T06:00:02.251+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Python</category><title>Python の lambda メモ</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;仕事の関係で Python の lambda に関して最近質問された。lambda は結構読みずらいようで質問の回数が多い気がする。毎回似たような質問に答えるのが面倒なので、回答用に概要をメモしておく。&lt;/p&gt;
&lt;h4&gt;Python の lambda&lt;/h4&gt;
&lt;p&gt;lambda は無名関数を作成するための機能。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;と同じ物をが、lambda だと以下のように記述できる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;簡単なサンプル&lt;/h4&gt;
&lt;p&gt;とりあえず簡単なサンプルが以下。時々 lambda は改行ができないと思っている人がいるみたいだが、括弧でかこめば普通に改行できる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# -*- coding: utf-8 -*-&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unittest&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TestLambda&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TestCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test_basic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# def を利用&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;

        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# lambda を利用&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;

        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;# 括弧を利用すると途中改行が可能&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
             &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assertEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unittest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;確かに lambda を使うべき場面もあるが、普通はlambda はそんなに多用しない方が良いと思う。利用しても、意味ない場合も多い。&lt;br /&gt;
変な所で、変なテクニック使ってもおもしろくともなんとも無いので、普通に読みやすく書くのが一番良い。&lt;br /&gt;
あと、書いたは良いが、質問される内容はもっと高度になる場合が多いので、このエントリは自分の手抜き用には役に立たないかもしれない。&lt;/p&gt;
</description><link>http://www.sakito.com/2012/10/python-lambda.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5542064418961639741.post-6169071396971855241</guid><pubDate>Sun, 21 Oct 2012 21:00:00 +0000</pubDate><atom:updated>2012-10-23T21:15:55.322+09:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Git</category><category domain="http://www.blogger.com/atom/ns#">Mercurial</category><title>Mercurial(hg) を使って GitHub に Pull Request する手順</title><description>&lt;h4&gt;概要&lt;/h4&gt;
&lt;p&gt;分散バージョン管理ツールとして自分は「&lt;a href=&quot;http://mercurial.selenic.com/&quot;&gt;Mercurial&lt;/a&gt;」を利用している。&lt;br /&gt;
自分にとって Git は難しすぎるので、できれば使いたくなかったので、Git を利用しないで GitHub に Pull Request する方法を調べた。&lt;/p&gt;
&lt;h4&gt;Pull Request が初めての場合&lt;/h4&gt;
&lt;p&gt;Pull Request が初めての場合、GitHub の公式マニュアルに従って練習すると良い。Pull Requestのマニュアルは「&lt;a href=&quot;https://help.github.com/articles/fork-a-repo&quot;&gt;Fork A Repo · github:help&lt;/a&gt;」にある。&lt;/p&gt;
&lt;p&gt;GitHub のマニュアルに従って、「&lt;a href=&quot;https://github.com/octocat/Spoon-Knife&quot;&gt;https://github.com/octocat/Spoon-Knife&lt;/a&gt;」を Fork して練習する。失敗しても誰も怒ったりしないので、自由にやるのが良い。&lt;/p&gt;
&lt;h4&gt;hg-git のインストールと設定&lt;/h4&gt;
&lt;p&gt;hg で GitHub のソースを clone するには「&lt;a href=&quot;http://pypi.python.org/pypi/hg-git/&quot;&gt;hg-git&lt;/a&gt;」を利用する。&lt;br /&gt;
「&lt;a href=&quot;http://pypi.python.org/pypi/hg-git/&quot;&gt;hg-git&lt;/a&gt;」は Git のバイナリがなくても、単体で Git レポジトリを扱うことができるライブラリ。pip 等で簡単にインストールできる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;pip install hg-git
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;hgrcに以下を設定する&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;[extensions]
hggit=
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;hg で GitHub のソースを clone する&lt;/h4&gt;
&lt;p&gt;hg-git を利用して GitHub のレポジトリを clone する。&lt;br /&gt;
例えばGitHub で「git@github.com:username/Spoon-Knife.git」のようなレポジトリの場合、以下のように指定すると clone できる。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg clone git+ssh://github.com/username/Spoon-Knife.git
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;Pull Request用に開発&lt;/h4&gt;
&lt;p&gt;master でそのまま開発すると、fork 元の変更に追随することができなくなるので、開発用の branch を作成する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;
cd Spoon-Knife
hg branch &lt;span class=&quot;s1&quot;&gt;&amp;#39;develop&amp;#39;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# コミット&lt;/span&gt;
hg ci -m&lt;span class=&quot;s2&quot;&gt;&amp;quot;develop&amp;quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 確認&lt;/span&gt;
hg branches
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;そして、開発用の branch から pull request 用の branch を作成する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg branch &lt;span class=&quot;s1&quot;&gt;&amp;#39;feature/samplespike&amp;#39;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# コミット&lt;/span&gt;
hg ci -m&lt;span class=&quot;s2&quot;&gt;&amp;quot;feature/samplespike&amp;quot;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# 確認&lt;/span&gt;
hg branches
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;pull request 用の branch で開発する。&lt;/p&gt;
&lt;h4&gt;push 用の bookmark 作成&lt;/h4&gt;
&lt;p&gt;hg-git では hg の bookmark が Git の branch になる。push を本当にする場合、bookmark を作成する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg bookmark -r feature/samplespike pullrequest/samplespike
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;pull requestのために、Commit を一つに纏める&lt;/h4&gt;
&lt;p&gt;開発によって、Commit が複数に分割されている場合があるが、分割されたpull request はしない方が良い。&lt;br /&gt;
Git の場合 rebase でこれを実施するが、hg では「&lt;a href=&quot;http://mercurial.selenic.com/wiki/HisteditExtension&quot;&gt;Histedit Extension&lt;/a&gt;」を利用する。Mercurial 2.3以降は標準添付なので以下のようにhgrcに設定する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;[extensions]
histedit=
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;利用しているバージョンが Mercurial 2.3 以下の場合は「&lt;a href=&quot;https://bitbucket.org/durin42/histedit/src&quot;&gt;histedit&lt;/a&gt;」からソースを取得して設定する必要がある。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg clone https://bitbucket.org/durin42/histedit
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ソースからの場合は hgrc に以下のように設定する。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;[extensions]
histedit = /path/to/hg_histedit.py
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;histedit の使い方は「hg help -e histedit」でhg の help を見ると和訳されている。&lt;br /&gt;
英語だが公式のマニュアルを見ても良い「&lt;a href=&quot;http://mercurial.selenic.com/wiki/HisteditExtension&quot;&gt;Histedit Extension&lt;/a&gt;」。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg histedit まとめたいバージョン
&lt;/pre&gt;&lt;/div&gt;
&lt;h4&gt;push の前に確認する&lt;/h4&gt;
&lt;p&gt;「hg log」や「hg glog」を利用して意図した通りになっているか十分確認する。push するとhisteditでの変更ができない。&lt;/p&gt;
&lt;p&gt;Hg-Gitプラグインは「--HG--」のようなコメントを挿入してしまう。これを抑止するにはソースを直接修正するしかない。&lt;br /&gt;
「hggit/git_handler.py」に該当部分が存在するので、気になる場合は、削除かコメントアウトしておくと良い。&lt;/p&gt;
&lt;h4&gt;push して pull request &lt;/h4&gt;
&lt;p&gt;hg-git でpush するのは hg で push するのと何も変らない。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg push
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;あとは GitHub のWeb から該当の branch を pull request すれば良い。&lt;/p&gt;
&lt;h4&gt;本家に追随する&lt;/h4&gt;
&lt;p&gt;本家が自分のpull requestを取り込みしてくれたら、追随する必要がある。&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;hg pull -r master git+ssh://github.com/octocat/Spoon-Knife.git
hg up
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで取り込める。master に commit していると面倒なことになるので、master では開発しないようにした方が良い。&lt;/p&gt;
&lt;h4&gt;まとめ&lt;/h4&gt;
&lt;p&gt;これでGitHub の pull request が hg で可能になる。&lt;/p&gt;</description><link>http://www.sakito.com/2012/10/mercurialhg-github-pull-request.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item></channel></rss>