Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12359697
jetbrains.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
jetbrains.py
View Options
# -------------------------------------------------------------
# Merge dictionaries :: Sources :: JetBrains IDEs
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Find application-level dictionaries
# from JetBrains IDEs
# License: BSD-2-Clause
# -------------------------------------------------------------
import
os
from
xml.etree
import
ElementTree
DICTIONARY_FILENAMES
=
[
"cachedDictionary.xml"
,
"spellchecker-dictionary.xml"
]
def
get_configuration_path
():
"""Find JetBrains configuration folder for Windows, macOS and other UNIX systems."""
try
:
return
os
.
environ
[
"APPDATA"
]
+
"/JetBrains"
except
KeyError
:
candidates
=
[
os
.
environ
[
"HOME"
]
+
"/Library/Application Support/JetBrains"
,
os
.
environ
[
"HOME"
]
+
"/.config/JetBrains"
,
]
for
candidate
in
candidates
:
if
os
.
path
.
exists
(
candidate
):
break
return
candidate
def
find_application_level_dictionaries
():
# We're looking for paths like:
# ~/.config/JetBrains/PyCharm2021.3/options/cachedDictionary.xml
base_path
=
get_configuration_path
()
if
not
os
.
path
.
exists
(
base_path
):
# No JetBrains IDE configuration folder detected
return
[]
return
[
candidate
for
candidate
in
[
os
.
path
.
join
(
base_path
,
entry
.
name
,
"options"
,
filename
)
for
filename
in
DICTIONARY_FILENAMES
for
entry
in
os
.
scandir
(
base_path
)
if
entry
.
is_dir
()
]
if
os
.
path
.
exists
(
candidate
)
]
def
extract_words
(
dictionary_path
):
tree
=
ElementTree
.
parse
(
dictionary_path
)
return
[
word
.
text
for
word
in
tree
.
getroot
()[
0
][
0
]]
def
extract_words_from_all_dictionaries
():
return
{
word
for
dictionary_path
in
find_application_level_dictionaries
()
for
word
in
extract_words
(
dictionary_path
)
}
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Fri, Oct 31, 02:05 (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3107581
Default Alt Text
jetbrains.py (1 KB)
Attached To
Mode
rMD Merge dev dictionaries
Attached
Detach File
Event Timeline
Log In to Comment