forked from vergecurrency/verge-core-installers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverge_blockchain_download.py
62 lines (54 loc) · 2.29 KB
/
verge_blockchain_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# Copyright (C) 2017 Halim Burak Yesilyurt <[email protected]>
# If you like my work and tip me, my XVG address: DQWikNX6mE3pTM617C4A8PHvT3QKApQUdW
import urllib2, zipfile,os.path,distutils.dir_util,shutil
url = "http://e1.verge-electrum.com/Wallet_v3-v4.x_Verge-Blockchain_2018-January-8.zip"
file_name = "~/Desktop/verge_blockchain.zip"
dir_name = "~/Desktop/temp_verge/"
app_support_folder = "~/Library/Application Support/VERGE/"
'''
Function : downloadAndSaveVergeBlockchain
It retrives latest blockchain zip file from server and it saves blockchain zip file to user's desktop folder.
'''
def downloadAndSaveVergeBlockchain():
u = urllib2.urlopen(url)
f = open(os.path.expanduser(file_name), 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading VERGE blockchain: %s Bytes: %s" % (os.path.expanduser(file_name), file_size)
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()
'''
Function : unzipBlockchain
It unzips downloaded file into temp_verge folder, after that it removes blockhain zip file in order to save disk space.
'''
def unzipBlockchain():
zip_ref = zipfile.ZipFile(os.path.expanduser(file_name))
if not os.path.exists(os.path.expanduser(dir_name)):
os.makedirs(os.path.expanduser(dir_name))
os.chdir(os.path.expanduser(dir_name))
print "Verge Blockchain Zip File is Extracting..."
zip_ref.extractall(os.path.expanduser(dir_name))
zip_ref.close()
os.remove(os.path.expanduser(file_name))
'''
Function : copyFile2AppSupportFolder
It copies extracted blockchain folder into ~/Library/Application\ Support//VERGE/ folder as it is suggested on the verge blockchain web-site.
'''
def copyFile2AppSupportFolder():
distutils.dir_util.copy_tree(os.path.expanduser(dir_name), os.path.expanduser(app_support_folder))
print "Copying extracted file.."
shutil.rmtree(os.path.expanduser(dir_name))
downloadAndSaveVergeBlockchain()
unzipBlockchain()
copyFile2AppSupportFolder()