动态感觉 静观其变

居住地:江西南昌,msn:xlp223(at)hotmail.com,gmail talk:myhat123(at)gmail.com, 欢迎交流。喜欢python,也喜欢rails框架。

逝者如斯
网志分类
· 所有网志
· python学习
· pylons学习
· erlang学习
· ruby学习
· linux
· dotnet
· java
· 其他动态语言
· 感想心得
· ice学习
· 生活琐事
· 其他小玩意
最新评论
· 07/04 select ...
搜索本站
友情链接
· 我们的小歪
· 管理我的Blog
· limodou的学习记录
· ywl51
· 花钱的年华
· python资料
· hd的blog
· oneZ
· hgf
· devin's braindump
· pylons
· myghty
· sqlalchemy
· Ian Bicking
· Ben Bangert
· michael
· xyb
· kjd
· eiffelqiu

订阅 RSS

0160873

歪酷博客


Hzg @ 2008-07-04 08:37

兑现昨晚的说法,公布自己瞎弄的sql,算是歪打正着吧。看看这个sql,你要觉得怪异,尽管说:
1)
select dy.jh, dy.jm, dy.lze as dylze, coalesce(ls.lze,0.00) as lslze, coalesce(dy.lze,0.00)+coalesce(ls.lze,0.00) as lze from
  (select d.jh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.pdssk) as pdlze, sum(c.zdssk) as zdlze,
   sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_bkml as b
where c.yxn=2008
   and c.jyr>='20070701' and c.jyr<='20080701'
   and c.bkdh='33-2' and c.dyfw='本地' and c.dylx!='零售'
   and b.nd=2008 and b.bkdh='33-2'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as dy,

  (select d.jh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.pdssk) as pdlze, sum(c.zdssk) as zdlze,
     sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_bkml as b
where c.yxn=2008
   and c.jyr>='20070701' and c.jyr<='20080701'
   and c.bkdh='33-2' and c.dyfw='本地' and c.dylx='零售'
   and b.nd=2008 and b.bkdh='33-2'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as ls
where dy.jh=ls.jh;

