Daemon Skeleton introduction

Posted by 4Aiur on 02/24/2013 in Python |

Daemon Skeleton introduction Past couple of days, i’ve builded some daemon tools, tired to do the same thing again and again, i think i need a template, to create python project with daemon easy and fast. So created this template Daemon Skeleton. In this template i used python-daemon as the daemonizer, and did some tweak, […]

Tags: ,

Ship access log to ElasticSearch

Posted by 4Aiur on 08/13/2012 in Python |

Ship access log to ElasticSearch This article introduce how to use a custom python script to parse Apache access log and shipping it to ElasticSearch. If you wan’t store the huge log to ElasticSearch, you should read Using Elasticsearch for logs, Using some popular OpenSource software, like Graylog2, Logstash, Apache Flume. System basic setup # […]

Tags:

OpenShift Command Line Interface

Posted by 4Aiur on 05/25/2012 in Python |

OpenShift Command Line Interface Working With Domains Creating a Domain rhc domain create -n DomainName -l rhlogin -p password [OptionalParameters] Deleting a Domain rhc domain show -l rhlogin rhc app destroy -a -l rhlogin rhc domain destroy -n -l rhlogin Viewing User Information rhc domain show -l rhloging Creating Applications Supported app types: nodejs-0.6 jbossas-7 […]

Tags:

Deploy web.py application on OpenShift

Posted by 4Aiur on 04/03/2012 in Python |

Deploy web.py application on OpenShift Prepare environment Install OpenShift client command line tool gem install rhc Generate a new SSH key ssh-keygen -t rsa -f ~/.ssh/rhcloud -C “your_email@youremail.com” edit ~/.ssh/config Host *.rhcloud.com IdentityFile ~/.ssh/rhcloud Create a Namespace rhc-create-domain -n namespace -a ~/.ssh/rhcloud -l rhlogin Create a application, and clone the git reposity rhc-create-app -a webpy […]

Tags: ,

Suppressing paramiko log

Posted by 4Aiur on 12/26/2011 in Python |

Suppressing paramiko log Backup paramiko source file. cd /usr/local/lib/python2.7/site-packages/ cp -p paramiko/util.py{,.bak} Modify paramiko/util.py. diff paramiko/util.py{,.bak} 265c265 return True Set logger name "suppress" in your code. self.client = SSHClient() self.client.set_log_channel(‘suppress’)

Tags: , ,

使用python实现简易的文件共享

Posted by 4Aiur on 01/21/2011 in Python |

使用python实现简易的文件共享 可以利用python的SimpleHTTPServer共享自己的文件给其他人 python -m SimpleHTTPServer 8000 需要从其他人那拷贝东西到自己机器上时可以用python的CGIHTTPServer这个模块,写一个CGI程序来接收文件。 # alias alias cgiserver=”ifconfig | grep –color -o ‘inet 1[79]2[^ ]*’; python -m CGIHTTPServer 8000″ # cgi_directories [‘/cgi-bin’, ‘/htbin’] # Create directory mkdir incoming/ cd incoming/ mkdir cgi-bin/ files # Create save file CGI program cat > cgi-bin/save_file.py %s cgiserver 其他人通过访问http://uripaddress:8000/upload.html来上传文件。

Tags: ,

使用python获取mp3中的歌词

Posted by 4Aiur on 12/09/2010 in Python |

使用python获取mp3中的歌词 安装依赖库eyeD3 $ sudo port install py26-eyed3 #!/usr/bin/env python # -*- coding: utf-8 -*- “”” dump_mp3_lyris.py Created by 4Aiur on 2010-12-09. “”” import os import eyeD3 def get_mp3_file(dir): mp3_files = [] files = os.listdir(dir) for file in files: if os.path.splitext(file)[1] == ‘.mp3’: mp3_files.append(os.path.join(dir,file)) return mp3_files def dump_lyrics(mp3_file): print(‘parse %s’ % (mp3_file)) lyrics_file = ‘%s.txt’ % […]

Tags:

使用python下载存放在Index中的资源

Posted by 4Aiur on 12/06/2010 in Python |

使用python下载存放在Index中的资源 Useing python threading download example. like this: wget -P result/ -nd -nH -r -l 1 -np -A pdf –http-user=book –http-password=cubook “http://www.4aiur.net/book/Programing/Python/” #!/usr/bin/env python # -*- coding: utf-8 -*- ”’ thread_download.py 下载网页中某种后缀名的文件 Created by 4Aiur on 2010-12-06. ”’ __version__ = “$Revision: 0.90 $” import threading import httplib import urlparse import base64 import re import os […]

Tags:

Python 三元表达式

Posted by 4Aiur on 12/06/2010 in Python |

Python 三元表达式 In [1]: x = 100 if True else 200 In [2]: x Out[2]: 100 In [3]: x = 100 if False else 200 In [4]: x Out[4]: 200

Tags:

python的ftp应用举例

Posted by 4Aiur on 05/04/2010 in Python |

python的ftp应用举例 使用python可以很方便的进行ftp操作,下面这个小程序的作用是成功下载远程服务器文件后,删除远程服务器上面的文件。 #!/usr/bin/env python2 # -*- coding: utf-8 -*- from ftplib import FTP import logging import os import socket logger = logging.getLogger(“download”) logger.setLevel(logging.DEBUG) fh = logging.FileHandler(“download.log”) formatter = logging.Formatter(“%(asctime)s – %(name)s – %(levelname)s – %(message)s”) fh.setFormatter(formatter) logger.addHandler(fh) def get_del(): ip = ‘127.0.0.1’ user_name = ‘foo’ passwd = ‘bar’ source_path = ‘/test_sour_dir/’ try: ftp = FTP(ip) […]

Tags:

Copyright © 2010-2019 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.