Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
EWOK
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lex gaMe
EWOK
Commits
ea8c8383
Commit
ea8c8383
authored
1 year ago
by
Empiriker
Browse files
Options
Downloads
Patches
Plain Diff
refactor progress indicator
parent
ffe7de7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/load_templates.py
+26
-24
26 additions, 24 deletions
src/load_templates.py
with
26 additions
and
24 deletions
src/load_templates.py
+
26
−
24
View file @
ea8c8383
...
@@ -6,35 +6,34 @@ import re
...
@@ -6,35 +6,34 @@ import re
import
threading
import
threading
import
time
import
time
from
typing
import
List
DUMPS_DIR
=
"
dumps
"
DUMPS_DIR
=
"
dumps
"
def
start_progress_indicator
():
def
start_progress_indicator
(
is_done
:
List
[
bool
],
msg
:
str
=
""
):
time_elapsed_indicator
.
stop
=
False
is_done
[
0
]
=
False
def
time_elapsed_indicator
():
start_time
=
time
.
time
()
while
not
is_done
[
0
]:
elapsed_time
=
time
.
time
()
-
start_time
print
(
f
"
\r
{
msg
}
Time elapsed:
{
elapsed_time
:
.
0
f
}
seconds
"
,
end
=
""
)
time
.
sleep
(
1
)
print
(
f
"
{
msg
}
Time elapsed:
{
elapsed_time
:
.
0
f
}
seconds
"
)
# type: ignore
indicator_thread
=
threading
.
Thread
(
target
=
time_elapsed_indicator
)
indicator_thread
=
threading
.
Thread
(
target
=
time_elapsed_indicator
)
indicator_thread
.
start
()
indicator_thread
.
start
()
return
indicator_thread
return
indicator_thread
def
stop_progress_indicator
(
indicator_thread
):
def
stop_progress_indicator
(
indicator_thread
,
is_done
:
List
[
bool
]
):
time_elapsed_indicator
.
stop
=
True
is_done
[
0
]
=
True
indicator_thread
.
join
()
indicator_thread
.
join
()
def
time_elapsed_indicator
():
start_time
=
time
.
time
()
while
not
time_elapsed_indicator
.
stop
:
elapsed_time
=
time
.
time
()
-
start_time
print
(
f
"
\r
Time elapsed:
{
elapsed_time
:
.
2
f
}
seconds
"
,
end
=
""
)
time
.
sleep
(
1
)
print
(
"
\r
Time elapsed: {elapsed_time:.2f} seconds
"
.
format
(
elapsed_time
=
elapsed_time
)
# type: ignore
)
def
get_most_recent_file
(
directory
,
lang_code
):
def
get_most_recent_file
(
directory
,
lang_code
):
pattern
=
re
.
compile
(
pattern
=
re
.
compile
(
r
""
+
lang_code
+
r
"
wiktionary-(\d+)-pages-articles-multistream.xml.bz2
"
r
""
+
lang_code
+
r
"
wiktionary-(\d+)-pages-articles-multistream.xml.bz2
"
...
@@ -53,20 +52,23 @@ def get_most_recent_file(directory, lang_code):
...
@@ -53,20 +52,23 @@ def get_most_recent_file(directory, lang_code):
def
load_templates
(
wiktlang
:
str
):
def
load_templates
(
wiktlang
:
str
):
print
(
f
"
Loading templates for
{
wiktlang
}
...
"
)
dump_file
=
get_most_recent_file
(
DUMPS_DIR
,
wiktlang
)
if
not
dump_file
:
raise
ValueError
(
f
"
Could not find dump file for
{
wiktlang
}
.
"
)
print
(
f
"
Loading templates from
{
dump_file
}
...
"
)
indicator_thread
=
start_progress_indicator
()
is_done
=
[
False
]
indicator_thread
=
start_progress_indicator
(
is_done
,
msg
=
f
"
Loading templates for
{
wiktlang
}
...
"
)
wxr
=
get_wiktextract_context
(
wiktlang
)
wxr
=
get_wiktextract_context
(
wiktlang
)
wxr
.
wtp
.
db_conn
.
execute
(
"
DELETE FROM pages
"
)
wxr
.
wtp
.
db_conn
.
execute
(
"
DELETE FROM pages
"
)
wxr
.
wtp
.
db_conn
.
commit
()
wxr
.
wtp
.
db_conn
.
commit
()
dump_file
=
get_most_recent_file
(
DUMPS_DIR
,
wiktlang
)
if
not
dump_file
:
raise
ValueError
(
f
"
Could not find dump file for
{
wiktlang
}
.
"
)
parse_wiktionary
(
parse_wiktionary
(
wxr
,
wxr
,
dump_file
,
dump_file
,
...
@@ -80,6 +82,6 @@ def load_templates(wiktlang: str):
...
@@ -80,6 +82,6 @@ def load_templates(wiktlang: str):
)
)
wxr
.
wtp
.
db_conn
.
commit
()
wxr
.
wtp
.
db_conn
.
commit
()
stop_progress_indicator
(
indicator_thread
)
stop_progress_indicator
(
indicator_thread
,
is_done
)
print
(
"
Done loading templates.
"
)
print
(
f
"
Done loading templates
for
{
wiktlang
}
.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment