mirror of
https://gitlab.com/LazyLibrarian/LazyLibrarian.git
synced 2026-02-06 10:47:15 +00:00
Moved filename,umlaut,apostrophe dicts into json file
This commit is contained in:
parent
646c1d026d
commit
242a5e89fc
@ -48,7 +48,7 @@ if sys.version_info < MIN_PYTHON_VERSION:
|
||||
exit(0)
|
||||
|
||||
|
||||
def sig_shutdown(*args):
|
||||
def sig_shutdown():
|
||||
lazylibrarian.SIGNAL = 'shutdown'
|
||||
|
||||
|
||||
|
||||
37
example.dicts.json
Normal file
37
example.dicts.json
Normal file
@ -0,0 +1,37 @@
|
||||
{
|
||||
"filename_dict": {
|
||||
"<": "",
|
||||
">": "",
|
||||
"...": "",
|
||||
" & ": " ",
|
||||
" = ": " ",
|
||||
"?": "",
|
||||
"$": "s",
|
||||
"|": "",
|
||||
" + ": " ",
|
||||
"\"": "",
|
||||
",": "",
|
||||
"*": "",
|
||||
":": "",
|
||||
";": "",
|
||||
"'": "",
|
||||
"//": "/",
|
||||
"\\\\": "\\"
|
||||
},
|
||||
"umlaut_dict": {
|
||||
"\u00e4": "ae",
|
||||
"\u00f6": "oe",
|
||||
"\u00fc": "ue",
|
||||
"\u00c4": "Ae",
|
||||
"\u00d6": "Oe",
|
||||
"\u00dc": "Ue",
|
||||
"\u00df": "ss"
|
||||
},
|
||||
"apostrophe_dict": {
|
||||
"`": "'",
|
||||
"\u2018": "'",
|
||||
"\u2019": "'",
|
||||
"\u201c": "\"",
|
||||
"\u201d": "\""
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,7 @@ from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from lazylibrarian.configtypes import ConfigDict
|
||||
from lazylibrarian.formatter import make_bytestr, make_unicode, unaccented, replace_all, namedic, get_list
|
||||
from lazylibrarian.formatter import make_bytestr, make_unicode, unaccented, replace_all, get_list
|
||||
|
||||
|
||||
class DirectoryHolder:
|
||||
@ -440,7 +440,7 @@ def safe_move(src, dst, action='move'):
|
||||
drive, path = os.path.splitdrive(dst)
|
||||
logger.debug("drive=[%s] path=[%s]" % (drive, path))
|
||||
# strip some characters windows can't handle
|
||||
newpath = replace_all(path, namedic)
|
||||
newpath = replace_all(path, lazylibrarian.DICTS.get('filename_dict', {}))
|
||||
# windows filenames can't end in space or dot
|
||||
while newpath and newpath[-1] in '. ':
|
||||
newpath = newpath[:-1]
|
||||
|
||||
@ -308,6 +308,7 @@ class StartupLazyLibrarian:
|
||||
|
||||
def init_build_lists(self, config: ConfigDict):
|
||||
lazylibrarian.GRGENRES = self.build_genres()
|
||||
lazylibrarian.DICTS = self.build_dicts()
|
||||
lazylibrarian.MONTHNAMES = self.build_monthtable(config)
|
||||
lazylibrarian.NEWUSER_MSG = self.build_logintemplate()
|
||||
lazylibrarian.NEWFILE_MSG = self.build_filetemplate()
|
||||
@ -419,6 +420,25 @@ class StartupLazyLibrarian:
|
||||
self.logger.error('No valid genres.json file found')
|
||||
return {"genreLimit": 4, "genreUsers": 10, "genreExclude": [], "genreExcludeParts": [], "genreReplace": {}}
|
||||
|
||||
def build_dicts(self):
|
||||
for json_file in [os.path.join(DIRS.DATADIR, 'dicts.json'),
|
||||
os.path.join(DIRS.PROG_DIR, 'example.dicts.json')]:
|
||||
if path_isfile(json_file):
|
||||
try:
|
||||
with open(syspath(json_file), 'r', encoding='utf-8') as json_data:
|
||||
res = json.load(json_data)
|
||||
self.logger.info("Loaded dicts from %s" % json_file)
|
||||
return res
|
||||
except Exception as e:
|
||||
self.logger.error('Failed to load %s, %s %s' % (json_file, type(e).__name__, str(e)))
|
||||
self.logger.error('No valid dicts.json file found')
|
||||
return {"filename_dict": {'<': '', '>': '', '...': '', ' & ': ' ', ' = ': ' ', '?': '', '$': 's', '|': '', ' + ': ' ',
|
||||
'"': '', ',': '', '*': '', ':': '', ';': '', '\'': '', '//': '/', '\\\\': '\\'},
|
||||
"umlaut_dict": {u'\xe4': 'ae', u'\xf6': 'oe', u'\xfc': 'ue', u'\xc4': 'Ae', u'\xd6': 'Oe', u'\xdc': 'Ue', u'\xdf': 'ss'},
|
||||
"apostrophe_dict": {u'\u0060': "'", u'\u2018': u"'", u'\u2019': u"'", u'\u201c': u'"', u'\u201d': u'"'}
|
||||
}
|
||||
|
||||
|
||||
def build_monthtable(self, config: ConfigDict):
|
||||
table = []
|
||||
json_file = os.path.join(DIRS.DATADIR, 'monthnames.json')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user