Skip to content

Commit

Permalink
Merge pull request #1377 from Signbank/rename_video_files
Browse files Browse the repository at this point in the history
#1373: Imperative function with side effects to rename video files
  • Loading branch information
susanodd authored Nov 11, 2024
2 parents 377c3e3 + 97a597f commit 0a6a44b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions signbank/dataset_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,48 @@ def gloss_annotations_check(dataset):
return results


def gloss_backup_videos(dataset):
backup_videos = []
default_language = dataset.default_language

all_glosses = Gloss.objects.filter(lemma__dataset=dataset,
lemma__lemmaidglosstranslation__language=default_language).order_by(
'lemma__lemmaidglosstranslation__text').distinct()
for gloss in all_glosses:
glossvideos = GlossVideo.objects.filter(gloss=gloss,
glossvideonme=None,
glossvideoperspective=None).order_by('version')
backup_videos_ordered = glossvideos.filter(version__gt=0).order_by('version')
if backup_videos_ordered.count() > 1:
gloss_videos = [gv for gv in backup_videos_ordered]
backup_videos.append((gloss, gloss_videos))
return backup_videos


def rename_backup_videos(gloss, glossvideos):

idgloss = gloss.idgloss
desired_filename_without_extension = idgloss + '-' + str(gloss.id) + '.mp4'
for inx, gloss_video in enumerate(glossvideos, 1):
_, bak = os.path.splitext(gloss_video.videofile.name)
desired_extension = '.bak' + str(gloss_video.id)
current_version = gloss_video.version
desired_filename = desired_filename_without_extension + desired_extension
current_filename = str(gloss_video.videofile)
if bak == desired_extension and inx == current_version:
continue
if bak != desired_extension:
source = os.path.join(settings.WRITABLE_FOLDER, current_filename)
destination = os.path.join(settings.WRITABLE_FOLDER, desired_filename)
print('rename_backup_videos move ', source, destination)
os.rename(source, destination)
gloss_video.videofile.name = desired_filename
if inx != current_version:
print('rename_backup_videos change version ', current_version, inx)
gloss_video.version = inx
gloss_video.save()


def gloss_videos_check(dataset):

results = dict()
Expand Down
2 changes: 1 addition & 1 deletion signbank/dictionary/dataset_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.core.paginator import Paginator
from django.views.generic.edit import CreateView, DeleteView, UpdateView
from signbank.dictionary.models import Dataset, Gloss, AnnotationIdglossTranslation
from signbank.dataset_checks import gloss_annotations_check, gloss_videos_check, gloss_video_filename_check, gloss_subclass_videos_check
from signbank.dataset_checks import (gloss_annotations_check, gloss_videos_check, gloss_video_filename_check, gloss_subclass_videos_check)
from signbank.tools import get_selected_datasets_for_user, get_dataset_languages
from signbank.settings.server_specific import *
from guardian.shortcuts import get_objects_for_user
Expand Down

0 comments on commit 0a6a44b

Please sign in to comment.