2013-02-11 57 views
0

我使用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

好吧,如果你不想做的正则表达式,如果该命令的输出是一致的,因为这简单的事会工作:

speed = float(info.split("\n")[-2].split(" ")[-2]) 

不知道这是否是速度但是,服务器。