2)
select dy.dqh, sum(coalesce(dy.lze,0.00)) as dylze, sum(coalesce(ls.lze,0.00)) as lslze, sum(coalesce(dy.lze,0.00)+coalesce(ls.lze,0.00)) as lze from
  (select d.jh, d.dqh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_tjlx as t
where c.yxn=2008
   and c.bkdh = t.bkdh
   and c.jyr>='20071201' and c.jyr<='20071210'
   and c.clbz!='变动' and c.dyfw='本地' and c.dylx!='零售'
   and t.nd=2008 and t.bkfl='畅销及潜力'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as dy,

  (select d.jh, d.dqh, d.jm, e.lze from nps_dxj as d left join (select c.sdxzqh as sdxzqh, sum(c.zdssk+c.pdssk) as lze
   from nps_card as c, nps_tjlx as t
where c.yxn=2008
   and c.bkdh = t.bkdh
   and c.jyr>='20071201' and c.jyr<='20071210'
   and c.clbz!='变动' and c.dyfw='本地' and c.dylx='零售'
   and t.nd=2008 and t.bkfl='畅销及潜力'
   group by c.sdxzqh
   order by c.sdxzqh) as e on d.jh=e.sdxzqh) as ls
where dy.jh=ls.jh
group by dy.dqh
order by dy.dqh;


 
Hzg @ 2008-07-03 23:24

sql到底要写成怎样才能晕?我一直都在门外,努力不让自己被sql弄晕,可是最近几天要处理一些数据,必须要把一些数据分开处理,终于写了一个超长的sql,可能对别人来说是超短的了,因为曾经有人说写了200行的sql,而我的只有20多行而已,可已经弄的有点吓人了,都不知道自己是怎样就把它写成了,明天我将公布这些sql,猜猜我能写成什么样吧。


 
Hzg @ 2008-06-29 19:43

今天带着小孩去看了电影《功夫熊猫》,看完之后,我的思绪还停留在这个电影的人物,情节中,颇有感触,试着对小孩提出了几个问题,让她去想想,让我也想想,有空自由讨论一番,回到家也给其他人大力推荐了一番。

1. 为什么神龙秘笈是无字的书,却不让大龙看?

2. 为什么熊猫看了神龙秘笈能悟到,大龙也看到了无字之书却悟不到?

3. 熊猫能学到功夫是什么原因? 大龙那么大的本领又是什么原因? 两者有什么不同?

确实要记录,中午思绪还停留在电影中,所以当时给小孩提的问题,现在都想不全了。


我想这个片子很多元素实际上中国的很多故事都有,但它用一种电影、动画的艺术形式表现出来了,同时在电影院里看,思考的成分也沉浸其中。


 
Hzg @ 2008-06-06 14:30

不知道为什么总是会碰到一些问题?filezilla server安装在windows xp上有个问题,经常会第一次连接挂死。抽空换了它,最近看到一个python ftpd的库,很有意思,非常小,是异步方式的,我想对我来说足够了,我把它做成windows service,让它自动运行起来,不用管它了。

http://code.google.com/p/pyftpdlib/

文档都不错,还有例子,我就照搬了,然后把windows service的套上去:

import win32serviceutil
import win32service
import win32event

from pyftpdlib import ftpserver

FTP_USER = 'nps_card'
FTP_PASS = 'nps_card'
HOME_DIR='d:\nps_data\'

class MyFtpd(object):
    def __init__(self):
        self.ftpd = None

    def main(self):
        # Instantiate a dummy authorizer for managing 'virtual' users
        authorizer = ftpserver.DummyAuthorizer()

        # Define a new user having full r/w permissions and a read-only
        # anonymous user
        authorizer.add_user(FTP_USER, FTP_PASS, HOME_DIR, perm='elradfmw')
        authorizer.add_anonymous(HOME_DIR)

        # Instantiate FTP handler class
        ftp_handler = ftpserver.FTPHandler
        ftp_handler.authorizer = authorizer

        # Define a customized banner (string returned when client connects)
        ftp_handler.banner = "pyftpdlib %s based ftpd ready." %ftpserver.__ver__

        # Instantiate FTP server class and listen to 0.0.0.0:21
        address = ('', 21)
        self.ftpd = ftpserver.FTPServer(address, ftp_handler)

        # set a limit for connections
        self.ftpd.max_cons = 256
        self.ftpd.max_cons_per_ip = 5

    def start(self):
        # start ftp server
        self.ftpd.serve_forever()

    def stop(self):
        self.ftpd.close_all()

class MyService(win32serviceutil.ServiceFramework):
    """NT Service."""
    
    _svc_name_ = "PyFtpService"
    _svc_display_name_ = "Py Ftp Service"

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        # create an event that SvcDoRun can wait on and SvcStop
        # can set.
        self.stop_event = win32event.CreateEvent(None, 0, 0, None)
        self.myftpd = MyFtpd()

    def SvcDoRun(self):
        self.myftpd.main()
        self.myftpd.start()
        # now, block until our event is set...
        win32event.WaitForSingleObject(self.stop_event, win32event.INFINITE)
   
    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        self.myftpd.stop()
        win32event.SetEvent(self.stop_event)

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(MyService)


然后用另外一个ftp client的库,ftputil,

http://ftputil.sschwarzer.net/trac

随后,做好server,放到实际环境下实验,结果发现还是存在问题,估计就是外网和内网之间的互联互通上的防火墙的问题,也会造成没有响应,后来发现去掉service,server端看日志,发现server并没有退出,但是不响应,看看例子上的代码,有个地方我删除了,有可能就是nat的问题,加上:

ftp_handler.masquerade_address = '10.146.x.188'

passive_ports的范围,似乎nat也做了限制,我不规定范围了。

代码改好之后,好像还是有点问题,还是有点晕,谁了解这些,可以和我说说么?期待有人和我说说。。。


 
Hzg @ 2008-06-03 15:35

开发用的机器做好程序后,要部署到服务端,一般手动的过程都是打包,上传,解包,重启服务等步骤,在ruby社区有个capistrano,就是自动部署用的,虽说可以独立使用,但是它的文档有一半的篇幅和ror有关,另外独立使用的文档偏少,而我现在也不怎么用ruby。所以就找了一下python社区中有无相关的工具。

还真有人作了一个包,我试了试,感觉还挺简单,也就是那几个动作,作一次就会。它的地址是:
http://www.nongnu.org/fab/index.html

我在archlinux下安装,碰到了一些问题,需要修改几个地方:
1)os.getlogin(),在gnome界面下使用,会报错,用pwd.getpwid(os.getuid())[0]来代替
2)fab的程序中,exit(1)之类的,要改成sys.exit(1)

保证程序不错后,还要保证paramiko这个包先安装,这个包是ssh用的,然后python setup.py install安装。

使用fabric,就是简单的写fabfile文件,文件就是py文件,内容就是几个简单的函数和变量:
1)变量
set(
  fab_hosts = ['172.16.7.13'],
  fab_user = 'hzg'
)
fab_hosts是远端服务器ip,fab_user是ssh的用户

2)函数
def deploy():
  "Build the project and deploy it to a specified environment."
  local("tar zcvf fx_analysis.tar.gz fx_analysis --exclude='*.XLS'")
  put("fx_analysis.tar.gz", "/home/hzg/work/fx_analysis.tar.gz")
  run("cd /home/hzg/work/; tar zxvf fx_analysis.tar.gz")

deploy函数,由fab来调用,其中它又调用了几个:
local()=>本地机器运行
put()=>上传文件到远端服务器
run()=>在远端服务器运行

还有一些:
send(), download, sudo()等之类,都很简单明了

3)使用方法
很简单,就一个fab,运行fab,自动会去找fabfile,deploy会显示出来。
要运行deploy的步骤,也很简单,fab deploy就可以了

(mypy)[hzg@myhost work]$ fab
   Fabric v. 0.0.5, Copyright (C) 2008 Christian Vest Hansen.
   Fabric comes with ABSOLUTELY NO WARRANTY; for details type `fab warranty'.
   This is free software, and you are welcome to redistribute it
   under certain conditions; type `fab license' for details.

No commands given.
Available commands are:
   deploy   : Build the project and deploy it to a specified environment.
   help     : Display Fabric usage help, or help for a given command.
   license  : Display the Fabric distribution license text.
   list     : Display a list of commands with descriptions.
   set      : Set a Fabric variable.
   shell    : Start an interactive shell connection to the specified hosts.
   warranty : Display warranty information for the Fabric software.
Done.

(mypy)[hzg@myhost work]$ fab deploy

这样就能自动远程部署了,当然可能功能上没有capistrano多,不过已经足够了。