Skip to content

Commit

Permalink
Merge pull request #509 from znick/update_to_python_3
Browse files Browse the repository at this point in the history
Update to python 3
  • Loading branch information
znick authored Dec 7, 2023
2 parents f043ab6 + bea6a05 commit d92197b
Show file tree
Hide file tree
Showing 293 changed files with 25,588 additions and 3,343 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/anytask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python 2.7
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 2.7
python-version: 3.8
- name: Install dependencies
run: |
pip install pip>=9.0.1
pip install --upgrade flake8 'setuptools-scm==5.0.2'
pip install -r requirements_local.txt
sudo apt-get install p7zip-full tar xz-utils bzip2 gzip
sudo apt-get install python3
- name: Lint with flake8
run: |
cd anytask
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/deploy_local_beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python 2.7
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 2.7
- name: Install virtualenv
run: pip2 install virtualenv
python-version: 3.8
- name: Install dependencies
run: pip3 install virtualenv
- name: Deploy
run: source deploy_local_beta/run.sh --python-path=python2
run: source deploy_local_beta/run.sh --python-path=python3
10 changes: 5 additions & 5 deletions .github/workflows/licensed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: Set up Python 2.7
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 2.7
python-version: 3.8
- uses: jonabc/setup-licensed@v1
with:
version: '2.15.2'
- name: Install virtualenv
run: pip2 install virtualenv
run: pip3 install virtualenv
- name: Init virtualenv and install dependencies
run: |
virtualenv --python=python2 venv-2.7
. venv-2.7/bin/activate
virtualenv --python=python3 venv
. venv/bin/activate
pip install pip>=9.0.1
pip install --upgrade flake8 'setuptools-scm==5.0.2'
pip install -r requirements.txt
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,3 @@
[submodule "bootbox"]
path = dependencies/bootbox
url = https://github.com/makeusabrew/bootbox.git
[submodule "rbtools"]
path = dependencies/rbtools
url = https://github.com/reviewboard/rbtools.git
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:2.7-slim
FROM python:3.8-slim

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
Expand Down Expand Up @@ -46,7 +46,7 @@ RUN set -ex \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
&& pip install -U virtualenv \
&& python2.7 -m virtualenv /venv \
&& python3 -m virtualenv /venv \
&& /venv/bin/pip install -U pip \
&& /venv/bin/pip install --no-cache-dir -r /requirements.txt \
&& /venv/bin/pip install --no-cache-dir dj_database_url==0.5.0 \
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Anytask [![Build Status](https://github.com/znick/anytask/actions/workflows/anytask.yml/badge.svg)](https://github.com/znick/anytask/actions)
=======

Used Python3.8

local install
-------------
Expand Down
44 changes: 31 additions & 13 deletions anytask/admission/models.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf-8 -*-

from django.db import models
from django.conf import settings
from django.contrib.sites.models import Site
from registration.models import RegistrationManager
from django.template.loader import render_to_string
from django.db.models import Q
from django.core.mail import send_mail
from mail.common import EmailSender

from django.contrib.auth.models import User

import datetime
import hashlib
import random
import json
import logging
import random
import re
import json

from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.mail import send_mail
from django.db import models
from django.db.models import Q
from django.template.loader import render_to_string

from mail.common import EmailSender
from registration.models import RegistrationManager

logger = logging.getLogger('django.request')

Expand Down Expand Up @@ -81,6 +81,24 @@ def create_inactive_user(self, username, email, password, send_email=True):

return new_user, registration_profile

def create_profile(self, user):
"""
Create a ``RegistrationProfile`` for a given
``User``, and return the ``RegistrationProfile``.
The activation key for the ``RegistrationProfile`` will be a
SHA1 hash, generated from a combination of the ``User``'s
username and a random salt.
"""
salt = hashlib.sha1(str(random.random()).encode('utf8')).hexdigest()[:5]
username = user.username
if isinstance(username, str):
username = username
activation_key = hashlib.sha1((salt + username).encode('utf8')).hexdigest()
return self.create(user=user,
activation_key=activation_key)

def send_mail_update_user(self, email):

subject = render_to_string('email_update_subject.txt')
Expand Down
2 changes: 1 addition & 1 deletion anytask/admission/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_register_activate(self, mock_contest_register):
# post register
response = client.post(reverse(admission.views.register), post_data, **test_header)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, "OK")
self.assertEqual(response.content, b"OK")

registration_profile = AdmissionRegistrationProfile.objects.all()
self.assertEqual(len(registration_profile), 1)
Expand Down
4 changes: 2 additions & 2 deletions anytask/admission/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def register(request):
if request.META['HTTP_EMAIL'] and request.META['HTTP_EMAIL'] != 'None':
user_info['ya_email'] = request.META['HTTP_EMAIL']

for key, post_data_key in settings.YA_FORMS_FIELDS.iteritems():
for key, post_data_key in settings.YA_FORMS_FIELDS.items():
user_info[key] = get_post_value(post_data, post_data_key)

for key, post_data_keys in settings.YA_FORMS_FIELDS_ADDITIONAL.iteritems():
for key, post_data_keys in settings.YA_FORMS_FIELDS_ADDITIONAL.items():
info_json = []
for post_data_key in post_data_keys:
info_json.append({
Expand Down
2 changes: 1 addition & 1 deletion anytask/anycontest/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests
import logging
import xmltodict
from BeautifulSoup import BeautifulStoneSoup
from bs4 import BeautifulStoneSoup

from django.conf import settings

Expand Down
7 changes: 4 additions & 3 deletions anytask/anycontest/management/commands/check_contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def handle(self, **options):
except Exception as e:
logger.exception(e)

# for contest_id, students_info in contest_marks.iteritems():
# for contest_id, students_info in contest_marks.items():
# set_contest_marks(contest_id, students_info)

# logging to cron log
print "Command check_contest check {0} submissions ({1} - with marks) took {2} seconds" \
.format(len(contest_submissions), contest_marks_len, time.time() - start_time)
duration = time.time() - start_time
print(f"Command check_contest check {len(contest_submissions)} submissions ({contest_marks_len} - with marks) "
f"took {duration} seconds")

@staticmethod
def handle_submission(contest_marks_len, contest_submission):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def handle(self, **options):
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email, "[email protected]"])

# logging to cron log
print "Command send_freezed_run_id_notify check {0} submissions took {1} seconds" \
.format(len(contest_submissions), time.time() - start_time)
print("Command send_freezed_run_id_notify check {0} submissions took {1} seconds"
.format(len(contest_submissions), time.time() - start_time))
2 changes: 1 addition & 1 deletion anytask/anycontest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ContestSubmission(models.Model):

sended_notify = models.BooleanField(default=False)

def __unicode__(self):
def __str__(self):
return u"{0} {1}".format(self.issue, self.run_id)

def upload_contest(self, extension=None, compiler_id=None):
Expand Down
29 changes: 16 additions & 13 deletions anytask/anycontest/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
from tasks.models import Task
from issues.models import Issue, File, Event
from issues.model_issue_status import IssueStatus
from common import get_contest_info
from .common import get_contest_info
from anycontest.models import ContestSubmission

from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils.translation import ugettext as _

import threading
import BaseHTTPServer
import SocketServer
import http.server as BaseHTTPServer
import socketserver as SocketServer
import time
import json
import tests_data
from . import tests_data
import cgi

CONTEST_PORT = 8079
Expand All @@ -39,13 +39,14 @@ def do_GET(self): # NOQA
if self.path.startswith("/anytask/contest?contestId="):
self.send_response(200)
self.end_headers()
json.dump(tests_data.CONTEST_INFO, self.wfile)
self.wfile.write(json.dumps(tests_data.CONTEST_INFO).encode('utf8'))
return

if self.path.startswith("/anytask/problems?contestId="):
self.send_response(200)
self.end_headers()
json.dump(tests_data.CONTEST_PROBLEMS, self.wfile)
data = json.dumps(tests_data.CONTEST_PROBLEMS).encode('utf8')
self.wfile.write(data)
return

if self.path == "/anytask/results?runId=1&contestId=0":
Expand All @@ -59,7 +60,7 @@ def do_GET(self): # NOQA
}
self.send_response(200)
self.end_headers()
json.dump(reply, self.wfile)
self.wfile.write(json.dumps(reply).encode('utf8'))
return

