Skip to content

Commit

Permalink
add ability to specify only your advisees
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmaaatttttt committed May 18, 2020
1 parent e2cca5e commit 746ff7e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
tmp-*
students.js
57 changes: 33 additions & 24 deletions condor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const optionDefinitions = [
{ name: 'cohort', alias: 'c', type: String },
{ name: 'assessment', alias: 'a', type: String},
];
let students = null;
try {
students = require("./students");
} catch(e) {
console.warn("no array of students found. Downloading assessments for all students. You can speficy your advisees by putting their names in an array in a students.js file. Example: const students = ['fname lname'];");
}
const commandLineOptions = commandLineArgs(optionDefinitions)

const pwd = __dirname;
Expand Down Expand Up @@ -104,32 +110,35 @@ function recursivelyNpmInstall(dir) {
function extractEachZip(zips, assessmentName, sourceDir, destDir) {
let origFolders = new Set(readdirSync(sourceDir, {withFileTypes: false}));
zips.forEach(z => {
z.zip.extractAllTo(sourceDir, true);
let files = readdirSync(sourceDir, {withFileTypes: false})
files
.filter(f => f.match(/^__MACOSX$/))
.forEach(d => deleteDir(path.join(sourceDir, d)));
files = readdirSync(sourceDir, {withFileTypes: false})
.filter(f => !origFolders.has(f));
const [_, firstName, lastName, ...rest] = z.filename.split('-');
let studentDir = `${firstName}-${lastName}-${assessmentName}`;
if (existsSync(path.join(sourceDir, studentDir))) {
studentDir = `${studentDir}-${uuid()}`;
}
if (files.length !== 1) {
mkdirSync(path.join(sourceDir, studentDir));
files.forEach(f =>
renameSync(path.join(sourceDir, f), path.join(sourceDir, studentDir, f))

)
} else {
let f = files[0];
renameSync(path.join(sourceDir, f), path.join(sourceDir, studentDir))
if (students && students.includes(`${firstName} ${lastName}`)) {
console.log("downloading", firstName)
z.zip.extractAllTo(sourceDir, true);
let files = readdirSync(sourceDir, {withFileTypes: false})
files
.filter(f => f.match(/^__MACOSX$/))
.forEach(d => deleteDir(path.join(sourceDir, d)));
files = readdirSync(sourceDir, {withFileTypes: false})
.filter(f => !origFolders.has(f));
let studentDir = `${firstName}-${lastName}-${assessmentName}`;
if (existsSync(path.join(sourceDir, studentDir))) {
studentDir = `${studentDir}-${uuid()}`;
}
if (files.length !== 1) {
mkdirSync(path.join(sourceDir, studentDir));
files.forEach(f =>
renameSync(path.join(sourceDir, f), path.join(sourceDir, studentDir, f))

)
} else {
let f = files[0];
renameSync(path.join(sourceDir, f), path.join(sourceDir, studentDir))
}
origFolders.add(studentDir);
recursivelyNpmInstall(path.join(sourceDir, studentDir));
// TODO: once all the folders ahve been npm installed, move them
//renameSync(path.join(sourceDir, studentDir), path.join(destDir, studentDir));
}
origFolders.add(studentDir);
recursivelyNpmInstall(path.join(sourceDir, studentDir));
// TODO: once all the folders ahve been npm installed, move them
//renameSync(path.join(sourceDir, studentDir), path.join(destDir, studentDir));
})

}
Expand Down

0 comments on commit 746ff7e

Please sign in to comment.