示例#1
0
文件: donkey.py 项目: Ninja-1/Circle2
 def view_status(data, self=self):
     self.reading_status = 1
     self.status = ""
     time.sleep(0.05)
     self.tell("g\n")
     time.sleep(0.1)
     self.reading_status = 0
     utility.mainthread_call(self.app.chat.show_after, self.chat_field, "overnet status : \n" + self.status)
示例#2
0
文件: proxy.py 项目: Ninja-1/Circle2
    def become_broken(self):
        self.lock.acquire()
        try:
            if not self.broken and self.running:
                error = Error('The connection to the firewall has gone down, or the proxy has crashed.\n\n'+\
                                            'Circle is now disconnected from the network. Sorry.')
                utility.mainthread_call(error.show)
            self.broken = 1

            raise Error('proxy broken')
        finally:
            self.lock.release()
示例#3
0
def meet(chat, params):
    """
    Expect the user name as a param.
    """
    # should reques the user identifier too <<<
    #check.check_matches(params, ['text'])
    #check.check_assertion(1 <= len(params) <= 1)
    name_of_requester = params[0]
    t_message = "Do you accept a voice session " + (name_of_requester and "with %s "%name_of_requester) + "?"
    
    def to_do():
        d = gtk.MessageDialog(parent=app.window, flags=0, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format= t_message);
        # trick to get the result
        ret = d.run()
        d.destroy()
        ret = {-8:"Yes", -9:"No", -4:"Abort", -5:"Ok", -6:"Cancel"}.get(ret, ret) # strange but work				
        app.chat.show("The result of the query is %s" % ret + '\n')	
        return
        
    utility.mainthread_call(to_do)
    return
示例#4
0
def request_meeting_task(server_acq):
    """
    function that is called in a thread
    """    
    
    server_address  = server_acq.address # address is (ip, port)
    server_nickname = server_acq.nickname

    #app.chat.show( "Sending the request of %s to adress %s\n" % (server_nickname, server_address))	

#@+at
#     node.call(self, address, query, low_priority=0, n_retries=udp_retries):
#         """Perform a UDP remote procedure call, and return the result.
# 
#              This will raise an Error("no reply") if the address can not be 
# contacted.
#              It will also raise an Error if the remote computer replies with 
# an
#              Error object."""
#@-at
#@@c
    
    #node.call receiver query="start meeting"
    ret = node.call(server_address, ("start meeting",))
    
    #if return yes: start a call to the receiver
    if ret == 1:
        server_ip = server_address[0]
        url = "callto://%s" % server_ip
        t_message = "%s accepted your request, and is ready to receive your call. Starting the meeting session." % server_nickname
        start_meeting_software(url)
    #else: show the error message (rejected, or technical failure)
    elif ret == 0:
        t_message = "%s reject your meeting request." % server_nickname
    else: # ret == -1 or anything else
        t_message = "%s had a technical inconvenient. Meeting session could not start."% server_nickname

    # show the message
    utility.mainthread_call(app.chat.show, t_message + '\n')
    return
示例#5
0
    def handle(self, request, address, call_id):
        """
        Manage the "start meeting" command.
        Test command: !node.handlers["start meeting"][0].handle("start meeting", None, None)
        """
        
        if (address, call_id) in self.answered_calls:
            return None # omit repeated ansers
        

        assert request == ("start meeting",), "This handler does not manage request '%s' (type %s)" % (request, type(request))

                
        # obtain the caller name
        caller_name = "unknown" # better than None ?
        for t_acq in app.name_server.acquaintances.values():
            if t_acq.address == address:
                caller_name = t_acq.nickname 
                break # found the searched name

        
        #app.chat.show( "Received a meeting request by user %s\n" % caller_name)	
        print "Received a meeting request by user %s\n" % caller_name
        
        # use the dialog to obtain the result
        result_list = [None]
        ok = threading.Semaphore(); ok.acquire()
        utility.mainthread_call(self.receiver_dialog, result_list, ok, caller_name)
        ok.acquire(); ok.release() # will wait until the dialog release the semaphore
        
        ret = result_list[0] # result_list[0] now store the dialog result
        
        #app.chat.show( "Your response to the meeting request is %s\n" % ret)	
        print "The result of the request is %s\n" % {1:"Yes", 0:"No", -1:"Technical error"}.get(ret, ret) # strange but work				
                
        self.answered_calls.append((address, call_id))
        return ret # return back to the client the resulting value
