Home

Advertisement

http://www.flickr.com/photos/20958118@N0

「かな」でIMEオンがデフォルトでこれは問題ないですが、IMEオフがわかりづらく、私的には「英数」キーでIMEオフが直感的なので。以下のスクショの順番にでキーバインドを変更すればいいです。

WS000000

 WS000001

WS000002

 WS000003

WS000004

Cool MacBook

  • Mar. 28th, 2009 at 9:27 AM
http://www.flickr.com/photos/20958118@N0

Cool MacBook, originally uploaded by hidelafoglia.

キーボードのバックライト(笑)がかっこいい。

New MacBook

  • Mar. 26th, 2009 at 8:38 AM
http://www.flickr.com/photos/20958118@N0

New MacBook, originally uploaded by hidelafoglia.

PCで一番重要なもの。
それはOSでもソフトウエアでもなくキーボードです。

前回の黒MacBookがかなりよかったので今回もMacBookにしましたが、新しい方はさらにいいです。しかも、キーボードが下から照らされてかっこいいです。

今回のMacBookではWindowsも使わないでみます。

http://www.flickr.com/photos/20958118@N0

The Buffer, originally uploaded by pahnl.

「CSVファイルで落としてください」という管理機能はよくある普通のリクエストです。

が、PHPが.htaccessで

php_value auto_prepend_file default-header.php

とかしているとすべてのURLのPHPスクリプトの実行前に、default-header.phpが走ってしまってその中で何らかの通常の出力処理をしていると、header()でContent-Typeを操作することができなくなったりします。Content-Typeが確定してしまっているからです。

そんなときは、auto_prepend_fileで指定されたスクリプトの先頭で、

 

<?php
ob_start();       //output buffering



をやっておきます。条件によってCSV(など)のダウンロードをするときには、




<?php
  ob_clean();     //output buffer clear
  header("Cache-Control: public");
  header('Content-type: application/x-csv');
  header('Content-Disposition: attachment; filename="address.csv"');



見たいにすればいいのではないでしょうか?




* 追記: exit() とかで抜けないとauto_append_fileで指定されたPHPスクリプトが動く可能性があるので必ず入れるようにした方がよい。

http://www.flickr.com/photos/20958118@N0

fixture, originally uploaded by nardell.
hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py dumpdata auth > auth.json

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "drop database tohyo" | sudo mysql

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ more ../mysql/create.sh
echo "CREATE DATABASE IF NOT EXISTS tohyo  DEFAULT CHARACTER SET utf8" | sudo mysql
echo "grant all privileges on tohyo.*  to 'tohyo'@'localhost' identified by 'tohyo'" | sudo
 mysql

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ ../mysql/create.sh



hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table microblog_tag
Creating table microblog_note
Creating table microblog_profile

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'hdknr'): admin
E-mail address: admin@hoge.com
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for microblog.Note model
Installing index for microblog.Profile model

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t


hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py loaddata auth.json
Installing json fixture 'auth' from absolute path.
Installed 35 object(s) from 1 fixture(s)

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t
+----+--------+
| id | name   |
+----+--------+
|  1 | member |
+----+--------+

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ cp auth.json microblog/fixture/initial_data.json

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "drop database tohyo" | sudo mysql
hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ ../mysql/create.sh

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py syncdb

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t

”アプリケーション”/fixture/initial_data.jsonはだめのようです。


hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !610
echo "drop database tohyo" | sudo mysql
hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !611
../mysql/create.sh

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !612
python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table microblog_tag
Creating table microblog_note
Creating table microblog_profile

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'hdknr'): admin
E-mail address: admin@hdknr.vpc
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
Installing index for microblog.Note model
Installing index for microblog.Profile model
Installing json fixture 'initial_data' from absolute path.
Installed 35 object(s) from 1 fixture(s)

hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ echo "select * from auth_group " | sudo mysql tohyo -t
+----+--------+
| id | name   |
+----+--------+
|  1 | member |
+----+--------+

プロジェクト直下に置くとよいみたいです。


これとは別にsqlも用意しておいた方がいいような気がしますがどうなんでしょうか。デプロイの経験が足りません。。。



ちなみに、



hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ python manage.py dumpdata auth --format=json --indent=2 > initial_data.json



で読みやすくしたほうがいいでしょうね。



ちなみに、多くのauthのデータはデフォルトのsyncdbで追加されるので、以下の用に削ったほうがいいかも。



hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ more initial_data.json

[

  {


    "pk": 1,


    "model": "auth.group",


    "fields": {


      "name": "member",


      "permissions": []


    }


  }


]



hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !630

echo "drop database tohyo" | sudo mysql


hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !631


../mysql/create.sh


hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !632


python manage.py syncdb


Creating table auth_permission


Creating table auth_group


Creating table auth_user


Creating table auth_message


Creating table django_content_type


Creating table django_session


Creating table django_site


Creating table django_admin_log


Creating table microblog_tag


Creating table microblog_note


Creating table microblog_profile



You just installed Django's auth system, which means you don't have any superusers defined.

Would you like to create one now? (yes/no): yes


Username (Leave blank to use 'hdknr'): admin


E-mail address: admin@hdknr.vpc


Password:


Password (again):


Superuser created successfully.


Installing index for auth.Permission model


Installing index for auth.Message model


Installing index for admin.LogEntry model


Installing index for microblog.Note model


Installing index for microblog.Profile model


Installing json fixture 'initial_data' from absolute path.


Installed 1 object(s) from 1 fixture(s)



hdknr@deb09:~/bitbucket/tohyo/trunk/tohyo$ !619

echo "select * from auth_group " | sudo mysql tohyo -t


+----+--------+


| id | name   |


+----+--------+


|  1 | member |


+----+--------+

SSL:Python:Twistedで証明書の確認

  • Mar. 18th, 2009 at 5:02 PM
http://www.flickr.com/photos/20958118@N0

New Working Certificates, originally uploaded by Blazingstar.

connectionMade()でダンプしても証明書情報がまだ来ていないようです。

#!/usr/bin/python

import sys

from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver
from twisted.internet import ssl, reactor
from OpenSSL import SSL, crypto

import hashlib

class SslClient(LineReceiver):
    def dump(self):
        print str(dir(crypto))
        cert = self.transport.socket.get_peer_certificate()     #X509
        if cert != None:
            print "X.509:subject:",str(cert.get_subject())
            print "X.509:issuer:",str(cert.get_issuer())
            print "X.509:pubkey:",str(cert.get_pubkey())
            print "X.509:serial:",str(cert.get_serial_number())
            print "X.509:version:",str(cert.get_version())

            ft=[crypto.FILETYPE_PEM,crypto.FILETYPE_ASN1]
            out=[crypto.dump_certificate(x,cert) for x in ft ]

            print "PEM"
            print  out[0]

    def connectionMade(self):
        self.count=0
        print "connected"
