From 719aca88b716ec5071971d76d807b1c8ea4a09ab Mon Sep 17 00:00:00 2001 From: mano3m Date: Sat, 5 Oct 2013 10:26:45 +0200 Subject: [PATCH] Clean-up read only files uTorrent --- couchpotato/core/downloaders/utorrent/main.py | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/couchpotato/core/downloaders/utorrent/main.py b/couchpotato/core/downloaders/utorrent/main.py index 304eeaf4..e6e251a3 100644 --- a/couchpotato/core/downloaders/utorrent/main.py +++ b/couchpotato/core/downloaders/utorrent/main.py @@ -130,15 +130,6 @@ class uTorrent(Downloader): # Get torrents for item in queue['torrents']: - # item[21] = Paused | Downloading | Seeding | Finished - status = 'busy' - if 'Finished' in item[21]: - status = 'completed' - self.removeReadOnly(item[26]) - elif 'Seeding' in item[21]: - status = 'seeding' - self.removeReadOnly(item[26]) - #Get files of the torrent torrent_files = '' try: @@ -147,6 +138,15 @@ class uTorrent(Downloader): except: log.debug('Failed getting files from torrent: %s', item[2]) + # item[21] = Paused | Downloading | Seeding | Finished + status = 'busy' + if 'Finished' in item[21]: + status = 'completed' + self.removeReadOnly(torrent_files) + elif 'Seeding' in item[21]: + status = 'seeding' + self.removeReadOnly(torrent_files) + statuses.append({ 'id': item[0], 'name': item[2], @@ -177,14 +177,12 @@ class uTorrent(Downloader): return False return self.utorrent_api.remove_torrent(item['id'], remove_data = delete_files) - def removeReadOnly(self, folder): - #Removes all read-only flags in a folder - if folder and os.path.isdir(folder): - for root, folders, filenames in os.walk(folder): - for filename in filenames: - filepath = os.path.join(root, filename) - #Windows only needs S_IWRITE, but we bitwise-or with current perms to preserve other permission bits on Linux - os.chmod(filepath, stat.S_IWRITE | os.stat(filepath).st_mode) + def removeReadOnly(self, files): + #Removes all read-only flags in a for all files + for filepath in files: + if os.path.isfile(filepath): + #Windows only needs S_IWRITE, but we bitwise-or with current perms to preserve other permission bits on Linux + os.chmod(filepath, stat.S_IWRITE | os.stat(filepath).st_mode) class uTorrentAPI(object):