示例#6
0
文件: donkey.py 项目: Ninja-1/Circle2
def start():

    # this plug-in is broken-- return immediately
    return

    if sys.platform.find("linux") == -1:
        app.config["use_overnet"] = 0
        return

    if hasattr(app, "overnet") and app.overnet != None:
        app.config["use_overnet"] = 0
        return

    client_file = os.path.join(utility.config_dir, "overnet" + overnet_version)

    if not os.path.isfile(client_file):

        sem = threading.Semaphore()
        sem.acquire()
        utility.mainthread_call(
            app.dialog_install_file,
            "Install the Overnet client.",
            "The Overnet binary client was not found.\nIn order to connect to the Overnet network,\nyou need to have this file in your .circle directory.\nDo you want to download and install it now?",
            "If you click on 'Install', a binary file will be downloaded from http://download.overnet.com/overnet"
            + overnet_version
            + ".tar.gz and installed it in your .circle directory. If you already have the overnet client, you may click on 'Cancel' and to install it manually.  Note: The overnet client is not part of Circle, and it is proprietary software. Running malicious files from untrusted sources might damage your system. For more information about Overnet, visit http://www.overnet.com",
            "use_overnet",
            sem,
        )

        sem.acquire()
        sem.release()

        if not app.config["use_overnet"]:
            app.overnet = None
            return

        utility.mainthread_call(
            app.chat.show, "Downloading the overnet client in " + client_file + " (this may take a while)...\n"
        )
        try:
            import urllib

            urllib.urlretrieve(
                "http://download.overnet.com/overnet" + overnet_version + ".tar.gz", client_file + ".tar.gz"
            )
        except error.Error:
            utility.mainthread_call(app.chat.show, "Could not download the overnet client.\n")
            app.config["use_overnet"] = 0
            app.overnet = None
            return

        if os.path.isfile(client_file + ".tar.gz"):
            try:
                os.system("/bin/gunzip -f " + client_file + ".tar.gz")
                os.system("/bin/tar -x -C " + utility.config_dir + " -f " + client_file + ".tar")
                os.chmod(client_file, 0755)
            except:
                pass

        # the flag might have changed while we downloaded
        if not app.config["use_overnet"]:
            utility.mainthread_call(app.chat.show, "Overnet client downloaded, I am not running it.\n")
            app.overnet = None
            return

        if not os.path.isfile(client_file):
            utility.mainthread_call(app.chat.show, "Could not download the overnet client.\n")
            app.config["use_overnet"] = 0
            app.overnet = None
            return

    def create_overnet(app=app):
        app.overnet = Donkey(app)
        app.overnet.start()

    utility.mainthread_call(create_overnet, app)
示例#7
0
文件: donkey.py 项目: Ninja-1/Circle2
 def view_message(data, self=self):
     utility.mainthread_call(self.app.chat.show, self.message)
