コード例 #1
0
ファイル: __init__.py プロジェクト: tactlabs/touchandgo
    def get_torrent(name, season=None, episode=None):
        interface = get_interface()
        settings = get_settings()
        path = abspath(__file__)
        dir_path = dirname(path)
        exec_ = join(dir_path, "..", "main.py")
        command = '%s %s \"%s\" ' % (py_exec, exec_, name)
        if season is not None:
            command += "%s %s " % (season, episode)
        lock = Lock(LOCK_FILE)
        if lock.is_same_file(name, season, episode) and \
                is_process_running(lock.get_pid()):
            data = lock._get_file_data()
            port = data[4]
        else:
            if settings.force_ts_proxy_port:
                port = settings.ts_proxy_port
            else:
                port = get_free_port()
            command += "--daemon --port %s " % port
            log.info(command)
            process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
            sleep(1)

        redirect_url = "http://%s:%s" % (interface, port)
        serving = False
        while not serving:
            try:
                req = requests.get("%s/status" % redirect_url)
                serving = True
            except requests.ConnectionError, e:
                sleep(1)
コード例 #2
0
ファイル: server.py プロジェクト: jjconti/touchandgo
    def get_torrent(name, season=None, episode=None):
        interface = get_interface()
        path = abspath(__file__)
        dir_path = dirname(path)
        exec_ = join(dir_path, "__init__.py")
        command = '%s %s \"%s\" ' % (py_exec, exec_, name)
        if season is not None:
            command += "%s %s " % (season, episode)
        lock = Lock(LOCKFILE)
        if lock.is_same_file(name, season, episode) and \
                is_process_running(lock.get_pid()):
            data = lock._get_file_data()
            port = data[4]
        else:
            port = get_free_port()
            command += "--daemon --port %s " % port
            log.debug(command)
            process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
            sleep(1)

        redirect_url = "http://%s:%s" % (interface, port)
        serving = False
        while not serving:
            try:
                req = requests.get("%s/status" % redirect_url)
                serving = True
            except requests.ConnectionError, e:
                sleep(1)
コード例 #3
0
ファイル: helpers.py プロジェクト: Zopieux/touchandgo
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        log.info("running daemon")
        create_process = False
        lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
                    args.sea_ep[1], args.port)
        if lock.is_locked():
            log.debug("lock active")
            lock_pid = lock.get_pid()
            if not lock.is_same_file(args.name, args.sea_ep[0],
                                     args.sea_ep[1]) \
                    or not is_process_running(lock_pid):
                try:
                    log.debug("killing process %s" % lock_pid)
                    os.kill(lock_pid, signal.SIGQUIT)
                except OSError:
                    pass
                except TypeError:
                    pass
                lock.break_lock()
                create_process = True
        else:
            create_process = True

        if create_process:
            log.debug("creating proccess")
            lock.acquire()
            callback()
            lock.release()
        else:
            log.debug("same daemon process")
コード例 #4
0
ファイル: server.py プロジェクト: jjconti/touchandgo
 def kill_():
     lock = Lock(LOCKFILE)
     try:
         kill(lock.get_pid(), signal.SIGQUIT)
     except Exception, e:
         pass
コード例 #5
0
ファイル: __init__.py プロジェクト: tactlabs/touchandgo
 def kill_():
     lock = Lock(LOCK_FILE)
     try:
         kill(lock.get_pid(), signal.SIGQUIT)
     except Exception, e:
         pass
コード例 #6
0
ファイル: helpers.py プロジェクト: zodman/touchandgo
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        log.info("running daemon")
        create_process = False
        lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
                    args.sea_ep[1], args.port)
        if lock.is_locked():
            log.debug("lock active")
            lock_pid = lock.get_pid()
            if not lock.is_same_file(args.name, args.sea_ep[0],
                                     args.sea_ep[1]) \
                    or not is_process_running(lock_pid):
                try:
                    log.debug("killing process %s" % lock_pid)
                    os.kill(lock_pid, signal.SIGQUIT)
                except OSError:
                    pass
                except TypeError:
                    pass
                lock.break_lock()
                create_process = True
        else:
            create_process = True

        if create_process:
            log.debug("creating proccess")
            lock.acquire()
            callback()
            lock.release()
        else:
            log.debug("same daemon process")
コード例 #7
0
ファイル: server.py プロジェクト: peregrinogris/touchandgo
 def kill_():
     lock = Lock(LOCKFILE)
     kill(lock.get_pid(), signal.SIGQUIT)
     return "OK"
コード例 #8
0
ファイル: helpers.py プロジェクト: tactlabs/touchandgo
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        try:
            log.info("running daemon")
            create_process = False
            pid = os.getpid()
            log.debug("%s, %s, %s", LOCK_FILE, pid, args)
            lock = Lock(LOCK_FILE, pid, args.name, args.season_number,
                        args.episode_number, args.port)
            if lock.is_locked():
                log.debug("lock active")
                lock_pid = lock.get_pid()
                is_same = lock.is_same_file(args.name, args.season_number,
                                            args.episode_number)
                if (not is_same or not is_process_running(lock_pid)):
                    try:
                        log.debug("killing process %s" % lock_pid)
                        os.kill(lock_pid, signal.SIGQUIT)
                    except OSError:
                        pass
                    except TypeError:
                        pass
                    lock.break_lock()
                    create_process = True
            else:
                log.debug("Will create process")
                create_process = True

            if create_process:
                log.debug("creating proccess")
                lock.acquire()
                callback()
                lock.release()
            else:
                log.debug("same daemon process")
        except Exception as e:
            log.error(e)