eclipse设置自动换行

哥虽然写代码不多,但是是个eclipse控,于是发现 Eclipse 使用系统内置的“ Text Editor ”做为文本编辑器,这个文本编辑器有一个问题,就是文本无法换行。特别是注释特别长时,你就知道麻烦了。

终于发现出了一个扩展插件 WordWrap ,这个插件非常小,但是安装这个插件以后就可以轻松实现文本编辑器的自动换行功能了。 谢谢这个作者哦!

安装方法:
使用Eclipse 的自动升级功能,菜单栏选【 Help 】→【 install new Software】
点解Add按钮,在“ Name ”中填入“ wordwrap ”,“ URL ”中填入“ http://ahtik.com/eclipse-update”

然后按照提示进行安装完成就可以了
装完后在代码编辑界面点右键,会出现“Word Warp ”属性,将这个属性选上就可以实现自动换行了!

参考
http://blog.csdn.net/wanghuan203/article/details/6995386

check 大小

# -*- coding: utf-8 -*-

#

import datetime,time
import os,shutil

for d in os.listdir("./log/"):
if os.lstat("./log/"+d).st_size == 0:
print d,'is no open'

print 'check end '
time.sleep(1)

##哈哈 小伙伴的

python文件夹递归拷贝 相当于 cp -R

#把某一目录下的所有文件复制到指定目录中 也会 覆盖文件内容呀 coverFiles 感觉可以不要了
def copyFiles(sourceDir, targetDir):
if sourceDir.find(".svn") > 0:
return
for myfile in os.listdir(sourceDir):
sourceFile = os.path.join(sourceDir, myfile)
targetFile = os.path.join(targetDir, myfile)
if os.path.isfile(sourceFile):
if not os.path.exists(targetDir):
os.makedirs(targetDir)
#if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):
open(targetFile, "wb").write(open(sourceFile, "rb").read())
if os.path.isdir(sourceFile):
#First_Directory = False
copyFiles(sourceFile, targetFile)

#wb 以二进制写模式打开 ;rb 以二进制读模式打开

#copyFiles(localpath+'/temp/',installpath+'/DBServer/x64')

python备份mysql


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import datetime
import glob
import time
import zipfile
import urllib
import re
import shutil
import subprocess
import sys
import commands

# by evan this one is good
#定义系统日志

def syslog(message=''):
systemlog=open(bak_log,'a')
systemlog.write(message+'\n')
systemlog.close()

def get_ip():
try:
url = "http://pv.sohu.com/cityjson"
#http://www.whereismyip.com
#http://www.ip138.com/ip2city.asp
request = urllib.urlopen(url).read()
myip = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}",request)
return myip[0]
except:
myip = u"获取不到外网IP,请重新运行脚本"
return myip
exit(1)

def zip_files(zip_src,zip_dest):
f = zipfile.ZipFile(zip_dest, 'w' ,zipfile.ZIP_DEFLATED)
f.write(zip_src)
f.close()

def zip_dir(dirname,zipfilename):
filelist = []
if os.path.isfile(dirname):
filelist.append(dirname)
else :
for root, dirs, files in os.walk(dirname):
for name in files:
filelist.append(os.path.join(root, name))

zf = zipfile.ZipFile(zipfilename, "w", zipfile.zlib.DEFLATED)
for tar in filelist:
arcname = tar[len(dirname):]
#print arcname
zf.write(tar,arcname)
zf.close()

def get_spid():
spid = []
zones = []
if games:
#spid = games[0].split("_")[1]
VSPDef = r"%s\data\VSPDef.txt" % games[0]
with open(VSPDef,"r") as f:
for line in f.readlines():
if "SPID =" in line:
spid = line.split("=")[-1].strip()
for zone in games:
zones.append(zone.split("\\")[-1].split("_")[-1])
else:
print u"空服务器"
exit(1)
return spid,zones

# 本机备份保留7天数据
def delOldBak(beforeTime, path = "."):
for root, dirs, files in os.walk(path):
for name in files:
f = os.path.join(root, name)
lastMTime = os.stat(f).st_mtime
if lastMTime <= beforeTime: try: if os.path.isfile(f): os.remove(f) elif os.path.isdir(f): shutil.rmtree(f) else: os.remove(f) print u"删除 {0}, 成功!".format(f) syslog("[%s]: 删除 [%s] 成功!: " % (timestat2,f)) except Exception as e: print u"删除 {0}, 失败! 错误如下:".format(f) syslog("[%s]: 删除 [%s] 失败!: " % (timestat2,f)) print e if __name__=="__main__": # 解决编码问题 #reload(sys) #sys.setdefaultencoding('utf-8') #获取本机公网ip ExtranetIP = get_ip() # 定义 timestat2 = time.strftime("%Y%m%d-%H%M%S", time.localtime()) bak_path = 'D:/gamebackup1' bakunix_path = '/cygdrive/d/gamebackup1/*' bak_log = "%s/backup.log" % bak_path games_path = 'D:/games' games = glob.glob(r"%s/*" % games_path) # 保留 7天数据 currTime = time.time() deltTime = 3600*24*7 # 获取spid spid,zones = get_spid() print spid,zones db_host="192.168.1.200" db_user="root" db_passwd="123456" db_charset="utf8" actor = "t_actor" ''' Host = "127.0.0.1", Port = 3306, DBName = "t1_actor", DBUser = "cqmaster", DBPass = "yFk1L/lNIiul9YDvcD8P6g==", ''' bak_host = { "hostname":'59.38.194.114', # 备份机器 "username":'root', # 账号 "password":'test', # 密码 "port":16247 # 端口 } #清理本地文件 #清理老文件 delOldBak(currTime - deltTime,bak_path) print u"[%s]: 备份的数据库和runtime列表:%s" % (timestat2,zones) syslog("[%s]: 备份的数据库和runtime列表:%s" % (timestat2,zones)) for zone in zones: #备份runtime #创建zip runtime_backup_name = bak_path+'/'+spid+'_runtime_'+ExtranetIP+'_'+zone+'_'+timestat2+".zip" print runtime_backup_name zip_dir(games_path+'/'+zone,runtime_backup_name) #备份mysql db_backup_name = bak_path+'/'+spid+'sql_'+ExtranetIP+'_'+zone+'_'+timestat2+".sql" print db_backup_name try: mysqldump = r"mysqldump.exe" rundump = "mysqldump.exe -a --add-locks -C -c -x -R -h%s -u%s -p%s %s%s --default_character-set=%s > %s" %(db_host, db_user, db_passwd, actor, zone[1:], db_charset, db_backup_name)
os.system(rundump)
print(rundump)
except Exception,e:
print u"[%s]: mysqldump数据库失败:%s%s" % (timestat2,actor,zone),e
#syslog("[%s]: mysqldump数据库失败:%s%s" % (timestat2,actor,z))