#       self.dump()
        self.sendLine("GET / HTTP/1.0\n\n")

    def connectionLost(self, reason):
        print 'connection lost (protocol)'

    def lineReceived(self,line):
        if self.count ==0:
            self.dump()
        self.count = self.count + 1
        print "receive:", line

#    def dataReceived(self,data):
#        print "data received:"

class SslClientFactory(ClientFactory):
    protocol = SslClient

    def clientConnectionFailed(self, connector, reason):
        print 'connection failed:', reason.getErrorMessage()
        reactor.stop()

    def clientConnectionLost(self, connector, reason):
        print 'connection lost:', reason.getErrorMessage()
        reactor.stop()

def main():
    factory = SslClientFactory()
    cname ="www.nri.co.jp"  #"trac.hdknr.com"
    reactor.connectSSL(cname,443, factory, ssl.ClientContextFactory())
    reactor.run()

if __name__ == '__main__':
    main()
 
実行


hdknr@deb09:~/tmp$ python ssl_client.py  > test.log


確認



connected
['Error', 'FILETYPE_ASN1', 'FILETYPE_PEM', 'NetscapeSPKI', 'NetscapeSPKIType', 'PKCS12Type'
, 'PKCS7Type', 'PKey', 'PKeyType', 'TYPE_DSA', 'TYPE_RSA', 'X509', 'X509Extension', 'X509Ex
tensionType', 'X509Name', 'X509NameType', 'X509Req', 'X509ReqType', 'X509StoreType', 'X509T
ype', 'X509_verify_cert_error_string', '_C_API', '__doc__', '__file__', '__name__', 'dump_c
ertificate', 'dump_certificate_request', 'dump_privatekey', 'load_certificate', 'load_certi
ficate_request', 'load_pkcs12', 'load_pkcs7_data', 'load_privatekey']
X.509:subject: <X509Name object '/C=JP/ST=Tokyo/L=Chiyoda-ku/O=Nomura Research Institute, L
td./OU=Corporate Communications Department 2/OU=Terms of use at www.verisign.co.jp/rpa (c)
04/OU=Authenticated by VeriSign Japan K.K./OU=Member, VeriSign Trust Network/CN=www.nri.co.
jp'
>
X.509:issuer: <X509Name object '/O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign Int
ernational Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 V
eriSign'
>
X.509:pubkey: <PKey object at 0x93d1440>
X.509:serial: 64454780886854630778464923473080159816
X.509:version: 2
PEM
-----BEGIN CERTIFICATE-----
MIIE8TCCBFqgAwIBAgIQMH2KDL1XmAaXQDFVFlcOSDANBgkqhkiG9w0BAQQFADCB
ujEfMB0GA1UEChMWVmVyaVNpZ24gVHJ1c3QgTmV0d29yazEXMBUGA1UECxMOVmVy
aVNpZ24sIEluYy4xMzAxBgNVBAsTKlZlcmlTaWduIEludGVybmF0aW9uYWwgU2Vy
dmVyIENBIC0gQ2xhc3MgMzFJMEcGA1UECxNAd3d3LnZlcmlzaWduLmNvbS9DUFMg
SW5jb3JwLmJ5IFJlZi4gTElBQklMSVRZIExURC4oYyk5NyBWZXJpU2lnbjAeFw0w
ODA2MTcwMDAwMDBaFw0wOTA3MDYyMzU5NTlaMIIBNDELMAkGA1UEBhMCSlAxDjAM
BgNVBAgTBVRva3lvMRMwEQYDVQQHFApDaGl5b2RhLWt1MSgwJgYDVQQKFB9Ob211
cmEgUmVzZWFyY2ggSW5zdGl0dXRlLCBMdGQuMS4wLAYDVQQLFCVDb3Jwb3JhdGUg
Q29tbXVuaWNhdGlvbnMgRGVwYXJ0bWVudCAyMTYwNAYDVQQLEy1UZXJtcyBvZiB1
c2UgYXQgd3d3LnZlcmlzaWduLmNvLmpwL3JwYSAoYykgMDQxLTArBgNVBAsTJEF1
dGhlbnRpY2F0ZWQgYnkgVmVyaVNpZ24gSmFwYW4gSy5LLjEnMCUGA1UECxMeTWVt
YmVyLCBWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMRYwFAYDVQQDFA13d3cubnJpLmNv
LmpwMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDYuuArumwjgRGCJ9e1b2i5
wdvsT6hKgSJccDYNJevtLPnTuam+Lh/oyaP5XrNnU3M1ThRUtPR1W9Z7aIHe/ZiI
58FnGbENPYDtuQeD8jsRSlBwWrlvXuKemV7gqyNn1yX9gXZURMmT9kYT4sgP8XSc
EZG3sbHfIBcz/2YInTyZowIDAQABo4IBeTCCAXUwCQYDVR0TBAIwADCBrAYDVR0g
BIGkMIGhMIGeBgtghkgBhvhFAQcBATCBjjAoBggrBgEFBQcCARYcaHR0cHM6Ly93
d3cudmVyaXNpZ24uY29tL0NQUzBiBggrBgEFBQcCAjBWMBUWDlZlcmlTaWduLCBJ
bmMuMAMCAQEaPVZlcmlTaWduJ3MgQ1BTIGluY29ycC4gYnkgcmVmZXJlbmNlIGxp
YWIuIGx0ZC4gKGMpOTcgVmVyaVNpZ24wEQYJYIZIAYb4QgEBBAQDAgZAMCgGA1Ud
JQQhMB8GCWCGSAGG+EIEAQYIKwYBBQUHAwEGCCsGAQUFBwMCMDQGCCsGAQUFBwEB
BCgwJjAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24uY29tMEYGA1Ud
HwQ/MD0wO6A5oDeGNWh0dHA6Ly9jcmwudmVyaXNpZ24uY29tL0NsYXNzM0ludGVy
bmF0aW9uYWxTZXJ2ZXIuY3JsMA0GCSqGSIb3DQEBBAUAA4GBALYhYXknbFyQndKr
dRSN351NMcvsvbwVp7DCrRYQZfTFbvZKKICTBW1Y3xcUkTJodzw0OadTFr/0egVz
K9HwTGVUIUmtrL011t3T4fNslEsDoL3Af+/wFG8qdpCgH1pRqBQWGIwKPPNZ+NUe
M6pMCtAc4Yhma8qSmomlmwV6Q2ir
-----END CERTIFICATE-----

receive: HTTP/1.1 200 OK
receive: Date: Wed, 18 Mar 2009 07:46:46 GMT
receive: Server: Apache
receive: Last-Modified: Wed, 18 Mar 2009 01:32:14 GMT
receive: ETag: "baae-a73b8380"
receive: Accept-Ranges: bytes
receive: Content-Length: 47790
receive: Connection: close
receive: Content-Type: text/html
receive:
connection lost (protocol)
connection lost: Connection was closed cleanly.

http://www.flickr.com/photos/20958118@N0

mail box, originally uploaded by TommyOshima.

Postfix:DebianでさらからMailJailの環境を作る - Windows Live"だけでは不足でした。(trac)

Djangoでメール送信。

hdknr@deb09:~/tohyo/tohyo/trunk/tohyo$ more microblog/mails.py
from django.core.mail import send_mail


def test():
    print send_mail('aaaaaaaaaaaaaa_subject____','message','tohyo@hdknr.test',['test@hdknr.test'],fail_silently=False)



実行するとエラー




Mar 14 03:20:19 deb09 postfix/smtp[3609]: 5CA881DD587: to=<mailjail@mailjail.local>, orig_to=<test@hdknr.test>, relay=none, delay=0.29, delays=0.16/0.05/0.07/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)




