mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 11:26:25 -05:00
Creating Channel.info_json_path property to avoid redefining channel's info json path.
This commit is contained in:
parent
808f46be5b
commit
e49ffc8a6c
3 changed files with 27 additions and 1 deletions
|
|
@ -101,3 +101,20 @@ async def test_channel_download_relationships(test_session, download_channel):
|
||||||
# Delete the Channel, and any relationships.
|
# Delete the Channel, and any relationships.
|
||||||
download_channel.delete_with_videos()
|
download_channel.delete_with_videos()
|
||||||
assert test_session.query(Download).count() == 0
|
assert test_session.query(Download).count() == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_channel_info_json(test_session, test_directory):
|
||||||
|
channel = Channel(name='new channel')
|
||||||
|
test_session.add(channel)
|
||||||
|
|
||||||
|
with pytest.raises(FileNotFoundError) as e:
|
||||||
|
# Cannot get info json because directory is not defined.
|
||||||
|
channel.info_json_path
|
||||||
|
assert 'directory' in str(e)
|
||||||
|
|
||||||
|
# Channel's directory is created if it does not exist.
|
||||||
|
channel.directory = test_directory / 'new channel'
|
||||||
|
assert channel.info_json_path == test_directory / 'new channel/new channel.info.json'
|
||||||
|
assert channel.directory.is_dir()
|
||||||
|
# info json file is not yet created.
|
||||||
|
assert not channel.info_json_path.exists()
|
||||||
|
|
|
||||||
|
|
@ -768,7 +768,7 @@ def update_channel_catalog(channel: Channel, info: dict):
|
||||||
|
|
||||||
# Write the Channel's info to a JSON file.
|
# Write the Channel's info to a JSON file.
|
||||||
if channel.directory:
|
if channel.directory:
|
||||||
info_json_path = channel.directory / f'{channel.name}.info.json'
|
info_json_path = channel.info_json_path
|
||||||
with info_json_path.open('wt') as fh:
|
with info_json_path.open('wt') as fh:
|
||||||
json.dump(info, fh, indent=2, sort_keys=True)
|
json.dump(info, fh, indent=2, sort_keys=True)
|
||||||
logger.debug(f'Wrote channel info json to {info_json_path}')
|
logger.debug(f'Wrote channel info json to {info_json_path}')
|
||||||
|
|
|
||||||
|
|
@ -556,6 +556,15 @@ class Channel(ModelHelper, Base):
|
||||||
def location(self) -> str:
|
def location(self) -> str:
|
||||||
return f'/videos/channel/{self.id}/video'
|
return f'/videos/channel/{self.id}/video'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def info_json_path(self) -> pathlib.Path:
|
||||||
|
if self.directory:
|
||||||
|
if not self.directory.exists():
|
||||||
|
self.directory.mkdir(parents=True)
|
||||||
|
return self.directory / f'{self.name}.info.json'
|
||||||
|
|
||||||
|
raise FileNotFoundError(f'Cannot create Channel info json because directory is not defined: {self}')
|
||||||
|
|
||||||
def delete_with_videos(self):
|
def delete_with_videos(self):
|
||||||
"""Delete all Video records (but not video files) related to this Channel. Then delete the Channel."""
|
"""Delete all Video records (but not video files) related to this Channel. Then delete the Channel."""
|
||||||
session = Session.object_session(self)
|
session = Session.object_session(self)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue