動作確認
Raspberry Pi2 + raspbian
ラインモニタのログ・ファイルをフォルダ単位でコピーするため、以下のようにしていた。
shutil.copytree(srcpath, dstpath + "/Log/")
しかしながら、昨夜、連続通信試験をしながらログをとっても、昼の作業のログしか取れてなかった。ファイル上書きに失敗しているようだった。
参考1. 上書きできないという質問 @ SO
参考2. distutils.dir_util.copy_tree()を使うには @ SO
以下のように変更した。
変更コミット @ github
#!/usr/bin/env python
'''
+v0.2 2015 Dec. 13
+ - fix bug > did not overwrite files
v0.1 2015 Dec. 12
- add USB memory insertion recognition
- add folder copy feature
@@ -20,6 +22,8 @@
import os.path
import sys
import time
+import distutils
+from distutils import dir_util
param = sys.argv
@@ -36,7 +40,7 @@
if os.path.isdir(srcpath) and os.path.isdir(dstpath):
if chk1==False and chk2==False and chk3==True:
print "inserted"
- shutil.copytree(srcpath, dstpath + "/Log/")
+ distutils.dir_util.copy_tree(srcpath, dstpath + "/Log/")
print "Copied"
time.sleep(0.5)