Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12298110
git.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
git.py
View Options
# -------------------------------------------------------------
# Merge dictionaries :: Publishers :: Git repository
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Description: Find application-level dictionaries
# from Git repository
# License: BSD-2-Clause
# -------------------------------------------------------------
import
os
from
tempfile
import
NamedTemporaryFile
from
typing
import
List
from
mergedictionaries.sources
import
GitRepository
from
mergedictionaries.utils.collections
import
remove_words
def
build_temporary_dictionary
(
words
):
fd
=
NamedTemporaryFile
(
delete
=
False
)
for
word
in
words
:
fd
.
write
(
f
"{word}
\n
"
.
encode
(
"utf-8"
))
fd
.
close
()
return
fd
.
name
def
write
(
words
,
target_repos
,
cached_repos
):
if
not
target_repos
:
return
tmp_dictionary_path
=
build_temporary_dictionary
(
words
)
for
repo
in
target_repos
:
GitRepository
(
repo
,
cached_repos
)
.
publish
(
tmp_dictionary_path
)
os
.
unlink
(
tmp_dictionary_path
)
def
delete_words
(
repo
:
GitRepository
,
words_to_delete
:
List
):
current_words
=
repo
.
extract_words
()
if
not
any
(
word
in
current_words
for
word
in
words_to_delete
):
# Nothing to do, the dictionary is already up to date.
return
words
=
remove_words
(
current_words
,
words_to_delete
)
tmp_dictionary_path
=
build_temporary_dictionary
(
words
)
repo
.
publish
(
tmp_dictionary_path
)
os
.
unlink
(
tmp_dictionary_path
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Wed, Oct 22, 14:03 (15 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3089914
Default Alt Text
git.py (1 KB)
Attached To
Mode
rMD Merge dev dictionaries
Attached
Detach File
Event Timeline
Log In to Comment