python入门及IDE搭建

IDE:eclipse3.8.2
插件:PyDev 2.8.2
python:python-2.7.6.amd64
具体软件,请朋友们自行下载。
版本一定要对应,pyDev只能选择2.8。选择3.4则eclipse3.8.2认不出来。另外快捷键会冲突,需要修改一下。
启动eclipse
【设置快捷键】
选择window -> preference -> General -> keys
查找Word completion,在binding:里面,按退格键(即:删除快捷键的意思)
查找Content Assist,在binding里面,添加快捷键alt+/
[img]http://dl2.iteye.com/upload/attachment/0095/2818/9fe53879-6b98-3a36-bd5c-9557d1d89a07.jpg[/img]
【关联python】
选择window -> preference -> PyDev -> INterpreters -> Python Interpreter
然后在上面的框里,new,设置python.exe的路径
[img]http://dl2.iteye.com/upload/attachment/0095/2820/ccd5e243-4898-35be-84c3-66fc69753e39.jpg[/img]
【例子】
然后启动项目,快乐的体验python吧。其实入门很简单,找几个现成的例子学习一下就可以。
一个简单的demo,这个事我兄弟大伟写的,他的博客是http://ailikes.iteye.com/
其中的语法,都可以通过eclipse的自动提示进行完成。非常爽。基本语法包括异常处理,日期处理,文件操作,for循环,if语句等等吧。请大家自行体会吧

# @author: xudawei
# @date:2014-03-12

import os
import shutil
import time
import socket
import sys
import logging
from test.test_socket import try_address


CURRENT_TIME = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
DEPLOY_HOME = "/application/search/vertical-search"
# logs directory
LOG_HOME = "/data0/search/vertical-search/vertical-search-deploy/logs"
# temp directory
TMP_HOME = "/tmp/src"
BACKUP_HOME = "/data0/search/vertical-search/backup/%s" % CURRENT_TIME
SERVER_IP = ["10.10.160.68", "10.10.160.69", "10.10.160.70"]
VERTICAL_SEARCH_SVN = "http://svn.pangu365.com/svn/techrd/apps/base_application/ba-vertical-search/trunk"

def package():
try:
# download source
# maybe required username and password
os.system("rm -rf %s" % TMP_HOME)
os.system("svn export %s %s" % (VERTICAL_SEARCH_SVN, TMP_HOME))
# generate package
os.system("cd %s/vertical-search-core && mvn clean -U deploy -Dmaven.test.skip=true -T 1C" % TMP_HOME)
logging.info("package success")
except Exception, e:
logging.error("package error: %s" % e)

# backup and deploy
def deployAll():
deployService()
deploySchedule()
deployImport()
deployShell()

def deployService():
# backup,stop,delete,scp,start
try:
os.system("cd %s/vertical-search-service && mvn clean package -U -Dmaven.test.skip=true -Ponline -T 1C" % TMP_HOME)
for index, item in enumerate(SERVER_IP):
os.system("ssh %s \"cp -r %s/vertical-search-service/ %s\"" % (item, DEPLOY_HOME, BACKUP_HOME))
os.system("ssh %s \"sh %s/vertical-search-service/bin/server.sh stop\"" % (item, DEPLOY_HOME))
os.system("ssh %s \"rm -rf %s/vertical-search-service/* \"" % (item, DEPLOY_HOME))
os.system("scp -r %s/vertical-search-service/target/deploy/* %s:%s/vertical-search-service/" % (TMP_HOME, item, DEPLOY_HOME))
os.system("ssh %s \"sh %s/vertical-search-service/bin/server.sh start \"" % (item, DEPLOY_HOME))
logging.info("deployService success at : %s" % item)
except Exception, e:
logging.error("deployService error: %s" % e)

# schedule same as service
def deploySchedule():
try:
os.system("cd %s/vertical-search-schedule && mvn clean package -U -Dmaven.test.skip=true -Ponline -T 1C" % TMP_HOME)
for index, item in enumerate(SERVER_IP):
os.system("ssh %s \"cp -r %s/vertical-search-schedule/ %s\"" % (item, DEPLOY_HOME, BACKUP_HOME))
os.system("ssh %s \"sh %s/vertical-search-schedule/bin/server.sh stop\"" % (item, DEPLOY_HOME))
os.system("ssh %s \"rm -rf %s/vertical-search-schedule/* \"" % (item, DEPLOY_HOME))
os.system("scp -r %s/vertical-search-schedule/target/deploy/* %s:%s/vertical-search-schedule/" % (TMP_HOME, item, DEPLOY_HOME))
os.system("ssh %s \"sh %s/vertical-search-schedule/bin/server.sh start \"" % (item, DEPLOY_HOME))
logging.info("deploySchedule success at : %s" % item)
except Exception, e:
logging.error("deploySchedule error: %s" % e)

def deployImport():
try:
for index, item in enumerate(SERVER_IP):
os.system("ssh %s \"cp -r %s/vertical-search-import/ %s\"" % (item, DEPLOY_HOME, BACKUP_HOME))
os.system("ssh %s \"rm -rf %s/vertical-search-import/* \"" % (item, DEPLOY_HOME))
os.system("scp -r %s/vertical-search-import/* %s:%s/vertical-search-import/" % (TMP_HOME, item, DEPLOY_HOME))
logging.info("deployImport success at : %s" % item)
except Exception, e:
logging.error("deployImport error: %s" % e)

def deployShell():
try:
for index, item in enumerate(SERVER_IP):
os.system("ssh %s \"cp -r %s/vertical-search-shell/ %s\"" % (item, DEPLOY_HOME, BACKUP_HOME))
os.system("ssh %s \"rm -rf %s/vertical-search-shell/* \"" % (item, DEPLOY_HOME))
os.system("scp -r %s/vertical-search-shell/* %s:%s/vertical-search-shell/" % (TMP_HOME, item, DEPLOY_HOME))
logging.info("deployShell success at : %s" % item)
except Exception, e:
logging.error("deployShell error: %s" % e)

if __name__ == "__main__":
try:
os.system("mkdir -p %s" % LOG_HOME)
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s", filename=LOG_HOME + "/deploy.log")

logging.info("begin deploy vertical-search")
# prepared
package()
# deploy
if len(sys.argv) == 1:
deployAll()
else:
for index, item in enumerate(sys.argv):
if item == sys.argv[0]:
logging.info("shell name is %s" % item)
elif item == "shell":
logging.info("the deploy project is shell")
deployShell()
elif item == "import":
logging.info("the deploy project is import")
deployImport()
elif item == "service":
logging.info("the deploy project is service")
deployService()
elif item == "schedule":
logging.info("the deploy project is schedule")
deploySchedule()
else:
print("input error shell|import|service|schedule")

localIP = socket.gethostbyname(socket.gethostname())
logging.info("this Script is running at: %s" % localIP)
# delete all source
shutil.rmtree(TMP_HOME)
os.system("rm -rf %s" % TMP_HOME)
logging.info("deploy vertical-search success")
except Exception, e:
logging.error("main error: %s" % e)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值