diff --git a/main/SABnzbd.py b/main/SABnzbd.py index 79c1982..e5fc2ec 100644 --- a/main/SABnzbd.py +++ b/main/SABnzbd.py @@ -334,8 +334,10 @@ def main(): try: web_dir = cfg['misc']['web_dir'] except: + web_dir = '' + if not web_dir: web_dir = 'templates' - cfg['misc']['web_dir'] = web_dir + cfg['misc']['web_dir'] = web_dir web_dir = real_path(sabnzbd.DIR_PROG, web_dir) logging.info("Web dir is %s", web_dir) diff --git a/main/sabnzbd/__init__.py b/main/sabnzbd/__init__.py index 22912af..4a9a234 100644 --- a/main/sabnzbd/__init__.py +++ b/main/sabnzbd/__init__.py @@ -35,7 +35,7 @@ from threading import RLock, Lock, Condition, Thread from sabnzbd.assembler import Assembler, PostProcessor from sabnzbd.downloader import Downloader, BPSMeter from sabnzbd.nzbqueue import NzbQueue, NZBQUEUE_LOCK -from sabnzbd.misc import MSGIDGrabber, URLGrabber, DirScanner, real_path +from sabnzbd.misc import MSGIDGrabber, URLGrabber, DirScanner, real_path, create_real_path from sabnzbd.nzbstuff import NzbObject from sabnzbd.utils.kronos import ThreadedScheduler from sabnzbd.rss import RSSQueue @@ -142,16 +142,7 @@ def dir_setup(config, cfg_name, def_loc, dir_name): my_dir = dir_name config['misc'][cfg_name] = my_dir - my_dir = real_path(def_loc, my_dir) - if not os.path.exists(my_dir): - logging.info('%s directory: %s does not exist, try to create it', cfg_name, my_dir) - try: - os.makedirs(my_dir) - except: - logging.error('Cannot create directory %s', my_dir) - if not os.access(my_dir, os.R_OK + os.W_OK): - logging.error('%s directory: %s error accessing', cfg_name, my_dir) - return "" + my_dir = create_real_path(cfg_name, def_loc, my_dir) logging.info("%s: %s", cfg_name, my_dir) return my_dir diff --git a/main/sabnzbd/interface.py b/main/sabnzbd/interface.py index e31bc46..b7208e2 100644 --- a/main/sabnzbd/interface.py +++ b/main/sabnzbd/interface.py @@ -38,7 +38,7 @@ from sabnzbd.utils import listquote from sabnzbd.utils.configobj import ConfigObj from Cheetah.Template import Template from sabnzbd.email import email_send -from sabnzbd.misc import real_path +from sabnzbd.misc import real_path, create_real_path from sabnzbd.constants import * @@ -623,27 +623,33 @@ class ConfigDirectories(ProtectedClass): cache_dir = None, nzb_backup_dir = None, dirscan_dir = None, dirscan_speed = None, extern_proc = None): - if download_dir and not os.access(real_path(sabnzbd.DIR_LCLDATA, download_dir), os.R_OK + os.W_OK): - return "Error: can't access download directory." - if not download_dir: - return "Error: download directory not set." + dd = create_real_path('download_dir', sabnzbd.DIR_LCLDATA, download_dir) + if not dd: + return "Error: cannot create download directory %s." % dd - if cache_dir and not os.access(real_path(sabnzbd.DIR_LCLDATA, cache_dir), os.R_OK + os.W_OK): - return "Error: can't access cache directory." - if not cache_dir: - return "Error: cache directory not set." + dd = create_real_path('cache_dir', sabnzbd.DIR_LCLDATA, cache_dir) + if not dd: + return "Error: cannot create cache directory %s." % dd - if log_dir and not os.access(real_path(sabnzbd.DIR_LCLDATA, log_dir), os.R_OK + os.W_OK): - return "Error: can't access log directory." - - if dirscan_dir and not os.access(real_path(sabnzbd.DIR_HOME, dirscan_dir), os.R_OK + os.W_OK): - return "Error: can't access dirscan directory." + dd = create_real_path('log_dir', sabnzbd.DIR_LCLDATA, log_dir) + if not dd: + return "Error: cannot create log directory %s." % dd + + dd = create_real_path('dirscan_dir', sabnzbd.DIR_HOME, dirscan_dir) + if not dd: + return "Error: cannot create dirscan_dir directory %s." % dd - if complete_dir and not os.access(real_path(sabnzbd.DIR_HOME, complete_dir), os.R_OK + os.W_OK): - return "Error: can't access complete directory." + dd = create_real_path('complete_dir', sabnzbd.DIR_HOME, complete_dir) + if not dd: + return "Error: cannot create complete_dir directory %s." % dd - if nzb_backup_dir and not os.access(real_path(sabnzbd.DIR_LCLDATA, nzb_backup_dir), os.R_OK + os.W_OK): - return "Error: can't access complete directory." + dd = create_real_path('nzb_backup_dir', sabnzbd.DIR_LCLDATA, nzb_backup_dir) + if not dd: + return "Error: cannot create nzb_backup_dir directory %s." % dd + + if extern_proc and not os.access(real_path(sabnzbd.DIR_HOME, extern_proc), os.R_OK): + return "Error: cannot find extern_proc %s." % real_path(sabnzbd.DIR_HOME, extern_proc) + sabnzbd.CFG['misc']['download_dir'] = download_dir sabnzbd.CFG['misc']['download_free'] = download_free @@ -771,12 +777,14 @@ class ConfigGeneral(ProtectedClass): sabnzbd.CFG['misc']['cleanup_list'] = listquote.simplelist(cleanup_list) sabnzbd.CFG['misc']['cache_limit'] = cache_limit - if web_dir and not os.access(os.path.abspath(sabnzbd.DIR_PROG+'/'+web_dir), os.R_OK): - return "Error: can't access template directory." - if web_dir and not os.access(os.path.abspath(sabnzbd.DIR_PROG+'/'+web_dir+'/main.tmpl'), os.R_OK): - return "Error: not a valid template directory (cannot see main.tmpl)." if not web_dir: - return "Error: template directory not set." + web_dir= 'templates' + dd = os.path.abspath(sabnzbd.DIR_PROG + '/' + web_dir) + if dd and not os.access(dd, os.R_OK): + return "Error: cannot access template directory %s" % dd + if dd and not os.access(dd + '/main.tmpl', os.R_OK): + return "Error: \"%s\" is not a valid template directory (cannot see main.tmpl)." % dd + sabnzbd.CFG['misc']['web_dir'] = web_dir return saveAndRestart(self.__root) diff --git a/main/sabnzbd/misc.py b/main/sabnzbd/misc.py index c6024b4..40f10af 100644 --- a/main/sabnzbd/misc.py +++ b/main/sabnzbd/misc.py @@ -176,6 +176,24 @@ def real_path(loc, path): ################################################################################ +# Create_Real_Path # +################################################################################ +def create_real_path(name, loc, path): + if path: + my_dir = real_path(loc, path) + if not os.path.exists(my_dir): + logging.info('%s directory: %s does not exist, try to create it', name, my_dir) + try: + os.makedirs(my_dir) + except: + logging.error('Cannot create directory %s', my_dir) + if not os.access(my_dir, os.R_OK + os.W_OK): + logging.error('%s directory: %s error accessing', name, my_dir) + return "" + return my_dir + + +################################################################################ # Get_User_ShellFolders # # Return a dictionary with Windows Special Folders diff --git a/main/templates/config_directories.tmpl b/main/templates/config_directories.tmpl index 3143c31..d0f5146 100644 --- a/main/templates/config_directories.tmpl +++ b/main/templates/config_directories.tmpl @@ -25,7 +25,7 @@

Directory configuration

- NOTE: New paths must already exist, only default directories were created automatically.
+ NOTE: Directories will be created automatically when Saving.