mirror of
https://github.com/KevinMidboe/transatlanticTorrentExpress.git
synced 2025-10-29 18:00:19 +00:00
Now uses logging to file.
This commit is contained in:
@@ -3,6 +3,9 @@ import os, sys
|
|||||||
from subprocess import check_output, Popen, PIPE
|
from subprocess import check_output, Popen, PIPE
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
|
# Local files
|
||||||
|
from logger import logger
|
||||||
|
|
||||||
def getConfig():
|
def getConfig():
|
||||||
print('Reading config')
|
print('Reading config')
|
||||||
pwd = os.path.dirname(os.path.abspath(__file__))
|
pwd = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -46,6 +49,7 @@ def transferFiles(files, localPath, remotePath, host=None, user=None):
|
|||||||
transferedFiles = []
|
transferedFiles = []
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
|
logger.info('Moving file: ', file)
|
||||||
file = os.path.join(localPath, file)
|
file = os.path.join(localPath, file)
|
||||||
|
|
||||||
if (host and user):
|
if (host and user):
|
||||||
@@ -57,7 +61,7 @@ def transferFiles(files, localPath, remotePath, host=None, user=None):
|
|||||||
stdout, stderr = rsyncProcess.communicate()
|
stdout, stderr = rsyncProcess.communicate()
|
||||||
|
|
||||||
if stderr:
|
if stderr:
|
||||||
print('Unable', stderr)
|
logger.error('Error when rsyncing', stderr)
|
||||||
|
|
||||||
print(stdout)
|
print(stdout)
|
||||||
transferedFiles.append(file)
|
transferedFiles.append(file)
|
||||||
@@ -69,6 +73,7 @@ def removeFromDeluge(execScript, files):
|
|||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
print('Removing {} from deluge'.format(file))
|
print('Removing {} from deluge'.format(file))
|
||||||
|
logger.info('Removing {} from deluge'.format(file))
|
||||||
cmd = "{} {} rm '{}'".format(execPython, execScript, file)
|
cmd = "{} {} rm '{}'".format(execPython, execScript, file)
|
||||||
|
|
||||||
delugeProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
|
delugeProcess = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
|
||||||
@@ -77,7 +82,7 @@ def removeFromDeluge(execScript, files):
|
|||||||
if stderr:
|
if stderr:
|
||||||
print('Deluge unable', stderr)
|
print('Deluge unable', stderr)
|
||||||
|
|
||||||
print('Successfully removed: ', file)
|
logger.info('Successfully removed: ', file)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
config = getConfig()
|
config = getConfig()
|
||||||
@@ -95,8 +100,8 @@ def main():
|
|||||||
|
|
||||||
newFiles = filesNotShared(localFiles, remoteFiles)
|
newFiles = filesNotShared(localFiles, remoteFiles)
|
||||||
if (newFiles):
|
if (newFiles):
|
||||||
print('New files: {}'.format(newFiles))
|
logger.info('New files: {}'.format(newFiles))
|
||||||
print('Existing files: {}'.format(list(set(remoteFiles).intersection(localFiles))))
|
logger.info('Existing files: {}'.format(list(set(remoteFiles).intersection(localFiles))))
|
||||||
|
|
||||||
transferedFiles = transferFiles(newFiles, localPath, remotePath, host, user)
|
transferedFiles = transferFiles(newFiles, localPath, remotePath, host, user)
|
||||||
removeFromDeluge(delugeScript, transferedFiles)
|
removeFromDeluge(delugeScript, transferedFiles)
|
||||||
|
|||||||
Reference in New Issue
Block a user