-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdater.py
More file actions
74 lines (60 loc) · 2.28 KB
/
updater.py
File metadata and controls
74 lines (60 loc) · 2.28 KB
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
63
64
65
66
67
68
69
70
71
72
73
#easy tf2 mapper updater!!
import os
import requests
import zipfile
import shutil
import urllib.request
response = input("Are you sure you want to do this? (y/n):")
if response == "y" or response == "yes":
#location = input("Paste directory of updater here: ")
try:
#
#gets file info
#
url = 'http://github.com/baldengineers/easytf2_mapper/archive/master.zip'
site = urllib.request.urlopen(url)
meta = site.info()
size = meta["Content-Length"]
print("File size: ",size," bytes.")
#
#downloads zip
#
with open('easytf2mapper-master.zip', 'wb') as handle:
response = requests.get('http://github.com/baldengineers/easytf2_mapper/archive/master.zip', stream=True)
if not response.ok:
print('something went wrong getting the file.')
for i,block in enumerate(response.iter_content(1024)):
print("\n"*50+"%d/%d bytes downloaded (%d percent)" % (i*1024, int(size), (float((i*1024)/int(size))*100)))
handle.write(block)
print('downloading complete.')
#
#unpacks master zip
#
zipupdate = zipfile.ZipFile('easytf2mapper-master.zip', 'r')
for file in zipupdate.namelist():
if file.startswith('easytf2_mapper-master/latestwinredist'):
zipupdate.extract(file, 'updated/')
zipupdate.close()
print('done unpacking master zip')
#
#unpacks latest zip
#
ziplatest = zipfile.ZipFile('updated/easytf2_mapper-master/latestwinredist/easytf2mapper_latest.zip')
for file in ziplatest.namelist():
if file.startswith('updater.exe'):
pass
else:
ziplatest.extract(file)
ziplatest.close()
print('done unpacking latest zip')
#removes zip after it's done
os.remove('easytf2mapper-master.zip')
shutil.rmtree('updated/easytf2_mapper-master/')
#status
print("Update successful. You can find the updated version in the /updated directory.")
except Exception as e:
#status if errors
print('ERROR!\n',str(e))
#gives status
else:
print("Aborted.")