Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- login=xxxx
- pass=yyyy
- host=zzzz.com
- remote_dir="/remote/test"
- local_dir="/local/test"
- import sqlite3
- import os
- import sys
- import subprocess
- from time import sleep
- # Create the database if it doesn't exist.
- if not os.path.exists("seedbox-sync.sqlite"):
- print("No database found, creating new one...")
- con=sqlite3.connect("seedbox-sync.sqlite")
- con.execute("create table rememberedFiles(filename varchar);")
- else:
- con=sqlite3.connect("seedbox-sync.sqlite")
- def isFileRemembered(filename):
- cur=con.cursor()
- cur.execute("select count(*) from rememberedFiles where filename=?",(filename,))
- r=[row[0] for row in cur.fetchall()][0]
- cur.close()
- return r>0
- def rememberFile(filename):
- con.execute("insert into rememberedFiles values(?)",(filename,))
- con.commit()
- # The main loop.
- while True:
- files=os.listdir(u""+remote_Dir) # If you call os.listdir() with a UTF-8 string the result will be an array of UTF-8 strings instead of ASCII. Needed for passing UTF-8 into sqlite3 for filenames with special characters.
- print("Sleeping for 10 seconds...")
- sleep(10) # Sleep for 10 seconds between scans.
- for file in files:
- if(isFileRemembered(file)):
- # This file has been copied already.
- print("Skipping file: "+file)
- continue
- # Sync the file.
- print("Syncing new file: "+file)
- cmd=["mirror -c --log=sync.log "]
- cmd.append(remote_Dir+"/"+file)
- cmd.append(local_Dir+"/")
- p=subprocess.Popen(cmd,shell=False)
- if p.wait()==0:
- rememberFile(file)
- print("Synced & remembered: "+file)
- else:
- print("Failed to sync: "+file)
- con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement