html tool

2014年5月26日星期一

python 版backup 的svn备份代码


本来计划改进上次写的一个批处理的svn路径list的备份
发现批处理中定义数据好麻烦,最后决定用python改写了,这样linux上也就可以使用了,go时发现http://www.cnblogs.com/heikediguo/archive/2012/07/12/2588163.html 已经做了自动更新的脚本,就拿来修改了一下(如下),还是没有写unittest 的coding 【popexizhi:不写unittest 就写coding的习惯一定要改,这个说明你没有全局规划,想到哪里写到哪里:)】

PS:
1.关于subprocess.call 【popexizhi:自己也是,go 了一下help list,问题开始与os.system('svn commit ...')没有效果,但shell中执行时没有问题的,so才开始从go中发现用subprocess.call的】

This module also defines two shortcut functions:
subprocess.call(*popenargs, **kwargs)
Run command with arguments. Wait for command to complete, then return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
2.AHK中如何运行python
run python E:\pc\other\thinking\learning\backup\testsvn.py 就ok了

参见:http://superuser.com/questions/336004/how-to-run-python-script-in-ahk
Try removing the quotes from your Run argument. It could be that AHK is attempting to run a file namedpython e:/copytimeinbuffer.py, instead of just python. (The path to your .py file is aseparate argument, and should not need to be quoted.)




# -*- coding: UTF8 -*-
# address : http://www.cnblogs.com/heikediguo/archive/2012/07/12/2588163.html
import subprocess
import sys
import string
import time

class Log:
    logfile = '';
    def config(self, _logfile):#调用这个方法实现判断日志文件位置
        if _logfile != '':
            self.logfile = _logfile;
        else:
            self.logfile = 'run.log';
 
    def log(self, _msg):#调用此方法实现保存记录到文件中去
        now = time.time()
        strtime = str(time.localtime(now)[0]) + '-' + str(time.localtime(now)[1]) \
                + '-' + str(time.localtime(now)[2]) \
                + ' ' + str(time.localtime(now)[3]) \
                + ':' + str(time.localtime(now)[4]) \
                + ':' + str(time.localtime(now)[5]);
        msg = strtime + ' ' + _msg + '\n';
        try:
            logfilehandle = open(self.logfile, 'a+');#返回一个文件句柄的
            logfilehandle.write(msg);#write file
            logfilehandle.close();
        except:
            exit(0);

def daemonize():
dir = 'E:\\pc\\other\\thinking\\'
run(dir+'learning\\unittest\\unittest')
run(dir+'')

#googlecode svn 处理
_gock= 'F:\pc\ckbf\db'
subprocess.call('svn add '+ _gock + ' --force') #增加全部增量文件
subprocess.call('svn commit '+ _gock + ' --message "脚本添加" ')


def run(path):
    log = Log()
    logfile = 'E:\\pc\\other\\svn-up.log'
    subprocess.call('svn commit ' + path + ' --message "脚本添加" ' )
    cur = path.replace('\\\\', '\\')
    print (cur + ' 已提交')
    subprocess.call('svn up ' + path)
    print ('=============================')
    #记录更新的日志
    log.config(logfile)
    log.log(cur + ' 已更新')
    if cur == 'toolbar':
       log.log('================================')




daemonize()

没有评论:

发表评论