Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

import os 

import sys 

import tempfile 

import time 

from subprocess import PIPE, Popen 

 

from twisted.internet.error import CannotListenError 

 

import deluge.common 

import deluge.configmanager 

import deluge.log 

 

deluge.log.setup_logger("none") 

 

 

def disable_new_release_check(): 

    import deluge.core.preferencesmanager 

    deluge.core.preferencesmanager.DEFAULT_PREFS["new_release_check"] = False 

 

 

def set_tmp_config_dir(): 

    config_directory = tempfile.mkdtemp() 

    deluge.configmanager.set_config_dir(config_directory) 

    return config_directory 

 

 

def rpath(*args): 

    return os.path.join(os.path.dirname(__file__), *args) 

 

# Initialize gettext 

deluge.common.setup_translations() 

 

 

def start_core(listen_port=58846): 

    cwd = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) 

    daemon_script = """ 

import sys 

import deluge.main 

 

sys.argv.extend(['-d', '-c', '%s', '-L', 'info', '-p', '%d']) 

 

deluge.main.start_daemon() 

""" 

    config_directory = set_tmp_config_dir() 

    fp = tempfile.TemporaryFile() 

    fp.write(daemon_script % (config_directory, listen_port)) 

    fp.seek(0) 

 

    core = Popen([sys.executable], cwd=cwd, stdin=fp, stdout=PIPE, stderr=PIPE) 

    while True: 

        line = core.stderr.readline() 

        if ("starting on %d" % listen_port) in line: 

            time.sleep(0.3)  # Slight pause just incase 

            break 

56        elif ("Couldn't listen on localhost:%d" % listen_port) in line: 

            raise CannotListenError("localhost", listen_port, "Could not start deluge test client: %s" % line) 

58        elif 'Traceback' in line: 

            raise SystemExit( 

                "Failed to start core daemon. Do \"\"\" %s \"\"\" to see what's " 

                "happening" % 

                "python -c \"import sys; import tempfile; import deluge.main; " 

                "import deluge.configmanager; config_directory = tempfile.mkdtemp(); " 

                "deluge.configmanager.set_config_dir(config_directory); " 

                "sys.argv.extend(['-d', '-c', config_directory, '-L', 'info']); " 

                "deluge.main.start_daemon()\"" 

            ) 

    return core