Skip to content

Loading…

rewrite of saveSearch() #509

Merged
merged 3 commits into from

5 participants

@bradallred

I work on a fork of SickBeard that adds a lot of search options (~40 with 4 additional download methods) and these are a couple of changes I have made to prevent saveSearch() from becoming unwieldy.

bradallred added some commits
@bradallred bradallred webserver: change saveSearch() to pack arguments into a dict
it is cumbersome for forks / future development to manually add variables to this function
3cccddc
@bradallred bradallred webserve: change the way sab_host is normalized into a / terminated URL
this will lessen the amount of work forks / future development will need to do when adding new URL options
ed1d232
@bradallred bradallred woops: didn't quite get this right when backporting
these functions need to return a tuple and we need to check return value before appending a message
52e20e4
@midgetspy
Owner

Great submission, thanks.

@midgetspy midgetspy merged commit 9a511dc into midgetspy:master
@zzappazz

I am by no means a regex expert, but won't this regex be confused by domain names that begin with an 's' ?
I would guess that the 's' in 'somename.com' would be swallowed as seemingly part of an 'https'.

midgetspy will have to look as he loves the regexes

just use http://docs.python.org/2/library/urlparse.html instead of reinventing the wheel

urlparse.urlparse('www.foo.com')
ParseResult(scheme='', netloc='', path='www.foo.com', params='', query='', fragment='')
urlparse.urlparse('http://www.foo.com')
ParseResult(scheme='http', netloc='www.foo.com', path='', params='', query='', fragment='')
urlparse.urlparse('http://www.foo.com/')
ParseResult(scheme='http', netloc='www.foo.com', path='/', params='', query='', fragment='')
urlparse.urlparse('https://www.foo.com/')
ParseResult(scheme='https', netloc='www.foo.com', path='/', params='', query='', fragment='')

@thezoggy

also this change breaks the page as you cant uncheck and save... as something that isnt checked off isnt passed. thus this needs to be reverted

@thezoggy thezoggy added a commit to thezoggy/Sick-Beard that referenced this pull request
@thezoggy thezoggy Revert "Merge pull request #509 from bradallred/master"
This reverts commit 9a511dc, reversing
changes made to acadc39.
a9b501d
@thezoggy

#536 reverts pull #509

@bradallred

what exactly is the problem with saving? it is possible that i mucked something up when backporting, but everything behaves as expected for me. (except for the regex which as noted doesnt work with a host that starts with 's' if the protocol is omitted)

what is the expected result of saveSearch() so that i can resubmit something that works for you? did you even test this?

@thezoggy

go tell sb to use torrents save check config and you see use_torrents = 1 now go uncheck it and hit save. you will see it is still 1 not 0. this is because when you dont have a checkbox checked its omitted from post.. which is why we explicitly define what is expected to be passed and default to 0/none if its not.. also with your changes i noticed that the save/test buttons for sab resulted in my sab host turning into http://http://http://http://http://http://localhost:8082/ overall there was just too many issues to deal with and we reverted the changes until it could be properly looked into

@bradallred

ah i think i see what happened. In my fork i think I had modified the html so ensure that a space was always submitted and i dealt with that using the trim call you see there. I obviously failed to realize that when i back-ported this.

@nmorey nmorey added a commit to nmorey/Sick-Beard that referenced this pull request
@nmorey nmorey Merge branch 'master' of https://github.com/midgetspy/Sick-Beard
* 'master' of https://github.com/midgetspy/Sick-Beard: (44 commits)
  Fixed an error when saving provider configurations.
  Removed providers which are no longer working.
  Add qualityChooser.js since it was removed in the .tmpl, removed line that called undefined `searchTvdb()`
  Prune out known win and osx folders in the sb browser/autocomplete that are just pointless/clutter. Users should not be storing or trying to load any data from as it would result in permission/conflicts/deletion by the os.
  Tweaked CSS for the rootDir listing. More log related and whitespace cleanup. Fixed the accessibility outline on the filebrowser to look a bit nicer.
  Fixed some jsHint concerns and improve readability
  qualityChooser related cleanup * Removed unused import, cleaned up some misc whitespace and added some padding for the searching animation on the tvdb search (new show). * We were importing qualityChooser.js in the inc_qualityChooser.tmpl and also in the newShow tmpl which resulted in a double loading the file..
  addNewShow tvdb languages fix
  Minor cleanup for previous formwizard changes, discovered that if we focused an element before the page finished loading it messed up the visible height.. moved the focus for the name to search inside of the actual formwizard routine (only way i could get it to work all the time and across step changes -- as i did not want to add another callback to just do this)
  Fix 'add show' default notice (disable shadow) and JSLint/JSHint file.
  Fix for windows users that do not use a login/username -- thanks mr_orange
  Revert "Merge pull request #509 from bradallred/master"
  Fix On Backlog Search. Fix the bug where every limited backlog will set new date for the full Backlog.
  Sort the splitQuality output so that it makes the webapi and displayShow show the quality in order of value correctly.
  Treat episodes on TVDB with the airdate of `0000-00-00` the same as if it was not set to anything. This resolves tv.py throwing: `Malformed air date retrieved from TVDB` This resolves tvrage.py throwing: `Error encountered while checking TVRage<->TVDB sync: year is out of range`
  Correctly sort shows on homepage that have 0 ep downloaded. (0/# sorts lower than 1/#)
  Upgrade tvdb_api from 1.7.2 -> 1.8.2. Should resolve cache issues with regards to users that are unable to write to the cache, depending on how the 'tmp' permissions are set up.
  Fix SB-API call on adding shows via tvdbid that contain no name -- resulted in a show folder called `None`. Fix SB-API sb.searchTVDB call on returning incorrect data for a tvdbid that contains no name. Report the failure to add a show to sb because it has no episode/season data rather than saying it has no name and to delete the .nfo file.
  Add .mp4 assumed quality as SD (we forgot to add this when the scene went from xvid.avi to x264.mp4).
  Fix the page bg from having funky issues on scrolling.
  ...
4af3add
@junalmeida junalmeida referenced this pull request in junalmeida/Sick-Beard
Closed

Bad Request When Saving Torrent Settings #14

@depassp depassp added a commit to depassp/Sick-Beard that referenced this pull request
@thezoggy thezoggy Revert "Merge pull request #509 from bradallred/master"
This reverts commit 9a511dc, reversing
changes made to acadc39.
9d68133
@jamesstout jamesstout added a commit to jamesstout/Sick-Beard that referenced this pull request
@thezoggy thezoggy Revert "Merge pull request #509 from bradallred/master"
This reverts commit 9a511dc, reversing
changes made to acadc39.
cb6d683
@ghost Unknown pushed a commit that referenced this pull request
@thezoggy thezoggy Revert "Merge pull request #509 from bradallred/master"
This reverts commit 9a511dc, reversing
changes made to acadc39.
b4aa7f2
@Elandril Elandril pushed a commit that referenced this pull request
@thezoggy thezoggy Revert "Merge pull request #509 from bradallred/master"
This reverts commit 9a511dc, reversing
changes made to acadc39.
febb3ed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. @bradallred

    webserver: change saveSearch() to pack arguments into a dict

    bradallred committed
    it is cumbersome for forks / future development to manually add variables to this function
  2. @bradallred

    webserve: change the way sab_host is normalized into a / terminated URL

    bradallred committed
    this will lessen the amount of work forks / future development will need to do when adding new URL options
  3. @bradallred

    woops: didn't quite get this right when backporting

    bradallred committed
    these functions need to return a tuple and we need to check return value before appending a message
This page is out of date. Refresh to see the latest.
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:
Something went wrong with that request. Please try again.