if self.path == "/anytask/results?runId=2&contestId=0":
Expand All @@ -78,7 +79,7 @@ def do_GET(self): # NOQA
}
self.send_response(200)
self.end_headers()
json.dump(reply, self.wfile)
self.wfile.write(json.dumps(reply).encode('utf8'))
return

if self.path == "/anytask/results?runId=3&contestId=0":
Expand All @@ -105,25 +106,27 @@ def do_GET(self): # NOQA
}
self.send_response(200)
self.end_headers()
json.dump(reply, self.wfile)
self.wfile.write(json.dumps(reply).encode('utf8'))
return

if self.path == "/anytask/results?runId=5&contestId=0":
reply = {"bad_answer": True}
self.send_response(200)
self.end_headers()
json.dump(reply, self.wfile)
self.wfile.write(json.dumps(reply).encode('utf8'))
return

self.send_response(501)
self.end_headers()

def do_POST(self): # NOQA
content_type, pdict = cgi.parse_header(self.headers.getheader("content-type"))
content_type, pdict = cgi.parse_header(self.headers.get("Content-Type"))
pdict['CONTENT-LENGTH'] = int(self.headers.get("Content-Length"))
pdict['boundary'] = pdict['boundary'].encode('ascii')
fields = cgi.parse_multipart(self.rfile, pdict)

