Report progress on GeoLite2 download
This commit is contained in:
parent
d50603f722
commit
ed965041e6
3 changed files with 15 additions and 9 deletions
|
@ -477,7 +477,7 @@ class UiWebsocketPlugin(object):
|
||||||
from util import helper
|
from util import helper
|
||||||
|
|
||||||
self.log.info("Downloading GeoLite2 City database...")
|
self.log.info("Downloading GeoLite2 City database...")
|
||||||
self.cmd("notification", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], 0])
|
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], 0])
|
||||||
db_urls = [
|
db_urls = [
|
||||||
"https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz",
|
"https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz",
|
||||||
"https://raw.githubusercontent.com/texnikru/GeoLite2-Database/master/GeoLite2-City.mmdb.gz"
|
"https://raw.githubusercontent.com/texnikru/GeoLite2-Database/master/GeoLite2-City.mmdb.gz"
|
||||||
|
@ -486,13 +486,18 @@ class UiWebsocketPlugin(object):
|
||||||
try:
|
try:
|
||||||
# Download
|
# Download
|
||||||
response = helper.httpRequest(db_url)
|
response = helper.httpRequest(db_url)
|
||||||
|
data_size = response.getheader('content-length')
|
||||||
|
data_recv = 0
|
||||||
data = StringIO.StringIO()
|
data = StringIO.StringIO()
|
||||||
while True:
|
while True:
|
||||||
buff = response.read(1024 * 512)
|
buff = response.read(1024 * 512)
|
||||||
if not buff:
|
if not buff:
|
||||||
break
|
break
|
||||||
data.write(buff)
|
data.write(buff)
|
||||||
|
data_recv += 1024 * 512
|
||||||
|
if data_size:
|
||||||
|
progress = int(float(data_recv) / int(data_size) * 100)
|
||||||
|
self.cmd("progress", ["geolite-info", _["Downloading GeoLite2 City database (one time only, ~20MB)..."], progress])
|
||||||
self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell())
|
self.log.info("GeoLite2 City database downloaded (%s bytes), unpacking..." % data.tell())
|
||||||
data.seek(0)
|
data.seek(0)
|
||||||
|
|
||||||
|
@ -500,16 +505,16 @@ class UiWebsocketPlugin(object):
|
||||||
with gzip.GzipFile(fileobj=data) as gzip_file:
|
with gzip.GzipFile(fileobj=data) as gzip_file:
|
||||||
shutil.copyfileobj(gzip_file, open(db_path, "wb"))
|
shutil.copyfileobj(gzip_file, open(db_path, "wb"))
|
||||||
|
|
||||||
self.cmd("notification", ["geolite-done", _["GeoLite2 City database downloaded!"], 5000])
|
self.cmd("progress", ["geolite-info", _["GeoLite2 City database downloaded!"], 100])
|
||||||
time.sleep(2) # Wait for notify animation
|
time.sleep(2) # Wait for notify animation
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.log.error("Error downloading %s: %s" % (db_url, err))
|
self.log.error("Error downloading %s: %s" % (db_url, err))
|
||||||
pass
|
pass
|
||||||
self.cmd("notification", [
|
self.cmd("progress", [
|
||||||
"geolite-error",
|
"geolite-info",
|
||||||
_["GeoLite2 City database download error: {}!<br>Please download manually and unpack to data dir:<br>{}"].format(err, db_urls[0]),
|
_["GeoLite2 City database download error: {}!<br>Please download manually and unpack to data dir:<br>{}"].format(err, db_urls[0]),
|
||||||
0
|
-100
|
||||||
])
|
])
|
||||||
|
|
||||||
def actionSidebarGetPeers(self, to):
|
def actionSidebarGetPeers(self, to):
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Notifications
|
||||||
|
|
||||||
|
|
||||||
add: (id, type, body, timeout=0) ->
|
add: (id, type, body, timeout=0) ->
|
||||||
id = id.replace /[^A-Za-z0-9]/g, ""
|
id = id.replace /[^A-Za-z0-9-]/g, ""
|
||||||
# Close notifications with same id
|
# Close notifications with same id
|
||||||
for elem in $(".notification-#{id}")
|
for elem in $(".notification-#{id}")
|
||||||
@close $(elem)
|
@close $(elem)
|
||||||
|
|
|
@ -711,7 +711,7 @@ jQuery.extend( jQuery.easing,
|
||||||
if (timeout == null) {
|
if (timeout == null) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
id = id.replace(/[^A-Za-z0-9]/g, "");
|
id = id.replace(/[^A-Za-z0-9-]/g, "");
|
||||||
ref = $(".notification-" + id);
|
ref = $(".notification-" + id);
|
||||||
for (i = 0, len = ref.length; i < len; i++) {
|
for (i = 0, len = ref.length; i < len; i++) {
|
||||||
elem = ref[i];
|
elem = ref[i];
|
||||||
|
@ -807,6 +807,7 @@ jQuery.extend( jQuery.easing,
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
/* ---- src/Ui/media/Wrapper.coffee ---- */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue