Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #509 from bradallred/master

rewrite of saveSearch()
  • Loading branch information...
commit 9a511dc9296dbc1292bd98c421cad9c85f416bdf 2 parents acadc39 + 52e20e4
@midgetspy authored
Showing with 32 additions and 60 deletions.
  1. +8 −7 sickbeard/config.py
  2. +24 −53 sickbeard/webserve.py
View
15 sickbeard/config.py
@@ -94,32 +94,32 @@ def change_NZB_DIR(nzb_dir):
if nzb_dir == '':
sickbeard.NZB_DIR = ''
- return True
+ return True, u"Removed NZB directory"
if os.path.normpath(sickbeard.NZB_DIR) != os.path.normpath(nzb_dir):
if helpers.makeDir(nzb_dir):
sickbeard.NZB_DIR = os.path.normpath(nzb_dir)
logger.log(u"Changed NZB folder to " + nzb_dir)
else:
- return False
+ return False, u"Unable to create NZB directory '" + nzb_dir + "', directory unchanged"
- return True
+ return True, u"Changed NZB directory to " + nzb_dir
def change_TORRENT_DIR(torrent_dir):
if torrent_dir == '':
sickbeard.TORRENT_DIR = ''
- return True
+ return True, u"Removed TORRENT directory"
if os.path.normpath(sickbeard.TORRENT_DIR) != os.path.normpath(torrent_dir):
if helpers.makeDir(torrent_dir):
sickbeard.TORRENT_DIR = os.path.normpath(torrent_dir)
- logger.log(u"Changed torrent folder to " + torrent_dir)
+ logger.log(u"Changed torrent directory to " + torrent_dir)
else:
- return False
+ return False, u"Unable to create TORRENT directory '" + torrent_dir + "', directory unchanged"
- return True
+ return True, u"Changed TORRENT directory to " + torrent_dir
def change_TV_DOWNLOAD_DIR(tv_download_dir):
@@ -152,6 +152,7 @@ def change_SEARCH_FREQUENCY(freq):
sickbeard.currentSearchScheduler.cycleTime = datetime.timedelta(minutes=sickbeard.SEARCH_FREQUENCY)
sickbeard.backlogSearchScheduler.cycleTime = datetime.timedelta(minutes=sickbeard.get_backlog_cycle_time())
+ return True, u"SEARCH_FREQUENCY changed to " + str(freq)
def change_VERSION_NOTIFY(version_notify):
View
77 sickbeard/webserve.py
@@ -762,64 +762,35 @@ def index(self):
return _munge(t)
@cherrypy.expose
- def saveSearch(self, use_nzbs=None, use_torrents=None, nzb_dir=None, sab_username=None, sab_password=None,
- sab_apikey=None, sab_category=None, sab_host=None, nzbget_password=None, nzbget_category=None, nzbget_host=None,
- torrent_dir=None, nzb_method=None, usenet_retention=None, search_frequency=None, download_propers=None):
+ def saveSearch(self, **postData):
results = []
- if not config.change_NZB_DIR(nzb_dir):
- results += ["Unable to create directory " + os.path.normpath(nzb_dir) + ", dir not changed."]
-
- if not config.change_TORRENT_DIR(torrent_dir):
- results += ["Unable to create directory " + os.path.normpath(torrent_dir) + ", dir not changed."]
-
- config.change_SEARCH_FREQUENCY(search_frequency)
-
- if download_propers == "on":
- download_propers = 1
- else:
- download_propers = 0
-
- if use_nzbs == "on":
- use_nzbs = 1
- else:
- use_nzbs = 0
-
- if use_torrents == "on":
- use_torrents = 1
- else:
- use_torrents = 0
-
- if usenet_retention == None:
- usenet_retention = 200
-
- sickbeard.USE_NZBS = use_nzbs
- sickbeard.USE_TORRENTS = use_torrents
-
- sickbeard.NZB_METHOD = nzb_method
- sickbeard.USENET_RETENTION = int(usenet_retention)
-
- sickbeard.DOWNLOAD_PROPERS = download_propers
-
- sickbeard.SAB_USERNAME = sab_username
- sickbeard.SAB_PASSWORD = sab_password
- sickbeard.SAB_APIKEY = sab_apikey.strip()
- sickbeard.SAB_CATEGORY = sab_category
-
- if sab_host and not re.match('https?://.*', sab_host):
- sab_host = 'http://' + sab_host
-
- if not sab_host.endswith('/'):
- sab_host = sab_host + '/'
-
+ for key, value in postData.items():
+ value = value.strip()
+ val = 1 if value == "on" else value
+ if hasattr(config, 'change_' + key.upper()):
+ ret, msg = getattr(config, 'change_' + key.upper())(val)
+ if ret == False:
+ results.append(msg)
+ elif hasattr(sickbeard, key.upper()):
+ setattr(sickbeard, key.upper(), val)
+ elif hasattr(sickbeard, key.lower()):
+ setattr(sickbeard, key.lower(), val)
+ else:
+ logger.log("Unknown search setting: " + key, logger.ERROR)
+
+ # handle some special cases
+ sickbeard.USENET_RETENTION = int(postData.get('usenet_retention', 200))
+
+ # this regex will match http or https urls or just a domain/address
+ regex = re.compile(r'^(http)?(?P<s>s|)?(://)?(?P<addr>[^/]*)/?')
+ # this substitution combined with above regex will return a '/' terminated url from given url or host
+ regex_sub = r'http\g<s>://\g<addr>/'
+
+ sab_host = re.sub(regex, regex_sub, postData.get('sab_host', ''))
sickbeard.SAB_HOST = sab_host
- sickbeard.NZBGET_PASSWORD = nzbget_password
- sickbeard.NZBGET_CATEGORY = nzbget_category
- sickbeard.NZBGET_HOST = nzbget_host
-
-
sickbeard.save_config()
if len(results) > 0:
Please sign in to comment.
Something went wrong with that request. Please try again.