なので、/etc/postfix/main.cfの修正




virtual_alias_maps = proxy:mysql:/etc/postfix/MySQL/mysql/virtual_alias_maps.cf,hash:/etc/postfix/virtual-test



deb09:/etc/postfix# more virtual-test

@hdknr.test     mailjail@mailjail.local




再度エラー。




Mar 14 03:20:19 deb09 postfix/smtp[3609]: B17571DD5CC: to=<mailjail@mailjail.local>, orig_to=<tohyo@hdknr.test>, relay=none, delay=0.04, delays=0.02/0.01/0/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)

Mar 14 03:20:19 deb09 postfix/qmgr[3601]: B17571DD5CC: removed




/etc/hosts修正。




deb09:/etc/postfix# vi /etc/hosts

127.0.1.1       deb09.hdknr.local       deb09   mailjail.local




それでもエラー。




Mar 14 03:23:28 deb09 postfix/smtp[3625]: AA87C1DD5CC: to=<mailjail@mailjail.local>, orig_to=<tohyo@hdknr.test>, relay=none, delay=0.08, delays=0.07/0.01/0/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=mailjail.local type=A: Host not found)




virtual に “mailjail.local”を追加する。




deb09:/etc/postfix# echo "insert into domain ( domain,transport) values('mailjail.local','mailjail')" | mysql postfix –t



deb09:/etc/postfix# echo "select * from domain" | mysql postfix -t

+----------------+-------------+---------+-----------+----------+-------+-----------+----------+---------------------+---------------------+--------+


| domain         | description | aliases | mailboxes | maxquota | quota | transport | backupmx | created             | modified            | active |


+----------------+-------------+---------+-----------+----------+-------+-----------+----------+---------------------+---------------------+--------+


| ALL            |             |       0 |         0 |        0 |     0 |           |        0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |      1 |


| hdknr.vpc      |             |      10 |        10 |       10 |     0 | virtual   |        0 | 2009-03-09 02:13:56 | 2009-03-09 02:13:56 |      1 |


| hdknr.test     |             |       0 |         0 |        0 |     0 | mailjail  |        0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |      1 |


| mailjail.local |             |       0 |         0 |        0 |     0 | mailjail  |        0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |      1 |


+----------------+-------------+---------+-----------+----------+-------+-----------+----------+---------------------+---------------------+--------+




うまくいきました。




Mar 14 03:30:58 deb09 postfix/pipe[3654]: 252D01DD5CB: to=<mailjail@mailjail.local>, orig_to=<test@hdknr.test>, relay=mailjail, delay=0.16, delays=0.09/0.03/0/0.04, dsn=2.0.0, status=sent (delivered via mailjail service)



hdknr@deb09:~/mailjail/mail$ more *

From tohyo@hdknr.test  Sat Mar 14 03:30:58 2009


Return-Path: <tohyo@hdknr.test>


Delivered-To: mailjail@mailjail.local


Received: from deb09.hdknr.local (localhost [127.0.0.1])


        by deb09.hdknr.local (Postfix) with ESMTP id 252D01DD5CB


        for <test@hdknr.test>; Sat, 14 Mar 2009 03:30:58 +0900 (JST)


Content-Type: text/plain; charset="utf-8"


MIME-Version: 1.0


Content-Transfer-Encoding: quoted-printable


Subject: aaaaaaaaaaaaaa_subject____


From: tohyo@hdknr.test


To: test@hdknr.test


Date: Fri, 13 Mar 2009 18:30:58 -0000


Message-ID: <20090313183058.3648.67160@deb09.hdknr.local>



message

http://www.flickr.com/photos/20958118@N0

Flower role model, originally uploaded by LeeRogers.

とりあえず、urls.pyで以下のようにして実装してみました。

from django.conf.urls.defaults import *
from django.http import HttpResponseRedirect

from microblog import views

