Browse Source

SABnzbd.py:

Recover when web_dir is empty

__init__.py / misc.py:
   Refactoring of dir_setup. Extract create_real_path an put it in misc.py

interface.py:
   Proper handling of directories on save.
   Improved checking of templates directories.
   Recover from empty template field.

config_directories.tmpl:
   Change notice on directories again.
tags/0.6.0
shypike 18 years ago
parent
commit
41b10cf8dc
  1. 4
      main/SABnzbd.py
  2. 13
      main/sabnzbd/__init__.py
  3. 54
      main/sabnzbd/interface.py
  4. 18
      main/sabnzbd/misc.py
  5. 2
      main/templates/config_directories.tmpl

4
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)

13
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

54
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)

18
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

2
main/templates/config_directories.tmpl

@ -25,7 +25,7 @@
</span>
<h2>Directory configuration</h2>
<p><strong>
<em>NOTE:</em> New paths must already exist, only default directories were created automatically.<br />
<em>NOTE:</em> Directories will be created automatically when Saving.<br />
</strong></p>
<form action="saveDirectories" method="post">
<div class="EntryBlock">

Loading…
Cancel
Save