我使用rsync命令获取文件信息:
info = subprocess.Popen(['sshpass', '-p', password, 'rsync', '-az', '--status', '--dry-run', source],
stdout=subprocess.PIPE)
我得到这样的输出:
drwxr-xr-x 4,096 2013/01/23 08:48:35 my_files
-rw-r--r-- 5,009,545 2013/01/16 04:20:48 my_files/NC_008253.fna
-rw-r--r-- 5,009,545 2013/01/16 04:20:52 my_files/ok.txt
-rw-r--r-- 5,009,545 2013/01/16 04:21:08 my_files/test.data
Number of files: 4 (reg: 3, dir: 1)
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0
Total file size: 15,028,635 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 135
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 25
Total bytes received: 147
sent 25 bytes received 147 bytes 11.10 bytes/sec
total size is 15,028,635 speedup is 87,375.78 (DRY RUN)
我想在bytes/sec i.e 11.10
之前解析数字。我怎样才能做到这一点?另外,它是服务器的带宽速度吗?
答案 0 :(得分:0)
好吧,如果你不想做正则表达式,并且命令的输出是一致的,那么这样简单的东西就可以了:
speed = float(info.split("\n")[-2].split(" ")[-2])
不知道这是否是服务器的速度。