LOGIN_URL=('/microblog/login/?next=%s' 
def action_acl(views,action,allow ):
    def _action(request,*args,**kwargs): 
        if not request.user.is_authenticated():
            return HttpResponseRedirect( LOGIN_URL % request.path)
        for u in request.user.groups.iterator():
            if u in allow:
                return getattr(views,action)(request,*args,**kwargs)
        return HttpResponseRedirect( LOGIN_URL  % request.path)
    return _action

urlpatterns = patterns('tohyo.microblog.views',
    (r'^note/'  ,  action_acl(views,'note_index',['member'] )),
)


action_acl関数で対象のアクションに対して許可されているロール(groups)を現在のユーザーを持っているかどうかを確認して認証されていない、


あるいはグループに属していない人をログインページに飛ばしています。


こんなんでいいのかな?
http://www.flickr.com/photos/20958118@N0

Rooted and went to new house, originally uploaded by yoshiko314.

Mar  9 03:10:48 deb09 postfix/trivial-rewrite[5593]: fatal: mysql:/etc/postfix/MySQL/mysql/virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem

deb09:/etc/postfix/MySQL/mysql# postmap -v  mysql:/etc/postfix/MySQL/mysql/virtual_alias_maps.cf

postmap: fatal: dict_mkmap_func: unsupported dictionary type: mysql does not allow map creation.

問題はこれか?

Mar  9 03:20:59 deb09 postfix/trivial-rewrite[5628]: warning: connect to mysql server localhost: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

chrootしているのです!

deb09:/etc/postfix/MySQL/mysql# grep proxy /etc/postfix/main.cf
transport_maps =proxy:mysql:/etc/postfix/MySQL/mysql/virtual_transport_maps.cf
virtual_transport=proxy:mysql:/etc/postfix/MySQL/mysql/virtual_transport_maps.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/MySQL/mysql/virtual_alias_maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/MySQL/mysql/virtual_domains_maps.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/MySQL/mysql/virtual_mailbox_maps.cf

うまくいった。忘れるんだよな。。。。

http://www.flickr.com/photos/20958118@N0

http_proxy以外にhttps_proxyも必要です。

[hdknr@localhost bin]$ curl -I http://www.msn.com
HTTP/1.0 405 Method Not Allowed
Date: Fri, 06 Mar 2009 05:59:15 GMT
Server: Microsoft-IIS/6.0
P3P: CP="BUS CUR CONo FIN IVDo ONL OUR PHY SAMo TELo"
S: TK2PTLRENB09
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 3026
X-Cache: MISS from proxy
X-Cache: MISS from proxy
X-Cache: MISS from nrisaf53.index.or.jp
Proxy-Connection: close

[hdknr@localhost bin]$ curl -I https://www.msn.com
curl: (6) Couldn't resolve host 'www.msn.com'

[hdknr@localhost bin]$ vi ~/.proxy
export https_proxy=http://xga00008:H7scJzUh@hoge.enterproise.com:86/

[hdknr@localhost bin]$ curl -I https://trac.hdknr.com
HTTP/1.0 200 Connection established

http://www.flickr.com/photos/20958118@N0

Yum, originally uploaded by Siggav.

sudo yum updateでエラー 。/etc/yum.confにproxyを設定してhttp_proxy環境変数も設定しているのですが。。。CentOS5.2

Total download size: 78 M
Is this ok [y/N]: y
Downloading Packages:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897


GPG key retrieval failed: [Errno 4] IOError: <urlopen error (-2, 'Name or service not known')>

GPGのキーをインストールする必要がある。

[hdknr@localhost bin]$ curl -I http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
HTTP/1.0 200 OK
Date: Wed, 04 Mar 2009 06:18:54 GMT
Server: Apache/2.0.52 (CentOS)
Last-Modified: Mon, 19 Feb 2007 17:57:47 GMT
ETag: "157c112-5e0-101f3cc0"
Accept-Ranges: bytes
Content-Length: 1504
Content-Type: text/plain; charset=UTF-8
X-Cache: MISS from proxy
X-Cache: MISS from proxy
X-Cache: MISS from nrisaf54.index.or.jp
Proxy-Connection: close
rpmコマンドでインポート。

[hdknr@localhost bin]$ sudo rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
error: http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5: import read failed(-1).
[hdknr@localhost bin]$ curl http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.6 (GNU/Linux)

mQGiBEWfB6MRBACrnYW6yKMT+MwJlCIhoyTxGf3mAxmnAiDEy6HcYN8rivssVTJk
CFtQBlBOpLV/OW2YtKrCO2xHn46eNfnMri8FGT8g+9JF3MUVi7kiV1He4iJynHXB
+F2ZqIvHf3IaUj1ys+p8TK64FDFxDQDrGQfIsD/+pkSGx53/877IrvdwjwCguQcr
Ioip5TH0Fj0OLUY4asYVZH8EAIqFHEqsY+9ziP+2R3/FyxSllKkjwcMLrBug+cYO
LYDD6eQXE9Mq8XKGFDj9ZB/0+JzK/XQeStheeFG75q3noq5oCPVFO4czuKErIRAB
qKbDBhaTj3JhOgM12XsUYn+rI6NeMV2ZogoQCC2tWmDETfRpYp2moo53NuFWHbAy
XjETA/sHEeQT9huHzdi/lebNBj0L8nBGfLN1nSRP1GtvagBvkR4RZ6DTQyl0UzOJ
RA3ywWlrL9IV9mrpb1Fmn60l2jTMMCc7J6LacmPK906N+FcN/Docj1M4s/4CNanQ
NhzcFhAFtQL56SNyLTCk1XzhssGZ/jwGnNbU/aaj4wOj0Uef5LRGQ2VudE9TLTUg
S2V5IChDZW50T1MgNSBPZmZpY2lhbCBTaWduaW5nIEtleSkgPGNlbnRvcy01LWtl
eUBjZW50b3Mub3JnPohkBBMRAgAkBQJFnwekAhsDBQkSzAMABgsJCAcDAgMVAgMD
FgIBAh4BAheAAAoJEKikR9zoViiXKlEAmwSoZDvZo+WChcg3s/SpNoWCKhMAAJwI
E2aXpZVrpsQnInUQWwkdrTiL5YhMBBMRAgAMBQJFnwiSBYMSzAIRAAoJEDjCFhY5
bKCk0hAAn134bIx3wSbq58E6P6U5RT7Z2Zx4AJ9VxnVkoGHkVIgSdsxHUgRjo27N
F7kBDQRFnwezEAQA/HnJ5yiozwgtf6jt+kii8iua+WnjqBKomPHOQ8moxbWdv5Ks
4e1DPhzRqxhshjmub4SuJ93sgMSAF2ayC9t51mSJV33KfzPF2gIahcMqfABe/2hJ
aMzcQZHrGJCEX6ek8l8SFKou7vICzyajRSIK8gxWKBuQknP/9LKsoczV+xsAAwUD
/idXPkk4vRRHsCwc6I23fdI0ur52bzEqHiAIswNfO521YgLk2W1xyCLc2aYjc8Ni
nrMX1tCnEx0/gK7ICyJoWH1Vc7//79sWFtX2EaTO+Q07xjFX4E66WxJlCo9lOjos
Vk5qc7R+xzLDoLGFtbzaTRQFzf6yr7QTu+BebWLoPwNTiE8EGBECAA8FAkWfB7MC
GwwFCRLMAwAACgkQqKRH3OhWKJfvvACfbsF1WK193zM7vSc4uq51XsceLwgAoI0/
9GxdNhGQEAweSlQfhPa3yYXH
=o/Mx
-----END PGP PUBLIC KEY BLOCK-----
いったんファイルにダウンロードする必要があるのです。

[hdknr@localhost bin]$ curl http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 > key.txt
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1504  100  1504    0     0   2671      0 --:--:-- --:--:-- --:--:--  489k
[hdknr@localhost bin]$ sudo rpm --import key.txt
yum updateがうまくいきました。CentOSをインストールしたら最初にGPGのパブリックキーをインストールしましょう!

 

 

Oracle: sqlplus on Debian Lenny

  • Mar. 4th, 2009 at 5:45 AM
http://www.flickr.com/photos/20958118@N0

Oracle Aoyama Center, originally uploaded by hidelafoglia.

hdknr@deb09:~$ tail /etc/apt/sources.list
#
deb http://oss.oracle.com/debian unstable main non-free

hdknr@deb09:~$ sudo aptitude update
発見 http://ftp.jp.debian.org lenny Release.gpg
発見 http://ftp.jp.debian.org lenny/main Translation-ja
無視 http://ftp.jp.debian.org lenny/non-free Translation-ja
無視 http://ftp.jp.debian.org lenny/contrib Translation-ja
発見 http://ftp.jp.debian.org lenny Release
取得:1 http://oss.oracle.com unstable Release.gpg [189B]
無視 http://oss.oracle.com unstable/main Translation-ja
無視 http://oss.oracle.com unstable/non-free Translation-ja
無視 http://ftp.jp.debian.org lenny/main Packages/DiffIndex
無視 http://ftp.jp.debian.org lenny/non-free Packages/DiffIndex
無視 http://ftp.jp.debian.org lenny/contrib Packages/DiffIndex
無視 http://ftp.jp.debian.org lenny/main Sources/DiffIndex
無視 http://ftp.jp.debian.org lenny/non-free Sources/DiffIndex
無視 http://ftp.jp.debian.org lenny/contrib Sources/DiffIndex
発見 http://ftp.jp.debian.org lenny/main Packages
発見 http://ftp.jp.debian.org lenny/non-free Packages
発見 http://ftp.jp.debian.org lenny/contrib Packages
取得:2 http://oss.oracle.com unstable Release [2126B]
発見 http://ftp.jp.debian.org lenny/main Sources
発見 http://ftp.jp.debian.org lenny/non-free Sources
発見 http://ftp.jp.debian.org lenny/contrib Sources
無視 http://oss.oracle.com unstable Release
発見 http://security.debian.org lenny/updates Release.gpg
無視 http://security.debian.org lenny/updates/main Translation-ja
取得:3 http://oss.oracle.com unstable/main Packages [386B]
無視 http://security.debian.org lenny/updates/contrib Translation-ja
取得:4 http://oss.oracle.com unstable/non-free Packages [671B]
発見 http://security.debian.org lenny/updates Release
無視 http://security.debian.org lenny/updates/main Packages/DiffIndex
無視 http://security.debian.org lenny/updates/contrib Packages/DiffIndex
無視 http://security.debian.org lenny/updates/main Sources/DiffIndex
無視 http://security.debian.org lenny/updates/contrib Sources/DiffIndex
発見 http://security.debian.org lenny/updates/main Packages
発見 http://security.debian.org lenny/updates/contrib Packages
発見 http://security.debian.org lenny/updates/main Sources
発見 http://security.debian.org lenny/updates/contrib Sources
3372B を 2s 秒でダウンロードしました (1269B/s)
パッケージリストを読み込んでいます... 98%
パッケージリストを読み込んでいます... 完了
W: GPG error: http://oss.oracle.com unstable Release: 公開鍵を利用できないため、以下の署名は検証できませんでした: NO_PUBKEY 2E2BCDBCB38A8516
W: これらの問題を解決するためには apt-get update を実行する必要があるかもしれません

現在の状態: 新規が 8165 個 [+4]。

hdknr@deb09:~$ apt-cache search oracle
:
:
ora2pg - Oracle to PostgreSQL database schema converter
oracle-xe - Oracle Database 10g Express Western European Edition
oracle-xe-client - Oracle Client 10g Express Edition
oracle-xe-universal - Oracle Database 10g Express Universal Edition
hdknr@deb09:~$ sudo aptitude install oracle-xe-client
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了
以下の新規パッケージがインストールされます:
  bc{a} libaio{a} oracle-xe-client
更新: 0 個、新規インストール: 3 個、削除: 0 個、保留: 0 個。
26.0MB のアーカイブを取得する必要があります。展開後に 71.0MB のディスク領域が新たに消費されます。
先に進みますか? [Y/n/?] y
警告: 以下のパッケージは信頼できないバージョンがインストールされます!

信頼できないパッケージはシステムのセキュリティを危うくする可能性があります。
自分がこのインストールを望んでいると確信できる場合のみ、インストールを先に進め
てください。

  oracle-xe-client libaio

この警告を無視して意地でも先に進みますか?
先に進む場合は "Yes" を、中断する場合は "No" を、入力してください:Yes

拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org lenny/main bc 1.06.94-3 [72.2kB]
取得:2 http://oss.oracle.com unstable/main libaio 0.3.104-1 [6018B]
取得:3 http://oss.oracle.com unstable/non-free oracle-xe-client 10.2.0.1-1.2 [25.9MB]
26.0MB を 44s 秒でダウンロードしました (587kB/s)
未選択パッケージ bc を選択しています。
(データベースを読み込んでいます ... 現在 61052 個のファイルとディレクトリがインストールされています。)
(.../archives/bc_1.06.94-3_i386.deb から) bc を展開しています...
未選択パッケージ libaio を選択しています。
(.../libaio_0.3.104-1_i386.deb から) libaio を展開しています...
未選択パッケージ oracle-xe-client を選択しています。
(.../oracle-xe-client_10.2.0.1-1.2_i386.deb から) oracle-xe-client を展開しています...
man-db のトリガを処理しています ...
bc (1.06.94-3) を設定しています ...
libaio (0.3.104-1) を設定しています ...
oracle-xe-client (10.2.0.1-1.2) を設定しています ...
Executing Post-install steps..........
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了
タスクの記述を読み込んでいます... 完了

hdknr@deb09:~$ /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin/sqlplus hdknr/hdknr@192.168.250.2:1521

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Mar 4 14:47:19 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

hdknr@deb09:~$ sudo lsof -i:1521
COMMAND  PID  USER   FD   TYPE DEVICE SIZE NODE NAME
sqlplus 4308 hdknr    4u  IPv4  10249       TCP hdknr.vpc:53506->vista:1521 (ESTABLISHED)

http://www.flickr.com/photos/20958118@N0

Mercurial (II), originally uploaded by emiedes.

インストールはhttp://mercurial.berkwood.com/ から最新バージョンのインストーラを落として実行するだけです。

C:\Users\hide>tree "\Program Files\Mercurial" /F
フォルダ パスの一覧
ボリューム シリアル番号は 0055-CA17 です
C:\PROGRAM FILES\MERCURIAL
│  add_path.exe
│  Contributors.txt
│  Copying.txt
│  hg.exe
│  hg.exe.local
│  library.zip
│  Mercurial.ini
│  Mercurial.url
│  mfc71.dll
│  msvcr71.dll
│  ReadMe.html
│  ReleaseNotes.txt
│  unins000.dat
│  unins000.exe
│  w9xpopen.exe

├─Contrib
│  │  mercurial.el
│  │  zsh_completion
│  │
│  └─Vim
│          hg-menu.vim
│          HGAnnotate.vim
│          hgcommand.vim
│          patchreview.txt
│          patchreview.vim

├─Docs
│      hg.1.html
│      hgignore.5.html
│      hgrc.5.html

└─Templates
    │  map-cmdline.changelog
    │  map-cmdline.compact
    │  map-cmdline.default
    │  template-vars.txt
    │
    ├─atom
    │      changelog.tmpl
    │      changelogentry.tmpl
    │      filelog.tmpl
    │      header.tmpl
    │      map
    │      tagentry.tmpl
    │      tags.tmpl
    │
    ├─coal
    │      header.tmpl
    │      map
    │
    ├─gitweb
    │      changelog.tmpl
    │      changelogentry.tmpl
    │      changeset.tmpl
    │      error.tmpl
    │      fileannotate.tmpl
    │      filediff.tmpl
    │      filelog.tmpl
    │      filerevision.tmpl
    │      footer.tmpl
    │      graph.tmpl
    │      header.tmpl
    │      index.tmpl
    │      manifest.tmpl
    │      map
    │      notfound.tmpl
    │      search.tmpl
    │      shortlog.tmpl
    │      summary.tmpl
    │      tags.tmpl
    │
    ├─monoblue
    │      changelog.tmpl
    │      changelogentry.tmpl
    │      changeset.tmpl
    │      error.tmpl
    │      fileannotate.tmpl
    │      filediff.tmpl
    │      filelog.tmpl
    │      filerevision.tmpl
    │      footer.tmpl
    │      graph.tmpl
    │      header.tmpl
    │      index.tmpl
    │      manifest.tmpl
    │      map
    │      notfound.tmpl
    │      search.tmpl
    │      shortlog.tmpl
    │      summary.tmpl
    │      tags.tmpl
    │
    ├─paper
    │      changeset.tmpl
    │      error.tmpl
    │      fileannotate.tmpl
    │      filediff.tmpl
    │      filelog.tmpl
    │      filelogentry.tmpl
    │      filerevision.tmpl
    │      footer.tmpl
    │      graph.tmpl
    │      header.tmpl
    │      index.tmpl
    │      manifest.tmpl
    │      map
    │      notfound.tmpl
    │      search.tmpl
    │      shortlog.tmpl
    │      shortlogentry.tmpl
    │      tags.tmpl
    │
    ├─raw
    │      changeset.tmpl
    │      error.tmpl
    │      fileannotate.tmpl
    │      filediff.tmpl
    │      index.tmpl
    │      manifest.tmpl
    │      map
    │      notfound.tmpl
    │
    ├─rss
    │      changelog.tmpl
    │      changelogentry.tmpl
    │      filelog.tmpl
    │      filelogentry.tmpl
    │      header.tmpl
    │      map
    │      tagentry.tmpl
    │      tags.tmpl
    │
    ├─spartan
    │      changelog.tmpl
    │      changelogentry.tmpl
    │      changeset.tmpl
    │      error.tmpl
    │      fileannotate.tmpl
    │      filediff.tmpl
    │      filelog.tmpl
    │      filelogentry.tmpl
    │      filerevision.tmpl
    │      footer.tmpl
    │      graph.tmpl
    │      header.tmpl
    │      index.tmpl
    │      manifest.tmpl
    │      map
    │      notfound.tmpl
    │      search.tmpl
    │      shortlog.tmpl
    │      shortlogentry.tmpl
    │      tags.tmpl
    │
    └─static
            background.png
            coal-file.png
            coal-folder.png
            excanvas.js
            graph.js
            hgicon.png
            hglogo.png
            style-coal.css
            style-gitweb.css
            style-monoblue.css
            style-paper.css
            style.css

パスは通るので、

C:\Users\hide>hg -v
Mercurial Distributed SCM (version 1.1.2+20090302)

Copyright (C) 2005-2008 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Vistaの場合、設定は \Users\(ユーザー名)\Mercurial.ini で行います。

C:\Users\hide>gvim Mercurial.ini

[ui]
username = hidelafoglia
ssh = "c:\Program Files\putty-0.60-jp20070603\plink.exe" -l hg -i c:\Users\hide\.ssh\bitbucket.ppk

bitbucket.ppkはputtygen.exeで作ったプライベートキーで、同時に生成されたパブリックキーをBitbucket.orgに登録しておきます。

WS000042

C:\Users\hide\Documents\temp>hg clone ssh://hg@bitbucket.org/hdknr/djangocamp/
destination directory: djangocamp
requesting all changes
adding changesets
adding manifests
adding file changes
added 44 changesets with 117 changes to 59 files (+1 heads)
updating working directory
59 files updated, 0 files merged, 0 files removed, 0 files unresolved

Cloneできました。

http://www.flickr.com/photos/20958118@N0


Authentic Harmony, originally uploaded by cresk.

apacheの設定。

hdknr@deb09:~/authentic/etc$ more authentic.hdknr.vpc.conf
<VirtualHost *:80>
      ServerAdmin webmaster@locahost
      ServerName authentic.hdknr.vpc
      DocumentRoot /home/hdknr/authentic/www
      <LocationMatch "^/authentic(/|$)">
          SetHandler python-program
          PythonHandler quixote.server.mod_python_handler
          PythonOption quixote-publisher-factory authentic.qommon.publisher.QommonPublisher
          PythonDebug On
      </LocationMatch>

     LogLevel warn
     ErrorLog  /home/hdknr/authentic/logs/error.log
     CustomLog /home/hdknr/authentic/logs/access.log combined
</VirtualHost>

で、このまま動かすと QommonPublisher.create_publisher()が呼ばれない。(呼ばれなければいけないのかがよくわかっていない)

そこで、handler()をいじってみる。

hdknr@deb09:~$ vi /var/lib/python-support/python2.5/quixote/server/mod_python_handler.py

def handler(req):
    opts = req.get_options()
    try:
        factory = opts['quixote-publisher-factory']
    except KeyError:
        apache.log_error('quixote-publisher-factory setting required')
        return apache.HTTP_INTERNAL_SERVER_ERROR
    pub = name2publisher.get(factory)
    if pub is None:
#        factory_fcn = import_object(factory)
#        pub = factory_fcn()
        factory_obj = import_object(factory)    #HDKNR
        pub =factory_obj.create_publisher()     #HDKNR
        name2publisher[factory] = pub
    return run(pub, req)


とりあえず、classmethodのQommonPublisher.create_publisher()が呼ばれるようになりましたが、前回のログと同じ原因でトレースバック。


うーん。。。。


 
http://www.flickr.com/photos/20958118@N0

それともmod_pythonとquixoteの設定が悪い?

Restarting web server: apache2 ... waiting .
hdknr@deb09:~/authentic/etc$ python
Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> m='authentic.qommon.publisher'
>>> c='QommonPublisher'
>>> __import__(m)
<module 'authentic' from '/usr/lib/python2.5/site-packages/authentic/__init__.pyc'>
>>> x=getattr(sys.modules[m],c)
>>> x.create_publisher()


を実行すると、



Traceback (most recent call last):

  File "<stdin>", line 1, in <module>


  File "/usr/lib/python2.5/site-packages/authentic/qommon/publisher.py", line 329, in create_publisher


    publisher = cls(cls.root_directory_class(),


TypeError: 'NoneType' object is not callable



/usr/lib/python2.5/site-packages/authentic/qommon/publisher.pyにデバッグ入れてみると、



*** APP_DIR <type 'NoneType'>

*** APP_NAME <type 'NoneType'>


*** DATA_DIR <type 'NoneType'>


*** ERROR_LOG <type 'NoneType'>


*** __doc__ <type 'NoneType'>


*** __init__ <type 'instancemethod'>


*** __module__ <type 'str'>


*** _app_logger <type 'NoneType'>


*** _clear_request <type 'instancemethod'>


*** _generate_cgitb_error <type 'instancemethod'>


*** _generate_internal_error <type 'instancemethod'>


*** _generate_plaintext_error <type 'instancemethod'>


*** _set_request <type 'instancemethod'>


*** admin_directory_class <type 'NoneType'>


*** admin_help_url <type 'NoneType'>


*** after_login_url <type 'str'>


*** backoffice_directory_class <type 'NoneType'>


*** backoffice_help_url <type 'NoneType'>


*** cfg <type 'NoneType'>


*** clean_afterjobs <type 'instancemethod'>


*** clean_sessions <type 'instancemethod'>


*** create_publisher <type 'instancemethod'>


*** cronjobs <type 'list'>


*** default_configuration_path <type 'NoneType'>


*** default_theme <type 'str'>


*** export_cfg <type 'instancemethod'>


*** extra_dirs <type 'NoneType'>


*** filter_output <type 'instancemethod'>


*** finish_failed_request <type 'instancemethod'>


*** finish_interrupted_request <type 'instancemethod'>


*** finish_successful_request <type 'instancemethod'>


*** format_publish_error <type 'instancemethod'>


*** get_admin_module <type 'instancemethod'>


*** get_admin_root <type 'instancemethod'>


*** get_app_logger <type 'instancemethod'>


*** get_app_logger_filename <type 'instancemethod'>


*** get_application_static_files_root_url <type 'instancemethod'>


*** get_backoffice_module <type 'instancemethod'>


*** get_backoffice_root <type 'instancemethod'>


*** get_request <type 'instancemethod'>


*** get_root_url <type 'instancemethod'>


*** get_site_language <type 'instancemethod'>


*** ident_methods <type 'NoneType'>


*** import_cfg <type 'instancemethod'>


*** install_lang <type 'instancemethod'>


*** load_extra_dirs <type 'instancemethod'>


*** load_translations <type 'instancemethod'>


*** log <type 'instancemethod'>


*** parse_request <type 'instancemethod'>


*** process <type 'instancemethod'>


*** process_request <type 'instancemethod'>


*** qommon_static_dir <type 'str'>


*** register_cronjob <type 'instancemethod'>


*** register_extra_dir <type 'instancemethod'>


*** register_ident_methods <type 'instancemethod'>


*** register_translation_domain <type 'instancemethod'>


*** reload_cfg <type 'instancemethod'>


*** root_directory_class <type 'NoneType'>

*** session_manager_class <type 'NoneType'>


*** set_app_dir <type 'instancemethod'>


*** set_config <type 'instancemethod'>


*** set_session_manager <type 'instancemethod'>


*** site_charset <type 'str'>


*** start_request <type 'instancemethod'>


*** supported_languages <type 'NoneType'>


*** translation_domains <type 'NoneType'>


*** translations <type 'dict'>


*** try_publish <type 'instancemethod'>


*** unpickler_class <type 'NoneType'>


*** user_class <type 'NoneType'>


*** write_cfg <type 'instancemethod'>



なので、確かにTraceBackさんの言うとおり。



stableのtar-ballのauthenticを使うべきか?

http://www.flickr.com/photos/20958118@N0

PostfixのVirtualで運用しているので、さらしているドメインにエリアスをテーブルに追加します。

[admin@fedora flickr]$ echo "select * from postfix.alias where goto like '%local%'" | sudo mysql -t
+-----------------+----------------------+---------+---------------------+---------------------+--------+
| address         | goto                 | domain  | created             | modified            | active |
+-----------------+----------------------+---------+---------------------+---------------------+--------+
| flickr@hoge.com | posting@flickr.local | hoge.com| 2009-02-20 06:04:21 | 2009-02-17 17:15:08 |      1 |
+-----------------+----------------------+---------+---------------------+---------------------+--------+

flickr.localのトランスポートをvirtualではなくmaster.cfに登録する名前にします。

[admin@hoge ]$ echo "select * from postfix.domain where domain='flickr.local'" | sudo mysql -t
+-------------------+----------------+---------+-----------+----------+-----------+----------+---------------------+---------------------+--------+
| domain            | description    | aliases | mailboxes | maxquota | transport | backupmx | created             | modified            | active |
+-------------------+----------------+---------+-----------+----------+-----------+----------+---------------------+---------------------+--------+
| flickr.local      | flicker poster |       0 |         0 |        0 | flickr    |        0 | 2009-02-20 15:08:43 | 2008-02-20 15:08:43 |      1 |
+-------------------+----------------+---------+-----------+----------+-----------+----------+---------------------+---------------------+--------+

master.cfで呼び出すプログラムを指定します。

flickr unix - n n - - pipe
  flags=FDRq user=admin argv=/home/admin/bin/flickr/mailpost.py $sender $recipient

プログラムは以下のようにします。実行権限をつけること。

#!/usr/bin/python2.5

import sys
import time
from email import message_from_file
import smtplib
import re


DIR='/home/admin/bin/flickr'

def main():
  m=message_from_file(sys.stdin)
  # only accept email submit by your GMAIL account.
  if re.search('your_gmail_address@gmail.com',m['from']) == None:
     main2(m)
     return
  del m['from']
  del m['to']
  m['from']='hdknr@hoge.com'             # your address registered to Flickr
  m['to'] = 'ABCSEFG@photos.flickr.com'  # given by Flickr to you
  smtp = smtplib.SMTP('localhost')
  smtp.sendmail(m['from'],[m['to']],m.as_string())
  smtp.quit()

def main2(msg):
  (sender,receipient)=('from','to')
  if len(sys.argv) > 1:
    sender=sys.argv[1]
    if len(sys.argv)> 2:
       receipient = sys.argv[2]
  filename = sender + "-" + receipient+'-'+time.strftime('%Y%m%dT%H%M%S',time.localtime()) + ".eml"

  if sys.stdin.isatty():
    print "*** NO STDIN ***"
    return

  f=open(DIR+'/'+filename,'w')
  if None != f:
    f.writelines(msg.as_string())
    f.close()


if __name__ == '__main__':
  main()
http://www.flickr.com/photos/20958118@N0

データベース作成

hdknr@deb09:~/django$ echo "CREATE DATABASE rioja DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" | sudo mysql
hdknr@deb09:~/django$ echo "grant all privileges on rioja.* to 'rioja'@'localhost' identified by 'rioja'" | sudo mysql
hdknr@deb09:~/django$ zcat rioja_jp_wp_main.sql.log.1.gz  | mysql -u rioja rioja -p      

プロジェクト作成

hdknr@deb09:~/django$ django-admin startproject rioja
hdknr@deb09:~/django/rioja$ python manage.py startapp wordpress
hdknr@deb09:~/django/rioja$ vi settings.py
DATABASE_ENGINE = 'mysql'          
DATABASE_NAME = 'rioja'            
DATABASE_USER = 'rioja'            
DATABASE_PASSWORD = 'rioja'      
DATABASE_HOST = ''       
DATABASE_PORT = '3306'    
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'wordpress',
)

inspectdbによりモデル自動生成

hdknr@deb09:~/django/rioja$ python manage.py inspectdb >> wordpress/models.py
hdknr@deb09:~/django/rioja$ vi wordpress/models.py
不必要な import とか削除

syncdbでDjangoデータベース初期化

hdknr@deb09:~/django/rioja$ python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'hdknr'): admin
E-mail address: admin@ic-tact.co.jp
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model

