use os.path.join()

This commit is contained in:
Zach Tibbitts 2007-03-22 21:52:56 +00:00
parent d889759b5d
commit 4c97301478
4 changed files with 25 additions and 25 deletions

View File

@ -30,9 +30,9 @@ CONFIG_DIR = xdg.BaseDirectory.save_config_path('deluge')
# the necessary substitutions are made at installation time # the necessary substitutions are made at installation time
INSTALL_PREFIX = '@datadir@' INSTALL_PREFIX = '@datadir@'
GLADE_DIR = INSTALL_PREFIX + '/share/deluge/glade' GLADE_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'glade')
PIXMAP_DIR = INSTALL_PREFIX + '/share/deluge/pixmaps' PIXMAP_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'pixmaps')
PLUGIN_DIR = INSTALL_PREFIX + '/share/deluge/plugins' PLUGIN_DIR = os.path.join(INSTALL_PREFIX, 'share', 'deluge', 'plugins')
def estimate_eta(state): def estimate_eta(state):
try: try:
@ -93,10 +93,10 @@ def ftime(seconds):
def get_glade_file(fname): def get_glade_file(fname):
return GLADE_DIR + "/" + fname return os.path.join(GLADE_DIR, fname)
def get_pixmap(fname): def get_pixmap(fname):
return PIXMAP_DIR + "/" + fname return os.path.join(PIXMAP_DIR, fname)
def open_url_in_browser(dialog, link): def open_url_in_browser(dialog, link):
try: try:

View File

