siteDownload command line action
This commit is contained in:
parent
54f9b49e90
commit
7cc408de4c
2 changed files with 34 additions and 4 deletions
|
@ -59,6 +59,10 @@ class Config(object):
|
||||||
action.add_argument('address', help='Site address')
|
action.add_argument('address', help='Site address')
|
||||||
action.add_argument('inner_path', help='File inner path')
|
action.add_argument('inner_path', help='File inner path')
|
||||||
|
|
||||||
|
# SiteDownload
|
||||||
|
action = self.subparsers.add_parser("siteDownload", help='Download a new site')
|
||||||
|
action.add_argument('address', help='Site address')
|
||||||
|
|
||||||
# SiteSign
|
# SiteSign
|
||||||
action = self.subparsers.add_parser("siteSign", help='Update and sign content.json: address [privatekey]')
|
action = self.subparsers.add_parser("siteSign", help='Update and sign content.json: address [privatekey]')
|
||||||
action.add_argument('address', help='Site to sign')
|
action.add_argument('address', help='Site to sign')
|
||||||
|
|
30
src/main.py
30
src/main.py
|
@ -235,8 +235,36 @@ class Actions(object):
|
||||||
print "Response time: %.3fs" % (time.time() - s)
|
print "Response time: %.3fs" % (time.time() - s)
|
||||||
print site.peers
|
print site.peers
|
||||||
|
|
||||||
|
def siteDownload(self, address):
|
||||||
|
from Site import Site
|
||||||
|
|
||||||
|
logging.info("Opening a simple connection server")
|
||||||
|
global file_server
|
||||||
|
from Connection import ConnectionServer
|
||||||
|
file_server = ConnectionServer("127.0.0.1", 1234)
|
||||||
|
|
||||||
|
site = Site(address)
|
||||||
|
|
||||||
|
on_completed = gevent.event.AsyncResult()
|
||||||
|
|
||||||
|
def onComplete(evt):
|
||||||
|
evt.set(True)
|
||||||
|
|
||||||
|
site.onComplete.once(lambda: onComplete(on_completed))
|
||||||
|
print "Announcing..."
|
||||||
|
site.announce()
|
||||||
|
|
||||||
|
s = time.time()
|
||||||
|
print "Downloading..."
|
||||||
|
site.downloadContent("content.json", check_modifications=True)
|
||||||
|
|
||||||
|
print on_completed.get()
|
||||||
|
print "Downloaded in %.3fs" % (time.time()-s)
|
||||||
|
|
||||||
|
|
||||||
def siteNeedFile(self, address, inner_path):
|
def siteNeedFile(self, address, inner_path):
|
||||||
from Site import Site
|
from Site import Site
|
||||||
|
|
||||||
def checker():
|
def checker():
|
||||||
while 1:
|
while 1:
|
||||||
s = time.time()
|
s = time.time()
|
||||||
|
@ -331,7 +359,6 @@ class Actions(object):
|
||||||
print "Response time: %.3fs (crypt: %s)" % (peer.ping(), peer.connection.crypt)
|
print "Response time: %.3fs (crypt: %s)" % (peer.ping(), peer.connection.crypt)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def peerGetFile(self, peer_ip, peer_port, site, filename, benchmark=False):
|
def peerGetFile(self, peer_ip, peer_port, site, filename, benchmark=False):
|
||||||
logging.info("Opening a simple connection server")
|
logging.info("Opening a simple connection server")
|
||||||
global file_server
|
global file_server
|
||||||
|
@ -352,7 +379,6 @@ class Actions(object):
|
||||||
else:
|
else:
|
||||||
print peer.getFile(site, filename).read()
|
print peer.getFile(site, filename).read()
|
||||||
|
|
||||||
|
|
||||||
def peerCmd(self, peer_ip, peer_port, cmd, parameters):
|
def peerCmd(self, peer_ip, peer_port, cmd, parameters):
|
||||||
logging.info("Opening a simple connection server")
|
logging.info("Opening a simple connection server")
|
||||||
global file_server
|
global file_server
|
||||||
|
|
Loading…
Reference in a new issue