テーブルが追加されただけで、wordpressのデータテーブルに変更ないです。

Admin画面の表示

hdknr@deb09:~/django/rioja$ vi urls.py
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
     (r'^admin/(.*)', admin.site.root),
)

hdknr@deb09:~/django/rioja$ vi wordpress/models.py

from django.contrib import admin
admin.site.register(WpPosts)

hdknr@deb09:~/django/rioja$ !py
python manage.py runserver 0.0.0.0:8000
Validating models...
Unhandled exception in thread started by <function inner_run at 0xa455d4c>
Traceback (most recent call last):
  File "/var/lib/python-support/python2.5/django/core/management/commands/runserver.py", line 48, in

inner_run
    self.validate(display_num_errors=True)
  File "/var/lib/python-support/python2.5/django/core/management/base.py", line 250, in validate
    raise CommandError("One or more models did not validate:\n%s" % error_text)
django.core.management.base.CommandError: One or more models did not validate:
wordpress.wpposts: "id": You can't use "id" as a field name, because each model automatically gets an

"id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field

or add primary_key=True to a field.

idというインスタンス変数はモデルに使わない!

hdknr@deb09:~/django/rioja$ vi wordpress/models.py
class WpPosts(models.Model):
#    id = models.IntegerField(db_column='ID') # Field name made lowercase.
    post_id = models.IntegerField(db_column='ID') # Field name made lowercase.
