checks.py 1.34 KB
Newer Older
putro's avatar
putro committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

import os
import sys
from utils import download
import subprocess

class MixError(Exception):
    pass

def checkAscii(file):
    """ Check if the a file is pure ascii """
    import codecs

    bad = 0
    f = codecs.open(file, encoding='ascii')
    lines = open(file).readlines()
    for i in range(0, len(lines)):
        try:
            l = f.readline()
        except:
            num = i + 1
            print "config file problem (%s): line %d contains non-ascii " \
                  "character, fix it" % (file, num)
            bad = 1
            break
    f.close()
    return bad



def OptionsCheck(config):
    """ performs some checks """

    try:
        f = open(os.path.dirname(sys.argv[0]) + "/check", "w")
    except:
putro's avatar
putro committed
38
        print "Error: you cannot write here, fix permission"
putro's avatar
putro committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        sys.exit()
    else:
        f.close()
        os.remove(os.path.dirname(sys.argv[0]) + "/check")

    try:
        download(config['stats']['stats_mlist'], config)
    except:
        print "Error: cannot download fresh remailer stats"



    try:
        mix = subprocess.Popen(config['options']['mixmaster'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    except OSError:     # usally means that mixmaster could not be executed
        raise MixError('Could not find mixmaster binary.')

    return True