當前位置: 首頁>>代碼示例>>Python>>正文


Python FileServer.openport方法代碼示例

本文整理匯總了Python中File.FileServer.openport方法的典型用法代碼示例。如果您正苦於以下問題:Python FileServer.openport方法的具體用法?Python FileServer.openport怎麽用?Python FileServer.openport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在File.FileServer的用法示例。


在下文中一共展示了FileServer.openport方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sitePublish

# 需要導入模塊: from File import FileServer [as 別名]
# 或者: from File.FileServer import openport [as 別名]
    def sitePublish(self, address, peer_ip=None, peer_port=15441, inner_path="content.json"):
        global file_server
        from Site import SiteManager
        from File import FileServer  # We need fileserver to handle incoming file requests
        from Peer import Peer

        logging.info("Creating FileServer....")
        file_server = FileServer()
        file_server_thread = gevent.spawn(file_server.start, check_sites=False)  # Dont check every site integrity
        file_server.openport()

        site = SiteManager.site_manager.list()[address]
        site.settings["serving"] = True  # Serving the site even if its disabled

        # Notify local client on new content
        if config.ip_external:
            logging.info("Sending siteReload")
            my_peer = Peer(config.ip_external, config.fileserver_port)
            logging.info(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path}))

        if peer_ip:  # Announce ip specificed
            site.addPeer(peer_ip, peer_port)
        else:  # Just ask the tracker
            logging.info("Gathering peers from tracker")
            site.announce()  # Gather peers

        published = site.publish(20, inner_path)  # Push to 20 peers
        if published > 0:
            time.sleep(3)
            logging.info("Serving files (max 60s)...")
            gevent.joinall([file_server_thread], timeout=60)
            logging.info("Done.")
        else:
            logging.info("No peers found, sitePublish command only works if you already have visitors serving your site")
開發者ID:handong890,項目名稱:ZeroNet,代碼行數:36,代碼來源:main.py

示例2: sitePublish

# 需要導入模塊: from File import FileServer [as 別名]
# 或者: from File.FileServer import openport [as 別名]
    def sitePublish(self, address, peer_ip=None, peer_port=15441, inner_path="content.json", diffs={}):
        global file_server
        from Site import Site
        from Site import SiteManager
        from File import FileServer  # We need fileserver to handle incoming file requests
        from Peer import Peer
        SiteManager.site_manager.load()

        logging.info("Loading site...")
        site = Site(address, allow_create=False)
        site.settings["serving"] = True  # Serving the site even if its disabled

        logging.info("Creating FileServer....")
        file_server = FileServer()
        site.connection_server = file_server
        file_server_thread = gevent.spawn(file_server.start, check_sites=False)  # Dont check every site integrity
        time.sleep(0.001)

        if not file_server_thread.ready():
            # Started fileserver
            file_server.openport()
            if peer_ip:  # Announce ip specificed
                site.addPeer(peer_ip, peer_port)
            else:  # Just ask the tracker
                logging.info("Gathering peers from tracker")
                site.announce()  # Gather peers
            published = site.publish(5, inner_path, diffs=diffs)  # Push to peers
            if published > 0:
                time.sleep(3)
                logging.info("Serving files (max 60s)...")
                gevent.joinall([file_server_thread], timeout=60)
                logging.info("Done.")
            else:
                logging.info("No peers found, sitePublish command only works if you already have visitors serving your site")
        else:
            # Already running, notify local client on new content
            logging.info("Sending siteReload")
            if config.fileserver_ip == "*":
                my_peer = Peer("127.0.0.1", config.fileserver_port)
            else:
                my_peer = Peer(config.fileserver_ip, config.fileserver_port)

            logging.info(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path}))
            logging.info("Sending sitePublish")
            logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs}))
            logging.info("Done.")
開發者ID:TheBojda,項目名稱:ZeroNet,代碼行數:48,代碼來源:main.py

示例3: sitePublish

# 需要導入模塊: from File import FileServer [as 別名]
# 或者: from File.FileServer import openport [as 別名]
	def sitePublish(self, address, peer_ip=None, peer_port=15441, inner_path="content.json"):
		global file_server
		from Site import Site
		from File import FileServer # We need fileserver to handle incoming file requests

		logging.info("Creating FileServer....")
		file_server = FileServer()
		file_server_thread = gevent.spawn(file_server.start, check_sites=False) # Dont check every site integrity
		file_server.openport()
		site = file_server.sites[address]
		site.settings["serving"] = True # Serving the site even if its disabled
		if peer_ip: # Announce ip specificed
			site.addPeer(peer_ip, peer_port)
		else: # Just ask the tracker
			logging.info("Gathering peers from tracker")
			site.announce() # Gather peers
		site.publish(20, inner_path) # Push to 20 peers
		time.sleep(3)
		logging.info("Serving files...")
		gevent.joinall([file_server_thread])
		logging.info("Done.")
開發者ID:simbam1,項目名稱:ZeroNet,代碼行數:23,代碼來源:main.py


注:本文中的File.FileServer.openport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。