'''
#同步rsync文件到备份服
print u"[%s]: rsync同步数据到备份服务器:[%s]" % (timestat2,bak_host['hostname'])
syslog("[%s]: rsync同步数据到备份服务器:[%s]" % (timestat2,bak_host['hostname']))
rsync_bin = r"D:/cqAdmin/cwRsync_5.5.0/bin/rsync.exe"
rsync_option = r"-vzrtopgu --ignore-existing --progress --port="+str(bak_host['port'])+" "+bakunix_path+" root@%s::gamebackup" % bak_host['hostname']
print rsync_option
if os.path.exists(rsync_bin):
try:
rsync = os.popen("\"%s\" %s" % (rsync_bin,rsync_option))
output = rsync.read()
rsync_error = []
for num in zones:
runtime_backup_name = spid+'_runtime_'+ExtranetIP+'_'+z
if output.find(runtime_backup_name) == -1:
rsync_error.append(runtime_backup_name)
if len(rsync_error) == 0:
print u"[%s]: rsync 备份数据同步成功" % timestat2
syslog("[%s]: rsync 备份数据同步成功" % timestat2)
else:
print u"[%s]: rsync 备份数据同步失败:%s" % (timestat2,rsync_error)
syslog("[%s]: rsync 备份数据同步失败:%s" % (timestat2,rsync_error))
#判断是否成功
except:
print u"[%s]: rsync 同步执行异常" % timestat2
syslog("[%s]: rsync 同步执行异常" % timestat2)
else:
print u" rsync 客户端未安装,rsync同步失败"
syslog(" rsync 客户端未安装,rsync同步失败")
'''

python异常处理举例

# -*- coding: utf-8 -*-

import sys ,os
db_host="192.168.1.200"
db_user="root"
db_passwd="123456"
db_charset="utf8"
actor = "eva"
zone="t5"

db_backup_name = "my.sql"
#print db_backup_name
try:
mysqldump = r"mysqldump.exe"
os.system(mysqldump+" -a --add-locks -C -c -x -R -h%s -u%s -p%s %s%s --default_character-set=%s > %s" %(db_host, db_user, db_passwd, actor, zone, db_charset, db_backup_name))
except Exception,e:
print u" mysqldump数据库失败:",e

http://www.cnblogs.com/dkblog/archive/2011/06/24/2089026.html

eclipse使用

Eclipse中添加多行注释的快捷键

# for c
apt-get install eclipse-cdt

https://packages.debian.org/wheezy/eclipse-cdt

第一种 //注释
选择你要注释的那一行或多行代码,按 Ctrl+/ 即可,取消注释也是选中之后按 Ctrl+/ 即可。此快捷键是 //注释 而不是 /**/注释。

第二种 /**/注释

Ctrl+Shift+/
说明:添加/* */注释

Ctrl+Shift+\
说明:消除/* */注释

要修改在eclispe中的命令的快捷键方式我们只需进入windows -> preference -> General -> key设置就行了

eclipse 使用

pip 安装和使用-tag

安装pip

easy_install pip 报错 那么就

wget https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
tar xvf pip-7.1.2.tar.gz
cd pip-7.1.2/
sudo python setup.py install

2. pip使用详解
2.1 pip安装包
pip install SomePackage
2.2 pip查看已安装的包
pip show –files SomePackage
2.3 pip检查哪些包需要更新
pip list –outdated
SomePackage (Current: 1.0 Latest: 2.0)
2.4 pip升级包
pip install –upgrade SomePackage

2.5 pip卸载包

$ pip uninstall SomePackage

3. pip使用实例
3.1 安装Django

pip install Django

3.2 卸载Django

pip uninstall Django

3.3 查看待更新包
pip list –outdate

4. pip参数解释

pip –help

Usage:
pip [options]

Commands:
install 安装包.
uninstall 卸载包.
freeze 按着一定格式输出已安装包列表
list 列出已安装包.
show 显示包详细信息.
search 搜索包,类似yum里的search.
wheel Build wheels from your requirements.
zip 不推荐. Zip individual packages.
unzip 不推荐. Unzip individual packages.
bundle 不推荐. Create pybundles.
help 当前帮助.

General Options:
-h, –help 显示帮助.
-v, –verbose 更多的输出,最多可以使用3次
-V, –version 现实版本信息然后退出.
-q, –quiet 最少的输出.
–log-file 覆盖的方式记录verbose错误日志,默认文件:/root/.pip/pip.log
–log 不覆盖记录verbose输出的日志.
–proxy Specify a proxy in the form [user:passwd@]proxy.server:port.
–timeout 连接超时时间 (默认15秒).
–exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup.
–cert 证书.