More fixes for python 3 compat

This commit is contained in:
Marc Aymerich 2015-04-03 10:14:45 +00:00
parent b3946168f3
commit 4a8a77715c
10 changed files with 58 additions and 37 deletions

12
TODO.md
View file

@ -238,7 +238,7 @@ require_once(/etc/moodles/.$moodle_host.config.php);``` moodle/drupl
* billline quantity eval('10x100') instead of miningless description '(10*100)'
* IMPORTANT do more test, make sure billed until doesn't get uodated whhen services are billed with les metric, and don't upgrade billed_until when undoing under this circumstances
# FIXME do more test, make sure billed until doesn't get uodated whhen services are billed with les metric, and don't upgrade billed_until when undoing under this circumstances
* line 513: change threshold and one time service metric change should update last value if not billed, only record for recurring invoicing. postpay services should store the last metric for pricing period.
* add ini, end dates on bill lines and breakup quanity into size(defaut:1) and metric
* threshold for significative metric accountancy on services.handler
@ -313,6 +313,16 @@ celery max-tasks-per-child
* webapp has_website list filter
# FIXME account deletion generates a integrity error
apt-get install python3 python3-pip
cp /usr/local/lib/python2.7/dist-packages/orchestra.pth /usr/local/lib/python3.4/dist-packages/
glic3rinu's django-fluent-dashboard
* gevent is not ported to python3 :'(
* uwsgi python3
# FIXME what to do when deleting accounts? set fk null and fill a username charfield? issues, invoices.. we whant all this to go away?
* implement delete All related services

View file

@ -273,7 +273,7 @@ class BillLine(models.Model):
rate = models.DecimalField(_("rate"), blank=True, null=True, max_digits=12, decimal_places=2)
quantity = models.DecimalField(_("quantity"), max_digits=12, decimal_places=2)
subtotal = models.DecimalField(_("subtotal"), max_digits=12, decimal_places=2)
tax = models.PositiveIntegerField(_("tax"))
tax = models.DecimalField(_("tax"), max_digits=2, decimal_places=2)
# Undo
# initial = models.DateTimeField(null=True)
# end = models.DateTimeField(null=True)

View file

@ -1,5 +1,5 @@
import copy
from urllib.parse import urlparse
from urllib.parse import parse_qs
from django import forms
from django.contrib import admin

View file

@ -86,22 +86,25 @@ def SSH(backend, log, server, cmds, async=False):
# Log results
logger.debug('%s running on %s' % (backend, server))
if async:
second = False
while True:
# Non-blocking is the secret ingridient in the async sauce
select.select([channel], [], [])
if channel.recv_ready():
part = channel.recv(1024)
part = channel.recv(1024).decode('utf-8')
while part:
log.stdout += part
part = channel.recv(1024)
part = channel.recv(1024).decode('utf-8')
if channel.recv_stderr_ready():
part = channel.recv_stderr(1024)
part = channel.recv_stderr(1024).decode('utf-8')
while part:
log.stderr += part
part = channel.recv_stderr(1024)
part = channel.recv_stderr(1024).decode('utf-8')
log.save(update_fields=['stdout', 'stderr'])
if channel.exit_status_ready():
break
if second:
break
second = True
else:
log.stdout += channel.makefile('rb', -1).read().decode('utf-8')
log.stderr += channel.makefile_stderr('rb', -1).read().decode('utf-8')

View file

@ -268,40 +268,46 @@ class MetricStorage(models.Model):
accounts.register(Order)
@receiver(pre_delete, dispatch_uid="orders.account_orders")
def account_orders(sender, **kwargs):
account = kwargs['instance']
if isinstance(account, Order.account.field.rel.to):
account._deleted = True
#@receiver(pre_delete, dispatch_uid="orders.account_orders")
#def account_orders(sender, **kwargs):
# account = kwargs['instance']
# if isinstance(account, Order.account.field.rel.to):
# account._deleted = True
# FIXME account deletion generates a integrity error
# TODO build a cache hash table {model: related, model: None}
@receiver(post_delete, dispatch_uid="orders.cancel_orders")
def cancel_orders(sender, **kwargs):
if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS:
instance = kwargs['instance']
# Account delete will delete all related orders, no need to maintain order consistency
if isinstance(instance, Order.account.field.rel.to):
# print 'aaaaaaaaaaaaaAAAAAAAAAAAAAAAAaa'
# if isinstance(instance, Order.account.field.rel.to):
# return
if sender is Order.account.field.rel.to:
return
# print 'delete', sender, kwargs
try:
print(instance.account.pk)
except Exception as e:
pass
print('delete', sender, instance, instance.pk)
if type(instance) in services:
for order in Order.objects.by_object(instance).active():
order.cancel()
elif not hasattr(instance, 'account'):
related = helpers.get_related_object(instance)
# FIXME this shit returns objects that are already deleted
# Indeterminate behaviour
if related and related != instance:
# if isinstance(related, Order.account.field.rel.to):
# return
print('related', type(related), related, related.pk)
# try:
# type(related).objects.get(pk=related.pk)
# except related.DoesNotExist:
# print('not exists', type(related), related, related.pk)
Order.update_orders(related)
@receiver(post_save, dispatch_uid="orders.update_orders")
def update_orders(sender, **kwargs):
if sender._meta.app_label not in settings.ORDERS_EXCLUDED_APPS:
instance = kwargs['instance']
# print 'save', sender, kwargs
if type(instance) in services:
Order.update_orders(instance)
elif not hasattr(instance, 'account'):

View file

@ -63,11 +63,14 @@ class MonthlyAvg(MonthlySum):
)
def compute_usage(self, dataset):
last = dataset.latest()
result = 0
try:
last = dataset.latest()
except dataset.model.DoesNotExist:
return result
epoch = self.get_epoch()
total = (last.created_at-epoch).total_seconds()
ini = epoch
result = 0
for data in dataset:
slot = (data.created_at-ini).total_seconds()
result += data.value * decimal.Decimal(str(slot/total))

View file

@ -40,8 +40,8 @@ class SystemUserBackend(ServiceController):
self.append(textwrap.dedent("""\
{ sleep 2 && killall -u %(user)s -s KILL; } &
killall -u %(user)s || true
userdel %(user)s || true
groupdel %(group)s || true""") % context
userdel %(user)s || exit_code=1
groupdel %(group)s || exit_code=1""") % context
)
self.delete_home(context, user)
@ -52,7 +52,7 @@ class SystemUserBackend(ServiceController):
def delete_home(self, context, user):
if user.home.rstrip('/') == user.get_base_home().rstrip('/'):
# TODO delete instead of this shit
self.append("mv %(home)s %(home)s.deleted" % context)
self.append("mv %(home)s %(home)s.deleted || exit_code=1" % context)
def get_groups(self, user):
if user.is_main:

View file

@ -119,13 +119,14 @@ function install_requirements () {
check_root
ORCHESTRA_PATH=$(get_orchestra_dir)
APT="python-pip \
python-psycopg2 \
APT="python3 \
python3-pip \
python3-psycopg2 \
postgresql \
rabbitmq-server \
python-dev \
python3-dev \
bind9utils \
python-cracklib \
python3-cracklib \
libz-dev \
libxml2-dev \
libxslt1-dev \
@ -166,7 +167,7 @@ function install_requirements () {
APT="${APT} \
iceweasel \
dnsutils \
python-mysqldb"
python3-mysqldb"
PIP="${PIP} \
selenium \
xvfbwrapper \
@ -199,7 +200,7 @@ function install_requirements () {
update-ca-certificates
fi
run pip install $PIP
run pip3 install $PIP
# Some versions of rabbitmq-server will not start automatically by default unless ...
sed -i "s/# Default-Start:.*/# Default-Start: 2 3 4 5/" /etc/init.d/rabbitmq-server

View file

@ -42,7 +42,7 @@ class Command(BaseCommand):
CELERYD_CHDIR="%(site_dir)s"
# How to call "manage.py celeryd_multi"
CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"
CELERYD_MULTI="python3 $CELERYD_CHDIR/manage.py celeryd_multi"
# Extra arguments to celeryd
CELERYD_OPTS="-P:w1 processes -c:w1 %(processes)s -Q:w1 celery"
@ -67,14 +67,14 @@ class Command(BaseCommand):
CELERYD_STATE_DB="$CELERYD_CHDIR/persistent_revokes"
# Celeryev
CELERYEV="$CELERYD_CHDIR/manage.py"
CELERYEV="python3 $CELERYD_CHDIR/manage.py"
CELERYEV_CAM="djcelery.snapshot.Camera"
CELERYEV_USER="$CELERYD_USER"
CELERYEV_GROUP="$CELERYD_USER"
CELERYEV_OPTS="celerycam"
# Celerybeat
CELERYBEAT="${CELERYD_CHDIR}/manage.py celerybeat"
CELERYBEAT="python3 ${CELERYD_CHDIR}/manage.py celerybeat"
CELERYBEAT_USER="$CELERYD_USER"
CELERYBEAT_GROUP="$CELERYD_USER"
CELERYBEAT_CHDIR="$CELERYD_CHDIR"

View file

@ -1,5 +1,3 @@
from __future__ import unicode_literals
import os, sys
from distutils.sysconfig import get_python_lib
from setuptools import setup, find_packages