@ -37,7 +37,7 @@
# 3. supp_torrent_state - supplementary torrent data, from Deluge # 3. supp_torrent_state - supplementary torrent data, from Deluge
import deluge_core import deluge_core
import os, shutil, statvfs import os, os.path, shutil, statvfs
import pickle import pickle
import time import time
import gettext import gettext
@ -170,7 +170,7 @@ class Manager:
# Ensure directories exist # Ensure directories exist
if not TORRENTS_SUBDIR in os.listdir(self.base_dir): if not TORRENTS_SUBDIR in os.listdir(self.base_dir):
os.mkdir(self.base_dir + "/" + TORRENTS_SUBDIR) os.mkdir(os.path.join(self.base_dir, TORRENTS_SUBDIR))
# Pre-initialize the core's data structures # Pre-initialize the core's data structures
deluge_core.pre_init(DelugeError, deluge_core.pre_init(DelugeError,
@ -210,7 +210,7 @@ class Manager:
self.prefs = DEFAULT_PREFS self.prefs = DEFAULT_PREFS
if not blank_slate: if not blank_slate:
try: try:
pkl_file = open(self.base_dir + "/" + PREFS_FILENAME, 'rb') pkl_file = open(os.path.join(self.base_dir, PREFS_FILENAME), 'rb')
self.prefs = pickle.load(pkl_file) self.prefs = pickle.load(pkl_file)
pkl_file.close() pkl_file.close()
except IOError: except IOError:
@ -222,14 +222,14 @@ class Manager:
# Apply DHT, if needed. Note that this is before any torrents are added # Apply DHT, if needed. Note that this is before any torrents are added
if self.get_pref('use_DHT'): if self.get_pref('use_DHT'):
if not blank_slate: if not blank_slate:
deluge_core.start_DHT(self.base_dir + "/" + DHT_FILENAME) deluge_core.start_DHT(os.path.join(self.base_dir, DHT_FILENAME))
else: else:
deluge_core.start_DHT("") deluge_core.start_DHT("")
# Unpickle the state, or create a new one # Unpickle the state, or create a new one
if not blank_slate: if not blank_slate:
try: try:
pkl_file = open(self.base_dir + "/" + STATE_FILENAME, 'rb') pkl_file = open(os.path.join(self.base_dir, STATE_FILENAME), 'rb')
self.state = pickle.load(pkl_file) self.state = pickle.load(pkl_file)
pkl_file.close() pkl_file.close()
@ -252,13 +252,13 @@ class Manager:
# Pickle the prefs # Pickle the prefs
print "Pickling prefs..." print "Pickling prefs..."
output = open(self.base_dir + "/" + PREFS_FILENAME, 'wb') output = open(os.path.join(self.base_dir, PREFS_FILENAME), 'wb')
pickle.dump(self.prefs, output) pickle.dump(self.prefs, output)
output.close() output.close()
# Pickle the state # Pickle the state
print "Pickling state..." print "Pickling state..."
output = open(self.base_dir + "/" + STATE_FILENAME, 'wb') output = open(os.path.join(self.base_dir, STATE_FILENAME), 'wb')
pickle.dump(self.state, output) pickle.dump(self.state, output)
output.close() output.close()
@ -269,7 +269,7 @@ class Manager:
# Stop DHT, if needed # Stop DHT, if needed
if self.get_pref('use_DHT'): if self.get_pref('use_DHT'):
print "Stopping DHT..." print "Stopping DHT..."
deluge_core.stop_DHT(self.base_dir + "/" + DHT_FILENAME) deluge_core.stop_DHT(os.path.join(self.base_dir, DHT_FILENAME))
# Shutdown torrent core # Shutdown torrent core
print "Quitting the core..." print "Quitting the core..."
@ -328,17 +328,17 @@ class Manager:
for filedata in temp_fileinfo: for filedata in temp_fileinfo:
filename = filedata['path'] filename = filedata['path']
try: try:
os.remove(temp.save_dir + "/" + filename) os.remove(os.path.join(temp.save_dir, filename))
except OSError: except OSError:
pass # No file just means it wasn't downloaded, we can continue pass # No file just means it wasn't downloaded, we can continue
# A function to try and reload a torrent from a previous session. This is # A function to try and reload a torrent from a previous session. This is
# used in the event that Deluge crashes and a blank state is loaded. # used in the event that Deluge crashes and a blank state is loaded.
def add_old_torrent(self, filename, save_dir, compact): def add_old_torrent(self, filename, save_dir, compact):
if not filename in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR): if not filename in os.listdir(os.path.join(self.base_dir, TORRENTS_SUBDIR)):
raise InvalidTorrentError(_("File was not found") + ": " + filename) raise InvalidTorrentError(_("File was not found") + ": " + filename)
full_new_name = self.base_dir + "/" + TORRENTS_SUBDIR + "/" + filename full_new_name = os.path.join(self.base_dir, TORRENTS_SUBDIR, filename)
# Create torrent object # Create torrent object
new_torrent = torrent_info(full_new_name, save_dir, compact) new_torrent = torrent_info(full_new_name, save_dir, compact)
@ -353,7 +353,7 @@ class Manager:
# Load all NEW torrents in a directory. The GUI can call this every minute or so, # Load all NEW torrents in a directory. The GUI can call this every minute or so,
# if one wants a directory to be 'watched' (personally, I think it should only be # if one wants a directory to be 'watched' (personally, I think it should only be
# done on user command). # done on user command).os.path.join(
def autoload_directory(self, directory, save_dir, compact): def autoload_directory(self, directory, save_dir, compact):
for filename in os.listdir(directory): for filename in os.listdir(directory):
if filename[-len(".torrent"):].lower() == ".torrent": if filename[-len(".torrent"):].lower() == ".torrent":
@ -614,7 +614,7 @@ class Manager:
# if filename_short in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR): # if filename_short in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR):
# raise DuplicateTorrentError("Duplicate Torrent, it appears: " + filename_short) # raise DuplicateTorrentError("Duplicate Torrent, it appears: " + filename_short)
full_new_name = self.base_dir + "/" + TORRENTS_SUBDIR + "/" + filename_short full_new_name = os.path.join(self.base_dir, TORRENTS_SUBDIR, filename_short)
shutil.copy(filename, full_new_name) shutil.copy(filename, full_new_name)

View File

@ -44,7 +44,7 @@ class DelugeGTK:
self.ipc_manager = ipc_manager.Manager(self) self.ipc_manager = ipc_manager.Manager(self)
self.torrent_file_queue = [] self.torrent_file_queue = []
#Load up a config file: #Load up a config file:
self.conf_file = dcommon.CONFIG_DIR + '/deluge.conf' self.conf_file = os.path.join(dcommon.CONFIG_DIR, 'deluge.conf')
if os.path.isdir(self.conf_file): if os.path.isdir(self.conf_file):
print 'Weird, the file I was trying to write to, %s, is an existing directory'%(self.conf_file) print 'Weird, the file I was trying to write to, %s, is an existing directory'%(self.conf_file)
sys.exit(0) sys.exit(0)
@ -68,8 +68,8 @@ class DelugeGTK:
#else: self.something_screwed_up = False #else: self.something_screwed_up = False
self.plugins = delugeplugins.PluginManager(self.manager, self) self.plugins = delugeplugins.PluginManager(self.manager, self)
self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR) self.plugins.add_plugin_dir(dcommon.PLUGIN_DIR)
if os.path.isdir(dcommon.CONFIG_DIR + '/plugins'): if os.path.isdir(os.path.join(dcommon.CONFIG_DIR , 'plugins')):
self.plugins.add_plugin_dir(dcommon.CONFIG_DIR + '/plugins') self.plugins.add_plugin_dir(os.path.join(dcommon.CONFIG_DIR, 'plugins'))
self.plugins.scan_for_plugins() self.plugins.scan_for_plugins()
self.config = pref.Preferences() self.config = pref.Preferences()
self.config.load_from_file(self.conf_file) self.config.load_from_file(self.conf_file)
@ -673,7 +673,7 @@ class DelugeGTK:
restore_torrents = dgtk.show_popup_question(self.window, restore_torrents = dgtk.show_popup_question(self.window,
_("Would you like to attempt to reload the previous session's downloads?")) _("Would you like to attempt to reload the previous session's downloads?"))
if restore_torrents: if restore_torrents:
torrent_subdir = self.manager.base_dir + "/" + deluge.TORRENTS_SUBDIR torrent_subdir = os.path.join(self.manager.base_dir, deluge.TORRENTS_SUBDIR)
for torrent in os.listdir(torrent_subdir): for torrent in os.listdir(torrent_subdir):
if torrent.endswith('.torrent'): if torrent.endswith('.torrent'):
self.interactive_add_torrent(torrent) self.interactive_add_torrent(torrent)

View File

@ -38,9 +38,9 @@ class PluginManager:
for folder in self.plugin_dirs: for folder in self.plugin_dirs:
plugin_folders = os.listdir(folder) plugin_folders = os.listdir(folder)
for plugin in plugin_folders: for plugin in plugin_folders:
if os.path.isfile(folder + "/" + plugin + "/plugin.py"): if os.path.isfile(os.path.join(folder, plugin, "plugin.py")):
self.path = folder + "/" + plugin self.path = os.path.join(folder, plugin)
execfile(folder + "/" + plugin + "/plugin.py") execfile(os.path.join(folder, plugin, "plugin.py"))
def get_available_plugins(self): def get_available_plugins(self):
return self.available_plugins.keys() return self.available_plugins.keys()