mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-11 05:33:37 +00:00
d3a7f0ff5e
Add newznab smart logic to avoid missing releases when there are a great many recent releases. Change improve performance by using newznab server advertised capabilities. Change config/providers newznab to display only non-default categories. Change use scene season for wanted segment in backlog if show is scene numbering. Change combine Manage Searches / Backlog Search / Limited and Full to Force. Change consolidate limited and full backlog. Change config / Search / Backlog search frequency to instead spread backlog searches over a number of days. Change migrate minimum used value for search frequency into new minimum 7 for search spread. Change restrict nzb providers to 1 backlog batch run per day. Add to Config/Search/Unaired episodes/Allow episodes that are released early. Add to Config/Search/Unaired episodes/Use specific api requests to search for early episode releases. Add use related ids for newznab searches to increase search efficiency. Add periodic update of related show ids. Change terminology Edit Show/"Post processing" tab name to "Other". Add advanced feature "Related show IDs" to Edit Show/Other used for finding episodes and TV info. Add search info source image links to those that have zero id under Edit Show/Other/"Related show IDs". Add "set master" button to Edit Show/Other/"Related show IDs" for info source that can be changed. Change terminology displayShow "Indexers" to "Links" to cover internal and web links. Change add related show info sources on displayShow page. Change don't display "temporarily" defunct TVRage image link on displayShow pages unless it is master info source. Change if a defunct info source is the master of a show then present a link on displayShow to edit related show IDs. Change simplify the next backlog search run time display in the page footer. Change try ssl when fetching data thetvdb, imdb, trakt, scene exception. Change improve reliability to Trakt notifier by using show related id support. Change improve config/providers newznab categories layout. Change show loaded log message at start up and include info source. Change if episode has no airdate then set status to unaired (was skipped). Technical Change move scene_exceptions table from cache.db to sickbeard.db. Add related ids to show obj. Add use of mapped indexer ids for newznab. Add indexer to sql in wanted_eps. Add aired in (scene) season for wanted episodes. Add need_anime, need_sports, need_sd, need_hd, need_uhd to wanted episodes and added as parameter to update_providers. Add fix for lib lockfile/mkdirlockfile. Add set master TV info source logic. Change harden ui input validation. Add per action dialog confirmation. Change to reload page under more events. Change implement "Mark all added episodes Wanted to search for releases" when setting new info source.
91 lines
3.3 KiB
Python
91 lines
3.3 KiB
Python
from __future__ import absolute_import, division
|
|
|
|
import time
|
|
import os
|
|
import sys
|
|
import errno
|
|
import shutil
|
|
|
|
from . import (LockBase, LockFailed, NotLocked, NotMyLock, LockTimeout,
|
|
AlreadyLocked)
|
|
|
|
class MkdirLockFile(LockBase):
|
|
"""Lock file by creating a directory."""
|
|
def __init__(self, path, threaded=True, timeout=None):
|
|
"""
|
|
>>> lock = MkdirLockFile('somefile')
|
|
>>> lock = MkdirLockFile('somefile', threaded=False)
|
|
"""
|
|
LockBase.__init__(self, path, threaded, timeout)
|
|
# Lock file itself is a directory. Place the unique file name into
|
|
# it.
|
|
self.unique_name = os.path.join(self.lock_file,
|
|
"%s.%s%s" % (self.hostname,
|
|
self.tname,
|
|
self.pid))
|
|
|
|
def acquire(self, timeout=None):
|
|
timeout = timeout if timeout is not None else self.timeout
|
|
end_time = time.time()
|
|
if timeout is not None and timeout > 0:
|
|
end_time += timeout
|
|
|
|
if timeout is None:
|
|
wait = 0.1
|
|
else:
|
|
wait = max(0, timeout / 10)
|
|
|
|
while True:
|
|
try:
|
|
os.mkdir(self.lock_file)
|
|
except OSError:
|
|
err = sys.exc_info()[1]
|
|
if err.errno == errno.EEXIST:
|
|
# Already locked.
|
|
if os.path.exists(self.unique_name):
|
|
# Already locked by me.
|
|
return
|
|
if timeout is not None and time.time() > end_time:
|
|
if timeout > 0:
|
|
raise LockTimeout("Timeout waiting to acquire"
|
|
" lock for %s" %
|
|
self.path)
|
|
else:
|
|
# Someone else has the lock.
|
|
raise AlreadyLocked("%s is already locked" %
|
|
self.path)
|
|
time.sleep(wait)
|
|
else:
|
|
# Couldn't create the lock for some other reason
|
|
raise LockFailed("failed to create %s" % self.lock_file)
|
|
else:
|
|
open(self.unique_name, "wb").close()
|
|
return
|
|
|
|
def release(self):
|
|
if not self.is_locked():
|
|
raise NotLocked("%s is not locked" % self.path)
|
|
elif not os.path.exists(self.unique_name):
|
|
raise NotMyLock("%s is locked, but not by me" % self.path)
|
|
os.unlink(self.unique_name)
|
|
self.delete_directory()
|
|
|
|
def delete_directory(self):
|
|
# NOTE(dims): We may end up with a race condition here. The path
|
|
# can be deleted between the .exists() and the .rmtree() call.
|
|
# So we should catch any exception if the path does not exist.
|
|
try:
|
|
shutil.rmtree(self.lock_file)
|
|
except Exception:
|
|
pass
|
|
|
|
def is_locked(self):
|
|
return os.path.exists(self.lock_file)
|
|
|
|
def i_am_locking(self):
|
|
return (self.is_locked() and
|
|
os.path.exists(self.unique_name))
|
|
|
|
def break_lock(self):
|
|
if os.path.exists(self.lock_file):
|
|
self.delete_directory()
|