from django.contrib import admin
admin.site.register(WpPosts)
admin.site.register(WpUsers)

hdknr@deb09:~/django/rioja$ python manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found

Django version 1.0.2 final, using settings 'rioja.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

WS000000

WS000001

WS000002

http://www.flickr.com/photos/20958118@N0

djangoの settingsの処理を調べていたら “__import__”を使っていることがわかりました。id:perezvon さんの記事で理解できました。ありがとうございます。

Pythonを使い始めた時、「動的にモジュールをインポートする(実行時にインポートするモジュールを決定する)にはどうすればいいんだろう」と疑問に思っていたのですが、組み込み関数の__import__を使えばできます。

__import__ - スコトプリゴニエフスク通信

ためしてみた。

hdknr@deb09:~/djangocamp/trunk/mysite$ python
Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> mod = __import__('sys',{},{},[] )
>>> dir(mod)
['__displayhook__', '__doc__', '__egginsert', '__excepthook__', '__name__', '__plen',
 '__stderr__', '__stdin__', '__stdout__', '_current_frames', '_getframe', 'api_version', 
'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 
'displayhook', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix',
 'executable', 'exit', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 
'getfilesystemencoding', 'getrecursionlimit', 'getrefcount', 'hexversion', 'maxint',
 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache',
 'platform', 'prefix', 'ps1', 'ps2', 'pydebug', 'setcheckinterval', 'setdlopenflags', 
'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion',
 'version', 'version_info', 'warnoptions']
