Completed
Push — master ( 18d750...3bad9e )
by Andrii
11:56
created

Daemon   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 50
rs 10
wmc 15

2 Methods

Rating   Name   Duplication   Size   Complexity  
F start() 0 45 14
A stop() 0 3 1
1
import os
2
import sys
3
import time
4
import socket
5
6
from pprint import pprint
7
8
from heppy.Error import Error
9
from heppy.Client import Client
10
from heppy.Request import Request
11
from heppy.Response import Response
12
13
class Daemon:
14
    @staticmethod
15
    def start(config, args = {}):
16
        try:
17
            client = Client(config['local']['address'])
18
            client.connect()
19
        except socket.error as e:
20
            os.system(config['zdir'] + '/eppyd ' + config['path'] + ' &')
21
            time.sleep(2)
22
            client = Client(config['local']['address'])
23
        if not args.get('login'):
24
            args['login'] = config['epp']['login']
25
        if not args.get('pw'):
26
            args['pw'] = config['epp']['password']
27
        greeting = client.request('greeting')
28
        if not greeting:
29
            Error.die(4, 'failed get greeting')
30
        greeting = Response.parsexml(greeting)
31
        pprint(greeting.data)
32
        if not args.get('objURIs'):
33
            args['objURIs'] = greeting.get('objURIs')
34
            for uri in list(args['objURIs']):
35
                if not uri in Request.modules:
36
                    del args['objURIs'][uri]
37
        if not args.get('extURIs'):
38
            args['extURIs'] = greeting.get('extURIs')
39
            for uri in list(args['extURIs']):
40
                if not uri in Request.modules:
41
                    del args['extURIs'][uri]
42
        #client = Client(config['local']['address'])
43
        request = Request.build('epp:login', args)
44
        query = str(request)
45
        print Request.prettifyxml(query)
46
        reply = client.request(query)
47
        print Request.prettifyxml(reply)
48
        error = None
49
        try:
50
            response = Response.parsexml(reply)
51
            data = response.data
52
            pprint(data)
53
        except Error as e:
54
            error = e.message
55
            data = e.data
56
        if error is not None and data['resultCode']!='2002':
57
            Error.die(2, 'failed start', data)
58
        print 'OK'
59
60
    @staticmethod
61
    def stop(config, args = {}):
62
        Error.die(3, 'failed stop', config)
63
64