Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shutil.move instead of os.rename in several places #1147

Merged
merged 1 commit into from
Jan 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tribler/Core/Upgrade/torrent_upgrade64.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def update_status():
file_path = os.path.join(root, name)
try:
tdef = TorrentDef.load(file_path)
os.rename(file_path, os.path.join(self.tmp_migration_dir, hexlify(tdef.infohash) + u".torrent"))
move(file_path, os.path.join(self.tmp_migration_dir, hexlify(tdef.infohash) + u".torrent"))
self.torrent_files_migrated += 1
except Exception as e:
self._logger.error(u"dropping corrupted torrent file %s: %s", file_path, str(e))
Expand Down
5 changes: 3 additions & 2 deletions Tribler/Core/Upgrade/upgrade.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
import os
import shutil

from Tribler.Core.CacheDB.db_versions import LATEST_DB_VERSION
from Tribler.Core.Upgrade.db_upgrader import DBUpgrader
from Tribler.Core.Upgrade.torrent_upgrade64 import TorrentMigrator64

from Tribler.dispersy.util import call_on_reactor_thread


# Database versions:
# *earlier versions are no longer supported
# 17 is used by Tribler 5.9.x - 6.0
Expand Down Expand Up @@ -68,6 +69,6 @@ def _stash_database_away(self):
self.db.close()
old_dir = os.path.dirname(self.db.sqlite_db_path)
new_dir = u'%s_backup_%d' % (old_dir, LATEST_DB_VERSION)
os.rename(old_dir, new_dir)
shutil.move(old_dir, new_dir)
os.makedirs(old_dir)
self.db.initialize()
19 changes: 9 additions & 10 deletions Tribler/Main/Utility/Feeds/rssparser.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# Written by Niels Zeilemaker

import imghdr
import logging
import os
import re
import sha
import tempfile
import time
import re
import logging
from copy import deepcopy
from shutil import copyfile
from urlparse import urlparse
import imghdr
import tempfile
from traceback import print_exc
from threading import Thread, RLock, Event
from traceback import print_exc

import requests

from Tribler.Core.RemoteTorrentHandler import RemoteTorrentHandler
from Tribler.Core.TorrentDef import TorrentDef
from Tribler.Core.Utilities.timeouturlopen import urlOpenTimeout
from Tribler.Core.Utilities.bencode import bdecode
from Tribler.Core.RemoteTorrentHandler import RemoteTorrentHandler


try:
from Tribler.Main.Utility.Feeds import feedparser
Expand Down Expand Up @@ -354,7 +353,7 @@ def __try_image(self, filepath, work_dir, image_count):
old_filepath = filepath
new_filename = u"thumbnail-%d.%s" % (image_count, image_type)
new_filepath = os.path.join(work_dir, new_filename)
os.rename(old_filepath, new_filepath)
move(old_filepath, new_filepath)

return new_filepath
else:
Expand Down
6 changes: 3 additions & 3 deletions Tribler/Main/vwxGUI/list_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,9 @@ def rename_or_merge(old, new):

elif os.path.exists(newfile):
os.remove(newfile)
os.rename(oldfile, newfile)
shutil.move(oldfile, newfile)
else:
os.rename(oldfile, newfile)
shutil.move(oldfile, newfile)
else:
os.renames(old, new)

Expand Down Expand Up @@ -974,7 +974,7 @@ def ShortenText(statictext, text):
def CreateBitmaps(self):
# Temporary silence wx errors. Avoids "No handler found for image type" errors.
nolog = wx.LogNull()

bitmap = None

thumb_dir = os.path.join(self.guiutility.utility.session.get_torrent_collecting_dir(), binascii.hexlify(self.original_data.infohash))
Expand Down
25 changes: 12 additions & 13 deletions Tribler/Main/vwxGUI/settingsDialog.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# Written by Niels Zeilemaker

# see LICENSE.txt for license information
import wx
import wx.lib.masked.textctrl
import wx.lib.imagebrowser as ib
import sys
import atexit
import logging
import os
import shutil
import sys
import tempfile
import atexit
import time
import logging

from Tribler.Core.simpledefs import UPLOAD, DOWNLOAD, STATEDIR_TORRENTCOLL_DIR
import wx.lib.imagebrowser as ib
import wx.lib.masked.textctrl

from Tribler.Core.Session import Session
from Tribler.Core.SessionConfig import SessionStartupConfig
from Tribler.Core.osutils import get_picture_dir

from Tribler.Core.simpledefs import UPLOAD, DOWNLOAD, STATEDIR_TORRENTCOLL_DIR
from Tribler.Main.globals import DefaultDownloadStartupConfig, get_default_dscfg_filename
from Tribler.Main.vwxGUI.GuiUtility import GUIUtility
from Tribler.Main.vwxGUI.GuiImageManager import GuiImageManager, data2wxBitmap, ICON_MAX_DIM
from Tribler.Main.vwxGUI.GuiUtility import GUIUtility
from Tribler.Main.vwxGUI.validator import DirectoryValidator, NetworkSpeedValidator,NumberValidator
from Tribler.Main.vwxGUI.widgets import _set_font, EditText, AnonymousSlidebar
from Tribler.Main.vwxGUI.validator import DirectoryValidator, NetworkSpeedValidator, \
NumberValidator


def create_section(parent, hsizer, label):
Expand Down Expand Up @@ -370,9 +369,9 @@ def rename_or_merge(old, new, ignore=True):
elif os.path.exists(newfile):
if not ignore:
os.remove(newfile)
os.rename(oldfile, newfile)
shutil.move(oldfile, newfile)
else:
os.rename(oldfile, newfile)
shutil.move(oldfile, newfile)
else:
os.renames(old, new)

Expand Down