if self.path.startswith("/anytask/submit"):
if "_failed_" in fields["file"][0]:
if b"_failed_" in fields["file"][0]:
reply = {
'error': {
'message': "Submit error in fake server!"
Expand All @@ -138,7 +141,7 @@ def do_POST(self): # NOQA

self.send_response(200)
self.end_headers()
json.dump(reply, self.wfile)
self.wfile.write(json.dumps(reply).encode('utf8'))
return

self.send_response(501)
Expand Down
4 changes: 2 additions & 2 deletions anytask/anyrb/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from rbtools.api.client import RBClient
from rbtools.api.errors import APIError, AuthorizationError, BadRequestError, ServerInterfaceError
from unpacker import unpack_files
from .unpacker import unpack_files

logger = logging.getLogger('django.request')

Expand Down Expand Up @@ -191,7 +191,7 @@ def create_review_request(self):
path=os.path.join(repository_path, '.git'),
tool='Git',
public=False)
except Exception as e:
except Exception:
logger.warning("Cant create repository '%s', trying to find it", repository_name)
repository = self.get_repository(repository_name)

Expand Down
4 changes: 2 additions & 2 deletions anytask/anyrb/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from django.test import TestCase
from unpacker import UnpackedFile, unpack_files
from .unpacker import UnpackedFile, unpack_files

CUR_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DIR = os.path.join(CUR_DIR, "test_data")
Expand All @@ -28,7 +28,7 @@ def _test_unpack(self, arcfilename):
]

with unpack_files(files) as unpacked_files:
unpacked_filenames = map(lambda x: x.filename(), unpacked_files)
unpacked_filenames = list(map(lambda x: x.filename(), unpacked_files))
self.assertListEqual(['1.txt', arcfilename + '/1.py', arcfilename + '/dir/1.pl'], unpacked_filenames)

def test_unpack_zip(self):
Expand Down
4 changes: 2 additions & 2 deletions anytask/anyrb/unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def filename(self):


def get_archiver(filename):
for suffix, archiver in ARCHIVERS.iteritems():
for suffix, archiver in iter(ARCHIVERS.items()):
if filename.lower().endswith(suffix):
return archiver
return None
Expand All @@ -70,7 +70,7 @@ def unpack_files(files):
try:
unpacked_filepath = os.path.join(root, unpacked_file)
unpacked_filename = unpacked_filepath[len(dst_dir):]
unpacked_filename = unpacked_filename.decode("utf-8", errors="ignore")
unpacked_filename = unpacked_filename
unpacked_file = UnpackedFile(unpacked_filepath, f.filename() + unpacked_filename)
res.append(unpacked_file)
except Exception as e:
Expand Down
7 changes: 3 additions & 4 deletions anytask/anysvn/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.conf.urls import patterns, url
from django.conf.urls import url
from anysvn.views import SvnAccesss

urlpatterns = patterns(
'anysvn.views',
urlpatterns = [
url(r'^access/$', SvnAccesss.as_view(),
name="anysvn.views.SvnAccesss.as_view"),
)
]
Loading

0 comments on commit d92197b

Please sign in to comment.