Updated ffsubsync to better manage access denied exception on files.

pull/1096/head
Louis Vézina 4 years ago
parent ea097d6ec4
commit 49dd078fa1

@ -24,8 +24,8 @@ def get_keywords():
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames = " (HEAD -> master)"
git_full = "558bc6dc1d5342d4a5910166cf12ebb5890e86b7"
git_date = "2020-07-11 17:02:56 -0700"
git_full = "997749de8aac74ec19137a2e641b97ef1bba81ea"
git_date = "2020-08-04 20:06:18 -0700"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import logging
import os
import platform

@ -206,7 +206,7 @@ def validate_args(args):
raise ValueError('need to specify input and output srt files for test cases')
if args.overwrite_input:
if args.extract_subs_from_stream is not None:
raise ValueError('input overwriting not allowed for extracting subtitles from referece')
raise ValueError('input overwriting not allowed for extracting subtitles from reference')
if args.srtin is None:
raise ValueError(
'need to specify input srt if --overwrite-input is specified since we cannot overwrite stdin'
@ -222,6 +222,19 @@ def validate_args(args):
raise ValueError('stream specified for reference subtitle extraction; -i flag for sync input not allowed')
def validate_file_permissions(args):
if not os.access(args.reference, os.R_OK):
raise ValueError('unable to read reference %s (try checking permissions)' % args.reference)
if not os.access(args.srtin, os.R_OK):
raise ValueError('unable to read input subtitles %s (try checking permissions)' % args.srtin)
if os.path.exists(args.srtout) and not os.access(args.srtout, os.W_OK):
raise ValueError('unable to write output subtitles %s (try checking permissions)' % args.srtout)
if args.make_test_case or args.serialize_speech:
npy_savename = os.path.splitext(args.reference)[0] + '.npz'
if os.path.exists(npy_savename) and not os.access(npy_savename, os.W_OK):
raise ValueError('unable to write test case file archive %s (try checking permissions)' % npy_savename)
def run(args):
result = {
'retval': 0,
@ -239,6 +252,12 @@ def run(args):
args.srtout = args.srtin
if args.gui_mode and args.srtout is None:
args.srtout = '{}.synced.srt'.format(os.path.splitext(args.srtin)[0])
try:
validate_file_permissions(args)
except ValueError as e:
logger.error(e)
result['retval'] = 1
return result
ref_format = _ref_format(args.reference)
if args.merge_with_reference and ref_format not in SUBTITLE_EXTENSIONS:
logger.error('merging synced output with reference only valid '

Loading…
Cancel
Save