Skip to content

Commit 32637e5

Browse files
committed
improved download-old-submissions
1 parent 314d2bf commit 32637e5

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

plugins/python3/src/plugin.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,37 +109,18 @@ impl LanguagePlugin for Python3Plugin {
109109
setup.exists() || requirements.exists() || test.exists() || tmc.exists()
110110
}
111111

112+
// returns the parent of the src directory, if one is found
112113
fn find_project_dir_in_zip<R: Read + Seek>(
113114
zip_archive: &mut ZipArchive<R>,
114115
) -> Result<PathBuf, TmcError> {
115116
for i in 0..zip_archive.len() {
116117
let file = zip_archive.by_index(i)?;
117118
let file_path = file.sanitized_name();
118-
if file_path.file_name() == Some(OsStr::new("setup.py"))
119-
|| file_path.file_name() == Some(OsStr::new("requirements.txt"))
120-
{
119+
if file_path.file_name() == Some(OsStr::new("src")) {
121120
if let Some(parent) = file_path.parent() {
122121
return Ok(parent.to_path_buf());
123122
}
124123
}
125-
if file_path.file_name() == Some(OsStr::new("__init__.py")) {
126-
if let Some(init_parent) = file_path.parent() {
127-
if init_parent.file_name() == Some(OsStr::new("test")) {
128-
if let Some(test_parent) = init_parent.parent() {
129-
return Ok(test_parent.to_path_buf());
130-
}
131-
}
132-
}
133-
}
134-
if file_path.file_name() == Some(OsStr::new("__main__.py")) {
135-
if let Some(main_parent) = file_path.parent() {
136-
if main_parent.file_name() == Some(OsStr::new("tmc")) {
137-
if let Some(tmc_parent) = main_parent.parent() {
138-
return Ok(tmc_parent.to_path_buf());
139-
}
140-
}
141-
}
142-
}
143124
}
144125
Err(TmcError::NoProjectDirInZip)
145126
}

tmc-langs-cli/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,11 @@ fn run_core(matches: &ArgMatches) -> Result<PrintToken> {
10831083
let submission_url = into_url(submission_url)?;
10841084
core.submit(submission_url, output_path, None)?;
10851085
}
1086-
core.reset(exercise_id, output_path)?;
1086+
1087+
// reset old exercise if it exists
1088+
if output_path.exists() {
1089+
core.reset(exercise_id, output_path)?;
1090+
}
10871091

10881092
let temp_zip = NamedTempFile::new().context("Failed to create a temporary archive")?;
10891093
core.download_old_submission(submission_id, temp_zip.path())?;

0 commit comments

Comments
 (0)