language: python
python:
    - "2.6"
    - "2.7"
    - "3.3"
    - "3.4"
script: python tests/test_all_of_the_units.py
branches:
only:
    - master
---

install:
    - pip install tox
script:
    - tox 
---

#-*-coding: utf-8-*-
notify{ 'Mac Warning':
    message => $operatingsystem ? {
        'Darwin' => 'To zdaje się być Mac.',
        default  => 'Jestem PC.',
    },
} 
---

#-*-coding: utf-8-*-
# Funkcje do pobrania zmiennych systemowych:
from psutil import cpu_percent, net_io_counters
# Funkcje do przerwy w działaniu:
from time import sleep
# Pakiet do usług mailowych:
import smtplib
import string

MAX_NET_USAGE = 400000
MAX_ATTACKS = 4
attack = 0
counter = 0
while attack <= MAX_ATTACKS:
    sleep(4)
    counter = counter + 1
    # Sprawdź użycie CPU
    if cpu_percent(interval = 1) > 70:
        attack = attack + 1
    # Sprawdź użycie sieci
    neti1 = net_io_counters()[1]
    neto1 = net_io_counters()[0]
    sleep(1)
    neti2 = net_io_counters()[1]
    neto2 = net_io_counters()[0]
    # Oblicz bajty na sekundę
    net = ((neti2+neto2) - (neti1+neto1))/2
    if net > MAX_NET_USAGE:
        attack = attack + 1
    if counter > 25:
        attack = 0 
        counter = 0 

    # Napisz bardzo ważnego maila, kiedy attack jest większy niż 4
    TO = "ty@twoj_email.com"
    FROM = "webmaster@twoja_domena.com"
    SUBJECT = "Twoja domena nie posiada zasobów!"
    text = "Napraw swój serwer!!"
    BODY = string.join(
             ("From: %s" %FROM,"To: %s" %TO,"Subject: %s" %SUBJECT, "",text), "\r\n")
    server = smtplib.SMTP('127.0.0.1')
    server.sendmail(FROM, [TO], BODY)
    server.quit()
---

#-*-coding:utf-8-*-
def primes(int kmax):

    cdef int n, k, i
    cdef int p[1000]
    result = []
    if kmax > 1000:
        kmax = 1000
    k= 0
    n= 2
    while k < kmax:
        i= 0
        while i < k and n % p[i] != 0:
            i = i + 1
        if i == k: 
            p[k] = n
            k = k + 1
            result.append(n) 
        n = n + 1
    return result
---
#-*-coding:utf-8-*-
def primes(kmax):
"""Obliczanie liczb pierwszych ze standardową składnią Pythona"""

    p= range(1000)
    result = []
    if kmax > 1000:
        kmax = 1000
    k= 0
    n= 2
    while k < kmax:
        i= 0
        while i < k and n % p[i] != 0: 
            i = i + 1
        if i == k: 
            p[k] = n
            k = k + 1
            result.append(n) 
        n = n + 1
    return result 
---

#-*-coding:utf-8-*-
import time
# aktywuj kompilator pyx
import pyximport  
pyximport.install()  
# liczby pierwsze zaimplementowane w Cythonie
import primesCy
# liczby pierwsze zaimplementowane w Pythonie
import primes

print("Cython:")
t1 = time.time()
print primesCy.primes(500)
t2 = time.time()
print("Czas Cythona: %s" %(t2-t1))
print("")
print("Python")
t1 = time.time()  
print(primes.primes(500))
t2 = time.time()
print("Czas Pythona: {}".format(t2-t1))
---

#include <string>
class MyClass {
private:
    std::string name;
public:
    std::string getName();
};
---

%include "string.i" 

%module myclass
%{
#include <string>
#include "MyClass.h"
%}

%extend MyClass {
    std::string __repr__()
    {
        return $self->getName();
    }
}
%include "MyClass.h"
---