>>> getattr(mod,'stdin')
<open file '<stdin>', mode 'r' at 0xb7d7c020>

relog:DjangoGraphviz

  • Feb. 17th, 2009 at 2:40 PM
http://www.flickr.com/photos/20958118@N0

 Ian Lewis' Blog のリログ

今日、Djangoアプリケーションのモデルの構成を分かりやすく見たくて、モデル構成からGraphviz ドットファイルを生成できれば、いいなと思って、DjangoGraphvizを見つけた。ただ、ここからダウンロードして、こう実行する。

DjangoGraphviz

 

Debian Lenny で試してみました。

hdknr@deb09:~/djangocamp/trunk$ curl http://code.unicoders.org/browser/django/trunk/utils/modelviz.py?format=raw > modelviz.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  5790  100  5790    0     0   2595      0  0:00:02  0:00:02 --:--:--  7394
hdknr@deb09:~/djangocamp/trunk$ hg add modelviz.py
hdknr@deb09:~/djangocamp/trunk$ PYTHONPATH=$PYTHONPATH:. DJANGO_SETTINGS_MODULE=mysite.settings python modelviz.py polls > share/polls.model.dot
hdknr@deb09:~/djangocamp/trunk$ dot share/polls.model.dot -Tpng > share/polls.model.png
hdknr@deb09:~/djangocamp/trunk$ rm share/*.dot
hdknr@deb09:~/djangocamp/trunk$ hg add share/*.png
hdknr@deb09:~/djangocamp/trunk$ hg commit -m "DjangoGraphviz sample to produce ER graph in PNG image"
hdknr@deb09:~/djangocamp/trunk$ hg push
pushing to ssh://hg@bitbucket.org/hdknr/djangocamp/
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 2 changes to 2 files
remote: bb/acl: hdknr is allowed. accepted payload.
remote: quota: 50.2 KB in use, 150.0 MB available (0.03% used)

Latest Month

April 2009
S M T W T F S
   1234
567891011
12131415161718
19202122232425
2627282930  

Syndicate

RSS Atom
Powered by LiveJournal.com
Designed by [info]chasethestars