示例#8
0
文件: donkey.py 项目: Ninja-1/Circle2
        def read_messages_task(self):
            buffer = ""
            while self.running:
                try:
                    str = ""
                    c = ""
                    while c != "\n":
                        c = os.read(self.shell_master, 1)
                        str = str + c
                except:
                    self.running = 0
                    return

                str = string.replace(str, "\r", "")
                str = string.replace(str, "> ", "")
                str = string.replace(str, chr(7), "")

                str = unicode(str, "latin-1")
                # print "overnet:",str

                if not self.reading_downloads:
                    if self.reading_message:
                        self.message = self.message + str

                if self.reading_status:
                    self.status += str
                    if string.find(str, "Users") != -1:
                        self.reading_status = 0

                if string.find(str, "Invalid Result number") != -1:
                    raise Error("eDonkey error: " + str)

                if string.find(str, "Connected to:") != -1:
                    self.display_message("overnet client c" + str[1:], "grey")
                    if self.connecting:
                        self.reading_message = 1
                        self.message = ""
                    else:
                        self.reading_message = 0
                    self.connecting = 0
                    self.connected = 1

                elif string.find(str, "Connecting to") != -1 and self.connecting:
                    self.display_message("overnet client c" + str[1:], "grey")
                elif string.find(str, "Disconnected") != -1:
                    self.display_message("overnet client disconnected.\n", "red")
                    self.connected = 0

                if self.waiting_results:
                    if str[0:16] == "Results returned" or str[0:11] == "Got results":
                        self.waiting_results = 0

                if self.reading_results:
                    if str[0:1] == "(":
                        self.results.append(str)
                    else:
                        self.tell(" ")

                    # if str[0:11] == 'press space':
                    #    print "overnet: pressing space"
                    #    self.lock.acquire()
                    #    self.tell(' ')
                    #    self.lock.release()
                    #    #time.sleep(0.01)

                if self.reading_downloads:
                    if string.find(str, "File Name") != -1:
                        self.downloads = []

                    if string.find(str, "Total") != -1:
                        self.lock.acquire()
                        self.reading_downloads = 0
                        self.lock.release()

                        for downloader in self.app.file_server.downloaders:
                            if downloader.node == self and not downloader.neverseen:
                                downloader.lock.acquire()
                                downloader.success = 1
                                downloader.lock.release()

                        for item in self.downloads:
                            number = self.downloads.index(item)
                            has_downloader = 0
                            for downloader in self.app.file_server.downloaders:
                                if string.find(item, downloader.data["filename"]) == -1:
                                    continue
                                else:
                                    downloader.lock.acquire()
                                    downloader.number = number
                                    downloader.success = 0
                                    downloader.neverseen = 0
                                    has_downloader = 1
                                    try:
                                        downloader.bytes_downloaded = (
                                            int(self.downloads[number + 1].split("\t")[4][:-1]) * 1024
                                        )
                                        downloader.speed_kBs = float(self.downloads[number + 1].split("\t")[5])
                                        downloader.availability = self.downloads[number + 1].split("\t")[6]
                                        downloader.status = self.downloads[number + 1].split("\t")[2]
                                        downloader.lock.release()
                                    except:
                                        break

                            if not has_downloader:
                                try:
                                    data = {
                                        "keywords": ["?"],
                                        "length": int(self.downloads[number + 1].split("\t")[3][:-1]) * 1024,
                                        "type": "file",
                                        "name": "file:?",
                                        "index": "?",
                                        "filename": self.downloads[number].split(" ", 1)[1][:-2],
                                    }
                                except:
                                    data = None
                                if data:
                                    downloader = file_server.Donkey_Downloader(self, data, self.app.config["download"])
                                    downloader.lock.acquire()
                                    downloader.number = number
                                    downloader.success = 0
                                    downloader.neverseen = 0
                                    downloader.lock.release()
                                    utility.mainthread_call(self.app.download_manager.assert_visible)
                                    self.app.file_server.downloaders.append(downloader)
                                    utility.mainthread_call(downloader.start)

                    if str.find("Downloading:") != -1:
                        str = None
                    if str:
                        self.downloads.append(str)
示例#9
0
文件: donkey.py 项目: Ninja-1/Circle2
 def display_message(self, msg, color="grey"):
     if self.app.chat.running:
         utility.mainthread_call(self.app.chat.show, msg, color)