Add assert_valid_state so I can stop copypasting this code.
This commit is contained in:
parent
787cec38aa
commit
d08415eaad
2 changed files with 9 additions and 6 deletions
|
@ -215,8 +215,7 @@ class Channel(ObjectBase):
|
|||
|
||||
@worms.transaction
|
||||
def set_automark(self, state):
|
||||
if state not in constants.VIDEO_STATES:
|
||||
raise exceptions.InvalidVideoState(state)
|
||||
self.ycdldb.assert_valid_state(state)
|
||||
|
||||
pairs = {
|
||||
'id': self.id,
|
||||
|
@ -339,8 +338,7 @@ class Video(ObjectBase):
|
|||
Note: Marking as downloaded will not create the queue file, this only
|
||||
updates the database. See yclddb.download_video.
|
||||
'''
|
||||
if state not in constants.VIDEO_STATES:
|
||||
raise exceptions.InvalidVideoState(state)
|
||||
self.ycdldb.assert_valid_state(state)
|
||||
|
||||
log.info('Marking %s as %s.', self, state)
|
||||
|
||||
|
|
|
@ -45,8 +45,7 @@ class YCDLDBChannelMixin:
|
|||
except exceptions.NoSuchChannel:
|
||||
pass
|
||||
|
||||
if automark not in constants.VIDEO_STATES:
|
||||
raise exceptions.InvalidVideoState(automark)
|
||||
self.assert_valid_state(automark)
|
||||
|
||||
name = objects.Channel.normalize_name(name)
|
||||
if name is None:
|
||||
|
@ -223,6 +222,7 @@ class YCDLDBVideoMixin:
|
|||
bindings.append(channel_id)
|
||||
|
||||
if state is not None:
|
||||
self.assert_valid_state(state)
|
||||
wheres.append('state')
|
||||
bindings.append(state)
|
||||
|
||||
|
@ -471,6 +471,11 @@ class YCDLDB(
|
|||
log.debug('Found closest YCDLDB at %s.', path)
|
||||
return ycdldb
|
||||
|
||||
@staticmethod
|
||||
def assert_valid_state(state):
|
||||
if state not in constants.VIDEO_STATES:
|
||||
raise exceptions.InvalidVideoState(state)
|
||||
|
||||
def get_all_states(self):
|
||||
'''
|
||||
Get a list of all the different states that are currently in use in
|
||||
|
|
Loading…
Reference in a new issue