Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit to multiple problems at once #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ Installation is done through [RubyGems][2]: `gem install marmoset`. Depending on
## Usage
MarmosetSubmit installs a `marmoset` executable on your system. The typical usage of it is best illustrated with an example.

### Submit to a single problem
Let's say you want to submit a file in the current directory named `wlppgen.ss` as your submission to part 4 of assignment 11 in CS 241 (which has the 'project name' of "A11P4" on Marmoset). You'd run:

``marmoset -u YourQuestUsername -c cs241 -a a11p4 -f wlppgen.ss``

You'll then be prompted for your Quest password, every time you run a `marmoset` command like this. If you'd like to skip the password prompt, you can include your password in the command like so:
You will be prompted for your Quest password every time you run a `marmoset` command like this. If you'd like to skip the password prompt, you can include your password in the command like so:

``marmoset -u YourQuestUsername ``**-p YourQuestPassword**`` -c cs241 -a a11p4 -f wlppgen.ss``

### Submit to multiple problems
You can also submit many problems at once. For example say on assignment A1 there is a question with 10 parts, each with its own .txt file. Instead of manually submitting 10 times, simply run:

``marmoset -u YourQuestUsername -c cs246``

This will go through all problem titles listed on marmoset and submit the matching file, with a .txt, .c, or .zip extension.

``marmoset -u YourQuestUsername -p YourQuestPassword -c cs241 -a a11p4 -f wlppgen.ss``

Here are all of the options, in more detail:

Expand Down
80 changes: 27 additions & 53 deletions bin/marmoset
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,35 @@ class MarmosetClient
problem_links = {}

@course_page.links.find_all{|l| l.href.include? 'submitProject.jsp'}.each do |view_link|

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the added whitespace?

index = @course_page.links.find_index{|l| l.href == view_link.href}
named_link = @course_page.links[index-2]
problem_links[named_link.text] = view_link
end

if @problem.nil?
if @filename.nil?
problem_links.each do |x|
name = x[0].strip

# Check if there is a file with acceptable extension
extensions_to_check = ['.txt', '.c', '.zip']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems pretty weird to limit it to these extensions, and I'd also assume you'd want .zip to have higher precedence (i.e. be earlier in the list) than .c. There will be some assignments where you need to submit a a1p1.zip, which contains a1p1.c.

At a minimum, I'd expect this list should be:

['.zip', '.txt', '.c', '.cc', '.cpp', '.h', '.hex', '.asm']

It would also be good to add whatever the extension for scheme files is by convention for CS courses.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about the zip. My first assignment only required txt files but the default list should probably be added to.

extensions_to_check.each do |ext|
if File.exists?(name+ext)
problem_link = x[1]
@submit_page = problem_link.click
@filename = name+ext
submit_problem
break
end
end
end
elsif
@problem.nil?
choose do |menu|
problem_links.each do |(name,problem_link)|
menu.choice(name.strip) do
@problem = name
@submit_page = problem_page.click
submit_problem
end
end
end
Expand All @@ -107,9 +125,9 @@ class MarmosetClient
prob_name.downcase.include? @problem.downcase
}
raise ProblemNotFound if problem_link.nil?

problem_link = problem_link[1]
@submit_page = problem_link.click
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw man - this dude is so cool though! Can you get rid of this only in the case that you're using multi-submit?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First time I'm going to introduce an old bug on purpose...

submit_problem
end
rescue ProblemNotFound
say "Problem #{@problem} could not be found in #{@course}."
Expand All @@ -118,62 +136,19 @@ class MarmosetClient
end

def submit_problem
say "Submitting ..."
print "Submitting #{@filename} ..."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from say to print?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted the output to be on one line so that it would be more clear which file failed to submit (if submit failed)

select_problem if @submit_page.nil?

form = @submit_page.forms.first
@submit_page.forms.first.file_uploads.first.file_name = @filename
@submit_response_page = @agent.submit(form)
say "Assignment submitted successfully."
print " success!\n"
rescue Mechanize::ResponseCodeError => e
puts <<-EOF
@LGf
tClfC
@@@@G @@C
L@ il@Lt@
;@ G@@;@tl@
@ @t .@@l
@i i@
;f G, ......
,@ @ :C@@@@@@@@@@@@@@C
@ C .iG@@@CttlllllllllltLG@L
,,@,,,.@@fllllllllllllllllllllllllll@
l@@@@@@@@@flllllllllllllllllllllllllli@.
l@@f G f@LLflllllllllllllllllllllllllli@.
C@@fllllLflllllllllllllllllllllltfC@@@@@@l;
L@t@tllllLfllllllllllllllllllllllllll@ ;tL@@G
.i@@@@@@tlGtllllLflllllllllllllllllllllllllt@ f@
@@@@GC:@GllllllllLflllllllllllllllllllllllllC; G@
i@G L@fGlllllllllllllllllllllllllllllllllll@ :@
C@f @; .GlllllllllllllllllllllllllllllllllL@ @t
@f@@.tf CllLC, lCllllllllllllllllllllllt@ t@
@G@G.;C LlLllf. ftlllllllllllllllllllll@: @i
@G@f ff LlLG@@@.,Glllllllllllltlllllll@i l@
:GC@:,@. GLL@@iLi Glllllllllllt@@GCfftGL
iC:@G@; ;CGL@@.iL LllllllllllllltLG@@@@@@@t
.G .: GlCL@C if Llllllllllllllllll@LiLG@@@f
:G@@@ lLtCf@l C, Cllllllllllllllll@t .G@
,@@@@;i@ tCltfi@ffG .Glllllllllllllll@l @G
,@@G ,@fGLlltf tCC, lflllllllllllllt@f G@
.@f @@tlllG .GlCGtlllllllllG@i .@.
@G @@CliC; @tllL@ClllllfG@G @l
t@ i@@CtGi,i@llllitG@fLG@@G. f@
@f i@@GGGLtfLLCG@@@@@@, :@
L ,lfGGGGGGtti; i@@l @;
@@ Cf
@@ ,
GC
@@
C@
@f
@@
f@
EOF
say "There was a problem submitting your assignment. Submit manually."
say "Error submitting file: #{@filename}"
end
end

PROGRAM_VERSION = 1.0.2
PROGRAM_VERSION = '1.0.2'

Choice.options do
option :username do
Expand Down Expand Up @@ -203,7 +178,7 @@ Choice.options do
desc 'Assignment problem name, e.g. A1P4'
end

option :filename, :required => true do
option :filename do #, :required => true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete unused code instead of commenting it out.

short '-f'
long '--infile=FILENAME'
desc 'The file to submit to marmoset'
Expand All @@ -228,5 +203,4 @@ end
client = MarmosetClient.new(Choice.choices)
client.login
client.select_course
client.select_problem
client.submit_problem
client.select_problem