Clean-up read only files uTorrent
This commit is contained in:
@@ -130,15 +130,6 @@ class uTorrent(Downloader):
|
|||||||
# Get torrents
|
# Get torrents
|
||||||
for item in queue['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
|
#Get files of the torrent
|
||||||
torrent_files = ''
|
torrent_files = ''
|
||||||
try:
|
try:
|
||||||
@@ -147,6 +138,15 @@ class uTorrent(Downloader):
|
|||||||
except:
|
except:
|
||||||
log.debug('Failed getting files from torrent: %s', item[2])
|
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({
|
statuses.append({
|
||||||
'id': item[0],
|
'id': item[0],
|
||||||
'name': item[2],
|
'name': item[2],
|
||||||
@@ -177,14 +177,12 @@ class uTorrent(Downloader):
|
|||||||
return False
|
return False
|
||||||
return self.utorrent_api.remove_torrent(item['id'], remove_data = delete_files)
|
return self.utorrent_api.remove_torrent(item['id'], remove_data = delete_files)
|
||||||
|
|
||||||
def removeReadOnly(self, folder):
|
def removeReadOnly(self, files):
|
||||||
#Removes all read-only flags in a folder
|
#Removes all read-only flags in a for all files
|
||||||
if folder and os.path.isdir(folder):
|
for filepath in files:
|
||||||
for root, folders, filenames in os.walk(folder):
|
if os.path.isfile(filepath):
|
||||||
for filename in filenames:
|
#Windows only needs S_IWRITE, but we bitwise-or with current perms to preserve other permission bits on Linux
|
||||||
filepath = os.path.join(root, filename)
|
os.chmod(filepath, stat.S_IWRITE | os.stat(filepath).st_mode)
|
||||||
#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):
|
class uTorrentAPI(object):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user