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

Python 2022 #223

Open
wants to merge 5 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
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ GEM
multi_json (1.15.0)
multi_test (0.1.2)
nenv (0.2.0)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-sftp (3.0.0)
net-ssh (>= 5.0.0, < 7.0.0)
net-ssh (6.1.0)
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-ssh (7.0.1)
net-ssh-gateway (2.0.0)
net-ssh (>= 4.0.0)
netrc (0.10.3)
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/task_download_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class TaskDownloadController < ApplicationController
include ActionController::Live

before_action :require_admin

def create
task_id = params[:task_id]
task = Task.find task_id

response.headers['Content-Disposition'] = "attachment; filename=\"homework.tar.gz\""

TarGzipWriter.wrap(response.stream) do |tar|
task.solutions.each do |solution|
filename = "#{solution.user.faculty_number}.#{Language.extension}"
code = solution.code

tar.add_file_simple(filename, 0644, code.length) { |io| io.write(code) }
end
end
ensure
response.stream.close
end
end
11 changes: 11 additions & 0 deletions app/services/tar_gzip_writer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'rubygems/package'

module TarGzipWriter
def self.wrap(io)
Zlib::GzipWriter.wrap(io) do |gzip|
Gem::Package::TarWriter.new(gzip) do |tar|
yield tar
end
end
end
end
1 change: 1 addition & 0 deletions app/views/solutions/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
за повече информация.
- else
= link_to 'Пусни тестовете', task_check_path(@task), method: :create, class: :action
= link_to 'Свали като архив', task_download_path(@task), method: :post, class: :action

%p
%strong= @solutions.count
Expand Down
8 changes: 4 additions & 4 deletions app/views/tasks/guides/python.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@

## От какво имате нужда

Ако пращате задача за първи път, първо се уверете, че използвате Python 3.5.1
Ако пращате задача за първи път, първо се уверете, че използвате Python 3.10.8

$ python -V
Python 3.5.1
Python 3.10.8

Ако версията e различна, значи сте на грешна. Качете си Python 3.5, понеже има
Ако версията e различна, значи сте на грешна. Качете си Python 3.10, понеже има
достатъчно разлики, за да работи едно решение при вас, но да не работи при нас.

Забележка: На някои системи, които имат инсталирани Python 2.x и 3.x вероятно е
нужно да изпълнявате командите с python3.8.
нужно да изпълнявате командите с python3.10.


## Примерен тест
Expand Down
2 changes: 1 addition & 1 deletion config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set :application, 'Trane Revisited'
set :scm, :git
set :repository, 'git://github.com/skanev/evans.git'
set :repository, 'https://github.com/joankaradimov/evans.git'
set :branch, 'master'
set :user, 'pyfmi'
set :user_and_host, '[email protected]'
Expand Down
7 changes: 7 additions & 0 deletions config/deploy/python22.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set :deploy_to, '/data/rails/pyfmi-2022'
set :database_name, 'pyfmi_2022'

role :web, '2022.fmi.py-bg.net'
role :app, '2022.fmi.py-bg.net'
role :db, '2022.fmi.py-bg.net', primary: true
role :sidekiq, '2022.fmi.py-bg.net'
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
end
resource :my_solution, only: %w(show update)
resource :check, controller: :task_checks, only: :create
resource :download, controller: :task_download, only: :create
end

resources :challenges, except: :destroy do
Expand Down
4 changes: 2 additions & 2 deletions lib/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def solution_dump(attributes)
def parsing?(code)
TempDir.for('code.py' => code) do |dir|
code_path = dir.join('code.py')
system "python3.8 -m py_compile #{code_path} > /dev/null 2>&1"
system "python3.10 -m py_compile #{code_path} > /dev/null 2>&1"
end
end

Expand All @@ -43,7 +43,7 @@ def run_tests(test, solution)
test_path = dir.join('test.py')
runner_path = File.expand_path("python/runner.py", File.dirname(__FILE__))

results = JSON.parse `python3.8 #{runner_path} #{test_path}`
results = JSON.parse `python3.10 #{runner_path} #{test_path}`

TestResults.new({
log: results['log'] || '',
Expand Down