2

そのため、サーバー上で異なる間隔で 3 つのことを行う必要があるスクリプトがあります。

  1. 24 時間以上新しいファイルがないか FTP をスキャンしてダウンロードする場合 (サブプロセスを使用)、
  2. 場所1をスキャンし、ファイルが存在する場合はファイルを移動し、ファイルの出所に基づいて名前を変更します(サブプロセスを使用)、
  3. ディレクトリをスキャンし、ファイルが存在する場合は、ファイルを別の FTP にアップロードします (サブプロセスを使用)。

これ以外はすべて問題ありません。3 回目のスキャン (2 回目のスキャンと同じ) で、何らかの理由でスクリプトが「ルート、ディレクトリ、ファイル内」を超えて移動したくない

import sys
import os
import subprocess 
import time
import datetime
from datetime import datetime as dt

# Local Directories 
N_dir_dest = '/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/N_dest' # Directory where the      NICK source video files needs to be downloaded to
M_dir_dest = '/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/M_dest' # Directory where the     NICK source video files needs to be downloaded to
encode_dest1 = '/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/encode_dest1' # Encoding Directory where source videos are moved to after being downloaded and renamed
encodeDrop_dir = '/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/encodeDrop_dir' # Files ready for uploading to BeeCell FTP 

#Script Starts

while True:
        time.sleep(10)
        if dt.now().hour in range(20, 23):
            print "Starting to Scan UK FTP for source files - time is: %s" % dt.now()
            thedownloadprocess = subprocess.Popen([sys.executable, "/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/BeeCell_FTP_incoming.py"])
            thedownloadprocess.communicate()
            time.sleep(3600)


        elif dt.now().minute in range(01, 15) or dt.now().minute in range(31, 45):
            time.sleep(10)
            print "Scanning %s and %s - time is: %s" % (N_dir_dest, M_dir_dest, dt.now())
            for root, dirs, files in os.walk(N_dir_dest) or os.walk(M_dir_dest):
                for file in files:
                    path_to_file = os.path.join(root, file)
                    if os.path.isfile(path_to_file) and file.endswith(('.mov', '.mpg', '.mp4')):
                        print "file: %s found - starting rename process" % path_to_file
                        renameprocess = subprocess.Popen([sys.executable, "/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/BeeCell_rname_files.py"])
                        renameprocess.communicate()
                        print "Finished Rename and encode - sleeping for 10 secs- time is: %s" % dt.now()
                        time.sleep(10)
                    else:
                        print "No files in %s or %s" % (N_dir_dest, M_dir_dest)
                        time.sleep(20) 



        elif dt.now().minute in range(16, 30) or dt.now().minute in range(46, 00): # checking every 120 seconds in the minute range 20 - 59
            time.sleep(10)
            print "scanning %s - time is: %s" % (encodeDrop_dir, dt.now())
            for root, dirs, files in os.walk(encodeDrop_dir):
                for file in files:
                    path_to_file = os.path.join(root, file)
                    if os.path.isfile(path_to_file) and file.endswith(('.mov', '.mpg', '.mp4')):
                        print "file: %s will be uploaded"
                        Nuploadprocess = subprocess.Popen([sys.executable, "/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/BeeCell_FTPupload.py"]) 
                        Nuploadprocess.communicate()
                        print "Finished Upload - sleeping for 10 secs- time is: %s" % dt.now()
                        time.sleep(10)
                    else:
                        print "No files in %s" % encodeDrop_dir
                        time.sleep(10)

        else:
            print "Relaxing"

スクリプトを実行すると、最初の「elif」は正常に実行され、ディレクトリにファイルが見つかった場合はサブプロセスが開始されますが、2 番目の「elif」では次のようにループします。

elif dt.now().minute in range(16, 30) or dt.now().minute in range(46, 00): # checking every 120 seconds in the minute range 20 - 59
            time.sleep(10)
            print "scanning %s - time is: %s" % (encodeDrop_dir, dt.now())
            for root, dirs, files in os.walk(encodeDrop_dir):

ループは、dt.now() 範囲が移動するまで続きます。最初の "elif" と 2 番目の "elif" のコードに違いは見られません - 何がうまくいかないのかを解明しようとしてここ数日間頭を悩ませた後、どんな提案も喜んで聞きます!! ??

OK追加された印刷機能:

    print "scanning %s - time is: %s" % (encodeDrop_dir, dt.now())
            print "Upload List: %s" % E_dir_oslist
            for root, dirs, files in os.walk(encodeDrop_dir):
                print "hello"
                for file in files:
                    print "hello 1"   

これは出力です:

/Volumes/VoigtKampff/Temp/_Jonatha/BeeCell/encodeDrop_dir をスキャン - 時刻: 2013-03-19 18:22:25.345483

アップロード リスト: []

こんにちは

更新:スキャン機能をサブプロセスが呼び出すスクリプトに移動すると、機能します。上記の方法で使用すると失敗する理由はまだわかりません。

4

0 に答える 0