Skip to content

Commit 6d98cde

Browse files
authored
Merge pull request #139 from noobLue/master
Re-add progress reporting for downloading exercises
2 parents 505e567 + 1fdb76a commit 6d98cde

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tmc-langs/src/lib.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ pub fn download_or_update_course_exercises(
160160
);
161161

162162
let exercises_details = client.get_exercises_details(exercises)?;
163-
164163
let mut projects_config = ProjectsConfig::load(projects_dir)?;
165164

166165
// separate exercises into downloads and skipped
@@ -232,6 +231,13 @@ pub fn download_or_update_course_exercises(
232231
});
233232
}
234233

234+
let exercises_len = to_be_downloaded.len();
235+
progress_reporter::start_stage::<()>(
236+
exercises_len * 2 + 1, // each download progresses at 2 points, plus the final finishing step
237+
format!("Downloading {} exercises", exercises_len),
238+
None,
239+
);
240+
235241
log::debug!("downloading exercises");
236242
// download and divide the results into successful and failed downloads
237243
let thread_count = to_be_downloaded.len().min(4); // max 4 threads
@@ -261,6 +267,23 @@ pub fn download_or_update_course_exercises(
261267

262268
let exercise_download_result = || -> Result<(), LangsError> {
263269
let zip_file = file_util::named_temp_file()?;
270+
271+
let target_exercise = match download_target {
272+
DownloadTarget::Template { ref target, .. } => target,
273+
DownloadTarget::Submission { ref target, .. } => target,
274+
};
275+
progress_reporter::progress_stage::<ClientUpdateData>(
276+
format!(
277+
"Downloading exercise {} to '{}'",
278+
target_exercise.id,
279+
target_exercise.path.display(),
280+
),
281+
Some(ClientUpdateData::ExerciseDownload {
282+
id: target_exercise.id,
283+
path: target_exercise.path.clone(),
284+
}),
285+
);
286+
264287
match &download_target {
265288
DownloadTarget::Template { target, .. } => {
266289
client.download_exercise(target.id, zip_file.path())?;
@@ -288,6 +311,19 @@ pub fn download_or_update_course_exercises(
288311
extract_project(&zip_file, &target.path, false)?;
289312
}
290313
}
314+
315+
progress_reporter::progress_stage::<ClientUpdateData>(
316+
format!(
317+
"Downloaded exercise {} to '{}'",
318+
target_exercise.id,
319+
target_exercise.path.display(),
320+
),
321+
Some(ClientUpdateData::ExerciseDownload {
322+
id: target_exercise.id,
323+
path: target_exercise.path.clone(),
324+
}),
325+
);
326+
291327
Ok(())
292328
}();
293329

@@ -355,6 +391,15 @@ pub fn download_or_update_course_exercises(
355391
};
356392
}
357393

394+
progress_reporter::finish_stage::<ClientUpdateData>(
395+
format!(
396+
"Successfully downloaded {} out of {} exercises.",
397+
successful.len(),
398+
exercises_len
399+
),
400+
None,
401+
);
402+
358403
let downloaded = successful
359404
.into_iter()
360405
.map(|t| match t {

0 commit comments

Comments
 (0)