11# -*- coding: UTF-8 -*-
22# A part of NonVisual Desktop Access (NVDA)
3- # Copyright (C) 2017 NV Access Limited
3+ # Copyright (C) 2017-2023 NV Access Limited
44# This file may be used under the terms of the GNU General Public License, version 2 or later.
55# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
66
77"""Upgrade speech dict files
88"""
99
10+ from typing import Any
1011import globalVars
1112import os
1213import api
1314import glob
1415from logHandler import log
1516from NVDAState import WritePaths
1617
17- voiceDictsPath = WritePaths .voiceDictsDir
18- voiceDictsBackupPath = WritePaths .voiceDictsBackupDir
18+
19+ def __getattr__ (attrName : str ) -> Any :
20+ """Module level `__getattr__` used to preserve backward compatibility.
21+ """
22+ import NVDAState
23+ if NVDAState ._allowDeprecatedAPI ():
24+ if attrName == "speechDictsPath" :
25+ log .warning (
26+ "speechDictHandler.dictFormatUpgrade.speechDictsPath is deprecated, "
27+ "instead use NVDAState.WritePaths.speechDictsDir" ,
28+ stack_info = True
29+ )
30+ return WritePaths .speechDictsDir
31+
32+ if attrName == "voiceDictsPath" :
33+ log .warning (
34+ "speechDictHandler.dictFormatUpgrade.voiceDictsPath is deprecated, "
35+ "instead use NVDAState.WritePaths.voiceDictsDir" ,
36+ stack_info = True
37+ )
38+ return WritePaths .voiceDictsDir
39+
40+ if attrName == "voiceDictsBackupPath" :
41+ log .warning (
42+ "speechDictHandler.dictFormatUpgrade.voiceDictsBackupPath is deprecated, "
43+ "instead use NVDAState.WritePaths.voiceDictsBackupDir" ,
44+ stack_info = True
45+ )
46+ return WritePaths .voiceDictsBackupDir
47+
48+ raise AttributeError (f"module { repr (__name__ )} has no attribute { repr (attrName )} " )
49+
1950
2051def createVoiceDictFileName (synthName , voiceName ):
2152 """ Creates a filename used for the voice dictionary files.
@@ -56,12 +87,12 @@ def _doSynthVoiceDictBackupAndMove(synthName, oldFileNameToNewFileNameList=None)
5687 """
5788 import shutil
5889
59- if not os .path .isdir (voiceDictsPath ):
60- os .makedirs (voiceDictsPath )
61- if not os .path .isdir (voiceDictsBackupPath ):
62- os .makedirs (voiceDictsBackupPath )
90+ if not os .path .isdir (WritePaths . voiceDictsDir ):
91+ os .makedirs (WritePaths . voiceDictsDir )
92+ if not os .path .isdir (WritePaths . voiceDictsBackupDir ):
93+ os .makedirs (WritePaths . voiceDictsBackupDir )
6394
64- newDictPath = os .path .join (voiceDictsPath , synthName )
95+ newDictPath = os .path .join (WritePaths . voiceDictsDir , synthName )
6596 needsUpgrade = not os .path .isdir (newDictPath )
6697 if needsUpgrade :
6798 log .info ("Upgrading voice dictionaries for %s" % synthName )
@@ -82,7 +113,7 @@ def _doSynthVoiceDictBackupAndMove(synthName, oldFileNameToNewFileNameList=None)
82113 log .debug ("processing file: %s" % actualPath )
83114 # files will be copied here before we modify them so as to avoid
84115 # any data loss.
85- shutil .copy (actualPath , voiceDictsBackupPath )
116+ shutil .copy (actualPath , WritePaths . voiceDictsBackupDir )
86117
87118 actualBasename = os .path .basename (actualPath )
88119 log .debug ("basename: %s" % actualBasename )
0 commit comments