2013-02-11 68 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]) 

不知道這是否是速度但是,服務器。